fix(priority): keep readable priority sync details

This commit is contained in:
liumangmang
2026-07-01 09:12:39 +08:00
parent fe40fcd4c9
commit d92537688a
6 changed files with 65 additions and 14 deletions
+9 -2
View File
@@ -619,6 +619,10 @@ def test_priority_sync_fetches_remote_accounts_and_backfills_info(db_session, mo
{"id": "A1", "name": "SmartUp-A1-Name", "priority": 15},
{"id": "A2", "name": "SmartUp-A2-Name", "priority": 25},
]
def get_groups(self, *args, **kwargs):
return [
{"id": "TG1", "name": "TG1-Readable-Group-Name"}
]
def update_account(self, account_id, data):
update_calls.append((account_id, data))
@@ -634,7 +638,7 @@ def test_priority_sync_fetches_remote_accounts_and_backfills_info(db_session, mo
assert res_a1["new_priority"] == 1
assert res_a1["source_rate"] == 1.0
assert res_a1["target_group_id"] == "TG1"
assert res_a1["target_group_name"] == "TG1" # fallback to tg_id since target_group_name is not set
assert res_a1["target_group_name"] == "TG1-Readable-Group-Name"
res_a2 = next(r for r in results if r["account_id"] == "A2")
assert res_a2["account_name"] == "SmartUp-A2-Name"
@@ -642,6 +646,10 @@ def test_priority_sync_fetches_remote_accounts_and_backfills_info(db_session, mo
assert res_a2["new_priority"] == 11
assert res_a2["source_rate"] == 2.0
# 验证本地 DB 中行的 imported_target_group_name 被正确更新写入
row1 = db_session.query(UpstreamGeneratedKey).filter_by(imported_account_id="A1").first()
assert row1.imported_target_group_name == "TG1-Readable-Group-Name"
def test_priority_sync_graceful_on_remote_list_failure(db_session, monkeypatch):
"""验证 list_accounts 抛异常时,优先级同步依然成功更新,且各项降级为账号 ID 和未知。"""
@@ -677,4 +685,3 @@ def test_priority_sync_graceful_on_remote_list_failure(db_session, monkeypatch):
assert res_a1["old_priority"] is None
assert res_a1["new_priority"] == 1
assert res_a1["status"] == "success"