修复(账号自动化): 租约 CK 续期不再冒充「首次登录」,补齐等待预算
排查「首次登录都关掉了为什么还在一直登录」时发现: - 真正在跑登录的是 lease_ck_refresh(租约 CK 续期,每 600 秒一轮), account_onboarding 确实已关;两者都显示成「自动化·首次登录」,所以很难分辨 - 根因是分类逻辑:trigger_source=automation 一律落 onboarding。但租约续期的 账号本来就有 CK,只是租约到期前提前续一次,不是首次登录 - 这批租约账号全部「等待验证码超时」失败,因为生产跑的还是旧镜像(60 秒 等待窗口),而且 lease_ck_refresh 的单账号总时长硬编码 240 秒,连新的 900 秒等待窗口都会被掐断 改动: - 新增 lease_refresh 分类:页面显示「自动化·租约CK续期」,日预算归到普通 重登(不再占用「首次登录」的 150/天额度) - lease_ck_refresh 单账号总时长 240 → 1800 秒,覆盖实测 8~13 分钟的投递延迟 - 登录预算建议的成功率样本纳入 lease_refresh 验证:1728 passed / 6 skipped,前端 tsc -b 通过,pyright 生产代码 0 错误
This commit is contained in:
@@ -37,7 +37,9 @@ from web.backend.services.automation.jobs import ck_health
|
||||
from web.backend.services.douyu_account_state import DouyuLiveAccountState
|
||||
from web.backend.services.douyu_read_gateway import StorehomeSnapshot
|
||||
from web.backend.services.login_quota_service import (
|
||||
CATEGORY_LEASE_REFRESH,
|
||||
CATEGORY_MANUAL,
|
||||
classify_login_category,
|
||||
finish_login_attempt,
|
||||
reserve_login_attempt,
|
||||
)
|
||||
@@ -354,6 +356,54 @@ def test_missing_storehome_goods_blocks_fulfillment_as_off_shelf():
|
||||
assert gate[:2] == ("not_available", "commodity_not_offered")
|
||||
|
||||
|
||||
def test_lease_refresh_category_overrides_onboarding(db):
|
||||
"""租约 CK 续期不能被判成「首次登录」。
|
||||
|
||||
这类账号**有 CK**,只是租约到期前提前续一次。以前 trigger_source=automation
|
||||
一律落 onboarding,页面显示成「自动化·首次登录」,还把租约续期的量算进
|
||||
「首次登录」的日预算里 —— 排查时极难看出是谁在发起登录。
|
||||
"""
|
||||
account = _account("lease-category")
|
||||
db.add(account)
|
||||
db.add(
|
||||
LoginQuotaSetting(
|
||||
id=1,
|
||||
daily_attempt_limit=20,
|
||||
hourly_attempt_limit=10,
|
||||
per_account_daily_limit=2,
|
||||
onboarding_daily_limit=1,
|
||||
relogin_ordinary_daily_limit=10,
|
||||
manual_daily_limit=10,
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
now = datetime.now(UTC).replace(microsecond=0)
|
||||
|
||||
assert (
|
||||
classify_login_category(
|
||||
account,
|
||||
mode="login",
|
||||
trigger_source="automation",
|
||||
category=CATEGORY_LEASE_REFRESH,
|
||||
)
|
||||
== CATEGORY_LEASE_REFRESH
|
||||
)
|
||||
|
||||
decision = reserve_login_attempt(
|
||||
db,
|
||||
account=account,
|
||||
mode="login",
|
||||
trigger_source="automation",
|
||||
batch_id="lease-batch",
|
||||
created_by=None,
|
||||
now=now,
|
||||
category=CATEGORY_LEASE_REFRESH,
|
||||
)
|
||||
assert decision.allowed
|
||||
assert decision.attempt is not None
|
||||
assert decision.attempt.category == CATEGORY_LEASE_REFRESH
|
||||
|
||||
|
||||
def test_login_quota_enforces_per_account_and_hourly_budget(db):
|
||||
first = _account("quota-first")
|
||||
second = _account("quota-second")
|
||||
|
||||
Reference in New Issue
Block a user