@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,142 @@
1
+ // The `=`-token parser (#1799, spec 2026-09-24 § 6 §2). Everything that
2
+ // derives liveness from the ledger reads a member's state off its token, so
3
+ // what this parser claims — and what it declines to claim — is the whole
4
+ // contract: a token it misreads is a member counted live forever, or a live
5
+ // one counted gone.
6
+
7
+ import { test } from "node:test";
8
+ import assert from "node:assert/strict";
9
+ import { parseToken, memberTokens, nextMergeBot } from "./ledger-grammar.mjs";
10
+
11
+ // Every outcome word the spec names, per family, verbatim — the must-ACCEPT
12
+ // half. A parser that refused everything would pass every refusal below.
13
+ const VOCABULARY = [
14
+ ["impl-412", ["PR#420", "bailed", "released", "killed", "tier-mismatch"]],
15
+ ["fix-pr-346", ["applied:73b356de", "applied:73b356de0123456789abcdef0123456789abcdef", "no-op", "failed", "killed"]],
16
+ ["finisher-pr-346", [
17
+ "labelled", "failed", "killed",
18
+ "halted:live-editor", "halted:rebase", "halted:past-pin", "halted:unreadable", "halted:missing", "halted:absent", "halted:other",
19
+ ]],
20
+ ["merge-bot-2", ["done", "killed"]],
21
+ ];
22
+
23
+ test("a bare member token is live, and names its family, number and binding", () => {
24
+ assert.deepEqual(parseToken("impl-412"), {
25
+ name: "impl-412", family: "impl", number: 412, retry: null, bound: "ticket", outcome: null, error: null,
26
+ });
27
+ assert.deepEqual(parseToken("fix-pr-346"), {
28
+ name: "fix-pr-346", family: "fix-pr", number: 346, retry: null, bound: "pr", outcome: null, error: null,
29
+ });
30
+ assert.deepEqual(parseToken("finisher-pr-346"), {
31
+ name: "finisher-pr-346", family: "finisher-pr", number: 346, retry: null, bound: "pr", outcome: null, error: null,
32
+ });
33
+ assert.deepEqual(parseToken("merge-bot-3"), {
34
+ name: "merge-bot-3", family: "merge-bot", number: 3, retry: null, bound: null, outcome: null, error: null,
35
+ });
36
+ });
37
+
38
+ // "Replacement members (`-b`) get their own token": the suffix is part of the
39
+ // name, so `impl-412-b` settles apart from `impl-412` while working the same
40
+ // ticket. `retry` carries the suffix letter on its own, so a reader ordering
41
+ // a ticket's attempts reads it here rather than re-parsing the name.
42
+ test("a replacement member's retry suffix is its own token, bound to the same number", () => {
43
+ const b = parseToken("impl-412-b");
44
+ assert.equal(b.name, "impl-412-b");
45
+ assert.equal(b.number, 412);
46
+ assert.equal(b.retry, "b");
47
+ const c = parseToken("fix-pr-346-c=no-op");
48
+ assert.equal(c.name, "fix-pr-346-c");
49
+ assert.equal(c.retry, "c");
50
+ assert.equal(parseToken("finisher-pr-346-b").family, "finisher-pr");
51
+ });
52
+
53
+ test("every outcome in the spec's vocabulary settles its own family", () => {
54
+ for (const [member, outcomes] of VOCABULARY) {
55
+ for (const outcome of outcomes) {
56
+ const t = parseToken(`${member}=${outcome}`);
57
+ assert.equal(t?.error, null, `${member}=${outcome} must parse: ${t?.error}`);
58
+ assert.equal(t.name, member);
59
+ assert.equal(t.outcome, outcome);
60
+ }
61
+ }
62
+ });
63
+
64
+ test("an outcome from another family's vocabulary, or none at all, is refused by name", () => {
65
+ const refused = [
66
+ ["impl-412=done", /expected PR#M \| bailed \| released \| killed \| tier-mismatch/],
67
+ ["impl-412=labelled", /not an outcome of impl-N/],
68
+ ["impl-412=", /'' is not an outcome of impl-N/],
69
+ ["impl-412=PR#", /not an outcome of impl-N/],
70
+ ["impl-412=#420", /not an outcome of impl-N/],
71
+ ["impl-412=PR#420=x", /not an outcome of impl-N/],
72
+ ["fix-pr-346=applied", /expected applied:<head> \| no-op \| failed \| killed/],
73
+ ["fix-pr-346=applied:", /not an outcome of fix-pr-M/],
74
+ ["fix-pr-346=applied:not-a-sha", /not an outcome of fix-pr-M/],
75
+ // The hex-length bounds themselves (7 to 40 inclusive): one hex char
76
+ // short of and one over the accepted range, so a bound loosened by one
77
+ // either way is caught rather than passing on the interior cases alone.
78
+ ["fix-pr-346=applied:abc123", /not an outcome of fix-pr-M/],
79
+ ["fix-pr-346=applied:73b356de0123456789abcdef0123456789abcdef0", /not an outcome of fix-pr-M/],
80
+ ["fix-pr-346=bailed", /not an outcome of fix-pr-M/],
81
+ ["finisher-pr-346=done", /expected labelled \| failed \| killed \| halted:<cause>/],
82
+ // #2083: a halt names one of the seven causes — a bare `halted`, an
83
+ // unknown cause, a cause with trailing text, or a cause in another case
84
+ // is not a halt the controller has a rule for.
85
+ ["finisher-pr-346=halted", /expected labelled \| failed \| killed \| halted:<cause>/],
86
+ ["finisher-pr-346=halted:", /not an outcome of finisher-pr-M/],
87
+ ["finisher-pr-346=halted:bogus", /expected labelled \| failed \| killed \| halted:<cause>/],
88
+ ["finisher-pr-346=halted:past-pin:x", /not an outcome of finisher-pr-M/],
89
+ ["finisher-pr-346=halted:Rebase", /not an outcome of finisher-pr-M/],
90
+ ["fix-pr-346=halted:rebase", /not an outcome of fix-pr-M/],
91
+ ["merge-bot-2=labelled", /expected done \| killed/],
92
+ ["merge-bot-2=PR#5", /not an outcome of merge-bot-n/],
93
+ ];
94
+ for (const [token, why] of refused) {
95
+ const t = parseToken(token);
96
+ assert.ok(t, `${token}: still a member token — its error is the answer, not silence`);
97
+ assert.match(t.error ?? "", why, `${token}: got ${JSON.stringify(t.error)}`);
98
+ }
99
+ });
100
+
101
+ // The other `=`-tokens a real row carries (`class=`, `ports=`, `ci=`, and
102
+ // #1773's `review=`/`reviewed=` pair) are not members, and neither are the
103
+ // merge bot's holds nor anything that only resembles one. Claiming any of
104
+ // them would count a phantom member live.
105
+ test("tokens that are not members are not claimed", () => {
106
+ for (const token of [
107
+ "#412", "→", "·", "PR#344", "MERGED", "73b356de", "class=routine", "ports=16324", "ci=123:1:success",
108
+ "review=wf:abc123", "review=member:review-pr-346", "reviewed=73b356de:3/1/0", "held-behind:#313",
109
+ // `conflict-hold-346` — no `#` — is the fixture that actually matters:
110
+ // it is a real CONFLICT_HOLD spelling (`#?` is optional there) AND the
111
+ // exact shape MEMBER would also accept if its family alternation ever
112
+ // grew a careless `conflict-hold` entry. The other two spellings below
113
+ // carry a literal `#` where MEMBER wants a digit, so they would stay
114
+ // unclaimed even under that mutation — this one does not.
115
+ "conflict-hold:#346", "conflict-hold-#346", "conflict-hold-346",
116
+ "ruled:6-applies", "review-pr-346", "impl", "impl-", "impl-0", "impl-0412", "impl-412x", "impl-412-bb",
117
+ "impl-412-B", "merge-bot", "merge-bot-3-b", "fix-pr-", "finisher-346",
118
+ ]) {
119
+ assert.equal(parseToken(token), null, `${token} must not parse as a member token`);
120
+ }
121
+ });
122
+
123
+ test("memberTokens reads a row's members in order and skips its free text", () => {
124
+ const row = "#324 impl-324=PR#346 → PR#346 · fix-pr-346 · class=routine · ports=16324 · ruled:6-applies · held-behind:#313";
125
+ assert.deepEqual(
126
+ memberTokens(row).map((t) => [t.name, t.outcome]),
127
+ [["impl-324", "PR#346"], ["fix-pr-346", null]],
128
+ );
129
+ assert.deepEqual(memberTokens("#7 nothing member-shaped here"), []);
130
+ });
131
+
132
+ // "n = 1 + the number of `merge-bot-` entries" — settled ones included, since
133
+ // a dead bot's replacement "gets a new n", and other families never counted.
134
+ test("nextMergeBot counts every merge-bot entry, live or settled, and nothing else", () => {
135
+ assert.equal(nextMergeBot([]), "merge-bot-1");
136
+ assert.equal(nextMergeBot(["impl-412", "fix-pr-346=no-op", "finisher-pr-346"]), "merge-bot-1");
137
+ assert.equal(nextMergeBot(["impl-412", "merge-bot-1=done", "fix-pr-346", "merge-bot-2=killed", "merge-bot-3"]), "merge-bot-4");
138
+ // A malformed entry is not a merge-bot entry, however much it starts like
139
+ // one: counting by prefix instead of by parseToken() inflated n past what
140
+ // ## Dispatched's real entries justify (measured: merge-bot-3, not -2).
141
+ assert.equal(nextMergeBot(["merge-bot-1=done", "merge-bot-2x-garbage"]), "merge-bot-2");
142
+ });
@@ -0,0 +1,197 @@
1
+ // The cockpit half of #816.
2
+ //
3
+ // `ledger.mjs read` answered an absent ledger and a real empty one identically
4
+ // — same stdout, same empty stderr, same exit 0 — and `read` is the subcommand
5
+ // board.mjs consumes. tryParse's fallback on a failed read is that same empty
6
+ // shape besides, so three distinct states (no ledger, an empty ledger, a read
7
+ // whose answer would not parse) reached the page as one empty board.
8
+ //
9
+ // ledger.test.mjs pins the CLI's half: the flag is honoured, and a real empty
10
+ // ledger is still accepted. This file pins the wiring and the rendering — that
11
+ // board.mjs actually passes the flag, that it keeps the three answers apart,
12
+ // and that the page draws two of them differently from the third.
13
+ //
14
+ // A separate file rather than more of board.test.mjs: the fleet runs several
15
+ // implementers at once and two PRs appending to one test file conflict, which
16
+ // costs the PR its CI entirely.
17
+
18
+ import { test } from "node:test";
19
+ import assert from "node:assert/strict";
20
+ import { spawnSync } from "node:child_process";
21
+ import { mkdtempSync, writeFileSync, chmodSync, readFileSync, existsSync } from "node:fs";
22
+ import { tmpdir } from "node:os";
23
+ import { join } from "node:path";
24
+ import { fileURLToPath } from "node:url";
25
+
26
+ const BOARD = fileURLToPath(new URL("./board.mjs", import.meta.url));
27
+ const REAL_SCRIPTS = fileURLToPath(new URL("./", import.meta.url));
28
+ const HTML = readFileSync(new URL("./board.html", import.meta.url), "utf8");
29
+
30
+ const EMPTY_LEDGER = "# Fleet run ledger\n\n## Rows\n\n\n## Filed\n\n\n## Ruled\n\n";
31
+
32
+ // gather() is driven out of process because it reads process.argv and would
33
+ // otherwise read the test runner's. `gh` is stubbed to fail for every read:
34
+ // those all degrade through tryRun to empty lists, they are not what this
35
+ // measures, and an unstubbed `gh` would put this repo's live issue list and the
36
+ // machine's network in the assertion path.
37
+ //
38
+ // `scriptDir` defaults to the REAL scripts directory, so the end-to-end arms
39
+ // spawn the real ledger.mjs. A stub there is free to honour a flag the real
40
+ // script ignores — which is the whole defect — so the two arms that decide
41
+ // whether the fix works must not use one.
42
+ function gatherLedger({ ledgerBody = null, scriptDir = REAL_SCRIPTS } = {}) {
43
+ const cwd = mkdtempSync(join(tmpdir(), "board-ledger-"));
44
+ const bin = mkdtempSync(join(tmpdir(), "board-ledger-bin-"));
45
+ writeFileSync(join(bin, "gh"), "#!/bin/sh\nexit 1\n");
46
+ chmodSync(join(bin, "gh"), 0o755);
47
+ const ledgerFile = join(cwd, "ledger.md");
48
+ if (ledgerBody !== null) writeFileSync(ledgerFile, ledgerBody);
49
+
50
+ const driver = `const { gather } = await import(${JSON.stringify(BOARD)});
51
+ const r = await gather({ ledgerFile: ${JSON.stringify(ledgerFile)},
52
+ scriptDir: ${JSON.stringify(scriptDir)}, interval: 15 });
53
+ console.log(JSON.stringify(r.ledger));`;
54
+ const r = spawnSync(process.execPath, ["--input-type=module", "-e", driver], {
55
+ cwd, encoding: "utf8", env: { ...process.env, PATH: `${bin}:${process.env.PATH}` },
56
+ });
57
+ assert.equal(r.status, 0, `the driver itself must not fail\n${r.stdout}${r.stderr}`);
58
+ return { ledger: JSON.parse(r.stdout.trim().split("\n").pop()), stderr: r.stderr };
59
+ }
60
+
61
+ // A stub ledger.mjs whose body is supplied per test, plus an argv sentinel so a
62
+ // test can assert what board.mjs actually spawned rather than inferring it.
63
+ function stubScripts(body) {
64
+ const dir = mkdtempSync(join(tmpdir(), "board-ledger-stub-"));
65
+ const argvFile = join(dir, "argv.txt");
66
+ writeFileSync(join(dir, "ledger.mjs"),
67
+ `import { writeFileSync } from "node:fs";\n` +
68
+ `writeFileSync(${JSON.stringify(argvFile)}, process.argv.slice(2).join("\\n"));\n${body}`);
69
+ return { scriptDir: dir, argvFile };
70
+ }
71
+
72
+ // ── the wiring ───────────────────────────────────────────────────────────────
73
+
74
+ // Without this the fix is one token from being disconnected while every state
75
+ // test below still passes: the stub's exit code decides the answer, so a
76
+ // gather() that dropped the flag would keep giving the right answer TO THE STUB
77
+ // and the wrong one to the real ledger.mjs, which is where it matters.
78
+ test("gather spawns `read` WITH --require-file (#816)", () => {
79
+ const { scriptDir, argvFile } = stubScripts(`console.log(JSON.stringify({ rows: [], filed: [], ruled: [] }));`);
80
+ gatherLedger({ scriptDir });
81
+ assert.equal(existsSync(argvFile), true, "the stub ledger was never spawned — this test measured nothing");
82
+ const argv = readFileSync(argvFile, "utf8").split("\n");
83
+ assert.ok(argv.includes("--require-file"), `board.mjs must pass the flag; got ${JSON.stringify(argv)}`);
84
+ assert.ok(argv.includes("read"), `board.mjs must still ask for read; got ${JSON.stringify(argv)}`);
85
+ });
86
+
87
+ // ── the three states, end to end against the real ledger.mjs ─────────────────
88
+
89
+ test("gather: no ledger file at all is `unread`, not an empty ledger (#816)", () => {
90
+ const { ledger } = gatherLedger({ ledgerBody: null });
91
+ assert.equal(ledger.state, "unread");
92
+ // The lists stay the shape computeBoard reads, so nothing downstream crashes
93
+ // on a state it cannot render — the state is additive, not a replacement.
94
+ assert.deepEqual({ rows: ledger.rows, filed: ledger.filed, ruled: ledger.ruled }, { rows: [], filed: [], ruled: [] });
95
+ });
96
+
97
+ // The discriminating half. These two produced identical `ledger` objects before
98
+ // the fix, which is the defect stated as an assertion: without this arm a
99
+ // gather() that reported "unread" for every ledger would pass the one above.
100
+ test("gather: a real EMPTY ledger is `read`, and still carries its empty lists (#816)", () => {
101
+ const { ledger } = gatherLedger({ ledgerBody: EMPTY_LEDGER });
102
+ assert.equal(ledger.state, "read");
103
+ assert.deepEqual({ rows: ledger.rows, filed: ledger.filed, ruled: ledger.ruled }, { rows: [], filed: [], ruled: [] });
104
+ });
105
+
106
+ test("gather: a ledger with rows is `read` and its rows arrive (#816)", () => {
107
+ const { ledger } = gatherLedger({ ledgerBody: EMPTY_LEDGER.replace("## Rows\n", "## Rows\n\n- #7 impl-7 · class=routine") });
108
+ assert.equal(ledger.state, "read");
109
+ assert.deepEqual(ledger.rows, ["#7 impl-7 · class=routine"]);
110
+ });
111
+
112
+ // The third state, which no real ledger.mjs can produce on demand — a stub is
113
+ // the only way to hand board.mjs stdout that arrives at exit 0 and will not
114
+ // parse. That is board.mjs's own branch under test, not ledger.mjs's flag.
115
+ test("gather: stdout that will not parse is `unparsed`, not `unread` and not an empty ledger (#816)", () => {
116
+ const { scriptDir } = stubScripts(`console.log("warning: something\\n{\\"rows\\": [");`);
117
+ const { ledger, stderr } = gatherLedger({ scriptDir });
118
+ assert.equal(ledger.state, "unparsed");
119
+ assert.deepEqual({ rows: ledger.rows, filed: ledger.filed, ruled: ledger.ruled }, { rows: [], filed: [], ruled: [] });
120
+ assert.match(stderr, /ledger read parse failed/, "a failed parse must still say so on stderr");
121
+ });
122
+
123
+ // A refusal and an unreachable node arrive the same way — no usable stdout —
124
+ // and both mean the same thing to the page: this board was not built from a
125
+ // ledger. The distinction that matters is against `read`, not between them.
126
+ test("gather: a non-zero exit from ledger.mjs is `unread` (#816)", () => {
127
+ const { scriptDir } = stubScripts(`process.exit(2);`);
128
+ assert.equal(gatherLedger({ scriptDir }).ledger.state, "unread");
129
+ });
130
+
131
+ // ── the rendering ────────────────────────────────────────────────────────────
132
+ //
133
+ // board.html is served as one self-contained file with an inline script, so the
134
+ // decision is lifted out of its source text and evaluated, the same technique
135
+ // spend-view.test.mjs uses. The declaration-count guard comes first: a second
136
+ // top-level declaration wins at runtime by hoisting and the lift below would
137
+ // still read the first one.
138
+
139
+ test("board.html declares ledgerBanner exactly once at top level", () => {
140
+ assert.equal(HTML.match(/^function\s+ledgerBanner\s*\(/gm)?.length, 1,
141
+ "ledgerBanner must be declared exactly once — a second declaration wins at runtime and the lift below would still read the first");
142
+ });
143
+
144
+ const BANNER_SRC = HTML.match(/^function\s+ledgerBanner\s*\(\w+\)\s*\{[\s\S]*?^\}$/m);
145
+
146
+ test("board.html still declares ledgerBanner in the shape this file lifts", () => {
147
+ // Named and outside the lift: an assertion thrown during the lift itself runs
148
+ // before node registers any test in this file, which reports one opaque
149
+ // file-level error instead of naming the claim that stopped holding.
150
+ assert.ok(BANNER_SRC, "board.html no longer declares ledgerBanner as a top-level function — update this test");
151
+ });
152
+
153
+ const ledgerBanner = BANNER_SRC
154
+ ? new Function(`${BANNER_SRC[0]}\nreturn ledgerBanner;`)()
155
+ : () => { throw new Error("ledgerBanner could not be lifted from board.html — see the shape test above"); };
156
+
157
+ test("ledgerBanner draws the two failure states differently from each other (#816)", () => {
158
+ const unread = ledgerBanner("unread");
159
+ const unparsed = ledgerBanner("unparsed");
160
+ assert.ok(unread, "an unread ledger must say so");
161
+ assert.ok(unparsed, "an unparseable ledger must say so");
162
+ // Two banners with the same words are one rendering wearing two names, which
163
+ // is the defect this ticket is about.
164
+ assert.notEqual(unread, unparsed, "the two failures must not render as the same message");
165
+ });
166
+
167
+ test("ledgerBanner stays silent for a ledger that was read (#816)", () => {
168
+ // The accept side. A run that has just started has an empty ledger and no
169
+ // rows, and a warning on every first tick trains the operator to ignore this
170
+ // strip — which would cost the two messages above their whole point.
171
+ assert.equal(ledgerBanner("read"), null, "a ledger read empty is the ordinary state, not a warning");
172
+ assert.equal(ledgerBanner(undefined), null, "a board.json written before this field existed must not warn either");
173
+ });
174
+
175
+ // The call site. Without this the whole decision can be disconnected in one
176
+ // token and every case above still passes against a function the page never
177
+ // calls — and the ordering claim is the other half: a stale board is stale
178
+ // whatever its ledger state, so the ledger message must not preempt it.
179
+ test("board.html routes the freshness banner through ledgerBanner, with stale still first (#816)", () => {
180
+ const render = HTML.match(/^function\s+render\s*\((\w+)\)\s*\{[\s\S]*?^\}$/m);
181
+ assert.ok(render, "board.html no longer declares render as a top-level function — update this test");
182
+ const body = render[0].split("\n").filter((l) => !/^\s*\/\//.test(l)).join("\n");
183
+ assert.match(body, /=\s*ledgerBanner\(\w+\.ledgerState\)/, "render must call ledgerBanner with the model's ledgerState");
184
+ // #1597 put a third arm between the two this pin was written for, and a
185
+ // non-greedy `else if` after "data stale" would happily match THAT one and
186
+ // go on reading like it still proved the ledger's position. So the order is
187
+ // asserted by INDEX over the whole chain rather than by one adjacency: a
188
+ // stale board is stale whatever else is true, a dead run outranks a
189
+ // degraded read of one input, and neither may hide the other.
190
+ const stale = body.indexOf("data stale");
191
+ const stall = body.search(/else if \(stallMsg\)/);
192
+ const ledger = body.search(/else if \(ledgerMsg\)/);
193
+ assert.ok(stale !== -1 && stall !== -1 && ledger !== -1,
194
+ "board.html no longer renders all three banner arms — update this test");
195
+ assert.ok(stale < stall, "a stale board must outrank the liveness stall it can no longer vouch for");
196
+ assert.ok(stall < ledger, "a stopped run must outrank a degraded read of one of its inputs");
197
+ });