@feigi/fleet-ctl 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/.claude-plugin/plugin.json +9 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +18 -0
  4. package/agents/fleet-finisher.agent.md +7 -0
  5. package/agents/fleet-implementer-alt.agent.md +210 -0
  6. package/agents/fleet-implementer.agent.md +210 -0
  7. package/agents/fleet-merge-bot.agent.md +7 -0
  8. package/agents/fleet-review-comments.agent.md +40 -0
  9. package/agents/fleet-review-correctness.agent.md +43 -0
  10. package/agents/fleet-review-runner.agent.md +73 -0
  11. package/agents/fleet-review-silent-failure.agent.md +49 -0
  12. package/agents/fleet-review-simplify.agent.md +46 -0
  13. package/agents/fleet-review-snapshot.agent.md +24 -0
  14. package/agents/fleet-review-tests.agent.md +46 -0
  15. package/agents/fleet-review-types.agent.md +41 -0
  16. package/agents/fleet-review-verifier.agent.md +29 -0
  17. package/commands/review-and-fix.md +98 -0
  18. package/commands/run-merge-bot.md +357 -0
  19. package/commands/run-team-help.md +17 -0
  20. package/package.json +23 -0
  21. package/scripts/agent-test-dir-prose.test.mjs +59 -0
  22. package/scripts/agent-test.test.mjs +1636 -0
  23. package/scripts/ambient-git-vars-mjs-prose.test.mjs +354 -0
  24. package/scripts/ambient-git-vars-prose.test.mjs +192 -0
  25. package/scripts/ancestry-check-position-prose.test.mjs +175 -0
  26. package/scripts/apply-ruleset.test.mjs +420 -0
  27. package/scripts/arg-header-probes-prose.test.mjs +393 -0
  28. package/scripts/arg.mjs +600 -0
  29. package/scripts/arg.test.mjs +1354 -0
  30. package/scripts/board-cli.test.mjs +694 -0
  31. package/scripts/board-identity.test.mjs +429 -0
  32. package/scripts/board-liveness-banner.test.mjs +119 -0
  33. package/scripts/board-prev-shape.test.mjs +229 -0
  34. package/scripts/board-tryparse-null.test.mjs +119 -0
  35. package/scripts/board.html +471 -0
  36. package/scripts/board.mjs +2037 -0
  37. package/scripts/board.test.mjs +3086 -0
  38. package/scripts/brief-after-cut-prose.test.mjs +53 -0
  39. package/scripts/candidates-exit3-prose.test.mjs +302 -0
  40. package/scripts/candidates.mjs +674 -0
  41. package/scripts/candidates.test.mjs +2101 -0
  42. package/scripts/caveat-unification-prose.test.mjs +98 -0
  43. package/scripts/ci-comment-rot-prose.test.mjs +2025 -0
  44. package/scripts/ci-completes-premise-prose.test.mjs +257 -0
  45. package/scripts/ci-state-prose.test.mjs +113 -0
  46. package/scripts/ci-state.mjs +761 -0
  47. package/scripts/ci-state.test.mjs +1640 -0
  48. package/scripts/ci-vacuous-green.test.mjs +368 -0
  49. package/scripts/citation-sweep-prose.test.mjs +1572 -0
  50. package/scripts/claim-lifecycle.test.mjs +185 -0
  51. package/scripts/claim-ticket.sh +417 -0
  52. package/scripts/claim-ticket.test.mjs +1121 -0
  53. package/scripts/closing-keyword-prose.test.mjs +193 -0
  54. package/scripts/cockpit-launch-idempotent-prose.test.mjs +165 -0
  55. package/scripts/cockpit-tick-nonblocking.test.mjs +210 -0
  56. package/scripts/compute-board.mjs +579 -0
  57. package/scripts/compute-board.test.mjs +1060 -0
  58. package/scripts/compute-spend.mjs +329 -0
  59. package/scripts/compute-spend.test.mjs +451 -0
  60. package/scripts/cross-repo-citation-prose.test.mjs +156 -0
  61. package/scripts/cwd-isolation-pins.mjs +83 -0
  62. package/scripts/dedupe-guard-prose.test.mjs +243 -0
  63. package/scripts/derive-testcmd.sh +239 -0
  64. package/scripts/derive-testcmd.test.mjs +380 -0
  65. package/scripts/diff-stats.mjs +231 -0
  66. package/scripts/diff-stats.test.mjs +408 -0
  67. package/scripts/dispatch-block-golden-prose.test.mjs +1024 -0
  68. package/scripts/dispatch-block-pins-prose.test.mjs +615 -0
  69. package/scripts/drop-merged-label.sh +173 -0
  70. package/scripts/drop-merged-label.test.mjs +480 -0
  71. package/scripts/expected-jobs-prose.test.mjs +80 -0
  72. package/scripts/filing-bar-seat-prose.test.mjs +242 -0
  73. package/scripts/filing-claim-bar-prose.test.mjs +166 -0
  74. package/scripts/finisher-dispatch-premise-prose.test.mjs +312 -0
  75. package/scripts/finisher-halt-prose.test.mjs +106 -0
  76. package/scripts/finisher-name-prose.test.mjs +134 -0
  77. package/scripts/finisher-own-tree-prose.test.mjs +285 -0
  78. package/scripts/finisher-pin-race-prose.test.mjs +339 -0
  79. package/scripts/fix-applier-correction-rules-prose.test.mjs +201 -0
  80. package/scripts/fix-applier-result-file-prose.test.mjs +100 -0
  81. package/scripts/fleet-bootstrap +155 -0
  82. package/scripts/fleet-heartbeat.mjs +272 -0
  83. package/scripts/fleet-heartbeat.test.mjs +450 -0
  84. package/scripts/fleet-provenance +207 -0
  85. package/scripts/fleet-provenance.test.mjs +64 -0
  86. package/scripts/fleet-run +148 -0
  87. package/scripts/fleet-run.test.mjs +90 -0
  88. package/scripts/fleet-state.mjs +400 -0
  89. package/scripts/fleet-state.test.mjs +373 -0
  90. package/scripts/fleet-tick-prose.test.mjs +299 -0
  91. package/scripts/fleet-tick.mjs +832 -0
  92. package/scripts/fleet-tick.test.mjs +1332 -0
  93. package/scripts/force-with-lease-reason-prose.test.mjs +184 -0
  94. package/scripts/frontmatter-allowlist.json +64 -0
  95. package/scripts/frontmatter-check.mjs +256 -0
  96. package/scripts/frontmatter-check.test.mjs +436 -0
  97. package/scripts/git-env.mjs +124 -0
  98. package/scripts/git-env.test.mjs +149 -0
  99. package/scripts/git-status-untracked-mode-sweep.test.mjs +216 -0
  100. package/scripts/gone-walk.test.mjs +213 -0
  101. package/scripts/gp-sep-invariant-prose.test.mjs +188 -0
  102. package/scripts/head-moved-after-label-prose.test.mjs +233 -0
  103. package/scripts/immutable-body-claim-prose.test.mjs +413 -0
  104. package/scripts/implementer-model-tier.test.mjs +643 -0
  105. package/scripts/inflight-citation-prose.test.mjs +144 -0
  106. package/scripts/inflight-exit2-prose.test.mjs +81 -0
  107. package/scripts/inflight-probe-guard-prose.test.mjs +109 -0
  108. package/scripts/inflight-scan-scope-prose.test.mjs +57 -0
  109. package/scripts/inflight.sh +1106 -0
  110. package/scripts/inflight.test.mjs +2984 -0
  111. package/scripts/injection-control-prose.test.mjs +404 -0
  112. package/scripts/install-root-audit.test.mjs +464 -0
  113. package/scripts/instrument-check-prose.test.mjs +235 -0
  114. package/scripts/instruments.sh +394 -0
  115. package/scripts/instruments.test.mjs +787 -0
  116. package/scripts/issue-tracker-prose.test.mjs +71 -0
  117. package/scripts/json.sh +248 -0
  118. package/scripts/json.test.mjs +364 -0
  119. package/scripts/ledger-dispatch.test.mjs +516 -0
  120. package/scripts/ledger-grammar.mjs +85 -0
  121. package/scripts/ledger-grammar.test.mjs +142 -0
  122. package/scripts/ledger-read-require-file.test.mjs +197 -0
  123. package/scripts/ledger.mjs +1753 -0
  124. package/scripts/ledger.test.mjs +3554 -0
  125. package/scripts/line-distance-prose.test.mjs +245 -0
  126. package/scripts/liveness-rationale-prose.test.mjs +83 -0
  127. package/scripts/locale-pin-prose.test.mjs +189 -0
  128. package/scripts/member-outcome-prose.test.mjs +167 -0
  129. package/scripts/member-outcomes-header.test.mjs +148 -0
  130. package/scripts/member-outcomes-prose.test.mjs +63 -0
  131. package/scripts/member-outcomes.mjs +231 -0
  132. package/scripts/member-outcomes.test.mjs +507 -0
  133. package/scripts/member-prompt-prose.test.mjs +161 -0
  134. package/scripts/member-record.mjs +605 -0
  135. package/scripts/member-record.test.mjs +516 -0
  136. package/scripts/member-write-guard.mjs +279 -0
  137. package/scripts/member-write-guard.test.mjs +211 -0
  138. package/scripts/merge-commit-probe-prose.test.mjs +122 -0
  139. package/scripts/merge-gate.mjs +262 -0
  140. package/scripts/merge-gate.test.mjs +613 -0
  141. package/scripts/muted-git-guard-sweep.test.mjs +493 -0
  142. package/scripts/net-ssh-precedence-prose.test.mjs +91 -0
  143. package/scripts/net-watchdog-prose.test.mjs +79 -0
  144. package/scripts/net.sh +409 -0
  145. package/scripts/net.test.mjs +211 -0
  146. package/scripts/no-ci-gate-prose.test.mjs +108 -0
  147. package/scripts/no-undo-audit.sh +1134 -0
  148. package/scripts/no-undo-audit.test.mjs +3965 -0
  149. package/scripts/no-wave.test.mjs +138 -0
  150. package/scripts/node-floor-sweep.test.mjs +611 -0
  151. package/scripts/pointer-target-prose.test.mjs +186 -0
  152. package/scripts/pr-overlap.mjs +417 -0
  153. package/scripts/pr-overlap.test.mjs +695 -0
  154. package/scripts/printf-die-sweep.test.mjs +384 -0
  155. package/scripts/prompt-renderer.mjs +39 -0
  156. package/scripts/prompt-renderer.test.mjs +68 -0
  157. package/scripts/prose-pin.mjs +808 -0
  158. package/scripts/prose-pin.test.mjs +1034 -0
  159. package/scripts/prove-merge.sh +228 -0
  160. package/scripts/prove-merge.test.mjs +995 -0
  161. package/scripts/pull-table-relabel-prose.test.mjs +60 -0
  162. package/scripts/quiet-payload-prose.test.mjs +222 -0
  163. package/scripts/reap.sh +1768 -0
  164. package/scripts/reap.test.mjs +4395 -0
  165. package/scripts/reaping-prose.test.mjs +159 -0
  166. package/scripts/refuter-scratch-prose.test.mjs +135 -0
  167. package/scripts/release-label-required-prose.test.mjs +71 -0
  168. package/scripts/release-label-split-prose.test.mjs +169 -0
  169. package/scripts/release-ticket.sh +1716 -0
  170. package/scripts/release-ticket.test.mjs +5106 -0
  171. package/scripts/renovate-release-contract.test.mjs +379 -0
  172. package/scripts/repo-root.mjs +544 -0
  173. package/scripts/repo-root.test.mjs +873 -0
  174. package/scripts/reporter-output-rule-prose.test.mjs +208 -0
  175. package/scripts/review-agent-report-only.test.mjs +49 -0
  176. package/scripts/review-core-cwd-isolation.test.mjs +374 -0
  177. package/scripts/review-core-reads.test.mjs +478 -0
  178. package/scripts/review-core-refuter-scratch.test.mjs +148 -0
  179. package/scripts/review-core-snapshot-path.test.mjs +777 -0
  180. package/scripts/review-core-specialist-scratch.test.mjs +189 -0
  181. package/scripts/review-core-testcmd.test.mjs +288 -0
  182. package/scripts/review-core-unrun.test.mjs +530 -0
  183. package/scripts/review-core-unverified-discriminant.test.mjs +208 -0
  184. package/scripts/review-core.mjs +1028 -0
  185. package/scripts/review-eval-resolver-path.test.mjs +55 -0
  186. package/scripts/review-eval.mjs +197 -0
  187. package/scripts/review-host-fixture.mjs +73 -0
  188. package/scripts/review-in-run-retry.test.mjs +187 -0
  189. package/scripts/review-no-vendor-dispatch.test.mjs +45 -0
  190. package/scripts/review-path-default.test.mjs +796 -0
  191. package/scripts/review-runner-spawns.test.mjs +93 -0
  192. package/scripts/review-runner.test.mjs +155 -0
  193. package/scripts/review-tier-audit.test.mjs +140 -0
  194. package/scripts/run-artifact-pr-prose.test.mjs +341 -0
  195. package/scripts/run-merge-bot-prose.test.mjs +1391 -0
  196. package/scripts/scratch-partition-invariant-prose.test.mjs +74 -0
  197. package/scripts/scripts-path-citation-sweep.test.mjs +73 -0
  198. package/scripts/section-between-guard-prose.test.mjs +378 -0
  199. package/scripts/select-dimensions.test.mjs +674 -0
  200. package/scripts/shared-refusal.test.mjs +388 -0
  201. package/scripts/shell-traps-prose.test.mjs +507 -0
  202. package/scripts/shortlist.mjs +355 -0
  203. package/scripts/shortlist.test.mjs +366 -0
  204. package/scripts/slow-transport.mjs +72 -0
  205. package/scripts/snapshot-repo.test.mjs +772 -0
  206. package/scripts/snapshot-runner-audience-prose.test.mjs +129 -0
  207. package/scripts/spend-view.test.mjs +312 -0
  208. package/scripts/staleness-qualifier-prose.test.mjs +251 -0
  209. package/scripts/staleness-verdict-prose.test.mjs +142 -0
  210. package/scripts/staleness.mjs +414 -0
  211. package/scripts/staleness.test.mjs +893 -0
  212. package/scripts/stalled-member-liveness-prose.test.mjs +219 -0
  213. package/scripts/stash-prohibition-prose.test.mjs +313 -0
  214. package/scripts/strip-comments.mjs +44 -0
  215. package/scripts/tier-check.mjs +468 -0
  216. package/scripts/tier-check.test.mjs +726 -0
  217. package/scripts/tier-guard-gate-prose.test.mjs +216 -0
  218. package/scripts/tier-outcomes-header.test.mjs +586 -0
  219. package/scripts/tier-outcomes.mjs +441 -0
  220. package/scripts/tier-outcomes.test.mjs +342 -0
  221. package/scripts/tier-roles.mjs +250 -0
  222. package/scripts/tier-roles.test.mjs +316 -0
  223. package/scripts/tracker-block-copy-prose.test.mjs +288 -0
  224. package/scripts/triage-labels-gloss-prose.test.mjs +97 -0
  225. package/scripts/unattended-git-sweep.test.mjs +142 -0
  226. package/scripts/verify-sha-exit2-prose.test.mjs +269 -0
  227. package/scripts/verify-sha.sh +117 -0
  228. package/scripts/verify-sha.test.mjs +693 -0
  229. package/scripts/watcher-degraded-block.test.mjs +372 -0
  230. package/scripts/watcher-key-prose.test.mjs +106 -0
  231. package/scripts/within-run-pair-prose.test.mjs +208 -0
  232. package/scripts/worktree-audit.sh +482 -0
  233. package/scripts/worktree-audit.test.mjs +1407 -0
  234. package/scripts/worktree-head-prose.test.mjs +276 -0
  235. package/scripts/worktree-listing-sweep.test.mjs +217 -0
  236. package/scripts/worktree-model-prose.test.mjs +216 -0
  237. package/scripts/worktree.sh +470 -0
  238. package/skills/next-ticket/SKILL.md +138 -0
  239. package/skills/run-team/SKILL.md +3603 -0
  240. package/skills/run-team/references/ci-and-staleness.md +75 -0
  241. package/skills/run-team/references/correction-tickets.md +37 -0
  242. package/skills/run-team/references/isolation.md +23 -0
  243. package/skills/run-team/references/member-lifecycle.md +73 -0
  244. package/skills/run-team/references/reaping.md +73 -0
  245. package/skills/sizing-a-ticket/SKILL.md +39 -0
@@ -0,0 +1,429 @@
1
+ // #1584: a board payload names the workspace it describes and the port it was
2
+ // served on, and the page names the repo in its tab title and its header.
3
+ //
4
+ // Before this, two cockpits were two identical windows: `board.html` carried a
5
+ // constant `<title>` and a constant header, the model's `repo` field was never
6
+ // read by the page at all, and the only identity anywhere near the payload was
7
+ // the `workspace` key #1585's launch handshake stamped onto the SERVED copy
8
+ // after computeBoard() had already returned — so `board.mjs build` printed a
9
+ // snapshot that could not say which of two workspaces it came from.
10
+ //
11
+ // Driven through the real CLI, out of process: gather() reads process.argv
12
+ // directly and resolveCockpitInstance()'s git probe is a spawn, so the join
13
+ // under test only exists in a child. The page half is lifted out of
14
+ // board.html's source text and called as a pure function — the page is served
15
+ // as one self-contained file with no build step and no DOM harness, the same
16
+ // seam spend-view.test.mjs and ledger-read-require-file.test.mjs already use.
17
+ //
18
+ // A separate file rather than more of board.test.mjs, for the reason
19
+ // board-prev-shape.test.mjs gives: the fleet runs several implementers at
20
+ // once and two PRs appending to one test file conflict, which costs the PR
21
+ // its CI entirely.
22
+
23
+ import { test } from "node:test";
24
+ import assert from "node:assert/strict";
25
+ import { spawnSync, spawn } from "node:child_process";
26
+ import { mkdtempSync, writeFileSync, chmodSync, rmSync, readFileSync, realpathSync, symlinkSync } from "node:fs";
27
+ import { tmpdir } from "node:os";
28
+ import { join } from "node:path";
29
+ import { fileURLToPath } from "node:url";
30
+ import { resolveCockpitInstance } from "./board.mjs";
31
+ import { gitEnv } from "./git-env.mjs";
32
+
33
+ const SCRIPT = fileURLToPath(new URL("./board.mjs", import.meta.url));
34
+ const HTML = readFileSync(new URL("./board.html", import.meta.url), "utf8");
35
+
36
+ // The port this file hardcoded before instance resolution existed, and the one
37
+ // the degrade arm still answers with. Spelled out rather than imported because
38
+ // board.mjs does not export it — the same copy board.test.mjs's window rows
39
+ // keep, and a drift would fail the degrade row below loudly.
40
+ const PORT_BASE = 8123;
41
+
42
+ // A PATH carrying git, a gh stub, and nothing else: every board built here
43
+ // stays offline, and `node` is deliberately unreachable so gather()'s ledger
44
+ // read fails fast instead of shelling out to a real ledger.mjs. None of these
45
+ // tests asserts a ticket.
46
+ function shimPath(ghBody) {
47
+ const bin = mkdtempSync(join(tmpdir(), "board-id-bin-"));
48
+ const real = spawnSync("sh", ["-c", "command -v git"], { encoding: "utf8" });
49
+ assert.equal(real.status, 0, "test setup: no git on PATH to shim, so the resolved arm cannot be reached");
50
+ symlinkSync(real.stdout.trim(), join(bin, "git"));
51
+ writeFileSync(join(bin, "gh"), ghBody);
52
+ chmodSync(join(bin, "gh"), 0o755);
53
+ return bin;
54
+ }
55
+
56
+ // Every gh read fails: each one goes through tryRun, which catches and
57
+ // degrades, so the board still builds and `repo` stays null.
58
+ const GH_FAILS = "#!/bin/sh\nexit 1\n";
59
+
60
+ // Answers only `gh repo view`, with the identity this instance should render.
61
+ const ghNamed = (nameWithOwner) => "#!/bin/sh\ncase \"$1 $2\" in\n\"repo view\") "
62
+ + `echo '{"nameWithOwner":"${nameWithOwner}","url":"https://example.test/${nameWithOwner}"}' ;;\n`
63
+ + "*) exit 1 ;;\nesac\n";
64
+
65
+ // realpath, not the bare mkdtemp path: on darwin $TMPDIR lives under /var,
66
+ // which is a symlink to /private/var, and resolveCockpitInstance canonicalises
67
+ // the workspace it derives. Comparing against the unresolved form would fail
68
+ // on the symlink rather than on the behaviour.
69
+ function gitRepo(prefix) {
70
+ const dir = realpathSync(mkdtempSync(join(tmpdir(), prefix)));
71
+ // GIT_DIR/GIT_WORK_TREE scrubbed off the fixture too: under an ambient one
72
+ // `git init` exits 0 having re-inited whichever directory the variable
73
+ // names, leaving this one silently not a repository.
74
+ const init = spawnSync("git", ["init", "-q"], { cwd: dir, stdio: "ignore", env: gitEnv() });
75
+ assert.equal(init.status, 0, "test setup: git init must succeed");
76
+ return dir;
77
+ }
78
+
79
+ // HOME is redirected at every child: gatherSpend() scans $HOME for this cwd's
80
+ // omp session transcripts, and pointing it at an empty directory keeps these
81
+ // runs off the machine's real session tree.
82
+ function runBuild(cwd, bin) {
83
+ const home = mkdtempSync(join(tmpdir(), "board-id-home-"));
84
+ const r = spawnSync(process.execPath, [SCRIPT, "build"], {
85
+ cwd, encoding: "utf8", timeout: 20000,
86
+ env: { ...process.env, PATH: bin, HOME: home },
87
+ });
88
+ rmSync(home, { recursive: true, force: true });
89
+ return r;
90
+ }
91
+
92
+ test("CLI: a built snapshot names the workspace it describes and the port that workspace is served on", () => {
93
+ const bin = shimPath(GH_FAILS), repo = gitRepo("board-id-build-");
94
+ try {
95
+ const r = runBuild(repo, bin);
96
+ assert.equal(r.status, 0, r.stderr);
97
+ const board = JSON.parse(r.stdout);
98
+ assert.ok(Array.isArray(board.tickets), `stdout must still be a board model: ${r.stdout.slice(0, 200)}`);
99
+
100
+ assert.equal(board.workspace, repo,
101
+ "a snapshot that cannot name its workspace is the anonymous file this ticket exists to remove");
102
+ // The port is the DERIVED one — the port this workspace's cockpit answers
103
+ // on, which is what makes a stray file self-identifying. Computed through
104
+ // the exported seam rather than hardcoded, so the hash algorithm stays
105
+ // free to be tested where it is defined, but the real CLI reached it
106
+ // through a real `git rev-parse`, which is the join under test.
107
+ const expected = resolveCockpitInstance({ cwd: repo, gitCommonDir: ".git" });
108
+ assert.equal(board.port, expected.port);
109
+ assert.notEqual(board.port, null);
110
+ } finally { for (const d of [bin, repo]) rmSync(d, { recursive: true, force: true }); }
111
+ });
112
+
113
+ // The fallback half of the same claim. A build outside any checkout has no
114
+ // workspace to name — but it must still SAY so, with both keys present and
115
+ // null where the identity is unknown, rather than dropping the fields and
116
+ // leaving a reader unable to tell an old payload from a degraded one.
117
+ test("CLI: a build with no resolvable workspace still carries both keys — null workspace, base port", () => {
118
+ const bin = shimPath(GH_FAILS);
119
+ const cwd = realpathSync(mkdtempSync(join(tmpdir(), "board-id-nogit-")));
120
+ try {
121
+ const r = runBuild(cwd, bin);
122
+ assert.equal(r.status, 0, r.stderr);
123
+ // Without this the row passes vacuously: a cwd that turned out to be
124
+ // inside some repository would take the resolved arm and never reach the
125
+ // degrade this test is about.
126
+ assert.match(r.stderr, /could not resolve --git-common-dir/, r.stderr);
127
+ const board = JSON.parse(r.stdout);
128
+ assert.ok("workspace" in board && "port" in board,
129
+ `both identity keys must be present even when there is no instance: ${r.stdout.slice(0, 200)}`);
130
+ assert.equal(board.workspace, null);
131
+ assert.equal(board.port, PORT_BASE);
132
+ } finally { for (const d of [bin, cwd]) rmSync(d, { recursive: true, force: true }); }
133
+ });
134
+
135
+ const withTimeout = (pr, ms, what) => Promise.race([
136
+ pr,
137
+ new Promise((_, rej) => setTimeout(() => rej(new Error(`timed out waiting for ${what}`)), ms).unref()),
138
+ ]);
139
+
140
+ function serveProcess(cwd, bin) {
141
+ const home = mkdtempSync(join(tmpdir(), "board-id-home-"));
142
+ const p = spawn(process.execPath, [SCRIPT, "serve", "--port", "0", "--interval", "3600"],
143
+ { cwd, env: { ...process.env, PATH: bin, HOME: home }, stdio: ["ignore", "ignore", "pipe"] });
144
+ p.stderr.setEncoding("utf8");
145
+ let buf = "";
146
+ const port = new Promise((res, rej) => {
147
+ p.stderr.on("data", (d) => {
148
+ buf += d;
149
+ const m = buf.match(/cockpit on http:\/\/localhost:(\d+)/);
150
+ if (m) res(Number(m[1]));
151
+ });
152
+ p.on("exit", (code) => rej(new Error(`serve exited (${code}) before announcing: ${buf}`)));
153
+ });
154
+ return { p, port };
155
+ }
156
+
157
+ // The announcement comes BEFORE the first tick (#1660 publishes identity at
158
+ // bind time so a racing launch's probe has something to read), so the first
159
+ // payload on the wire can still be that stub. Poll for a real tick rather than
160
+ // racing it — `generatedAt` is the field only computeBoard() produces.
161
+ async function builtBoard(port) {
162
+ const ms = 20000, deadline = Date.now() + ms;
163
+ for (;;) {
164
+ const res = await fetch(`http://localhost:${port}/board.json`);
165
+ if (res.status === 200) {
166
+ const body = await res.json();
167
+ if (typeof body.generatedAt === "number") return body;
168
+ } else { await res.arrayBuffer(); }
169
+ if (Date.now() > deadline) throw new Error(`no built board on port ${port} after ${ms}ms`);
170
+ await new Promise((r) => setTimeout(r, 100));
171
+ }
172
+ }
173
+
174
+ // The end-to-end claim the whole ticket is for: two cockpits up at once are
175
+ // two DIFFERENT windows — different identity in the payload, and a different
176
+ // name in the tab strip and the header, each naming its own repo.
177
+ //
178
+ // `--port 0` on both, deliberately, and not only to keep the test off this
179
+ // machine's derived ports: an ephemeral bind is the one case where the port
180
+ // the caller asked for and the port the board is reachable on differ, so the
181
+ // payload echoing the REQUEST would say `port: 0` here and nowhere else.
182
+ test("CLI: two concurrent cockpits carry two identities, and their titles name two different repos", async () => {
183
+ const binA = shimPath(ghNamed("acme/one")), binB = shimPath(ghNamed("acme/two"));
184
+ const repoA = gitRepo("board-id-a-"), repoB = gitRepo("board-id-b-");
185
+ const procs = [];
186
+ try {
187
+ const a = serveProcess(repoA, binA), b = serveProcess(repoB, binB);
188
+ procs.push(a.p, b.p);
189
+ const [portA, portB] = await withTimeout(Promise.all([a.port, b.port]), 20000, "both cockpits to announce");
190
+ const [boardA, boardB] = await withTimeout(
191
+ Promise.all([builtBoard(portA), builtBoard(portB)]), 20000, "both cockpits to build a board");
192
+
193
+ assert.equal(boardA.workspace, repoA);
194
+ assert.equal(boardB.workspace, repoB);
195
+ assert.notEqual(boardA.workspace, boardB.workspace, "two workspaces cannot share one identity");
196
+
197
+ // The port SERVED, not the port requested: both asked for 0.
198
+ assert.equal(boardA.port, portA);
199
+ assert.equal(boardB.port, portB);
200
+ assert.notEqual(boardA.port, boardB.port);
201
+
202
+ assert.equal(boardA.repo, "acme/one");
203
+ assert.equal(boardB.repo, "acme/two");
204
+ assert.notEqual(boardTitle(boardA.repo), boardTitle(boardB.repo),
205
+ "two boards rendering one title is the defect this ticket names");
206
+ assert.match(boardTitle(boardA.repo), /acme\/one/);
207
+ assert.match(boardTitle(boardB.repo), /acme\/two/);
208
+ } finally {
209
+ for (const p of procs) p.kill("SIGKILL");
210
+ for (const d of [binA, binB, repoA, repoB]) rmSync(d, { recursive: true, force: true });
211
+ }
212
+ });
213
+
214
+ // ── the page ────────────────────────────────────────────────────────────────
215
+ //
216
+ // A lift reads a COPY, so the guards below keep that copy tied to the page: a
217
+ // second top-level declaration would win at runtime by hoisting while the lift
218
+ // still read the first.
219
+
220
+ for (const [name, re] of [
221
+ ["TITLE", /^const TITLE = /gm],
222
+ ["boardTitle", /^function\s+boardTitle\s*\(/gm],
223
+ ]) {
224
+ test(`board.html declares ${name} exactly once at top level`, () => {
225
+ assert.equal(HTML.match(re)?.length, 1,
226
+ `${name} must be declared exactly once — a second top-level declaration wins at runtime and the lift below would still read the first`);
227
+ });
228
+ }
229
+
230
+ const TITLE_SRC = HTML.match(/^const TITLE = .*$/m);
231
+ const BOARD_TITLE_SRC = HTML.match(/^function\s+boardTitle\s*\(.*$/m);
232
+
233
+ test("board.html still declares TITLE and boardTitle in the shape this file lifts", () => {
234
+ // Named and outside the lift: an assertion thrown during the lift itself
235
+ // runs before node registers any test here, which reports one opaque
236
+ // file-level error instead of naming the claim that stopped holding.
237
+ assert.ok(TITLE_SRC, "board.html no longer declares TITLE as a one-line top-level const — update this test");
238
+ assert.ok(BOARD_TITLE_SRC, "board.html no longer declares boardTitle as a one-line top-level function — update this test");
239
+ });
240
+
241
+ const boardTitle = TITLE_SRC && BOARD_TITLE_SRC
242
+ ? new Function(`${TITLE_SRC[0]}\n${BOARD_TITLE_SRC[0]}\nreturn boardTitle;`)()
243
+ : () => { throw new Error("boardTitle could not be lifted from board.html — see the shape test above"); };
244
+
245
+ test("boardTitle names the repo when the payload carries one", () => {
246
+ assert.equal(boardTitle("acme/one"), "fleet cockpit — acme/one");
247
+ });
248
+
249
+ // The three ways a payload arrives with no repo to name, all of which used to
250
+ // be impossible to get wrong because the page never read the field: `gh repo
251
+ // view` failed (null), it answered malformed ("" via gather's `?? repo`
252
+ // chain), and the identity stub served before the first tick carries no
253
+ // `repo` key at all (undefined). Rendering `fleet cockpit — undefined` on any
254
+ // of them is worse than the constant this replaces.
255
+ test("boardTitle falls back to the bare constant for every no-repo shape", () => {
256
+ for (const v of [null, undefined, ""]) {
257
+ assert.equal(boardTitle(v), "fleet cockpit", `a ${JSON.stringify(v)} repo must render today's constant`);
258
+ }
259
+ });
260
+
261
+ // Ties the fallback to what the page actually shows before any poll returns —
262
+ // a drifting copy in the markup would leave the tab flickering between two
263
+ // spellings of the same constant on the first tick.
264
+ test("the page's own <title> and header are the constant boardTitle falls back to", () => {
265
+ const title = HTML.match(/<title>([^<]*)<\/title>/);
266
+ assert.ok(title, "board.html no longer carries a <title> — update this test");
267
+ assert.equal(title[1], boardTitle(null));
268
+ const h1 = HTML.match(/<h1[^>]*\sid="heading"[^>]*>([^<]*)<\/h1>/);
269
+ assert.ok(h1, "board.html no longer carries the heading element render writes to — update this test");
270
+ assert.equal(h1[1], "🛰 " + boardTitle(null));
271
+ });
272
+
273
+ // A DOM this page's own script can write to, without a browser: render() is
274
+ // lifted out of board.html's source (the same seam boardTitle above uses)
275
+ // and run against a document stub just capable enough to hold the writes —
276
+ // children are kept (so a test can read back what a column holds), innerHTML
277
+ // writes are still swallowed as a clearing no-op (the setter below), and
278
+ // style writes land on a plain object but nothing here reads them back.
279
+ class FakeNode {
280
+ constructor() { this.children = []; this.style = {}; }
281
+ set innerHTML(_) { this.children = []; }
282
+ append(...nodes) { this.children.push(...nodes); }
283
+ replaceChildren(...nodes) { this.children = nodes; }
284
+ }
285
+ function fakeDocument() {
286
+ const byId = new Map();
287
+ return {
288
+ title: "",
289
+ createElement: () => new FakeNode(),
290
+ createTextNode: (text) => ({ text }),
291
+ getElementById(id) {
292
+ if (!byId.has(id)) byId.set(id, new FakeNode());
293
+ return byId.get(id);
294
+ },
295
+ };
296
+ }
297
+
298
+ // `poll()`'s call at the bottom is the one line this lift must never run —
299
+ // it fetches immediately, which a test document has nothing to answer.
300
+ const SCRIPT_SRC = HTML.match(/<script>([\s\S]*)<\/script>/)?.[1]
301
+ ?.replace(/\bpoll\(\);\s*$/, "");
302
+
303
+ test("board.html's <script> still declares render in the shape this file lifts", () => {
304
+ assert.ok(SCRIPT_SRC, "board.html no longer has a lift-able <script> body — update this test");
305
+ });
306
+
307
+ function renderHarness() {
308
+ const document = fakeDocument();
309
+ const render = new Function("document", `${SCRIPT_SRC}\nreturn render;`)(document);
310
+ return { document, render };
311
+ }
312
+
313
+ const baseModel = () => ({
314
+ interval: 15, repoUrl: null, generatedAt: Date.now(),
315
+ attention: [], tickets: [], spend: null, queue: {}, filed: [],
316
+ });
317
+
318
+ // The regression this ticket exists to prevent, pinned on the OBSERVABLE
319
+ // rewrite rather than the source text: a board whose repo read fails on a
320
+ // later tick must go back to the bare constant. A gate on the repo being
321
+ // present — however many tokens of indirection sit between the gate and the
322
+ // literal `.repo` — leaves the title pinned from a tick that is no longer
323
+ // current, and this catches that by calling render() twice and reading what
324
+ // it actually wrote, not how it decided to write it.
325
+ test("render rewrites the title and header on every tick, reverting when repo disappears", () => {
326
+ const { document, render } = renderHarness();
327
+ render({ ...baseModel(), repo: "acme/one" });
328
+ assert.equal(document.title, "fleet cockpit — acme/one");
329
+ assert.equal(document.getElementById("heading").textContent, "🛰 fleet cockpit — acme/one");
330
+
331
+ render({ ...baseModel(), repo: null });
332
+ assert.equal(document.title, "fleet cockpit",
333
+ "a repo that stops resolving must clear the tab title on the very next render, not leave the prior tick's name showing");
334
+ assert.equal(document.getElementById("heading").textContent, "🛰 fleet cockpit");
335
+ });
336
+
337
+ // #1848: each column scrolls on its own (#1759), and a scroll offset lives on
338
+ // the element — so a tick that throws the columns away and builds new ones
339
+ // resets every column to the top within one poll. The columns must be the
340
+ // SAME nodes tick after tick, while what they hold is the new tick's alone:
341
+ // a column that kept its node by appending onto last tick's cards would show
342
+ // every ticket twice and a stale count.
343
+ test("render keeps each column's node across ticks and rewrites only what it holds", () => {
344
+ const { document, render } = renderHarness();
345
+ const board = document.getElementById("board");
346
+ render({ ...baseModel(), tickets: [
347
+ { issue: 1, column: "POOL" }, { issue: 2, column: "POOL" }, { issue: 3, column: "REVIEW" },
348
+ ] });
349
+ const before = [...board.children];
350
+ assert.equal(before.length, 5);
351
+
352
+ render({ ...baseModel(), tickets: [{ issue: 4, column: "POOL" }] });
353
+ assert.equal(board.children.length, 5, "a tick must not add a second set of columns");
354
+ board.children.forEach((col, i) => assert.equal(col, before[i],
355
+ "a column rebuilt as a new node loses its scroll position on every poll"));
356
+
357
+ const [pool, , review] = board.children;
358
+ const count = (col) => col.children[0].children[0].textContent;
359
+ const issues = (col) => col.children.slice(1).map((c) => c.children[0].children[0].textContent);
360
+ assert.equal(count(pool), "1");
361
+ assert.deepEqual(issues(pool), ["#4"], "a column must hold this tick's cards, not last tick's as well");
362
+ assert.equal(count(review), "0");
363
+ assert.deepEqual(issues(review), []);
364
+ });
365
+
366
+ // #1857 review: colNodes' persistent nodes meant a ticket that makes card()
367
+ // throw (a non-array `flags`, hitting `for (const f of t.flags || [])`) left
368
+ // every column at or after the throw point silently stuck on the previous
369
+ // tick while columns before it updated — a mixed-tick board indistinguishable
370
+ // from a healthy render. Building every column's contents before writing any
371
+ // of them to the DOM means a throw leaves ALL columns on the previous tick
372
+ // together, never a mix.
373
+ test("a malformed ticket that makes card() throw leaves every column on the previous tick, never a mix", () => {
374
+ const { document, render } = renderHarness();
375
+ const board = document.getElementById("board");
376
+ render({ ...baseModel(), tickets: [
377
+ { issue: 1, column: "POOL" }, { issue: 2, column: "REVIEW" },
378
+ ] });
379
+ const count = (col) => col.children[0].children[0].textContent;
380
+ assert.equal(count(board.children[0]), "1", "POOL");
381
+ assert.equal(count(board.children[2]), "1", "REVIEW");
382
+
383
+ // POOL comes before REVIEW in COLUMNS order and gets a real, valid change;
384
+ // REVIEW gets the malformed ticket that makes card() throw. A build that
385
+ // writes POOL to the DOM before reaching REVIEW's throw would let POOL show
386
+ // this tick's data while REVIEW is stuck on last tick's — the mix this test
387
+ // exists to catch.
388
+ assert.throws(() => render({ ...baseModel(), tickets: [
389
+ { issue: 1, column: "POOL" }, { issue: 3, column: "POOL" }, { issue: 4, column: "REVIEW", flags: 42 },
390
+ ] }), /is not iterable/, "a non-array flags value must still surface as a thrown error, not swallow silently");
391
+
392
+ assert.equal(count(board.children[0]), "1",
393
+ "POOL must NOT have updated to this tick's count of 2 — a column written before the throw is the mixed-tick bug this test exists to catch");
394
+ assert.equal(count(board.children[2]), "1", "REVIEW must also stay on the previous tick, consistent with POOL");
395
+ });
396
+
397
+ // #1584 adds a second reader of the model's repo IDENTITY (`acme/one`) beside
398
+ // the long-standing reader of its repo URL. A card's PR link must keep
399
+ // resolving against the URL — the field that carries the host, so links work
400
+ // on GitHub Enterprise — or a card clicked on one board opens nothing, or the
401
+ // wrong thing.
402
+ test("card still builds its PR link from the model's repoUrl, not from the repo name", () => {
403
+ const card = HTML.match(/^function\s+card\s*\(\w+\)\s*\{[\s\S]*?^\}$/m);
404
+ assert.ok(card, "board.html no longer declares card as a top-level function — update this test");
405
+ assert.match(card[0], /a\.href\s*=\s*\(?\s*repoUrl\s*\)?\s*\?\s*repoUrl\s*\+/,
406
+ "the PR link must be built from repoUrl; the repo name is not a URL");
407
+ });
408
+
409
+ // #2108 review: capMsg used to be reachable only through the single-slot
410
+ // stale-banner element, behind a stale/stall/ledger priority chain — a
411
+ // co-occurring higher-priority message masked it completely, on a tick that
412
+ // left it exactly as unreported as the pre-#2108 silent truncation it exists
413
+ // to disclose. The footer does not compete for that slot.
414
+ test("#2108: a capped-read notice reaches the footer even when a higher-priority banner wins the single slot", () => {
415
+ const { document, render } = renderHarness();
416
+ const banner = document.getElementById("stale-banner");
417
+ const foot = document.getElementById("footer");
418
+ const capNotice = "the open-PR read hit its --limit, so a PR past it shows REVIEW with CI unknown";
419
+
420
+ render({ ...baseModel(), capNotice });
421
+ assert.match(banner.textContent, /open-PR read hit its --limit/, "capMsg alone must still win the empty banner slot");
422
+ assert.ok(foot.children.some((c) => c.textContent?.includes("open-PR read hit its --limit")),
423
+ "capMsg must also reach the footer when nothing else is competing for the banner");
424
+
425
+ render({ ...baseModel(), ledgerState: "unread", capNotice });
426
+ assert.match(banner.textContent, /ledger not read/, "the higher-priority ledger banner must still win the single slot");
427
+ assert.ok(foot.children.some((c) => c.textContent?.includes("open-PR read hit its --limit")),
428
+ "a co-occurring ledger banner must not silently drop the cap notice — it has no other surface once the banner slot is taken");
429
+ });
@@ -0,0 +1,119 @@
1
+ // #1597: the cockpit half of the liveness mark — the banner board.html draws
2
+ // from a run's liveness verdict, and the wiring that carries a mark written by
3
+ // fleet-heartbeat.mjs through to the board board.mjs builds.
4
+ //
5
+ // The wiring half drives the real scripts out of process, in a throwaway
6
+ // repository.
7
+ //
8
+ // A separate file rather than more of board.test.mjs, for the reason
9
+ // ledger-read-require-file.test.mjs gives: the fleet runs several implementers
10
+ // at once and two PRs appending to one test file conflict, which costs the PR
11
+ // its CI entirely. These tests first landed at the end of that file, whose
12
+ // header scopes it to #816 — which is the same conflict, one file over.
13
+
14
+ import { test } from "node:test";
15
+ import assert from "node:assert/strict";
16
+ import { spawnSync } from "node:child_process";
17
+ import { mkdtempSync, writeFileSync, chmodSync, readFileSync, existsSync } from "node:fs";
18
+ import { tmpdir } from "node:os";
19
+ import { join } from "node:path";
20
+ import { fileURLToPath } from "node:url";
21
+
22
+ const BOARD = fileURLToPath(new URL("./board.mjs", import.meta.url));
23
+ const HTML = readFileSync(new URL("./board.html", import.meta.url), "utf8");
24
+
25
+ // ── the liveness banner (#1597) ──────────────────────────────────────────────
26
+ //
27
+ // Same lift technique and the same reason as ledgerBanner in
28
+ // ledger-read-require-file.test.mjs: the page is one self-contained file and
29
+ // its decisions are reachable only through their source text. The
30
+ // declaration-count guard comes first for the same hoisting reason.
31
+
32
+ test("board.html declares livenessBanner exactly once at top level", () => {
33
+ assert.equal(HTML.match(/^function\s+livenessBanner\s*\(/gm)?.length, 1,
34
+ "livenessBanner must be declared exactly once — a second declaration wins at runtime and the lift below would still read the first");
35
+ });
36
+
37
+ const LIVENESS_SRC = HTML.match(/^function\s+livenessBanner\s*\(\w+\)\s*\{[\s\S]*?^\}$/m);
38
+
39
+ test("board.html still declares livenessBanner in the shape this file lifts", () => {
40
+ assert.ok(LIVENESS_SRC, "board.html no longer declares livenessBanner as a top-level function — update this test");
41
+ });
42
+
43
+ const livenessBanner = LIVENESS_SRC
44
+ ? new Function(`${LIVENESS_SRC[0]}\nreturn livenessBanner;`)()
45
+ : () => { throw new Error("livenessBanner could not be lifted from board.html — see the shape test above"); };
46
+
47
+ test("livenessBanner renders the verdict's own words and composes none of its own", () => {
48
+ // The page must not phrase this. compute-board.mjs builds `text` through
49
+ // fleet-state.mjs's stallReport(), the same function fleet-tick prints, so
50
+ // a rewrite of one surface cannot leave the other describing the same dead
51
+ // run differently. A banner that reworded here would be a second answer.
52
+ const text = "heartbeat STALLED: last beat 2026-01-01T00:00:00.000Z (90m ago, 70m past the 20m interval it promised)"
53
+ + " — the beat stopped without a recorded reason; 3 ticket(s) claimed and in flight, pool supply 4";
54
+ assert.equal(livenessBanner({ kind: "stale", text }), "⚠ " + text);
55
+ });
56
+
57
+ test("livenessBanner stays silent for a run with nothing to report", () => {
58
+ // Null is the healthy verdict AND the run that never beat — computeBoard
59
+ // collapses both, because a banner that fires on a beating fleet is a
60
+ // banner the operator learns to read past, which costs it the one night it
61
+ // exists for.
62
+ assert.equal(livenessBanner(null), null);
63
+ assert.equal(livenessBanner(undefined), null,
64
+ "a board.json written before this field existed must render, not warn");
65
+ // And a payload carrying the key with no words is not a banner either: an
66
+ // empty amber strip claims a verdict the board does not hold.
67
+ assert.equal(livenessBanner({ kind: "stale" }), null);
68
+ assert.equal(livenessBanner({ kind: "stale", text: "" }), null);
69
+ });
70
+
71
+ // ── the mark's wiring, end to end (#1597) ────────────────────────────────────
72
+ //
73
+ // Everything above tests the cockpit's halves in isolation, and the one
74
+ // failure none of them can see is the one that matters most here: the
75
+ // heartbeat and the board agreeing on WHICH FILE. A cockpit reading a path
76
+ // nothing writes renders a permanently empty liveness surface, and every
77
+ // other test in this repo stays green while it does — the panel is supposed
78
+ // to be empty on a healthy run, so "no banner" is indistinguishable from
79
+ // "wired to nowhere".
80
+ //
81
+ // So this drives the real fleet-heartbeat.mjs and the real board.mjs through
82
+ // their own default path resolution, in a throwaway repository, and asserts
83
+ // the mark one wrote reaches the board the other built.
84
+ test("a mark written by the real heartbeat reaches the real board (#1597)", () => {
85
+ const repo = mkdtempSync(join(tmpdir(), "board-liveness-e2e-"));
86
+ assert.equal(spawnSync("git", ["init", "-q", repo], { encoding: "utf8" }).status, 0);
87
+ const bin = mkdtempSync(join(tmpdir(), "board-liveness-bin-"));
88
+ writeFileSync(join(bin, "gh"), "#!/bin/sh\nexit 1\n");
89
+ chmodSync(join(bin, "gh"), 0o755);
90
+ const env = { ...process.env, PATH: `${bin}:${process.env.PATH}` };
91
+
92
+ // `--stop` rather than a beat: a deliberate stop is reported at once, where
93
+ // a live beat would have to be backdated by hand — and backdating means
94
+ // writing the file this test is trying to prove nobody has to write by hand.
95
+ // No --state either, on purpose: the default resolution IS the subject.
96
+ const heartbeat = fileURLToPath(new URL("./fleet-heartbeat.mjs", import.meta.url));
97
+ const stop = spawnSync(process.execPath, [heartbeat, "--stop", "budget exhausted"],
98
+ { cwd: repo, encoding: "utf8", env });
99
+ assert.equal(stop.status, 0, stop.stderr);
100
+ assert.equal(existsSync(join(repo, ".fleet", "heartbeat.json")), true,
101
+ "the heartbeat did not write where this test expected — the premise is gone, not the wiring");
102
+
103
+ const build = spawnSync(process.execPath, [BOARD, "build"], { cwd: repo, encoding: "utf8", env });
104
+ assert.equal(build.status, 0, build.stderr);
105
+ const model = JSON.parse(build.stdout);
106
+ assert.ok(model.liveness, "the board found no mark — the two scripts disagree about the state file's path");
107
+ assert.equal(model.liveness.kind, "stopped");
108
+ assert.match(model.liveness.text, /recorded reason: budget exhausted/);
109
+ // The gh stub fails every read and there is no ledger file at all — both
110
+ // inputs `claimed`/`supply` derive from never actually read, so the report
111
+ // must say `unknown`, not smuggle a false "0" past a failure that never
112
+ // happened to land on a real empty state (#1732 follow-up: the old
113
+ // behaviour here silently reported "0 claimed, pool supply 0" off exactly
114
+ // this failure, indistinguishable from a genuinely empty, healthy read).
115
+ assert.equal(model.liveness.claimed, null);
116
+ assert.equal(model.liveness.supply, null);
117
+ assert.match(model.liveness.text, /unknown ticket\(s\) claimed and in flight/);
118
+ assert.match(model.liveness.text, /pool supply unknown/);
119
+ });