Skip to content
quarry Artifact [7cb92113c4]
Login

Artifact [7cb92113c4]

Artifact 7cb92113c419dabac74dd8f6004bef04d6aa4d3e83bcaca3a1aa7c6fa71b017b:


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)
	}
}