@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,1060 @@
1
+ // Regression gate for the pure board core. Zero deps:
2
+ // node --test plugin/scripts/compute-board.test.mjs
3
+ // Locks stage-derivation and the red-vs-stale distinction — the only tricky
4
+ // logic — against a "simplification" silently breaking it.
5
+ import { test } from "node:test";
6
+ import assert from "node:assert/strict";
7
+ import { parseRow, deriveColumn, deriveFlags, STALE_MS } from "./compute-board.mjs";
8
+
9
+ test("parseRow: a merged row", () => {
10
+ const r = parseRow("#332 impl-332=PR#344 → PR#344 → MERGED 73b356de");
11
+ assert.equal(r.issue, 332);
12
+ assert.equal(r.impl, "impl-332");
13
+ assert.equal(r.pr, 344);
14
+ assert.equal(r.merged, true);
15
+ assert.equal(r.sha, "73b356de");
16
+ assert.equal(r.agent, null, "impl-332 settled at PR#344 — nobody is live on this row");
17
+ assert.equal(r.heldBehind, null);
18
+ });
19
+
20
+ test("parseRow: an in-review row with a live review runner, ruling and held-behind", () => {
21
+ const r = parseRow("#324 impl-324=PR#346 → PR#346 · review=member:review-pr-346-b · ports=16324 · ruled:6-applies · held-behind:#313");
22
+ assert.equal(r.issue, 324);
23
+ assert.equal(r.impl, "impl-324");
24
+ assert.equal(r.agent, "review-pr-346-b");
25
+ assert.equal(r.pr, 346);
26
+ assert.equal(r.merged, false);
27
+ assert.equal(r.heldBehind, 313);
28
+ });
29
+
30
+ test("parseRow: implementing row, no PR yet", () => {
31
+ const r = parseRow("#340 impl-340");
32
+ assert.equal(r.pr, null);
33
+ assert.equal(r.merged, false);
34
+ assert.deepEqual(r.causes, []);
35
+ });
36
+
37
+ test("parseRow: enrichment cause tokens are lowercased", () => {
38
+ const r = parseRow("#319 impl-319 KILLED");
39
+ assert.deepEqual(r.causes, ["killed"]);
40
+ });
41
+
42
+ test("parseRow: a non-ticket line returns null", () => {
43
+ assert.equal(parseRow("## Rows"), null);
44
+ });
45
+
46
+ test("deriveColumn: MERGED wins from the ledger alone", () => {
47
+ const p = parseRow("#332 impl-332=PR#344 → PR#344 → MERGED 73b356de");
48
+ assert.equal(deriveColumn(p, { open: false, labels: [] }), "MERGED");
49
+ });
50
+
51
+ test("deriveColumn: READY when the PR carries ready-to-merge", () => {
52
+ const p = parseRow("#324 impl-324=PR#346 → PR#346 · review=member:review-pr-346");
53
+ assert.equal(deriveColumn(p, { open: true, labels: ["ready-to-merge"] }), "READY");
54
+ });
55
+
56
+ test("deriveColumn: REVIEW when a PR exists without the label", () => {
57
+ const p = parseRow("#324 impl-324=PR#346 → PR#346 · review=member:review-pr-346");
58
+ assert.equal(deriveColumn(p, { open: true, labels: [] }), "REVIEW");
59
+ });
60
+
61
+ test("deriveColumn: IMPLEMENTING when there is no PR yet", () => {
62
+ const p = parseRow("#340 impl-340");
63
+ assert.equal(deriveColumn(p, null), "IMPLEMENTING");
64
+ });
65
+
66
+ const MIN = 60 * 1000;
67
+
68
+ test("deriveFlags: red CI flags red-ci", () => {
69
+ const p = parseRow("#324 impl-324=PR#346 → PR#346");
70
+ const f = deriveFlags(p, { ci: "red", column: "REVIEW", sinceEnteredStage: null, now: 0 });
71
+ assert.ok(f.includes("red-ci"));
72
+ });
73
+
74
+ test("deriveFlags: unknown CI never flags red", () => {
75
+ const p = parseRow("#324 impl-324=PR#346 → PR#346");
76
+ const f = deriveFlags(p, { ci: "unknown", column: "REVIEW", sinceEnteredStage: null, now: 0 });
77
+ assert.ok(!f.includes("red-ci"));
78
+ });
79
+
80
+ test("deriveFlags: held-behind carries the blocker number", () => {
81
+ const p = parseRow("#324 impl-324=PR#346 → PR#346 · held-behind:#313");
82
+ const f = deriveFlags(p, { ci: "green", column: "REVIEW", sinceEnteredStage: null, now: 0 });
83
+ assert.ok(f.includes("held-behind:#313"));
84
+ });
85
+
86
+ test("deriveFlags: stale when dwell exceeds the column threshold", () => {
87
+ const p = parseRow("#340 impl-340");
88
+ const now = 100 * MIN;
89
+ const f = deriveFlags(p, { ci: null, column: "IMPLEMENTING", sinceEnteredStage: now - (STALE_MS.IMPLEMENTING + MIN), now });
90
+ assert.ok(f.includes("stale"));
91
+ });
92
+
93
+ test("deriveFlags: fresh dwell is not stale", () => {
94
+ const p = parseRow("#340 impl-340");
95
+ const now = 100 * MIN;
96
+ const f = deriveFlags(p, { ci: null, column: "IMPLEMENTING", sinceEnteredStage: now - MIN, now });
97
+ assert.ok(!f.includes("stale"));
98
+ });
99
+
100
+ test("deriveFlags: cause tokens surface as flags", () => {
101
+ const p = parseRow("#319 impl-319 KILLED");
102
+ const f = deriveFlags(p, { ci: null, column: "IMPLEMENTING", sinceEnteredStage: 0, now: 0 });
103
+ assert.ok(f.includes("killed"));
104
+ });
105
+
106
+ import { computeBoard, mergedReadPrs } from "./compute-board.mjs";
107
+ import { deriveRun } from "./fleet-tick.mjs";
108
+
109
+ const baseInputs = () => ({
110
+ ledger: {
111
+ rows: [
112
+ "#332 impl-332=PR#344 → PR#344 → MERGED 73b356de",
113
+ "#324 impl-324=PR#346 → PR#346 · review=member:review-pr-346 · held-behind:#313",
114
+ "#340 impl-340",
115
+ ],
116
+ filed: ["#351 flaky retry marker in ci logs"],
117
+ ruled: ["#346 6-applies keep the fallback"],
118
+ },
119
+ issues: [{ number: 341, title: "add a --json flag", labels: ["ready-for-agent"] }],
120
+ prs: [
121
+ { number: 344, state: "MERGED", labels: [], title: "impl 332" },
122
+ { number: 346, state: "OPEN", labels: [], title: "impl 324" },
123
+ ],
124
+ ci: { 344: "green", 346: "red" },
125
+ prev: null,
126
+ now: 1000,
127
+ repo: "owner/repo",
128
+ repoUrl: "https://example.test/owner/repo",
129
+ workspace: "/w/one",
130
+ port: 8337,
131
+ });
132
+
133
+ test("computeBoard: one ticket per column, POOL from an unrowed ready issue", () => {
134
+ const b = computeBoard(baseInputs());
135
+ const col = (n) => b.tickets.find((t) => t.issue === n).column;
136
+ assert.equal(col(332), "MERGED");
137
+ assert.equal(col(324), "REVIEW");
138
+ assert.equal(col(340), "IMPLEMENTING");
139
+ assert.equal(col(341), "POOL");
140
+ });
141
+
142
+ // #1331: candidates.mjs's EXCLUDE negates all five wayfinder:* labels so a
143
+ // wayfinder ticket never enters the DISPATCH scan regardless of triage role,
144
+ // but the POOL loop below used to show one anyway — a ready-for-agent
145
+ // wayfinder ticket (#1293's shape) rendered as an undispatchable POOL card,
146
+ // inflating the operator's read of available work. Filtered by label prefix
147
+ // here, in the POOL loop itself, not by narrowing gather()'s gh query —
148
+ // narrowing the query also strips the ticket from `issues`, which titleFor()
149
+ // below reads for ledger rows that have nothing to do with POOL (see the next
150
+ // test).
151
+ test("computeBoard: an unrowed wayfinder:* issue never becomes a POOL card", () => {
152
+ const b = computeBoard({
153
+ ...baseInputs(),
154
+ issues: [{ number: 341, title: "add a --json flag", labels: ["ready-for-agent", "wayfinder:task"] }],
155
+ });
156
+ assert.equal(b.tickets.find((t) => t.issue === 341), undefined);
157
+ });
158
+
159
+ // The fix for the regression above must not reach into gather()'s gh query:
160
+ // doing so also drops the wayfinder-labelled issue from `issues`, which
161
+ // titleFor() reads for every non-PR ledger row (e.g. #340, IMPLEMENTING, no
162
+ // PR yet) whose issue happens to carry a wayfinder label for an unrelated
163
+ // reason. Losing that lookup regresses #340's card to a bare `#340` even
164
+ // though only the POOL column was ever supposed to change.
165
+ test("computeBoard: a ledger-row ticket linked to a wayfinder-labelled issue keeps its real title", () => {
166
+ const b = computeBoard({
167
+ ...baseInputs(),
168
+ issues: [
169
+ { number: 341, title: "add a --json flag", labels: ["ready-for-agent"] },
170
+ { number: 340, title: "real ledger-row title", labels: ["wayfinder:task"] },
171
+ ],
172
+ });
173
+ assert.equal(b.tickets.find((t) => t.issue === 340).title, "real ledger-row title");
174
+ });
175
+
176
+ // #786 review: board.mjs used to default a PR row's missing `state` to
177
+ // "UNKNOWN" before handing it here. That default was inert — `pr.state ===
178
+ // "OPEN"` (below) is already false for `undefined`, same as for "UNKNOWN" —
179
+ // so board.mjs now passes `state` through raw. Pin the OBSERVABLE effect
180
+ // rather than the internal sentinel value: a PR row with no `state` at all
181
+ // still lands in REVIEW like any other open-PR ticket, not crashed or
182
+ // silently misplaced by the missing field.
183
+ test("computeBoard: a PR row with no state still lands in REVIEW", () => {
184
+ const b = computeBoard({
185
+ ...baseInputs(),
186
+ prs: [{ number: 344, labels: [], title: "impl 332" }],
187
+ ledger: { rows: ["#332 impl-332=PR#344 → PR#344"], filed: [], ruled: [] },
188
+ });
189
+ assert.equal(b.tickets.find((t) => t.issue === 332).column, "REVIEW");
190
+ });
191
+
192
+ test("computeBoard: ruling attaches to the PR ticket", () => {
193
+ const b = computeBoard(baseInputs());
194
+ assert.equal(b.tickets.find((t) => t.issue === 324).ruling, "6-applies keep the fallback");
195
+ });
196
+
197
+ test("computeBoard: attention holds only flagged tickets, red-ci before held-behind", () => {
198
+ const b = computeBoard(baseInputs());
199
+ assert.deepEqual(b.attention.map((t) => t.issue), [324]); // red-ci + held-behind
200
+ assert.ok(b.attention[0].flags.includes("red-ci"));
201
+ });
202
+
203
+ test("computeBoard: filed follow-ups are parsed to {issue,subject}", () => {
204
+ const b = computeBoard(baseInputs());
205
+ assert.deepEqual(b.filed, [{ issue: 351, subject: "flaky retry marker in ci logs" }]);
206
+ });
207
+
208
+ test("computeBoard: dwell carries forward while the column is unchanged", () => {
209
+ const first = computeBoard({ ...baseInputs(), now: 1000 });
210
+ const second = computeBoard({ ...baseInputs(), prev: first, now: 5000 });
211
+ // #340 stayed IMPLEMENTING → keep the original entry time
212
+ assert.equal(second.tickets.find((t) => t.issue === 340).sinceEnteredStage, 1000);
213
+ });
214
+
215
+ test("computeBoard: dwell resets when the column changes", () => {
216
+ const first = computeBoard({ ...baseInputs(), now: 1000 });
217
+ const moved = baseInputs();
218
+ moved.ledger.rows[2] = "#340 impl-340=PR#360 → PR#360"; // now REVIEW
219
+ moved.prs.push({ number: 360, state: "OPEN", labels: [], title: "impl 340" });
220
+ const second = computeBoard({ ...moved, prev: first, now: 5000 });
221
+ assert.equal(second.tickets.find((t) => t.issue === 340).sinceEnteredStage, 5000);
222
+ });
223
+
224
+ test("computeBoard: queue counts pool and review-backlog", () => {
225
+ const b = computeBoard(baseInputs());
226
+ assert.equal(b.queue.pool, 1);
227
+ // #324 has a reviewer token, so it is NOT backlog
228
+ assert.equal(b.queue.reviewBacklog, 0);
229
+ });
230
+
231
+ test("computeBoard: the instance identity — repo, repoUrl, workspace, port — is echoed, never derived", () => {
232
+ const b = computeBoard(baseInputs());
233
+ assert.equal(b.repo, "owner/repo");
234
+ assert.equal(b.repoUrl, "https://example.test/owner/repo");
235
+ // #1584: gather() joins these from resolveCockpitInstance(); this module
236
+ // reads no cwd, no git and no socket, so an echo is the whole contract.
237
+ assert.equal(b.workspace, "/w/one");
238
+ assert.equal(b.port, 8337);
239
+ });
240
+
241
+ // A caller with no instance to name — every hand-built inputs object, and the
242
+ // gather() drivers in board-prev-shape.test.mjs — must still produce a board
243
+ // carrying both KEYS. `undefined` disappears from JSON.stringify, and the
244
+ // launch handshake #1585 added reads `workspace` straight off the served
245
+ // JSON: a board with the key missing is a board it can never match.
246
+ test("computeBoard: absent workspace/port are null, not missing keys", () => {
247
+ const inp = baseInputs();
248
+ delete inp.workspace;
249
+ delete inp.port;
250
+ const b = computeBoard(inp);
251
+ assert.equal(b.workspace, null);
252
+ assert.equal(b.port, null);
253
+ });
254
+
255
+ test("computeBoard: a PR with no CI entry is unknown, not null (null means no PR)", () => {
256
+ const inp = baseInputs();
257
+ delete inp.ci[346]; // #324's PR exists but CI has not reported
258
+ const t = computeBoard(inp).tickets.find((x) => x.issue === 324);
259
+ assert.equal(t.ci, "unknown");
260
+ // a genuinely PR-less ticket still reports null
261
+ assert.equal(computeBoard(inp).tickets.find((x) => x.issue === 340).ci, null);
262
+ });
263
+
264
+ test("computeBoard: ledgerState reflects gather()'s read outcome", () => {
265
+ for (const state of ["unread", "unparsed", "read"]) {
266
+ const inp = baseInputs();
267
+ inp.ledger = { ...inp.ledger, state };
268
+ assert.equal(computeBoard(inp).ledgerState, state);
269
+ }
270
+ });
271
+
272
+ test("computeBoard: ledgerState defaults to read when gather() reports none", () => {
273
+ const inp = baseInputs(); // ledger has no `state` key
274
+ assert.equal(computeBoard(inp).ledgerState, "read");
275
+ });
276
+
277
+ // --------------------------------------------------------------------------
278
+ // The liveness surface — #1597. `beat` is telemetry beside `spend`, under the
279
+ // same rule: it can only ever POPULATE or OMIT `liveness`, never move a
280
+ // ticket. The cockpit is one renderer of the heartbeat's mark, never the
281
+ // thing that holds it.
282
+
283
+ // `now` in baseInputs is 1000ms past the epoch, which is a fine clock for
284
+ // dwell but useless for an age in minutes — so the liveness cases move it
285
+ // somewhere a 20-minute-old mark can exist behind it.
286
+ const NOW = 2_000_000_000_000;
287
+ const livenessInputs = (beat) => ({ ...baseInputs(), now: NOW, beat });
288
+
289
+ test("computeBoard: a stalled beat populates `liveness` with what is stranded", () => {
290
+ const b = computeBoard(livenessInputs({ at: NOW - 90 * 60_000, interval: 1200, stopped: "" }));
291
+ assert.equal(b.liveness.kind, "stale");
292
+ // Counted off THIS model rather than re-queried: a ticket past POOL and
293
+ // short of MERGED is one the ledger placed and nothing landed — the same
294
+ // population the claim label marks, reached from the ledger the cockpit
295
+ // already read. #324 (REVIEW) and #340 (IMPLEMENTING); #332 merged, #341 is
296
+ // still pool.
297
+ assert.equal(b.liveness.claimed, 2);
298
+ assert.equal(b.liveness.supply, b.queue.pool);
299
+ // The rendered line rides the payload because board.html is served as one
300
+ // self-contained file and cannot import the rule. A second wording on the
301
+ // page is a second answer to "is this run dead".
302
+ assert.match(b.liveness.text, /heartbeat STALLED/);
303
+ assert.match(b.liveness.text, /2 ticket\(s\) claimed and in flight/);
304
+ assert.match(b.liveness.text, /70m past the 20m interval it promised/);
305
+ });
306
+
307
+ test("computeBoard: a failed ledger or pool read reports `unknown`, never a false zero", () => {
308
+ // #1597 follow-up. `claimed`/`supply` derive from `ledger.rows`/`issues`,
309
+ // which both collapse to the SAME empty array on a genuinely-drained read
310
+ // and on a failed one (gather()'s tryRun/tryParse fallback) — the exact
311
+ // collapse `ledgerState` exists to undo elsewhere on this same board. A
312
+ // stall banner that quietly prints "0 claimed, pool supply 0" off a read
313
+ // that never happened is the one report an operator has no reason to
314
+ // distrust, and it also outranks and hides the ledger-read-failed banner
315
+ // that would have explained the zeros.
316
+ const stale = { at: NOW - 90 * 60_000, interval: 1200, stopped: "" };
317
+
318
+ // Ledger read failed — the ticket-derived half must go unknown, and the
319
+ // pool half, which never depended on the ledger, must stay a real count.
320
+ const noLedger = computeBoard({
321
+ ...livenessInputs(stale), ledger: { rows: [], filed: [], ruled: [], state: "unread" },
322
+ });
323
+ assert.equal(noLedger.liveness.claimed, null);
324
+ assert.equal(noLedger.liveness.supply, noLedger.queue.pool);
325
+ assert.match(noLedger.liveness.text, /unknown ticket\(s\) claimed and in flight/);
326
+
327
+ // Pool read failed — the reverse split.
328
+ const noPool = computeBoard({ ...livenessInputs(stale), poolOk: false });
329
+ assert.equal(noPool.liveness.claimed, 2);
330
+ assert.equal(noPool.liveness.supply, null);
331
+ assert.match(noPool.liveness.text, /pool supply unknown/);
332
+
333
+ // Both failed at once.
334
+ const both = computeBoard({
335
+ ...livenessInputs(stale), ledger: { rows: [], filed: [], ruled: [], state: "unparsed" }, poolOk: false,
336
+ });
337
+ assert.equal(both.liveness.claimed, null);
338
+ assert.equal(both.liveness.supply, null);
339
+
340
+ // A read that genuinely succeeded and came back empty is still a real 0,
341
+ // never smuggled into `unknown` by an over-broad guard.
342
+ const emptyOk = computeBoard({
343
+ ...livenessInputs(stale), ledger: { rows: [], filed: [], ruled: [], state: "read" },
344
+ });
345
+ assert.equal(emptyOk.liveness.claimed, 0);
346
+ });
347
+
348
+ test("#2108: a capped pool read reaches the stall line as a floor, the same value the footer shows", () => {
349
+ // stall() is handed the model's pool, so the line cannot print a bare count
350
+ // the footer beside it has already retracted with a `+`.
351
+ const stale = { at: NOW - 90 * 60_000, interval: 1200, stopped: "" };
352
+ const b = computeBoard({ ...livenessInputs(stale), poolCapped: true });
353
+ assert.equal(b.queue.pool, "1+");
354
+ assert.equal(b.liveness.supply, "1+");
355
+ assert.match(b.liveness.text, /pool supply 1\+/);
356
+ });
357
+
358
+ test("computeBoard: a healthy or absent beat omits the surface rather than rendering an empty one", () => {
359
+ // Null, not an `{ ok: true }`-shaped nothing: the page hides the banner on
360
+ // null, and a banner that fires on every healthy tick is a banner the
361
+ // operator learns to read past — which would cost exactly the one night it
362
+ // was built for.
363
+ assert.equal(computeBoard(livenessInputs({ at: NOW - 60_000, interval: 300, stopped: "" })).liveness, null);
364
+ assert.equal(computeBoard(livenessInputs(null)).liveness, null);
365
+ // And a caller that passes no `beat` at all — every hand-built test driver,
366
+ // and any board.json written before this key existed — gets the same null
367
+ // rather than a crash or an undefined key.
368
+ const inp = baseInputs();
369
+ delete inp.beat;
370
+ assert.equal(computeBoard(inp).liveness, null);
371
+ });
372
+
373
+ test("computeBoard: a deliberate stop reaches the page with its reason", () => {
374
+ const b = computeBoard(livenessInputs({ at: NOW - 60_000, interval: 300, stopped: "budget exhausted" }));
375
+ assert.equal(b.liveness.kind, "stopped");
376
+ assert.match(b.liveness.text, /recorded reason: budget exhausted/);
377
+ });
378
+
379
+ test("computeBoard: a liveness input can never change a ticket's stage", () => {
380
+ // The constraint the ticket states in its own words, and the one a
381
+ // populate/omit assertion alone would not catch: a stall must not flag,
382
+ // re-column, re-dwell or promote anything. The dead controller is the
383
+ // reason nobody is moving the tickets; it is not itself a ticket movement.
384
+ const quiet = computeBoard(livenessInputs(null));
385
+ for (const beat of [
386
+ { at: NOW - 90 * 60_000, interval: 1200, stopped: "" },
387
+ { at: NOW - 60_000, interval: 300, stopped: "budget exhausted" },
388
+ { at: NOW - 60_000, interval: 300, stopped: "" },
389
+ ]) {
390
+ const b = computeBoard(livenessInputs(beat));
391
+ assert.deepEqual(b.tickets, quiet.tickets, "a liveness input moved a ticket");
392
+ assert.deepEqual(b.attention, quiet.attention, "a liveness input raised an attention row");
393
+ assert.deepEqual(b.queue, quiet.queue, "a liveness input changed the queue counts");
394
+ }
395
+ });
396
+
397
+ // --------------------------------------------------------------------------
398
+ // #1820: the Pull-era ledger. The rows below are #1820's own reproduction
399
+ // rows, verbatim, measured on main @ 9b147b2 as stale IMPLEMENTING/REVIEW
400
+ // cards that all counted in the stall report's `claimed`. PRs 920, 931 and
401
+ // 932 are open; 930 is not in the open list, and gh reports it merged.
402
+ const REPRO_ROWS = [
403
+ "#901 excluded · behind-pr:#880",
404
+ "#902 excluded · behind-issue:#870",
405
+ "#903 impl-903=bailed",
406
+ "#904 impl-904=killed",
407
+ "#905 impl-905=PR#920 · fix-pr-920=failed",
408
+ "#906 impl-906",
409
+ "#907 impl-907=PR#930",
410
+ "#908 impl-908=PR#931 · review=wf:r123",
411
+ "#909 impl-909=PR#932 · review=member:review-pr-932",
412
+ ];
413
+ const openPr = (number, labels = [], headRefOid = null) => ({ number, state: "OPEN", labels, title: `pr ${number}`, headRefOid });
414
+ const HOUR = 60 * MIN;
415
+ // A prior stage entry 1 h old for every row, in the column each row showed on
416
+ // main — the measurement's setup, so every non-terminal card is past its
417
+ // dwell threshold and any `stale` a card should not carry would show.
418
+ const reproInputs = (over = {}) => {
419
+ const now = 10 * HOUR;
420
+ const rows = over.rows ?? REPRO_ROWS;
421
+ const was = (n) => ([905, 907, 908, 909].includes(n) ? "REVIEW" : "IMPLEMENTING");
422
+ return {
423
+ ...baseInputs(),
424
+ ledger: { rows, filed: [], ruled: [] },
425
+ issues: [],
426
+ prs: [openPr(920), openPr(931), openPr(932)],
427
+ merged: [930],
428
+ ci: {},
429
+ prev: { tickets: rows.map((r) => Number(r.slice(1).split(" ")[0])).map((issue) => ({ issue, column: was(issue), sinceEnteredStage: now - HOUR })) },
430
+ now,
431
+ ...over,
432
+ };
433
+ };
434
+ const card = (b, n) => b.tickets.find((t) => t.issue === n);
435
+
436
+ test("#1820: an Exclusion is a POOL card with its premise as a badge — never stale, never in attention", () => {
437
+ const b = computeBoard(reproInputs());
438
+ for (const [n, badge] of [[901, "excluded:#880"], [902, "excluded:#870"]]) {
439
+ assert.equal(card(b, n).column, "POOL");
440
+ assert.deepEqual(card(b, n).flags, [badge]);
441
+ assert.equal(card(b, n).agent, null);
442
+ assert.ok(!b.attention.some((t) => t.issue === n), `#${n} is supply, not a stranded claim`);
443
+ }
444
+ assert.equal(b.queue.pool, 2, "both Exclusions count as pool supply");
445
+ assert.equal(b.queue.supply, 2);
446
+ });
447
+
448
+ test("#1820: a branch-named behind-pr premise is its own badge, not a number", () => {
449
+ // Live-ledger shape: the premise is the branch name recorded before its PR existed.
450
+ const b = computeBoard(reproInputs({ rows: ["#1716 excluded · behind-pr:implementer/1715-impl-1715", "#1717 excluded · behind-pr:#implementer/1690-slug"] }));
451
+ assert.deepEqual(card(b, 1716).flags, ["excluded:implementer/1715-impl-1715"]);
452
+ assert.deepEqual(card(b, 1717).flags, ["excluded:implementer/1690-slug"]);
453
+ assert.equal(card(b, 1716).column, "POOL");
454
+ });
455
+
456
+ test("#1820: `excluded` only as the row's first word makes an Exclusion", () => {
457
+ const b = computeBoard(reproInputs({ rows: ["#1705 impl-1705 · previously excluded · behind-pr:#60"] }));
458
+ assert.equal(card(b, 1705).column, "IMPLEMENTING");
459
+ assert.equal(card(b, 1705).agent, "impl-1705");
460
+ assert.ok(!card(b, 1705).flags.some((f) => f.startsWith("excluded")));
461
+ });
462
+
463
+ test("#1820: a released or bailed implementer is a POOL card while ready-for-agent, else no card", () => {
464
+ const gone = computeBoard(reproInputs());
465
+ assert.equal(card(gone, 903), undefined, "#903 bailed and left the ready-for-agent list — relabelled out by cause");
466
+ const rows = ["#903 impl-903=bailed", "#910 impl-910=released"];
467
+ const back = computeBoard(reproInputs({
468
+ rows,
469
+ issues: [{ number: 903, title: "t903", labels: ["ready-for-agent"] }, { number: 910, title: "t910", labels: ["ready-for-agent"] }],
470
+ }));
471
+ for (const n of [903, 910]) {
472
+ assert.equal(card(back, n).column, "POOL");
473
+ assert.deepEqual(card(back, n).flags, []);
474
+ }
475
+ assert.equal(back.tickets.length, 2, "one card per ticket, not a row card beside the pool card");
476
+ });
477
+
478
+ test("#1820: a killed or tier-mismatch implementer stays IMPLEMENTING, flagged in attention", () => {
479
+ const b = computeBoard(reproInputs({ rows: ["#904 impl-904=killed", "#911 impl-911=tier-mismatch"] }));
480
+ assert.equal(card(b, 904).column, "IMPLEMENTING");
481
+ assert.ok(card(b, 904).flags.includes("killed"));
482
+ assert.equal(card(b, 911).column, "IMPLEMENTING");
483
+ assert.ok(card(b, 911).flags.includes("tier-mismatch"));
484
+ assert.deepEqual(b.attention.map((t) => t.issue).sort(), [904, 911]);
485
+ assert.equal(card(b, 904).agent, null, "a settled member is not live");
486
+ });
487
+
488
+ test("#1820: the uppercase enrichment causes keep working, and KILLED beside =killed flags once", () => {
489
+ const b = computeBoard(reproInputs({ rows: ["#912 impl-912 BLOCKED", "#913 impl-913=PR#931 SHA-OFF-BRANCH", "#914 impl-914=killed KILLED"] }));
490
+ assert.ok(card(b, 912).flags.includes("blocked"));
491
+ assert.ok(card(b, 913).flags.includes("sha-off-branch"));
492
+ assert.equal(card(b, 914).flags.filter((f) => f === "killed").length, 1);
493
+ });
494
+
495
+ test("#1820: the row's LAST impl token decides, retry suffix included", () => {
496
+ const b = computeBoard(reproInputs({
497
+ rows: ["#915 impl-915=killed · impl-915-b", "#916 impl-916=bailed · impl-916-b=PR#931", "#917 impl-917=PR#920 · impl-917-b"],
498
+ }));
499
+ assert.equal(card(b, 915).column, "IMPLEMENTING");
500
+ assert.equal(card(b, 915).agent, "impl-915-b");
501
+ assert.ok(!card(b, 915).flags.includes("killed"), "the killed attempt was replaced");
502
+ assert.equal(card(b, 916).column, "REVIEW");
503
+ assert.equal(card(b, 916).pr, 931);
504
+ assert.equal(card(b, 917).column, "IMPLEMENTING", "a live retry after a settled PR is back at work");
505
+ assert.equal(card(b, 917).pr, null);
506
+ });
507
+
508
+ // #1843: the deciding impl token is the one with the greatest retry suffix,
509
+ // wherever it sits in the row. ledger.mjs appends in retry order, so only a
510
+ // hand-written `row` rewrite reorders them — and every ordering of the same
511
+ // tokens must render the same card. No `prev`, so no card is stale and
512
+ // `attention` holds only what the tokens themselves earn.
513
+ const permutations = (xs) => (xs.length <= 1 ? [xs]
514
+ : xs.flatMap((x, i) => permutations([...xs.slice(0, i), ...xs.slice(i + 1)]).map((rest) => [x, ...rest])));
515
+ const cardFor = (row, n) => {
516
+ const b = computeBoard(reproInputs({ rows: [row], prev: { tickets: [] } }));
517
+ return { card: card(b, n), attention: b.attention.map((t) => t.issue) };
518
+ };
519
+
520
+ test("#1843: a replacement written before its predecessor still decides the card", () => {
521
+ for (const row of ["#5 impl-5-b · class=routine · impl-5=killed", "#5 impl-5=killed · class=routine · impl-5-b"]) {
522
+ assert.equal(parseRow(row).impl, "impl-5-b", row);
523
+ const { card: c, attention } = cardFor(row, 5);
524
+ assert.equal(c.column, "IMPLEMENTING", row);
525
+ assert.equal(c.agent, "impl-5-b", row);
526
+ assert.deepEqual(c.flags, [], `${row}: the killed attempt was replaced`);
527
+ assert.deepEqual(attention, [], row);
528
+ }
529
+ });
530
+
531
+ test("#1843: the greatest retry suffix decides in every ordering of a row's impl tokens", () => {
532
+ const rows = permutations(["impl-5=killed", "impl-5-b=PR#9", "impl-5-c"]).map((p) => `#5 ${p.join(" · ")}`);
533
+ for (const row of rows) {
534
+ assert.equal(parseRow(row).impl, "impl-5-c", row);
535
+ assert.deepEqual(cardFor(row, 5), cardFor(rows[0], 5), row);
536
+ }
537
+ const { card: c } = cardFor(rows[0], 5);
538
+ assert.equal(c.column, "IMPLEMENTING", "impl-5-c is live, back at work after PR#9");
539
+ assert.equal(c.pr, null);
540
+ assert.deepEqual(c.flags, []);
541
+ });
542
+
543
+ test("#1843: a malformed token never decides, however great its retry suffix", () => {
544
+ for (const row of ["#5 impl-5=PR#931 · impl-5-b=PR#93l", "#5 impl-5-b=PR#93l · impl-5=PR#931"]) {
545
+ assert.equal(parseRow(row).impl, "impl-5", row);
546
+ const { card: c } = cardFor(row, 5);
547
+ assert.equal(c.column, "REVIEW", row);
548
+ assert.equal(c.pr, 931, row);
549
+ assert.ok(c.flags.includes("ledger-error"), row);
550
+ }
551
+ });
552
+
553
+ test("#1843: two distinct impl names at one retry suffix render one card in either order", () => {
554
+ // Not a row anything writes; the pick between them is incidental, but it
555
+ // must be a function of the tokens, never of which one was typed last.
556
+ assert.deepEqual(cardFor("#5 impl-5=killed · impl-6", 5), cardFor("#5 impl-6 · impl-5=killed", 5));
557
+ });
558
+
559
+ // review-1912-b: laterAttempt's retry-vs-number precedence let a token from
560
+ // a DIFFERENT ticket's impl-N lineage outrank this row's own impl token
561
+ // whenever the foreign token carried a higher retry suffix, reintroducing
562
+ // #1843's own bug class (a dead/unrelated token's outcome read instead of
563
+ // this ticket's live one) by a different mechanism than row position. A
564
+ // foreign impl number is not "a later attempt" of this ticket at all — retry
565
+ // only orders attempts on ONE number — so it must never outrank this row's
566
+ // own impl token, however great its retry suffix.
567
+ test("review-1912-b: a foreign ticket's impl token never outranks this row's own impl token, however great its retry suffix", () => {
568
+ for (const row of ["#5 impl-5 impl-3-z=killed", "#5 impl-3-z=killed impl-5"]) {
569
+ assert.equal(parseRow(row).impl, "impl-5", row);
570
+ assert.equal(parseRow(row).implOutcome, null, row);
571
+ const { card: c } = cardFor(row, 5);
572
+ assert.equal(c.column, "IMPLEMENTING", row);
573
+ assert.deepEqual(c.flags, [], `${row}: ticket 5 is live, not killed — impl-3-z is ticket 3's token`);
574
+ }
575
+ });
576
+
577
+ // #2083: a finisher halt is the finisher working correctly — it refused to
578
+ // label — so the PR parks in REVIEW with no `ready-to-merge`. The cockpit's
579
+ // severity-4 flag is what puts it in front of a human.
580
+ const HALTED = "#941 impl-941=PR#931 · reviewed=abc1234:0/0/0 · finisher-pr-931=halted:unreadable";
581
+
582
+ test("#2083: a PR whose latest finisher halted carries the cause as a flag, ranked exactly at severity 4", () => {
583
+ // Two killed (severity 4) rows around the halted one: attention sorts by
584
+ // severity and is otherwise stable, so the halted card stays between them
585
+ // only at exactly 4 — at 5 it would lead, at 3 or below it would trail.
586
+ const b = computeBoard(reproInputs({
587
+ rows: ["#904 impl-904=killed", HALTED, "#942 impl-942=killed", "#943 impl-943=PR#932 · held-behind:#931"],
588
+ prev: { tickets: [] },
589
+ }));
590
+ assert.equal(card(b, 941).column, "REVIEW");
591
+ assert.deepEqual(card(b, 941).flags, ["halted:unreadable"]);
592
+ assert.deepEqual(b.attention.map((t) => t.issue), [904, 941, 942, 943]);
593
+ });
594
+
595
+ test("#2083: a later finisher attempt decides — a live or labelled `-b` clears the halt, in any token order", () => {
596
+ for (const [row, flags] of [
597
+ ["#941 impl-941=PR#931 · finisher-pr-931=halted:past-pin · finisher-pr-931-b", []],
598
+ ["#941 impl-941=PR#931 · finisher-pr-931-b · finisher-pr-931=halted:past-pin", []],
599
+ ["#941 impl-941=PR#931 · finisher-pr-931=halted:live-editor · finisher-pr-931-b=labelled", []],
600
+ ["#941 impl-941=PR#931 · finisher-pr-931=failed · finisher-pr-931-b=halted:rebase", ["halted:rebase"]],
601
+ // A bare copy beside the settled token is what a whole-line rewrite
602
+ // leaves; the member is still settled halted.
603
+ ["#941 impl-941=PR#931 · finisher-pr-931 · finisher-pr-931=halted:other", ["halted:other"]],
604
+ // Another PR's finisher is not this PR's latest attempt.
605
+ ["#941 impl-941=PR#931 · finisher-pr-931=halted:missing · finisher-pr-950-b=labelled", ["halted:missing"]],
606
+ ["#941 impl-941=PR#931 · finisher-pr-950=halted:missing", []],
607
+ ]) {
608
+ const { card: c } = cardFor(row, 941);
609
+ assert.equal(c.column, "REVIEW", row);
610
+ assert.deepEqual(c.flags, flags, row);
611
+ }
612
+ });
613
+
614
+ test("#2083: a halt a human already resolved — PR labelled or merged — flags nothing", () => {
615
+ const ready = computeBoard(reproInputs({ rows: [HALTED], prs: [openPr(931, ["ready-to-merge"])], prev: { tickets: [] } }));
616
+ assert.equal(card(ready, 941).column, "READY");
617
+ assert.deepEqual(card(ready, 941).flags, []);
618
+ const merged = computeBoard(reproInputs({ rows: [HALTED], prs: [], merged: [931], prev: { tickets: [] } }));
619
+ assert.equal(card(merged, 941).column, "MERGED");
620
+ assert.deepEqual(card(merged, 941).flags, []);
621
+ });
622
+
623
+ test("#1820: a live implementer is IMPLEMENTING, and still earns stale", () => {
624
+ const b = computeBoard(reproInputs());
625
+ assert.equal(card(b, 906).column, "IMPLEMENTING");
626
+ assert.equal(card(b, 906).agent, "impl-906");
627
+ assert.ok(card(b, 906).flags.includes("stale"));
628
+ });
629
+
630
+ test("#1820: MERGED comes from gh for a row PR absent from the open list", () => {
631
+ const b = computeBoard(reproInputs());
632
+ assert.equal(card(b, 907).column, "MERGED");
633
+ assert.deepEqual(card(b, 907).flags, [], "MERGED is terminal — never stale");
634
+ });
635
+
636
+ test("#1820: a closed-unmerged PR keeps today's REVIEW column", () => {
637
+ const b = computeBoard(reproInputs({ merged: [] }));
638
+ assert.equal(card(b, 907).column, "REVIEW");
639
+ // `merged` absent entirely — a hand-built caller — means none known.
640
+ const inp = reproInputs();
641
+ delete inp.merged;
642
+ assert.equal(card(computeBoard(inp), 907).column, "REVIEW");
643
+ });
644
+
645
+ test("#1820: an explicit MERGED token still wins, over the open list and gh alike", () => {
646
+ const b = computeBoard(reproInputs({
647
+ rows: ["#918 impl-918=PR#931 → PR#931 → MERGED 73b356de"],
648
+ prs: [openPr(931, ["ready-to-merge"])],
649
+ merged: [],
650
+ }));
651
+ assert.equal(card(b, 918).column, "MERGED");
652
+ });
653
+
654
+ test("#1820: the merged read is consulted only for PRs absent from the open list", () => {
655
+ const b = computeBoard(reproInputs({ rows: ["#919 impl-919=PR#931"], merged: [931] }));
656
+ assert.equal(card(b, 919).column, "REVIEW", "the open list is gh's fresher answer for an open PR");
657
+ });
658
+
659
+ // #1841: MERGED is terminal. A row PR absent from the open list stays MERGED
660
+ // once the previous board already showed the SAME PR, on this ticket,
661
+ // MERGED — whether today's merged-PR read failed outright (`[]`) or simply
662
+ // succeeded without listing that PR (since #1840 gather() never asks about a
663
+ // carried-forward PR, so a successful read never lists it). Keyed on the PR,
664
+ // not just the ticket: a retry under a NEW PR after an earlier one merged
665
+ // must not inherit that earlier verdict.
666
+ test("#1841: a failed merged read carries forward the previous board's MERGED, preserving dwell and excluding it from claimed", () => {
667
+ const b = computeBoard(reproInputs({
668
+ rows: ["#907 impl-907=PR#930"],
669
+ merged: [], // the merged-PR read failed and degraded to []
670
+ prev: { tickets: [{ issue: 907, pr: 930, column: "MERGED", sinceEnteredStage: 3 * HOUR }] },
671
+ beat: { at: 10 * HOUR - 90 * MIN, interval: 1200, stopped: "" },
672
+ }));
673
+ const t = card(b, 907);
674
+ assert.equal(t.column, "MERGED");
675
+ assert.equal(t.sinceEnteredStage, 3 * HOUR, "dwell carried forward from the previous board, not reset");
676
+ assert.deepEqual(t.flags, [], "MERGED is terminal — never stale");
677
+ assert.equal(b.liveness.claimed, 0, "a carried-forward MERGED ticket is not an outstanding claim");
678
+ });
679
+
680
+ test("#1841: a successful merged read that simply omits the PR still carries MERGED forward", () => {
681
+ const b = computeBoard(reproInputs({
682
+ rows: ["#907 impl-907=PR#930"],
683
+ merged: [999], // read succeeded without this PR, which gather() no longer asks about (#1840)
684
+ prev: { tickets: [{ issue: 907, pr: 930, column: "MERGED", sinceEnteredStage: 3 * HOUR }] },
685
+ }));
686
+ assert.equal(card(b, 907).column, "MERGED");
687
+ });
688
+
689
+ test("#1841: with no previous board, a failed merged read still leaves the row REVIEW, as today", () => {
690
+ const b = computeBoard(reproInputs({
691
+ rows: ["#907 impl-907=PR#930"],
692
+ merged: [],
693
+ prev: null,
694
+ }));
695
+ assert.equal(card(b, 907).column, "REVIEW");
696
+ });
697
+
698
+ test("#1841: an open PR is never forced to MERGED by carry-forward", () => {
699
+ const b = computeBoard(reproInputs({
700
+ rows: ["#908 impl-908=PR#931"],
701
+ prs: [openPr(931)],
702
+ prev: { tickets: [{ issue: 908, pr: 931, column: "MERGED", sinceEnteredStage: 3 * HOUR }] },
703
+ }));
704
+ assert.equal(card(b, 908).column, "REVIEW", "the open list is gh's fresher answer — a stale MERGED carry-forward must not override it");
705
+ });
706
+
707
+ test("#1841: a retry under a different PR does not inherit the previous board's MERGED for this ticket", () => {
708
+ const b = computeBoard(reproInputs({
709
+ rows: ["#907 impl-907=PR#930 impl-907-b=PR#940"],
710
+ prs: [],
711
+ merged: [], // PR#940 was never observed open or merged this run
712
+ prev: { tickets: [{ issue: 907, pr: 930, column: "MERGED", sinceEnteredStage: 3 * HOUR }] },
713
+ }));
714
+ assert.equal(card(b, 907).column, "REVIEW", "the previous MERGED verdict was about PR#930, not today's PR#940 — carry-forward is keyed on the PR, not just the ticket");
715
+ });
716
+
717
+ test("#1841: a previous board entry for this ticket that was not MERGED never triggers carry-forward", () => {
718
+ const b = computeBoard(reproInputs({
719
+ rows: ["#907 impl-907=PR#930"],
720
+ merged: [],
721
+ prev: { tickets: [{ issue: 907, pr: 930, column: "REVIEW", sinceEnteredStage: 3 * HOUR }] },
722
+ }));
723
+ assert.equal(card(b, 907).column, "REVIEW");
724
+ });
725
+
726
+ test("#1841: another ticket's MERGED entry in the same previous board does not carry forward onto this row", () => {
727
+ const b = computeBoard(reproInputs({
728
+ rows: ["#907 impl-907=PR#930", "#908 impl-908=PR#940"],
729
+ prs: [],
730
+ merged: [],
731
+ prev: { tickets: [
732
+ { issue: 907, pr: 930, column: "MERGED", sinceEnteredStage: 3 * HOUR },
733
+ { issue: 908, pr: 940, column: "REVIEW", sinceEnteredStage: 1 * HOUR },
734
+ ] },
735
+ }));
736
+ assert.equal(card(b, 907).column, "MERGED", "#907's own previous MERGED still carries forward");
737
+ assert.equal(card(b, 908).column, "REVIEW", "#908 must not inherit #907's MERGED from the same prev.tickets array");
738
+ });
739
+
740
+ test("#1841: a no-impl-token PR-bound row (amendment 2a) also carries MERGED forward", () => {
741
+ const b = computeBoard(reproInputs({
742
+ rows: ["#1237 -> PR#1237 · review=member:review-pr-1237"],
743
+ prs: [],
744
+ merged: [],
745
+ prev: { tickets: [{ issue: 1237, pr: 1237, column: "MERGED", sinceEnteredStage: 3 * HOUR }] },
746
+ }));
747
+ assert.equal(card(b, 1237).column, "MERGED");
748
+ });
749
+
750
+ // #1840: gather() asks gh about mergedReadPrs()'s set and nothing else, so
751
+ // that set has to be EXACTLY the row PRs whose card `merged` can change: one
752
+ // it leaves out renders REVIEW however long ago it merged, and one it adds is
753
+ // a wasted question. The invariant is read off computeBoard() itself — the
754
+ // PRs whose column moves between "gh knows of no merge" and "gh calls every
755
+ // PR merged" — so the two functions cannot drift apart unseen.
756
+ test("#1840: mergedReadPrs is exactly the row PRs whose column the merged read can change", () => {
757
+ const rows = [
758
+ "#901 impl-901=PR#931", // open: the open list answers it
759
+ "#902 impl-902=PR#932 → MERGED 73b356de", // token-MERGED
760
+ "#903 impl-903=PR#933", // carried forward (#1841)
761
+ "#904 impl-904=PR#930 impl-904-b=PR#940", // retried under a new PR: 940 is not carried
762
+ "#905 impl-905=PR#950", // previous board had it, not as MERGED
763
+ "#906 impl-906", // implementing, no PR
764
+ "#907 impl-907=released", // released, no PR
765
+ "#908 excluded · behind-pr:#931 impl-908=PR#960", // an Exclusion is POOL whatever it carries
766
+ "#1237 -> PR#1237 · review=member:review-pr-1237", // amendment 2a: no impl token, PR-bound
767
+ "#909 impl-909=PR#950", // a second row on 950: asked once
768
+ ];
769
+ const prev = { tickets: [
770
+ { issue: 903, pr: 933, column: "MERGED", sinceEnteredStage: HOUR },
771
+ { issue: 904, pr: 930, column: "MERGED", sinceEnteredStage: HOUR },
772
+ { issue: 905, pr: 950, column: "REVIEW", sinceEnteredStage: HOUR },
773
+ ] };
774
+ const inp = { ledger: { rows, filed: [], ruled: [] }, prs: [openPr(931)], prev };
775
+ const need = mergedReadPrs(inp);
776
+ assert.deepEqual(need, [940, 950, 1237]);
777
+ const col = (merged) => new Map(computeBoard(reproInputs({ ...inp, merged })).tickets.map((t) => [t.issue, t.column]));
778
+ const none = col([]);
779
+ const all = col([930, 931, 932, 933, 940, 950, 960, 1237]);
780
+ const moved = new Set([...none].filter(([issue, c]) => all.get(issue) !== c).map(([issue]) => rows.map(parseRow).find((p) => p.issue === issue).pr));
781
+ assert.deepEqual([...moved].sort((a, b) => a - b), need);
782
+ });
783
+
784
+ // #1840 review: a ledger row whose PR mention is 22+ digits parses (via
785
+ // `Number()`) to a value outside Number.isSafeInteger, which readMerged()
786
+ // would stringify in exponential form (`1e+21`) — not a valid gh api
787
+ // graphql alias/argument, and one that fails the WHOLE batched query, not
788
+ // just that row. mergedReadPrs excludes it before it ever reaches gh, the
789
+ // same way a PR-less row is excluded, so every other row PR's lookup stays
790
+ // intact.
791
+ test("#1840: a PR number outside Number.isSafeInteger is excluded from mergedReadPrs, so it cannot poison the batch for other row PRs", () => {
792
+ const need = mergedReadPrs({
793
+ ledger: { rows: [
794
+ "#907 impl-907=PR#930",
795
+ "#908 impl-908=PR#1000000000000000000000", // 22 digits: Number() -> 1e+21
796
+ ], filed: [], ruled: [] },
797
+ prs: [], prev: null,
798
+ });
799
+ assert.deepEqual(need, [930], "the unsafe-integer PR is left out; 930 still gets asked about");
800
+ });
801
+
802
+ test("#1820: review=wf/member, or a live fix-pr/finisher-pr, is under review; agent is the latest live member", () => {
803
+ const b = computeBoard(reproInputs());
804
+ assert.equal(card(b, 908).column, "REVIEW");
805
+ assert.equal(card(b, 908).agent, null, "a Workflow review names no member");
806
+ assert.equal(card(b, 909).agent, "review-pr-932");
807
+ assert.equal(card(b, 905).agent, null, "fix-pr-920 settled failed — nobody is live");
808
+ assert.equal(b.queue.reviewBacklog, 1, "only #905 has neither review= nor reviewed=");
809
+
810
+ const live = computeBoard(reproInputs({
811
+ rows: [
812
+ "#920 impl-920=PR#931 · fix-pr-931",
813
+ "#921 impl-921=PR#932 · review=member:review-pr-932 reviewed=abc1234:1/0/0 · finisher-pr-932",
814
+ "#922 impl-922=PR#920 · review=wf:r1=failed review=fallback:review-pr-920-b",
815
+ "#923 impl-923=PR#931 · review=member:review-pr-931 reviewed=abc1234:0/0/0",
816
+ ],
817
+ }));
818
+ assert.equal(card(live, 920).agent, "fix-pr-931");
819
+ assert.equal(card(live, 921).agent, "finisher-pr-932");
820
+ assert.equal(card(live, 922).agent, "review-pr-920-b");
821
+ assert.equal(card(live, 923).agent, null, "reviewed= settles the runner that produced it");
822
+ assert.equal(live.queue.reviewBacklog, 0);
823
+ });
824
+
825
+ test("#1820: live-ledger PR rows — settled finisher, fallback runner", () => {
826
+ const b = computeBoard(reproInputs({
827
+ rows: [
828
+ "#1715 impl-1715=PR#1824 · class=correction · reviewed=41901d4c:0/1/0 · finisher-pr-1824=labelled",
829
+ "#1721 impl-1721=PR#1825 · class=correction · review=fallback:review-pr-1825-b",
830
+ "#1755 impl-1755=PR#1830 · class=routine",
831
+ ],
832
+ prs: [openPr(1824, ["ready-to-merge"]), openPr(1825), openPr(1830)],
833
+ }));
834
+ assert.equal(card(b, 1715).column, "READY");
835
+ assert.equal(card(b, 1715).agent, null);
836
+ assert.equal(card(b, 1721).agent, "review-pr-1825-b");
837
+ assert.equal(b.queue.reviewBacklog, 1, "only #1755 is waiting on a reviewer");
838
+ });
839
+
840
+ test("#1820: the reproduction's stall report counts only the real claims", () => {
841
+ const b = computeBoard({ ...reproInputs(), beat: { at: 10 * HOUR - 90 * MIN, interval: 1200, stopped: "" } });
842
+ // #904 killed, #905/#908/#909 in review, #906 live — Exclusions, the bailed
843
+ // #903 and the merged #907 are nobody's outstanding claim.
844
+ assert.equal(b.liveness.claimed, 5);
845
+ assert.deepEqual(b.attention.map((t) => t.issue).sort(), [904, 905, 906, 908, 909]);
846
+ });
847
+
848
+ test("#1820: `## Dispatched` is not read — row tokens alone decide", () => {
849
+ const b = computeBoard(reproInputs({
850
+ rows: ["#906 impl-906"],
851
+ ledger: { rows: ["#906 impl-906"], dispatched: ["impl-906=bailed", "impl-950"], filed: [], ruled: [] },
852
+ }));
853
+ assert.equal(card(b, 906).column, "IMPLEMENTING");
854
+ assert.equal(card(b, 906).agent, "impl-906");
855
+ assert.equal(card(b, 950), undefined);
856
+ });
857
+
858
+ test("#1820: a malformed member outcome is never fatal and never counted live, and earns a `ledger-error` flag instead of rendering as a quiet, healthy row", () => {
859
+ const b = computeBoard(reproInputs({ rows: ["#924 impl-924=PR#931 · fix-pr-931=exploded"] }));
860
+ assert.equal(card(b, 924).column, "REVIEW");
861
+ assert.equal(card(b, 924).agent, null);
862
+ assert.ok(card(b, 924).flags.includes("ledger-error"), "a malformed outcome must be visible, not indistinguishable from a healthy row");
863
+ });
864
+
865
+ test("#1820: a bare `review-pr-<n>` token (no `review=` prefix) names nobody — only ledger-grammar.mjs member families and `review=` tokens are read", () => {
866
+ const b = computeBoard(reproInputs({ rows: ["#960 impl-960=PR#931 review-pr-960"] }));
867
+ assert.equal(card(b, 960).agent, null, "review-pr-960 is neither a ledger-grammar.mjs member family nor a review= token");
868
+ assert.equal(card(b, 960).column, "REVIEW");
869
+ assert.equal(b.queue.reviewBacklog, 1, "no review=, no reviewed=, no live fix-pr/finisher-pr — the bare token does not exempt it");
870
+ });
871
+
872
+ // --------------------------------------------------------------------------
873
+ // #1820 amendment 5a (#1842): a `review=` token puts a PR under review only
874
+ // while it is live. A settled `review=…=failed` is a dead review — the PR is
875
+ // owed one again, as run-team SKILL.md defines review-due and as
876
+ // fleet-tick.mjs's `reviewedAny` reads the token.
877
+
878
+ // fleet-tick.mjs's review-due for the same rows, observed through deriveRun
879
+ // rather than restated: every PR open, unlabelled and closing an issue.
880
+ // `headRefOid` defaults to a fixed placeholder, never absent — (#2083) a
881
+ // genuinely missing head reads as "moved past reviewed=" in deriveRun, so
882
+ // an omitted-by-accident fixture would silently exercise past-pin's
883
+ // redispatch path instead of refusing the way production's openPrs() does.
884
+ const tickReviewDue = (rows, prs, headRefOid = "abc1234abc1234abc1234abc1234abc1234abcd") => deriveRun({ rows, dispatched: [], drain: null },
885
+ prs.map((number) => ({ number, labels: [], closingIssuesReferences: [{ number }], headRefOid }))).reviewDue;
886
+
887
+ test("#1820 amendment 5a: a settled `review=...=failed` with no redispatch is owed a review — reviewBacklog agrees with fleet-tick.mjs's reviewDue", () => {
888
+ const row = "#961 impl-961=PR#961 · review=member:review-pr-961=failed";
889
+ const b = computeBoard(reproInputs({ rows: [row], prs: [openPr(961)] }));
890
+ assert.equal(card(b, 961).column, "REVIEW");
891
+ assert.equal(card(b, 961).agent, null, "the reviewer settled failed; nobody is live");
892
+ assert.equal(b.queue.reviewBacklog, 1, "a dead review is no review");
893
+ assert.deepEqual(tickReviewDue([row], [961]), [961], "the tick lists the same PR as review-due");
894
+ });
895
+
896
+ test("#1820 amendment 5a: `=failed` then a live redispatch is under review; any `reviewed=` stays out of the backlog whatever review= tokens it carries", () => {
897
+ for (const row of [
898
+ "#962 impl-962=PR#931 · review=wf:r1=failed review=fallback:review-pr-931-b",
899
+ "#962 impl-962=PR#931 · review=member:review-pr-931=failed review=wf:r2",
900
+ "#962 impl-962=PR#931 · review=member:review-pr-931=failed reviewed=abc1234:0/0/0",
901
+ "#962 impl-962=PR#931 · reviewed=abc1234:1/0/0 review=wf:r2=failed",
902
+ "#962 impl-962=PR#931 · review=wf:r1=failed review=fallback:review-pr-931-b=failed reviewed=abc1234:0/1/0",
903
+ // A live fix-applier or finisher is reviewing it too, as before (#1820).
904
+ "#962 impl-962=PR#931 · review=member:review-pr-931=failed · fix-pr-931",
905
+ "#962 impl-962=PR#931 · review=member:review-pr-931=failed · finisher-pr-931",
906
+ ]) {
907
+ const b = computeBoard(reproInputs({ rows: [row] }));
908
+ assert.equal(card(b, 962).column, "REVIEW", row);
909
+ assert.equal(b.queue.reviewBacklog, 0, row);
910
+ }
911
+ });
912
+
913
+ test("#1820 amendment 5a: on the same ledger and PR list, the cockpit's backlog is fleet-tick.mjs's reviewDue, row by row and in total", () => {
914
+ // [row, its PR, owed a review]. Every PR is open, unlabelled and closes an
915
+ // issue, and no row carries a live fix-pr-/finisher-pr-, which the tick's
916
+ // review-due does not read.
917
+ const cases = [
918
+ ["#961 impl-961=PR#961 · review=member:review-pr-961=failed", 961, true],
919
+ ["#962 impl-962=PR#962 · review=fallback:review-pr-962-b=failed", 962, true],
920
+ ["#963 impl-963=PR#963 · review=wf:r1=failed", 963, true],
921
+ ["#964 impl-964=PR#964 · review=wf:r1=failed review=fallback:review-pr-964-b=failed", 964, true],
922
+ ["#965 impl-965=PR#965 · review=member:review-pr-965=failed · fix-pr-965=failed", 965, true],
923
+ ["#966 impl-966=PR#966", 966, true],
924
+ ["#967 impl-967=PR#967 · review=wf:r1=failed review=fallback:review-pr-967-b", 967, false],
925
+ ["#968 impl-968=PR#968 · review=wf:r3", 968, false],
926
+ ["#969 impl-969=PR#969 · review=member:review-pr-969=failed reviewed=abc1234:0/0/0", 969, false],
927
+ ["#970 impl-970=PR#970 · reviewed=abc1234:1/0/0 review=wf:r2=failed", 970, false],
928
+ // A live copy left beside its settled one by a whole-line rewrite: the
929
+ // tick's `reviewedAny` counts any live review= token on the row, so the
930
+ // row is not owed one — the ruling's "neither a live review= nor a
931
+ // reviewed=", not the last review= token's liveness.
932
+ ["#971 impl-971=PR#971 · review=member:review-pr-971 review=member:review-pr-971=failed", 971, false],
933
+ // Amendment 2a rows — no impl token, PR from the mention or the row key.
934
+ ["#1237 review=wf:r9=failed", 1237, true],
935
+ ["#1238 -> PR#1238 · review=member:review-pr-1238=failed review=fallback:review-pr-1238-b", 1238, false],
936
+ ];
937
+ for (const [row, pr, owed] of cases) {
938
+ const b = computeBoard(reproInputs({ rows: [row], prs: [openPr(pr)] }));
939
+ assert.equal(b.tickets[0].column, "REVIEW", row);
940
+ assert.equal(b.queue.reviewBacklog, owed ? 1 : 0, `${row}: cockpit`);
941
+ assert.deepEqual(tickReviewDue([row], [pr]), owed ? [pr] : [], `${row}: tick`);
942
+ }
943
+ const rows = cases.map(([row]) => row);
944
+ const prs = cases.map(([, pr]) => pr);
945
+ const b = computeBoard(reproInputs({ rows, prs: prs.map((n) => openPr(n)) }));
946
+ assert.equal(b.queue.reviewBacklog, tickReviewDue(rows, prs).length);
947
+ assert.equal(b.queue.reviewBacklog, cases.filter(([, , owed]) => owed).length);
948
+ });
949
+
950
+ test("#2083: a returned review whose finisher halted past-pin against a head it never read is owed a review again — cockpit and tick agree", () => {
951
+ // reviewed= first, then a fresher finisher discovers the head moved past
952
+ // it and halts — the same chronology the fleet-tick.test.mjs fixture
953
+ // above uses, so the halt is the row's freshest event.
954
+ const row = "#972 impl-972=PR#972 · reviewed=abc1234:0/0/0 · finisher-pr-972=halted:past-pin";
955
+ const staleHead = "def5678def5678def5678def5678def5678def";
956
+ const b = computeBoard(reproInputs({ rows: [row], prs: [openPr(972, [], staleHead)] }));
957
+ assert.equal(card(b, 972).column, "REVIEW");
958
+ assert.equal(b.queue.reviewBacklog, 1, "the halt's automatic re-review has not happened at this head yet");
959
+ assert.deepEqual(tickReviewDue([row], [972], staleHead), [972], "the tick agrees");
960
+ });
961
+
962
+ test("#2083: once the head matches the reviewed= that answered a past-pin halt, neither counts it owed", () => {
963
+ const row = "#973 impl-973=PR#973 · finisher-pr-973=halted:past-pin · reviewed=abc1234:0/0/0";
964
+ const b = computeBoard(reproInputs({ rows: [row], prs: [openPr(973, [], "ABC1234")] }));
965
+ assert.equal(b.queue.reviewBacklog, 0, "the automatic re-review already answered the halt");
966
+ assert.deepEqual(tickReviewDue([row], [973], "ABC1234"), [], "the tick agrees");
967
+ });
968
+
969
+ // #1926: a `review=` token outside the wf/member/fallback grammar is still
970
+ // read as live (compute-board.mjs's note above REVIEW). fleet-tick.mjs
971
+ // refuses such a ledger outright; the cockpit renders it instead, and reads
972
+ // the review as in flight — `=failed` settles only an in-grammar token.
973
+ test("#1926: a `review=` token outside the grammar reads as a live review that names nobody", () => {
974
+ const base = "#972 impl-972=PR#972";
975
+ assert.equal(parseRow(base).underReview, false, "control: the row's other tokens put it under no review");
976
+ for (const tok of [
977
+ "review=bogus:x",
978
+ "review=member",
979
+ "review=member:",
980
+ "review=",
981
+ "review=WF:r1",
982
+ "review=member:a=b",
983
+ "review=bogus:x=failed",
984
+ ]) {
985
+ const r = parseRow(`${base} · ${tok}`);
986
+ assert.equal(r.underReview, true, tok);
987
+ assert.equal(r.agent, null, `${tok}: no kind to name a runner by`);
988
+ }
989
+ });
990
+
991
+ // --------------------------------------------------------------------------
992
+ // #1820 amendment 2a (#1839): a PR-bound row with no `impl` token — the shape
993
+ // `ledger.mjs dispatch <pr> fix-pr-<pr>|finisher-pr-<pr>` appends for a PR
994
+ // this run's implementers did not open — takes its PR the way fleet-tick.mjs
995
+ // does, the first `PR#M` mention else the row key, and that PR decides the
996
+ // card exactly as an impl token's `=PR#M` outcome does. Measured before the
997
+ // fix: this row was `IMPLEMENTING pr=null`, merged or not.
998
+ const INHERITED = "#1237 -> PR#1237 · review=member:review-pr-1237";
999
+
1000
+ test("#1820 amendment 2a: a PR-bound row with no impl token is a REVIEW card for its open PR", () => {
1001
+ const b = computeBoard(reproInputs({ rows: [INHERITED], prs: [openPr(1237)] }));
1002
+ assert.equal(card(b, 1237).column, "REVIEW");
1003
+ assert.equal(card(b, 1237).pr, 1237);
1004
+ assert.equal(card(b, 1237).agent, "review-pr-1237");
1005
+ assert.equal(b.queue.reviewBacklog, 0, "its live review= runner is reviewing it");
1006
+ });
1007
+
1008
+ test("#1820 amendment 2a: the same row is MERGED once gh reports its PR merged", () => {
1009
+ const b = computeBoard(reproInputs({ rows: [INHERITED], prs: [], merged: [1237] }));
1010
+ assert.equal(card(b, 1237).column, "MERGED");
1011
+ assert.equal(card(b, 1237).pr, 1237);
1012
+ assert.deepEqual(card(b, 1237).flags, [], "MERGED is terminal — never stale");
1013
+ });
1014
+
1015
+ test("#1820 amendment 2a: with no PR#M mention, a PR-bound member or review token keys the PR to the row key; a mention wins over the key", () => {
1016
+ for (const row of ["#1237 fix-pr-1237", "#1237 finisher-pr-1237=labelled", "#1237 review=wf:r9", "#1237 reviewed=abc1234:0/0/0"]) {
1017
+ assert.equal(parseRow(row).pr, 1237, row);
1018
+ }
1019
+ assert.equal(parseRow("#1300 PR#1301 · fix-pr-1301").pr, 1301);
1020
+ assert.equal(parseRow("#1237: fix-pr-1237").pr, null, "colon-suffixed first word is not an exact `#N` key match");
1021
+ });
1022
+
1023
+ test("#1820 amendment 2a: an Exclusion, and a row with no impl token and no PR-bound signal, keep no PR", () => {
1024
+ const b = computeBoard(reproInputs({
1025
+ rows: ["#901 excluded · behind-pr:#880", "#1500 excluded · behind-pr:#1499 · PR#1499 still open", "#1501 class=routine"],
1026
+ prs: [openPr(1499)],
1027
+ }));
1028
+ for (const [n, badge] of [[901, "excluded:#880"], [1500, "excluded:#1499"]]) {
1029
+ assert.equal(card(b, n).column, "POOL");
1030
+ assert.deepEqual(card(b, n).flags, [badge]);
1031
+ assert.equal(card(b, n).pr, null, `#${n} is supply — a PR mention on it names no card of its own`);
1032
+ }
1033
+ assert.equal(card(b, 1501).column, "IMPLEMENTING");
1034
+ assert.equal(card(b, 1501).pr, null);
1035
+ });
1036
+
1037
+ test("#1820 amendment 2a: a row carrying any impl token is untouched, a malformed one included — its key is a ticket, not a PR", () => {
1038
+ const b = computeBoard(reproInputs({ rows: ["#925 impl-925=PR#93l · review=member:review-pr-925"], prs: [openPr(925)] }));
1039
+ assert.equal(card(b, 925).column, "IMPLEMENTING");
1040
+ assert.equal(card(b, 925).pr, null);
1041
+ assert.ok(card(b, 925).flags.includes("ledger-error"));
1042
+ });
1043
+
1044
+ // fleet-tick.mjs's PR for a row, observed rather than restated: a merge hold on
1045
+ // a queued PR counts only when the row carrying the hold is keyed to that PR.
1046
+ const tickKeysTo = (row, n) => deriveRun({ rows: [`${row} held-behind:#1`], dispatched: [], drain: null }, [
1047
+ { number: n, labels: [{ name: "ready-to-merge" }], closingIssuesReferences: [] },
1048
+ { number: 1, labels: [], closingIssuesReferences: [] },
1049
+ ]).mergeHeld === 1;
1050
+
1051
+ test("#1820 amendment 2a: on the same PR-signaled row text, the cockpit's PR is fleet-tick.mjs's", () => {
1052
+ const rows = [INHERITED, "#1237 fix-pr-1237", "#1237 finisher-pr-1237=labelled", "#1237 reviewed=abc1234:1/0/0", "#1300 PR#1301 · fix-pr-1301"];
1053
+ for (const row of rows) {
1054
+ const pr = parseRow(row).pr;
1055
+ assert.ok(pr != null && tickKeysTo(row, pr), `${row}: cockpit ${pr}, tick disagrees`);
1056
+ }
1057
+ // Keyed only by an exact `#N` first word, as fleet-tick.mjs keys it.
1058
+ assert.equal(parseRow("#1237: fix-pr-1237").pr, null);
1059
+ assert.ok(!tickKeysTo("#1237: fix-pr-1237", 1237));
1060
+ });