Fork Horse repository, listed by its owner. Publisher snapshot.

packages/forkhorse-dashboard/test/archive-fixtures.ts

Snapshot at 34e3175

Containing directory

4,315 bytes · typescriptView raw
1import type { StateResponse } from "../src/contracts.ts";
2import type { RaceFixture } from "./race-fixtures.ts";
3import { reviewFixtureState } from "./review-fixtures.ts";
4
5/** FH-050/052 contract fixtures. Never evidence of core, Cloudflare or owner acceptance. */
6export const archiveScenarios = [
7  "archive-ready",
8  "archive-list",
9  "archive-claim",
10  "archive-race",
11  "archive-finished-race",
12  "archive-review",
13  "archive-main-moved",
14  "archive-blocker",
15  "archive-conflict",
16  "archive-missing",
17  "archive-error",
18];
19export function archiveFixtureState(id = "archive-ready"): StateResponse {
20  const state = reviewFixtureState("review-promoted");
21  state.project.id = id;
22  state.claims = [];
23  state.races = [];
24  state.activity = [];
25  state.reconcilerAlerts = [];
26  state.packets[0].archived = null;
27  state.packets.push({
28    id: "FH-READY",
29    title: "Next packet",
30    goal: "Keep active work visible.",
31    paths: ["docs/**"],
32    acceptance: ["Visible in Work"],
33    archived: null,
34  });
35  if (id === "archive-list")
36    state.packets[0].archived = { at: "2026-10-13T14:20:00Z", by: "owner" };
37  if (id === "archive-claim")
38    state.claims = [
39      {
40        packet: "FH-040",
41        agent: "builder",
42        repoName: state.forks[0].repoName,
43        paths: ["packages/forkhorse-dashboard/**"],
44        createdAt: "2026-10-13T14:00:00Z",
45      },
46    ];
47  if (id === "archive-race") {
48    state.packets[0].mode = "race";
49    const race = archiveRace();
50    const entrant = race.entrants[0];
51    state.races = [race];
52    state.claims = [{ packet: race.packet, agent: entrant.agent, repoName: entrant.repoName,
53      paths: state.packets[0].paths, createdAt: entrant.claimedAt, usage: entrant.usage }];
54    state.reviews = [];
55    state.ledger = [];
56  }
57  if (id === "archive-finished-race") {
58    state.packets[0].mode = "race";
59    const finishedAt = "2026-10-13T14:10:00Z";
60    const race = archiveRace(finishedAt);
61    const review = state.reviews[0];
62    // The promoted review and exact ledger reference identify the winning entrant.
63    const winner = { ...race.entrants[0], agent: review.agent, repoName: review.repoName,
64      firstPushAt: "2026-10-13T14:01:00Z", reviewRequestedAt: "2026-10-13T14:02:00Z",
65      receiptPassedAt: "2026-10-13T14:03:00Z", approvedAt: "2026-10-13T14:04:00Z",
66      promotedAt: finishedAt, place: 1, closedBy: null };
67    const other = { ...race.entrants[0], place: 2, closedBy: "race-finished" as const };
68    if (!state.agents.some((agent) => agent.name === winner.agent))
69      state.agents.push({ name: winner.agent, createdAt: "2026-10-13T13:59:00Z" });
70    review.createdAt = winner.reviewRequestedAt;
71    review.approvedAt = winner.approvedAt;
72    state.ledger[0].recordedAt = finishedAt;
73    state.ledger[0].race = race.packet;
74    state.races = [{ ...race, status: "finished", finishedAt, winner: winner.agent,
75      ledgerEntryId: state.ledger[0].id, places: [{ agent: winner.agent, place: 1 },
76        { agent: other.agent, place: 2 }], entrants: [winner, other] }];
77  }
78  if (id === "archive-review" || id === "archive-main-moved") {
79    state.reviews[0].promoted = false;
80    if (id === "archive-main-moved") state.ledger[0].after = "7".repeat(40);
81  }
82  if (id === "archive-blocker")
83    state.blockers = [
84      {
85        id: "1-collision",
86        packet: "FH-READY",
87        pushingPacket: "FH-040",
88        claimingAgent: "docs",
89        pushingAgent: "builder",
90        repoName: state.forks[0].repoName,
91        sha: state.reviews[0].sha,
92        paths: ["docs/**"],
93        resolved: null,
94      },
95    ];
96  return state;
97}
98
99/** Complete accepted FH-052/053 race wire shape for archive gate fixtures. */
100export function archiveRace(closedAt: string | null = null): RaceFixture["races"][number] {
101  return {
102    packet: "FH-040", tokenBudget: null, places: [], status: "open", finishedAt: null, winner: null, ledgerEntryId: null,
103    judge: null, verdict: null,
104    entrants: [{
105      agent: "builder", repoName: "demo--builder-1", claimedAt: "2026-10-13T14:00:00Z",
106      firstPushAt: null, reviewRequestedAt: null, receiptPassedAt: null, approvedAt: null,
107      promotedAt: null, place: null, closedAt, closedBy: closedAt ? "release" : null,
108      usage: { reported: null, metered: null }, budget: "unchecked",
109    }],
110  };
111}
112