import { useScenarioHistory } from "../interactive/scenario-history-context"; import { describeRunHistory, flakinessOf, type ScenarioRunEvent, type ScenarioRunStatus } from "../lib/run-history"; import { Badge } from "@/components/ui/badge"; import { cn } from "@/lib/utils"; /** How many trailing runs the strip shows; older entries stay in the tooltip count. */ const MAX_DOTS = 10; const DOT_COLOR: Record = { passed: "bg-pass", failed: "bg-fail", skipped: "bg-skip", pending: "bg-pend", }; function dotTitle(e: ScenarioRunEvent): string { const parts = [new Date(e.timestamp).toLocaleString(), e.status]; if (e.commitSha) parts.push(e.commitSha.slice(0, 8)); return parts.join(" · "); } /** * Compact run-over-run timeline for one scenario: a dot per recent run, * oldest → newest. Renders nothing outside or when the * report was generated without --history-file — history is presentation-layer * data and never part of the StoryReport contract. */ export function ScenarioRunHistory({ scenarioId }: { scenarioId: string }) { const history = useScenarioHistory(); const entries = history?.[scenarioId]; if (!entries || entries.length < 2) return null; // one run = no timeline yet const recent = entries.slice(-MAX_DOTS); // Judge flakiness on the same window the dots show, so the badge never // contradicts the strip next to it. const flaky = flakinessOf(recent) === "flaky"; const summary = flaky ? `${describeRunHistory(recent)} · Flaky` : describeRunHistory(recent); return ( <> {flaky ? ( Flaky ) : null} {recent.map((e, i) => ( ))} ); }