feat(automation): 巡检和重登优先保住高价值账号的 CK
价值按套装和积分现算,不看标签。第 1、2 档 6 小时巡检一次,并先占重登名额。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1777,11 +1777,21 @@ class TestHighValueAccountFilters:
|
||||
assert set(names) == {"acc_crown", "acc_mengtu_owned", "acc_broken"}
|
||||
|
||||
def test_high_value_broken_filter(self):
|
||||
# 高价值但 CK 异常待抢救
|
||||
# 高价值但 CK 异常待抢救:两套都能换、只剩一套、或积分≥300
|
||||
items = self._query(high_value_filter="high_value_broken")
|
||||
names = [it.username for it in items]
|
||||
assert names == ["acc_broken"]
|
||||
|
||||
self.acc_bairimeng_owned.ck_check_status = "invalid"
|
||||
self.acc_both_owned.ck_check_status = "invalid"
|
||||
self.session.commit()
|
||||
names = [
|
||||
it.username for it in self._query(high_value_filter="high_value_broken")
|
||||
]
|
||||
assert "acc_bairimeng_owned" in names
|
||||
assert "acc_broken" in names
|
||||
assert "acc_both_owned" not in names
|
||||
|
||||
def test_summary_returns_high_value_breakdown(self):
|
||||
from web.backend.routers.accounts import accounts_summary
|
||||
|
||||
|
||||
@@ -84,6 +84,24 @@ class TestSelection(_Base):
|
||||
self.account("ovr-never")
|
||||
assert self.selected()[0].username == "ovr-never"
|
||||
|
||||
def test_assigned_and_recent_login_lead_within_the_same_group(self):
|
||||
"""没查过的仍整体优先;同一档里已分配的在前,再按最近登录。"""
|
||||
stale = self.account("ovr-stale-assigned", queried_days_ago=30)
|
||||
stale.assigned_to = self.admin.id
|
||||
recent = self.account("ovr-recent")
|
||||
recent.cookie_updated_at = datetime.now(UTC)
|
||||
older = self.account("ovr-older")
|
||||
older.cookie_updated_at = datetime.now(UTC) - timedelta(days=10)
|
||||
assigned = self.account("ovr-assigned")
|
||||
assigned.assigned_to = self.admin.id
|
||||
assigned.cookie_updated_at = datetime.now(UTC) - timedelta(days=1)
|
||||
self.session.commit()
|
||||
|
||||
names = [a.username for a in self.selected()]
|
||||
assert names.index("ovr-assigned") < names.index("ovr-recent")
|
||||
assert names.index("ovr-recent") < names.index("ovr-older")
|
||||
assert names.index("ovr-older") < names.index("ovr-stale-assigned")
|
||||
|
||||
def test_recently_queried_is_skipped(self):
|
||||
"""刚查过的要跳过(`refresh_days` 之内不再查)。"""
|
||||
self.account("ovr-fresh", queried_days_ago=1)
|
||||
|
||||
@@ -184,6 +184,29 @@ class TestCkHealthSelection(_Base):
|
||||
assert ids[0] == never.id
|
||||
assert stale.id in ids
|
||||
|
||||
def test_high_value_is_rechecked_sooner_and_sorted_first(self):
|
||||
"""第 1、2 档 6 小时一查,并且到点后排在普通账号前面。"""
|
||||
job = self._job()
|
||||
job.interval_seconds = 24 * 3600
|
||||
now = datetime.now(UTC)
|
||||
plain_recent = self.make_account(
|
||||
"plain-recent", ck_checked_at=now - timedelta(hours=7)
|
||||
)
|
||||
plain_old = self.make_account(
|
||||
"plain-old", ck_checked_at=now - timedelta(hours=30)
|
||||
)
|
||||
valuable = self.make_account("valuable", ck_checked_at=now - timedelta(hours=7))
|
||||
valuable.overview_queried_at = now
|
||||
valuable.high_value_owned = []
|
||||
valuable.points = 800
|
||||
self.session.commit()
|
||||
|
||||
ids = self._selected_ids(job)
|
||||
assert valuable.id in ids
|
||||
assert plain_recent.id not in ids
|
||||
assert plain_old.id in ids
|
||||
assert ids.index(valuable.id) < ids.index(plain_old.id)
|
||||
|
||||
def test_generated_sql_is_mysql_compatible(self):
|
||||
"""回归:选行 SQL 不能出现 MySQL 不认识的 NULLS FIRST。
|
||||
|
||||
|
||||
@@ -259,6 +259,21 @@ class TestSelection(_Base):
|
||||
self.make_account(f"a{index}")
|
||||
assert len(self._ids(job)) == 3
|
||||
|
||||
def test_high_value_is_picked_before_plain(self):
|
||||
"""名额先给第 1 档,其次第 2 档,普通失效号排最后。"""
|
||||
job = self.job(batch_size=3)
|
||||
plain = self.make_account("plain")
|
||||
one_suit = self.make_account("one-suit")
|
||||
one_suit.overview_queried_at = datetime.now(UTC)
|
||||
one_suit.high_value_owned = ["套装-兔兔白日梦"]
|
||||
both = self.make_account("both")
|
||||
both.overview_queried_at = datetime.now(UTC)
|
||||
both.high_value_owned = []
|
||||
self.session.commit()
|
||||
|
||||
ids = self._ids(job)
|
||||
assert ids == [both.id, one_suit.id, plain.id]
|
||||
|
||||
|
||||
class TestSettlement(_Base):
|
||||
"""结算:成功清零;失败按分型决定重试还是转人工。
|
||||
|
||||
Reference in New Issue
Block a user