fix(system): sort recent tasks by finished_at desc
「最近任务」原先按 kv 键名排序;改为按 finished_at 倒序, 缺完成时间的排末尾。前端渲染侧同步按 finished_at 排序兜底。
This commit is contained in:
1 parent
8e7ead1669
commit
e7b48ba5d9
3 files changed
+70
-5
No files matched your search
@@ -681,6 +681,48 @@ def test_overview_adjacent_previous_with_seed_and_dual_fields():
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def test_system_tasks_sorted_by_finished_at_desc():
|
||||
"""最近任务按 finished_at 倒序;缺时间的排末尾。"""
|
||||
import json
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
db, q = setup(tmp)
|
||||
try:
|
||||
repo = Repository(db)
|
||||
# 故意打乱写入/键名字母序,避免 ORDER BY k 碰巧正确
|
||||
samples = (
|
||||
("zzz_old", FIXED_NOW - 300),
|
||||
("aaa_mid", FIXED_NOW - 100),
|
||||
("mmm_new", FIXED_NOW - 10),
|
||||
("no_time", None),
|
||||
)
|
||||
for name, finished in samples:
|
||||
payload = {
|
||||
"name": name,
|
||||
"ok": True,
|
||||
"started_at": (finished - 5) if finished is not None else FIXED_NOW,
|
||||
"error": None,
|
||||
"summary": {},
|
||||
}
|
||||
if finished is not None:
|
||||
payload["finished_at"] = finished
|
||||
repo.kv_set(f"task:last:{name}", json.dumps(payload))
|
||||
# 清掉 fixture 里的旧任务,只保留本用例
|
||||
for legacy in ("snapshot", "fans", "discovery"):
|
||||
repo.kv_delete(f"task:last:{legacy}")
|
||||
DASHBOARD_CACHE.clear()
|
||||
system = q.system()
|
||||
assert list(system["tasks"].keys()) == [
|
||||
"mmm_new", "aaa_mid", "zzz_old", "no_time",
|
||||
]
|
||||
overview = q.overview()
|
||||
# overview 也走 _task_records,顺序应一致
|
||||
assert list(overview["tasks"].keys()) == list(system["tasks"].keys())
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def main_test():
|
||||
test_overview()
|
||||
test_video_listing_filters_and_sorting()
|
||||
@@ -696,6 +738,7 @@ def main_test():
|
||||
test_fans_candidates_system_and_export()
|
||||
test_system_status_uses_completed_date_and_running_flags()
|
||||
test_system_next_runs_follow_last_completion_not_wall_clock()
|
||||
test_system_tasks_sorted_by_finished_at_desc()
|
||||
test_growth_auto_falls_back_to_one_day()
|
||||
test_snapshot_recent_next_run_follows_completion()
|
||||
test_overview_adjacent_previous_with_seed_and_dual_fields()
|
||||
|
||||
Reference in new issue
Block a user