package api
import "testing"
// A pipeline run three times is one check: its newest run. The panel
// listed all three and counted each failure; the accept gate counted
// the oldest pass beside a newer failure.
func TestNewestRunsKeepsOneRunPerPipeline(t *testing.T) {
runs := []CIRun{
{RunID: "a", Workflow: "quarry", Pipeline: "ci/quarry.json", Status: "completed", Started: "2026-10-14T00:12:00Z"},
{RunID: "b", Workflow: "race", Pipeline: "ci/race.json", Status: "completed", Started: "2026-10-14T00:12:01Z"},
{RunID: "c", Workflow: "quarry", Pipeline: "ci/quarry.json", Status: "failed", Started: "2026-10-14T00:43:00Z"},
{RunID: "d", Workflow: "quarry", Pipeline: "ci/quarry.json", Status: "failed", Started: "2026-10-14T00:27:00Z"},
}
got := newestRuns(runs)
if len(got) != 2 {
t.Fatalf("FAIL: %d rows, want one per pipeline: %+v", len(got), got)
}
ids := map[string]bool{}
for _, r := range got {
ids[r.RunID] = true
}
if !ids["c"] || !ids["b"] {
t.Errorf("FAIL: kept %v, want the newest quarry run (c) and the race run (b)", ids)
}
}