fix(douyu): 补全账号能力目录并回收失效租约

This commit is contained in:
yml
2026-11-22 20:36:40 +08:00
parent 1906f924bc
commit af05c54c3f
18 changed files with 839 additions and 121 deletions
+74
View File
@@ -295,6 +295,80 @@ def test_supply_shortage_enqueues_missing_coverage(db):
assert work.priority == 35
def test_supply_shortage_does_not_reselect_account_with_active_sync(db):
first = _account("supply-active-work", points=400)
second = _account("supply-next-work", points=400)
db.add_all([first, second])
db.flush()
enqueue_account_work(
db,
account_id=first.id,
work_type="storehome_sync",
priority=10,
due_at=NOW,
)
db.add(
AccountSupplyTarget(
platform="douyu",
scope="elite",
commodity_id="C",
value_class=VALUE_HIGH,
target_covered=1,
target_available=1,
target_allocatable=1,
)
)
db.commit()
result = enqueue_supply_replenishment(db, now=NOW, max_per_target=10)
queued = (
db.query(AccountWorkItem)
.filter(AccountWorkItem.work_type == "storehome_sync")
.order_by(AccountWorkItem.account_id.asc())
.all()
)
assert result.queued == 1
assert [row.account_id for row in queued] == [first.id, second.id]
def test_supply_replenishment_respects_sync_queue_target(db, monkeypatch):
monkeypatch.setenv("ACCOUNT_SYNC_QUEUE_TARGET_PENDING", "1")
queued_account = _account("supply-queue-full", points=400)
missing = _account("supply-wait-next-round", points=400)
db.add_all([queued_account, missing])
db.flush()
enqueue_account_work(
db,
account_id=queued_account.id,
work_type="storehome_sync",
priority=10,
due_at=NOW,
)
db.add(
AccountSupplyTarget(
platform="douyu",
scope="elite",
commodity_id="C",
value_class=VALUE_HIGH,
target_covered=1,
target_available=1,
target_allocatable=1,
)
)
db.commit()
result = enqueue_supply_replenishment(db, now=NOW, max_per_target=10)
assert result.queued == 0
assert (
db.query(AccountWorkItem)
.filter(AccountWorkItem.work_type == "storehome_sync")
.count()
== 1
)
def test_supply_target_configuration_is_idempotent(db):
first = upsert_supply_target(
db,