fix(reconciliation): R6 改用 removal_candidates 视图,定时批每日只占一个名额
build / build (push) Successful in 2m28s
build / build (push) Successful in 2m28s
白盒补充复核提出的三项: - P1 R6 与 /monitor/overview「需下架」计数口径不一致:R6 原先只在扫描结果里存在 且上游 parse_status=completed 时才生成,上游仍在 processing/finalizing 或单条读取 失败导致扫描缺行时,总览有数、对账无记录(陷阱 15)。改为直接由 removal_candidates 视图行生成,台账细节按 publication 回填,计数与总览同一来源;补单测覆盖 「上游 processing」「扫描未见」两种差异。 - P2 定时批失败后每个 tick 都重建:每日占位只排除 running/succeeded,failed 不占位, 一次失败当天会每分钟刷批。占位条件加入 failed,重跑改为显式手动触发;补 PG 集成用例。 - P2 队列不可用时前端显示 0 等待 · 0 运行:改为按 available 判定并显示不可用文案; 补组件用例。
This commit is contained in:
@@ -72,3 +72,43 @@ func TestReconciliationRunUniquenessStaleAndRetentionIntegration(t *testing.T) {
|
||||
t.Fatalf("new findings=%d err=%v", count, err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestScheduledReconciliationClaimsOncePerDayAfterFailure freezes the operator
|
||||
// expectation "每天最多一批": a failed scheduled batch keeps the day's slot so a
|
||||
// transient upstream error cannot spawn a new batch on every scheduler tick.
|
||||
// A retry after a failure is an explicit manual trigger.
|
||||
func TestScheduledReconciliationClaimsOncePerDayAfterFailure(t *testing.T) {
|
||||
url := isolatedIntegrationDatabaseURL(t, os.Getenv("TEST_DATABASE_URL"))
|
||||
if url == "" {
|
||||
t.Skip("TEST_DATABASE_URL is not set")
|
||||
}
|
||||
ctx := context.Background()
|
||||
pool, err := pgxpool.New(ctx, url)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer pool.Close()
|
||||
if err := ApplyMigrations(ctx, pool); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store := NewStore(pool)
|
||||
dayStart := time.Date(2026, 12, 1, 0, 0, 0, 0, time.UTC)
|
||||
run := func(id string, started time.Time) governance.ReconciliationRun {
|
||||
return governance.ReconciliationRun{ID: id, KBID: "kb-sched", State: "running", Trigger: "schedule",
|
||||
StartedAt: started, Counts: governance.ReconciliationCounts{}}
|
||||
}
|
||||
first, claimed, err := store.ClaimScheduledReconciliationRun(ctx, run("sched-1", dayStart.Add(2*time.Hour)), dayStart, dayStart.Add(2*time.Hour))
|
||||
if err != nil || !claimed {
|
||||
t.Fatalf("first claim claimed=%t err=%v", claimed, err)
|
||||
}
|
||||
if err := store.FailReconciliationRun(ctx, first.ID, "remote_scan_failed", dayStart.Add(2*time.Minute)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, claimed, err := store.ClaimScheduledReconciliationRun(ctx, run("sched-2", dayStart.Add(3*time.Minute)), dayStart, dayStart.Add(3*time.Minute)); err != nil || claimed {
|
||||
t.Fatalf("same-day reclaim after failure claimed=%t err=%v", claimed, err)
|
||||
}
|
||||
nextDay := dayStart.Add(24 * time.Hour)
|
||||
if _, claimed, err := store.ClaimScheduledReconciliationRun(ctx, run("sched-3", nextDay.Add(2*time.Hour)), nextDay, nextDay.Add(2*time.Hour)); err != nil || !claimed {
|
||||
t.Fatalf("next-day claim claimed=%t err=%v", claimed, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ func (s *Store) ClaimScheduledReconciliationRun(ctx context.Context, run governa
|
||||
SELECT $1,$2,'running','schedule',$3,$4::jsonb,$5
|
||||
WHERE NOT EXISTS(
|
||||
SELECT 1 FROM reconciliation_runs
|
||||
WHERE test_kb_id=$2 AND trigger='schedule' AND state IN ('running','succeeded') AND started_at >= $6
|
||||
WHERE test_kb_id=$2 AND trigger='schedule' AND state IN ('running','succeeded','failed') AND started_at >= $6
|
||||
)
|
||||
ON CONFLICT DO NOTHING
|
||||
RETURNING `+reconciliationRunColumns,
|
||||
|
||||
Reference in New Issue
Block a user