fix(supply): 有效 CK 即可用并修复自动化页空注册表
- 供给覆盖/候选取消 24h CK 新鲜度硬门槛,有效 CK 直接可用 - Web/API 进程登记作业注册表,修复作业配置/运行记录空白 - 补充有效 CK、空注册表回归测试 - 文档记录 CK 获取/首次登录缺口
This commit is contained in:
@@ -887,3 +887,54 @@ def test_supply_replenishment_skips_allocatable_only_shortage(db):
|
||||
assert result.capacity_shortages == 1
|
||||
assert result.queued == 0
|
||||
assert db.query(AccountWorkItem).count() == 0
|
||||
|
||||
|
||||
def test_valid_ck_older_than_24h_counts_in_supply_coverage(db):
|
||||
account = _account("supply-old-valid-covered", points=400)
|
||||
account.ck_checked_at = NOW - timedelta(days=3)
|
||||
db.add(account)
|
||||
db.flush()
|
||||
db.add_all(
|
||||
[
|
||||
_state(account),
|
||||
AccountSupplyTarget(
|
||||
platform="douyu",
|
||||
scope="elite",
|
||||
commodity_id="C",
|
||||
value_class=VALUE_HIGH,
|
||||
target_covered=1,
|
||||
target_available=1,
|
||||
target_allocatable=0,
|
||||
),
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
target = db.query(AccountSupplyTarget).one()
|
||||
|
||||
inventory = evaluate_supply_target(db, target, now=NOW)
|
||||
|
||||
assert inventory.covered == 1
|
||||
assert inventory.available == 1
|
||||
|
||||
|
||||
def test_valid_ck_older_than_24h_is_still_a_sync_candidate(db):
|
||||
account = _account("supply-old-valid-candidate", points=400)
|
||||
account.ck_checked_at = NOW - timedelta(days=3)
|
||||
db.add(account)
|
||||
db.flush()
|
||||
db.add(
|
||||
AccountSupplyTarget(
|
||||
platform="douyu",
|
||||
scope="elite",
|
||||
commodity_id="C",
|
||||
value_class=VALUE_HIGH,
|
||||
target_covered=1,
|
||||
target_available=1,
|
||||
target_allocatable=0,
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
result = enqueue_supply_replenishment(db, now=NOW, max_per_target=10)
|
||||
|
||||
assert result.queued == 1
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
"""自动化 API 在独立后台进程模式下不能因为空注册表返回空白页。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from web.backend.models import AutomationRun, User
|
||||
from web.backend.routers import automation as automation_router
|
||||
from web.backend.services.automation import reset_registry
|
||||
|
||||
|
||||
def _admin(db) -> User:
|
||||
user = User(
|
||||
username="automation-registry-admin",
|
||||
password_hash="h",
|
||||
role="super_admin",
|
||||
is_active=True,
|
||||
)
|
||||
db.add(user)
|
||||
db.commit()
|
||||
return user
|
||||
|
||||
|
||||
def test_list_jobs_registers_default_jobs_when_api_process_registry_is_empty(db):
|
||||
reset_registry()
|
||||
admin = _admin(db)
|
||||
|
||||
result = automation_router.list_jobs(db=db, current=admin)
|
||||
|
||||
keys = {job["key"] for job in result["jobs"]}
|
||||
assert "account_sync_queue" in keys
|
||||
assert "account_supply_replenishment" in keys
|
||||
assert result["scheduler"]["enabled"] is not None
|
||||
|
||||
|
||||
def test_list_runs_registers_default_jobs_when_api_process_registry_is_empty(db):
|
||||
reset_registry()
|
||||
admin = _admin(db)
|
||||
db.add(
|
||||
AutomationRun(
|
||||
job_key="account_sync_queue",
|
||||
status="success",
|
||||
message="test",
|
||||
started_at=datetime.now(UTC),
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
result = automation_router.list_runs(job_key=None, limit=10, db=db, current=admin)
|
||||
|
||||
assert any(item["job_key"] == "account_sync_queue" for item in result["items"])
|
||||
Reference in New Issue
Block a user