@@ -2546,6 +2546,7 @@ def test_login_success_sets_httponly_cookie(tmp_path):
25462546 json = {"username" : "root" , "password" : "rootpw" })
25472547 assert response .status_code == 200
25482548 assert response .json () == {"username" : "root" , "is_admin" : True ,
2549+ "is_operator" : True ,
25492550 "role" : "admin" , "must_change_password" : False }
25502551 cookie = response .headers ["set-cookie" ]
25512552 assert "httponly" in cookie .lower () and "samesite=lax" in cookie .lower ()
@@ -2649,6 +2650,7 @@ def test_credentials_endpoint_exposes_admin_flag(tmp_path):
26492650 client .post ("/api/auth/login" , json = {"username" : "guest" , "password" : "guestpw" })
26502651 body = client .get ("/api/credentials" ).json ()
26512652 assert body ["viewer" ] == "guest" and body ["is_admin" ] is False
2653+ assert body ["is_operator" ] is False
26522654
26532655
26542656def test_credentials_endpoint_exposes_expiring_credits (tmp_path ):
@@ -3963,6 +3965,23 @@ def test_retention_task_purges_expired_model_cooldowns(repo):
39633965 assert RetentionTask (collector ).run_once ()["expired_coolings" ] == 0
39643966
39653967
3968+ def test_retention_task_prunes_audit_events (repo ):
3969+ """留存任务按保留期回收审计流水;未注入时计数为 0(README「审计保留 90 天」)。"""
3970+ from src .db .repo import AuditRepository
3971+
3972+ _credentials , db = repo
3973+ audit = AuditRepository (db )
3974+ # 两条都远在过去;retention_days=0 → cutoff=当前时刻,两条都 < cutoff 即被删
3975+ audit .record (actor = "root" , action = "login.success" , now = 100 )
3976+ audit .record (actor = "root" , action = "login.failure" , now = 200 )
3977+ collector = StatsCollector (db )
3978+ report = RetentionTask (collector , retention_days = 0 , audit = audit ).run_once ()
3979+ assert report ["purged_audit" ] == 2
3980+ assert audit .query () == []
3981+ # 不传 audit(旧调用方)时不报错,计数为 0
3982+ assert RetentionTask (collector ).run_once ()["purged_audit" ] == 0
3983+
3984+
39663985def test_list_all_exposes_model_cooldowns (tmp_path ):
39673986 """管理台列表带出生效中的模型冷却(过期行不下发)。"""
39683987 from src .engine .scheduler import ModelCooldown
0 commit comments