优化(账号自动化): 受保护账号极验重登允许按上限重试
This commit is contained in:
@@ -22,6 +22,7 @@ from datetime import UTC, datetime, timedelta
|
||||
from tests.support.db import get_test_engine, make_test_session
|
||||
from web.backend.models import (
|
||||
Account,
|
||||
AccountLease,
|
||||
AccountWorkItem,
|
||||
AutomationJob,
|
||||
LoginAttempt,
|
||||
@@ -92,6 +93,21 @@ class _Base:
|
||||
self.session.commit()
|
||||
return account
|
||||
|
||||
def protect(self, account):
|
||||
now = datetime.now(UTC)
|
||||
self.session.add(
|
||||
AccountLease(
|
||||
account_id=account.id,
|
||||
holder_user_id=self.admin.id,
|
||||
scope="elite",
|
||||
purpose="platform_fulfillment",
|
||||
status="active",
|
||||
leased_at=now,
|
||||
)
|
||||
)
|
||||
self.session.commit()
|
||||
return account
|
||||
|
||||
def make_attempt(
|
||||
self,
|
||||
account,
|
||||
@@ -450,6 +466,64 @@ class TestSelection(_Base):
|
||||
self.make_account("credential", relogin_failure_kind="credential")
|
||||
assert self._ids(job) == [keep.id]
|
||||
|
||||
def test_protected_captcha_retries_until_attempt_cap(self):
|
||||
job = self.job()
|
||||
retryable = self.protect(
|
||||
self.make_account("protected-captcha", relogin_failure_kind="captcha")
|
||||
)
|
||||
exhausted = self.protect(
|
||||
self.make_account(
|
||||
"protected-exhausted",
|
||||
relogin_attempts=2,
|
||||
relogin_failure_kind="captcha",
|
||||
)
|
||||
)
|
||||
self.make_account(
|
||||
"ordinary-captcha",
|
||||
relogin_failure_kind="captcha",
|
||||
)
|
||||
|
||||
ids = self._ids(job)
|
||||
|
||||
assert retryable.id in ids
|
||||
assert exhausted.id not in ids
|
||||
|
||||
def test_protected_captcha_work_item_is_claimable(self):
|
||||
job = self.job()
|
||||
protected = self.protect(
|
||||
self.make_account("protected-captcha", relogin_failure_kind="captcha")
|
||||
)
|
||||
ordinary = self.make_account("ordinary", relogin_failure_kind="")
|
||||
now = datetime.now(UTC)
|
||||
protected_work = enqueue_account_work(
|
||||
self.session,
|
||||
account_id=protected.id,
|
||||
work_type=ck_relogin.WORK_LOGIN_RELOGIN,
|
||||
priority=10,
|
||||
due_at=now - timedelta(hours=1),
|
||||
max_attempts=20,
|
||||
)
|
||||
enqueue_account_work(
|
||||
self.session,
|
||||
account_id=ordinary.id,
|
||||
work_type=ck_relogin.WORK_LOGIN_RELOGIN,
|
||||
priority=30,
|
||||
due_at=now - timedelta(hours=2),
|
||||
max_attempts=20,
|
||||
)
|
||||
self.session.commit()
|
||||
|
||||
claimed = ck_relogin._claim_relogin_work(
|
||||
self.session,
|
||||
job,
|
||||
now,
|
||||
max_attempts=2,
|
||||
protection=load_protection_snapshot(self.session),
|
||||
limit=1,
|
||||
)
|
||||
|
||||
assert [item.id for item in claimed] == [protected_work.id]
|
||||
|
||||
def test_retryable_kinds_stay_eligible(self):
|
||||
job = self.job()
|
||||
code = self.make_account("code", relogin_failure_kind="email_code")
|
||||
@@ -635,6 +709,32 @@ class TestSettlement(_Base):
|
||||
assert account.relogin_failure_kind == "captcha"
|
||||
assert account.relogin_next_at is None # 不再自动排期
|
||||
|
||||
def test_protected_captcha_retries_once_then_goes_manual(self):
|
||||
account = self.protect(self.make_account("protected-cap"))
|
||||
first_task = self.make_attempt(
|
||||
account,
|
||||
attempt_status="failed",
|
||||
attempt_message="极验验证失败: slide",
|
||||
)
|
||||
first, _ = self._settle([(account, first_task)], max_attempts=2)
|
||||
self.session.refresh(account)
|
||||
|
||||
assert first["retry"] == 1 and first["manual"] == 0
|
||||
assert account.relogin_attempts == 1
|
||||
assert account.relogin_next_at is not None
|
||||
|
||||
second_task = self.make_attempt(
|
||||
account,
|
||||
attempt_status="failed",
|
||||
attempt_message="极验验证失败: slide",
|
||||
)
|
||||
second, _ = self._settle([(account, second_task)], max_attempts=2)
|
||||
self.session.refresh(account)
|
||||
|
||||
assert second["retry"] == 0 and second["manual"] == 1
|
||||
assert account.relogin_attempts == 2
|
||||
assert account.relogin_next_at is None
|
||||
|
||||
def test_quota_backs_off_to_next_day(self):
|
||||
account = self.make_account("quota")
|
||||
task = self.make_attempt(
|
||||
|
||||
Reference in New Issue
Block a user