@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,229 @@
1
+ // #1192: the `--prev` read guarded only the PARSE, so a previous board that
2
+ // parsed as JSON but carried a wrong-typed `tickets` crashed the gather its own
3
+ // comment promises it cannot ("a corrupt/partial board.json is ignored, not
4
+ // fatal"). `{"tickets": 5}` reached the prevCi map's `.filter` and left gather()
5
+ // as a TypeError through main()'s handler — the build refused, and the message
6
+ // named an "intermediate value" rather than the file the operator passed, so
7
+ // `--prev` was not implicated in the failure it caused.
8
+ //
9
+ // The guard rejects the SHAPE where the payload enters, next to the parse, and
10
+ // both faults take the one existing ignore path. Not per-read defaults: the
11
+ // prevCi expression's `|| []` is exactly the wrong seam and shows why — it
12
+ // defends against an ABSENT `tickets` and not against a present one of the
13
+ // wrong type, and it is one of three reads of this payload (`prev?.repo`,
14
+ // `prev?.repoUrl`, and compute-board.mjs's dwell tracking, which consumes the
15
+ // whole `prev` gather() returns).
16
+ //
17
+ // Driven through the exported `gather()` and through the real CLI: the value
18
+ // half (carry-forward present or empty) is only observable at gather()'s
19
+ // return, and the contract half (exit code unchanged, nothing on stdout) is
20
+ // only observable at the process boundary. Out of process either way, for the
21
+ // reason board.test.mjs's own gather drivers give — gather() reads process.argv
22
+ // and would otherwise read the test runner's.
23
+ //
24
+ // A separate file rather than more of board.test.mjs, the same reason
25
+ // board-tryparse-null.test.mjs gives: the fleet runs several implementers at
26
+ // once and two PRs appending to one test file conflict, which costs the PR its
27
+ // CI entirely.
28
+
29
+ import { test } from "node:test";
30
+ import assert from "node:assert/strict";
31
+ import { spawnSync } from "node:child_process";
32
+ import { mkdtempSync, writeFileSync, chmodSync } from "node:fs";
33
+ import { tmpdir } from "node:os";
34
+ import { join } from "node:path";
35
+ import { fileURLToPath } from "node:url";
36
+
37
+ const BOARD = fileURLToPath(new URL("./board.mjs", import.meta.url));
38
+
39
+ // What ci-state.mjs emits on a quota refusal: a payload at exit 2, which
40
+ // runCiState reads as "no answer" (board.test.mjs's RATE_LIMITED_EXIT_2 pins
41
+ // that reading). Some route into the carry-forward arm is what these tests
42
+ // need, not this one in particular — since #875 a salvaged payload that will
43
+ // not parse reaches it too — and a payload at exit 2 is the route with the
44
+ // least of its own machinery: one write and one exit code, no truncation to
45
+ // stage. Without SOME such route every ci value comes from mapCi and the
46
+ // previous board is never consulted, so an empty carry-forward would be
47
+ // indistinguishable from a consulted one.
48
+ const CI_READ_FAILS = `import { writeSync } from "node:fs";
49
+ writeSync(1, JSON.stringify({ pr: 42, verdict: "rate-limited", reasons: ["quota"] }) + "\\n");
50
+ process.exit(2);`;
51
+
52
+ // `prevBody` is written RAW, not through JSON.stringify: half the cases below
53
+ // are payloads JSON.stringify cannot produce (`not json`) or would launder.
54
+ //
55
+ // The gather has to COMPLETE, not merely not-throw: a driver that died on the
56
+ // prevCi TypeError exits non-zero with no stdout, and every value assertion
57
+ // below would read `undefined` from a parse of nothing. Asserting status here
58
+ // keeps that failure legible at the one place it can happen.
59
+ function gathered(prevBody) {
60
+ const cwd = mkdtempSync(join(tmpdir(), "board-prevshape-"));
61
+ const bin = mkdtempSync(join(tmpdir(), "board-prevshape-bin-"));
62
+ const scriptDir = mkdtempSync(join(tmpdir(), "board-prevshape-scripts-"));
63
+
64
+ writeFileSync(join(scriptDir, "ci-state.mjs"), CI_READ_FAILS);
65
+ // A real ledger answer, so the only unusual read on this stderr is the one
66
+ // under test — the assertions below count lines.
67
+ writeFileSync(join(scriptDir, "ledger.mjs"),
68
+ `console.log(JSON.stringify({ rows: [], filed: [], ruled: [] }));`);
69
+ writeFileSync(join(bin, "gh"),
70
+ '#!/bin/sh\ncase "$1 $2" in\n"pr list") echo \'[{"number":42,"state":"OPEN","labels":[],"title":"t"}]\' ;;\n*) exit 1 ;;\nesac\n');
71
+ chmodSync(join(bin, "gh"), 0o755);
72
+
73
+ const prevFile = join(cwd, "prev.json");
74
+ writeFileSync(prevFile, prevBody);
75
+
76
+ const driver = `const { gather } = await import(${JSON.stringify(BOARD)});
77
+ const r = await gather({ ledgerFile: ${JSON.stringify(join(cwd, "nope.md"))},
78
+ prevFile: ${JSON.stringify(prevFile)},
79
+ scriptDir: ${JSON.stringify(scriptDir)}, interval: 15 });
80
+ console.log(JSON.stringify({ ci: r.ci, prev: r.prev }));`;
81
+ const r = spawnSync(process.execPath, ["--input-type=module", "-e", driver], {
82
+ cwd, encoding: "utf8", env: { ...process.env, PATH: `${bin}:${process.env.PATH}` },
83
+ });
84
+ assert.equal(r.status, 0,
85
+ `the gather refused a previous board it promises to ignore\n${r.stderr}`);
86
+ return { ...JSON.parse(r.stdout.trim().split("\n").pop()), stderr: r.stderr, prevFile };
87
+ }
88
+
89
+ const ignoreLines = (stderr) =>
90
+ stderr.split("\n").filter((l) => l.includes("ignoring unreadable prev board"));
91
+
92
+ // ── the invalid-shape class ──────────────────────────────────────────────────
93
+ //
94
+ // One row per DISTINCT route into the defect, not per value: a wrong-typed
95
+ // container, a wrong-typed entry, and a wrong-typed payload are three
96
+ // different reads, and the three kind words below are the three branches of
97
+ // the guard's own naming expression — a `typeof`-only version reports both
98
+ // `null` and `[]` as "object", which is the diagnostic the operator cannot act
99
+ // on. Every row asserts the gather COMPLETED (inside `gathered`) with an empty
100
+ // carry-forward and exactly one diagnostic naming the file.
101
+ const REFUSED = [
102
+ // `{"tickets": 5}` is the ticket's own reproduction (#1192): a wrong-typed
103
+ // container reached the prevCi map's `.filter` and crashed gather() before
104
+ // this guard existed.
105
+ ['{"tickets": 5}', /expected tickets to be an array, got number/],
106
+ // The case an `Array.isArray` check alone lets straight through: `[null]`
107
+ // IS an array, so it clears the container check and throws on the per-entry
108
+ // `t.pr` read inside the prevCi map instead. The whole payload is refused
109
+ // rather than the bad entry filtered out — a board with one unreadable
110
+ // ticket is not a board whose OTHER tickets can be trusted to carry CI
111
+ // state forward.
112
+ ['{"tickets": [null]}', /expected tickets\[0\] to be a JSON object, got null/],
113
+ ['{"tickets": "5"}', /expected tickets to be an array, got string/],
114
+ ['{"tickets": {"42": "red"}}', /expected tickets to be an array, got object/],
115
+ ['{"tickets": [1]}', /expected tickets\[0\] to be a JSON object, got number/],
116
+ ['{"tickets": [{"pr": 42, "ci": "red"}, "x"]}', /expected tickets\[1\] to be a JSON object, got string/],
117
+ ['{"tickets": [[]]}', /expected tickets\[0\] to be a JSON object, got array/],
118
+ // Top-level faults. These four did NOT crash before the guard — `prev?.x`
119
+ // reads undefined off all of them — so the defect here is the silence: the
120
+ // operator passed a file that is not a board and the run said nothing, then
121
+ // carried nothing forward. Ignoring them is unchanged; SAYING so is new.
122
+ ["null", /expected a JSON object, got null/],
123
+ ["5", /expected a JSON object, got number/],
124
+ ['"a board"', /expected a JSON object, got string/],
125
+ ["[]", /expected a JSON object, got array/],
126
+ ];
127
+
128
+ for (const [body, reason] of REFUSED) {
129
+ test(`gather: an unusable previous board ${body} is ignored with one named diagnostic (#1192)`, () => {
130
+ const r = gathered(body);
131
+ assert.equal(r.ci[42], "unknown", "an unusable previous board must carry nothing forward");
132
+ // Nothing reaches the payload's other three readers either — `prev?.repo`,
133
+ // `prev?.repoUrl` and compute-board.mjs's dwell tracking, which reads the
134
+ // returned `prev` through the same `(prev?.tickets || []).map` shape.
135
+ assert.equal(r.prev, null);
136
+ const lines = ignoreLines(r.stderr);
137
+ assert.equal(lines.length, 1, `expected exactly one diagnostic, got:\n${r.stderr}`);
138
+ assert.ok(lines[0].includes(r.prevFile), `diagnostic must name the file: ${lines[0]}`);
139
+ assert.match(lines[0], reason);
140
+ });
141
+ }
142
+
143
+ // A parse fault is the path that already worked, and its wording is not the
144
+ // shape fault's: re-using one message for both would put a reader who sees
145
+ // "expected a JSON object" in front of a file that never parsed.
146
+ test("gather: a previous board that is not JSON still takes the ignore path with its own message (#1192)", () => {
147
+ const r = gathered("not json at all");
148
+ assert.equal(r.ci[42], "unknown");
149
+ const lines = ignoreLines(r.stderr);
150
+ assert.equal(lines.length, 1, `expected exactly one diagnostic, got:\n${r.stderr}`);
151
+ assert.match(lines[0], /is not valid JSON/);
152
+ assert.doesNotMatch(lines[0], /expected a JSON object/,
153
+ "a parse fault must not be reported as a shape fault");
154
+ });
155
+
156
+ // ── the accept side: what this guard must NOT refuse ─────────────────────────
157
+
158
+ test("gather: a well-formed previous board still supplies the carry-forward (#1192)", () => {
159
+ // The behaviour the guard exists to protect, not merely to leave alone: PR
160
+ // 42's own CI read fails here, so "red" can only have come from this file.
161
+ // A guard that refused the payload — or nulled `prev` on its way past —
162
+ // would show up here as "unknown" and nowhere else.
163
+ const r = gathered('{"tickets": [{"pr": 42, "ci": "red"}]}');
164
+ assert.equal(r.ci[42], "red");
165
+ assert.deepEqual(r.prev, { tickets: [{ pr: 42, ci: "red" }] },
166
+ "an accepted payload must reach gather()'s callers whole — compute-board.mjs reads it for dwell");
167
+ assert.deepEqual(ignoreLines(r.stderr), [], "a usable previous board must draw no diagnostic");
168
+ });
169
+
170
+ // The rows a stricter guard gets wrong. `prev?.tickets || []` reads all three
171
+ // as the empty carry-forward today, so all three are USABLE payloads, and a
172
+ // guard written as `!Array.isArray(p.tickets)` or `"tickets" in p` would
173
+ // start refusing boards that work — printing a diagnostic about a file whose
174
+ // only fault is having no tickets on it, and throwing away the `repo`/`repoUrl`
175
+ // the same payload still carries.
176
+ const ACCEPTED = ['{}', '{"tickets": null}', '{"tickets": []}', '{"repo": "o/r"}'];
177
+
178
+ for (const body of ACCEPTED) {
179
+ test(`gather: a previous board with no usable tickets, ${body}, is accepted in silence (#1192)`, () => {
180
+ const r = gathered(body);
181
+ assert.equal(r.ci[42], "unknown");
182
+ assert.deepEqual(r.prev, JSON.parse(body), "a payload with nothing to carry is still a payload");
183
+ assert.deepEqual(ignoreLines(r.stderr), [],
184
+ "nullish/empty tickets is an empty carry-forward, not a fault");
185
+ });
186
+ }
187
+
188
+ // ── the process contract: an ignored previous board is not an error ──────────
189
+ //
190
+ // Only observable out here: `gather()`'s return says nothing about the exit
191
+ // code, and the diagnostic's CHANNEL is the thing a cockpit consuming
192
+ // `board build` stdout depends on. The stub `gh` fails every call — each gh
193
+ // read degrades through tryRun — so the board still builds with no network and
194
+ // no read of this repo's live issue list.
195
+ function runBuild(prevArgs) {
196
+ const cwd = mkdtempSync(join(tmpdir(), "board-prevshape-cli-"));
197
+ const home = mkdtempSync(join(tmpdir(), "board-prevshape-home-"));
198
+ const bin = mkdtempSync(join(tmpdir(), "board-prevshape-cli-bin-"));
199
+ writeFileSync(join(bin, "gh"), "#!/bin/sh\nexit 1\n");
200
+ chmodSync(join(bin, "gh"), 0o755);
201
+ return spawnSync(process.execPath, [BOARD, "build", "--ledger", join(cwd, "nope.md"), ...prevArgs], {
202
+ cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024,
203
+ env: { ...process.env, HOME: home, PATH: `${bin}:${process.env.PATH}` },
204
+ });
205
+ }
206
+
207
+ test("build: an ignored previous board changes neither the exit code nor stdout (#1192)", () => {
208
+ const prevFile = join(mkdtempSync(join(tmpdir(), "board-prevshape-file-")), "prev.json");
209
+ writeFileSync(prevFile, '{"tickets": 5}');
210
+ const withPrev = runBuild(["--prev", prevFile]);
211
+ // The baseline is measured in the same run rather than asserted as a
212
+ // constant: "whatever it would have been with no --prev at all" is the
213
+ // criterion, and a rig that started failing for its own reasons would
214
+ // otherwise read as this fix regressing.
215
+ const without = runBuild([]);
216
+ assert.equal(withPrev.status, without.status,
217
+ `--prev changed the exit code: ${withPrev.status} vs ${without.status}\n${withPrev.stderr.slice(-400)}`);
218
+ // Pinned absolutely too, so a rig broken in both arms cannot pass by
219
+ // agreeing with itself. 70 was the pre-fix answer — main()'s internal-fault
220
+ // handler (#1093) — and 2 is a refusal.
221
+ assert.equal(withPrev.status, 0, withPrev.stderr.slice(-400));
222
+ // stderr carries it, and only once.
223
+ assert.equal(ignoreLines(withPrev.stderr).length, 1, withPrev.stderr);
224
+ // stdout stays the board and nothing else: the cockpit parses this whole.
225
+ const board = JSON.parse(withPrev.stdout);
226
+ assert.ok(Array.isArray(board.tickets), "stdout must still be a board model");
227
+ assert.doesNotMatch(withPrev.stdout, /ignoring unreadable prev board/,
228
+ "a diagnostic on stdout would break every consumer that parses it");
229
+ });
@@ -0,0 +1,119 @@
1
+ // #1181: board.mjs's `tryParse` guarded its INPUT string against nullish and
2
+ // not its PARSED VALUE. `JSON.parse("null")` succeeded and yielded null, so a
3
+ // bare `null` payload skipped the fallback and reached the caller as its
4
+ // answer — the shape #1170 fixed one function over, in `mapCi`.
5
+ //
6
+ // That gap does not crash either of tryParse's two current callers today:
7
+ // withNumber's own array guard already rejects a null `rows` at the open-PR read's
8
+ // call site, and gather()'s ledger branch already treats a null parse as
9
+ // falsy. This guard is defense in depth, not a crash fix — what it actually
10
+ // changes is (a) one named "payload is JSON null" stderr line in place of a
11
+ // caller's own, more generic shape complaint, and (b) real protection for a
12
+ // future tryParse caller with no shape guard of its own downstream. The two
13
+ // "refusal" tests below pin that stderr line; their value assertions were
14
+ // already true before this guard existed, and stay here as regression
15
+ // coverage for the caller-visible shape, not as proof of the fix.
16
+ //
17
+ // Driven through the exported `gather()` rather than against `tryParse`, which
18
+ // is module-private: the guard is only observable where a caller consumes the
19
+ // result, and that is the boundary a consumer actually sees. Out of process for
20
+ // the reason board.test.mjs's own gather drivers are — gather() reads
21
+ // process.argv and would otherwise read the test runner's.
22
+ //
23
+ // A separate file rather than more of board.test.mjs, the same reason
24
+ // ledger-read-require-file.test.mjs gives: the fleet runs several implementers
25
+ // at once and two PRs appending to one test file conflict, which costs the PR
26
+ // its CI entirely.
27
+ //
28
+ // The accept side of a well-formed payload is board.test.mjs's "a well-formed
29
+ // issue/PR row passes through unchanged", at this same seam; what is pinned
30
+ // here is the accept side this guard could newly break — a parsed answer that
31
+ // is FALSY but readable.
32
+
33
+ import { test } from "node:test";
34
+ import assert from "node:assert/strict";
35
+ import { spawnSync } from "node:child_process";
36
+ import { mkdtempSync, writeFileSync, chmodSync } from "node:fs";
37
+ import { tmpdir } from "node:os";
38
+ import { join } from "node:path";
39
+ import { fileURLToPath } from "node:url";
40
+
41
+ const BOARD = fileURLToPath(new URL("./board.mjs", import.meta.url));
42
+
43
+ // `repo view` answers a real object so nothing but the read under test can put
44
+ // the string "parse failed" on stderr; the assertions below are scoped to their
45
+ // own read besides, so neither guard rests on the other.
46
+ const REPO_JSON = '{"nameWithOwner":"o/r","url":"https://example.invalid/o/r"}';
47
+
48
+ // `ledgerBody` is the body of a stub `ledger.mjs`. board.mjs spawns
49
+ // `node <scriptDir>/ledger.mjs`, and only a stub can hand it stdout that
50
+ // arrives at exit 0 and parses to something no real ledger.mjs emits.
51
+ function gatherWith({ issuesJson = "[]", prsJson = "[]", ledgerBody = null } = {}) {
52
+ const cwd = mkdtempSync(join(tmpdir(), "board-tpnull-"));
53
+ const bin = mkdtempSync(join(tmpdir(), "board-tpnull-bin-"));
54
+ const scriptDir = mkdtempSync(join(tmpdir(), "board-tpnull-scripts-"));
55
+
56
+ writeFileSync(join(scriptDir, "ci-state.mjs"), "process.stdout.write('{}');\n");
57
+ writeFileSync(join(scriptDir, "ledger.mjs"),
58
+ ledgerBody ?? `console.log(JSON.stringify({ rows: [], filed: [], ruled: [] }));`);
59
+ writeFileSync(join(bin, "gh"),
60
+ `#!/bin/sh\ncase "$1 $2" in\n` +
61
+ `"issue list") echo '${issuesJson}' ;;\n` +
62
+ `"pr list") echo '${prsJson}' ;;\n` +
63
+ `"repo view") echo '${REPO_JSON}' ;;\n` +
64
+ `*) exit 1 ;;\nesac\n`);
65
+ chmodSync(join(bin, "gh"), 0o755);
66
+
67
+ const driver = `const { gather } = await import(${JSON.stringify(BOARD)});
68
+ const r = await gather({ ledgerFile: ${JSON.stringify(join(cwd, "ledger.md"))},
69
+ prevFile: null, scriptDir: ${JSON.stringify(scriptDir)}, interval: 15 });
70
+ console.log(JSON.stringify({ issues: r.issues, prs: r.prs, ledger: r.ledger }));`;
71
+ const r = spawnSync(process.execPath, ["--input-type=module", "-e", driver], {
72
+ cwd, encoding: "utf8", env: { ...process.env, PATH: `${bin}:${process.env.PATH}` },
73
+ });
74
+ assert.equal(r.status, 0, `the driver itself must not fail\n${r.stdout}${r.stderr}`);
75
+ return { ...JSON.parse(r.stdout.trim().split("\n").pop()), stderr: r.stderr };
76
+ }
77
+
78
+ // ── the refusal ──────────────────────────────────────────────────────────────
79
+
80
+ test("gather: a `gh` payload that parses to JSON null degrades to an empty list, not to null (#1181)", () => {
81
+ const r = gatherWith({ issuesJson: "null" });
82
+ assert.deepEqual(r.issues, []);
83
+ // Even without this guard tryParse still returns null here, and
84
+ // withNumber's own array check already rejects a null `rows` — this site
85
+ // never actually crashed. What the guard changes is the wording: this
86
+ // named line in place of withNumber's generic "expected an array of rows,
87
+ // got null" shape complaint.
88
+ assert.match(r.stderr, /gh issue list: payload is JSON null/);
89
+ // And not worded as the catch branch's fault: the parse succeeded. Reusing
90
+ // that message is the likeliest way to write this guard, and it puts the two
91
+ // states the ledger read deliberately keeps apart (#816) back under one
92
+ // wording, sending whoever reads it looking for malformed stdout that is not
93
+ // there.
94
+ assert.doesNotMatch(r.stderr, /gh issue list parse failed/);
95
+ });
96
+
97
+ test("gather: a ledger read that parses to JSON null is `unparsed`, and says which fault it was (#1181)", () => {
98
+ const r = gatherWith({ ledgerBody: `console.log("null");` });
99
+ assert.equal(r.ledger.state, "unparsed");
100
+ assert.deepEqual({ rows: r.ledger.rows, filed: r.ledger.filed, ruled: r.ledger.ruled },
101
+ { rows: [], filed: [], ruled: [] });
102
+ assert.match(r.stderr, /ledger read: payload is JSON null/);
103
+ });
104
+
105
+ // ── the accept side: what this guard must NOT refuse ─────────────────────────
106
+
107
+ test("gather: a falsy-but-readable parsed payload still reaches the caller (#1181)", () => {
108
+ // `0` stands for the whole falsy-but-readable class — `false` and `""` reach
109
+ // the identical comparison — and it is the value that discriminates the
110
+ // guard actually written from the one a reader reaches for: `=== null`
111
+ // forwards it, `!parsed` swallows it. The forwarding is observable because
112
+ // withNumber is then the thing that refuses it, and it names what it saw.
113
+ const r = gatherWith({ issuesJson: "0" });
114
+ assert.deepEqual(r.issues, []);
115
+ assert.match(r.stderr, /gh issue list: expected an array of rows, got 0/,
116
+ "tryParse must forward a falsy answer to its caller's own shape guard, not intercept it");
117
+ assert.doesNotMatch(r.stderr, /gh issue list: payload is JSON null/,
118
+ "0 is not null — reporting it as such is the falsiness bug this pins");
119
+ });