@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,129 @@
1
+ // #141. `review-and-fix.md` establishes that `./agent-test` is not the command
2
+ // to hand a specialist in a review snapshot: `agent-test` is a TRACKED
3
+ // bootstrap (#55) present in any `git archive HEAD | tar -x` copy, and it
4
+ // materializes the runner via `claim-ticket.sh --write-runner`, which derives
5
+ // the isolation triple from the directory name — a snapshot is not a claimed
6
+ // worktree, so every snapshot in the fleet resolves to the same fixed ports.
7
+ // The "filesystem isolation is not stack isolation"
8
+ // guard in both run-team documents said the opposite — it paired the snapshot
9
+ // with `./agent-test` and closed with "say both, every time", handing a
10
+ // specialist on a snapshot a command that collides with every sibling's.
11
+ //
12
+ // The reason moved once, and the conclusion did not. Until #1056 the
13
+ // materialization simply FAILED there (`claim-ticket: not inside a git
14
+ // repository`, since a bare extraction has no `.git`); the snapshot is now
15
+ // `git init`ed at cut time, so the bootstrap succeeds and produces a runner
16
+ // that is the wrong command for a different, older reason — the stack this
17
+ // section is named for. Measured in a snapshot cut by the current block:
18
+ // `--write-runner` exits 0 and reports `ports derive from the issue number:
19
+ // postgres=16000 ollama=22000`.
20
+ //
21
+ // The two audiences are not interchangeable and neither pin below stands alone:
22
+ // the member in a worktree DOES have the runner and must keep being told to use
23
+ // it, so a sweep that strips `./agent-test` from the guard is the opposite
24
+ // failure and has to redden too.
25
+ //
26
+ // Why point rather than restate: the bullet immediately above this guard in
27
+ // run-team/SKILL.md reserves specialist tree isolation — snapshot provisioning
28
+ // included — to `review-and-fix.md`, so naming the specialist's command here
29
+ // would trade one contradiction for a duplicate that can drift. But a pointer
30
+ // outlives its target silently — measured, deleting review-and-fix.md's
31
+ // specialist-command bullet reddened nothing — so the third pin below holds the
32
+ // TARGET present instead of copying it.
33
+ //
34
+ // THE CEILING, same as agent-test-dir-prose.test.mjs: PRESENCE pins over a
35
+ // bounded slice. A later sentence re-pairing the snapshot with the runner stays
36
+ // green. Reflow stays green by design — `phrase()` matches across any run of
37
+ // whitespace, so run-team/SKILL.md's hard-wrapped copy and isolation.md's long
38
+ // lines take the same regexes.
39
+ import { test } from "node:test";
40
+ import assert from "node:assert/strict";
41
+ import { readFileSync, readdirSync } from "node:fs";
42
+ import { join } from "node:path";
43
+ import { between, phrase } from "./prose-pin.mjs";
44
+
45
+ const REPO = join(import.meta.dirname, "..");
46
+ const read = (...p) => readFileSync(join(REPO, ...p), "utf8");
47
+ const RUN_TEAM = read("skills", "run-team", "SKILL.md");
48
+ const ISOLATION = read("skills", "run-team", "references", "isolation.md");
49
+ const REVIEW_AND_FIX = read("commands", "review-and-fix.md");
50
+
51
+ // Each row carries its label once: the row name is also `between()`'s `what`,
52
+ // so the test name and the doc named in a drift failure cannot disagree.
53
+ const slices = [
54
+ ["run-team/SKILL.md", RUN_TEAM, "Filesystem isolation is not stack isolation", "Scratchpad paths need two levels"],
55
+ ["references/isolation.md", ISOLATION, "## Filesystem isolation is not stack isolation", "## Scratchpad paths need two levels"],
56
+ ];
57
+
58
+ for (const [name, text, from, to] of slices) {
59
+ const slice = () => between(text, from, to, name);
60
+
61
+ test(`${name} sends the specialist on a snapshot to review-and-fix.md for the command`, () => {
62
+ assert.match(slice(), phrase("`review-and-fix.md`"));
63
+ });
64
+
65
+ test(`${name} keeps \`./agent-test\` as the worktree audience's command`, () => {
66
+ assert.match(slice(), phrase("worktree uses `./agent-test`"));
67
+ });
68
+ }
69
+
70
+ // Both pins above POINT at review-and-fix.md rather than restate it, so the
71
+ // target's presence needs its own pin or the pointer orphans in silence. The end
72
+ // anchor is the generic next-bullet marker, not the following bullet's wording,
73
+ // which would make an unrelated rewrite of that bullet a boundary failure here.
74
+ // Bounding is not optional: the glob occurs twice in that file, so an unbounded
75
+ // pin would stay satisfied by the other occurrence with this bullet deleted.
76
+ test("review-and-fix.md still hands specialists the command both guards point at", () => {
77
+ const bullet = between(REVIEW_AND_FIX, "Give specialists a stack-free test command", "\n- **", "review-and-fix.md");
78
+ assert.match(bullet, phrase("node --test plugin/scripts/*.test.mjs"));
79
+ });
80
+
81
+ // #1150: any member that dispatches a child writes the child's absolute scratch
82
+ // path into its prompt, and the child never derives its own. This bullet is the
83
+ // fallback dispatch site — a member hand-dispatching the specialists because the
84
+ // review could not run — so "their own scratch dir" has to name the directory
85
+ // and who resolves it, pinned with its path. Same bullet slice as above.
86
+ test("review-and-fix.md's fallback specialist dispatch assigns each specialist an absolute scratch path", () => {
87
+ const bullet = between(REVIEW_AND_FIX, "Give specialists a stack-free test command", "\n- **", "review-and-fix.md");
88
+ assert.match(
89
+ bullet,
90
+ phrase("`<scratch>/pr<N>/fleet-review-<key>/`, resolved to an absolute path that you write into that specialist's prompt; a specialist never derives its own"),
91
+ "the fallback specialist dispatch no longer names the directory each specialist gets, or no longer has the dispatcher write it, absolute, into the specialist's prompt",
92
+ );
93
+ });
94
+
95
+ // The same contradiction in the other voice: a test file whose comment tells the
96
+ // reader to run it with the worktree runner. A specialist reads that comment on
97
+ // a snapshot, where the runner is not. `node --test <path>` is what most other
98
+ // suite comments here already say, and it runs in both trees — measured on the
99
+ // two files this replaced it in, from the worktree root and from a real
100
+ // `git archive HEAD | tar -x` snapshot (35 and 72 tests, 0 fail, in each; the
101
+ // snapshot carried no `agent-test`).
102
+ //
103
+ // The pattern is a runner invocation whose next token is a path — it holds a
104
+ // separator or ends in `.test.mjs` — so it skips agent-test-dir-prose.test.mjs,
105
+ // whose header discusses the runner as a subject rather than as an instruction.
106
+ // Narrower spellings were measured and rejected: anchoring on a literal
107
+ // `skills/` misses the same instruction written with a `./` on the path, a bare
108
+ // relative path, a quoted glob, or no `./` on the runner, and requiring the
109
+ // argument to end in `.test.mjs` drops the directory form the runner also takes.
110
+ // The `(?!\/\/)` is load-bearing rather than defensive: `\s+` must cross
111
+ // newlines to reach a block comment's continuation, and without the lookahead
112
+ // correct prose that merely ends a line on the runner's name reds too —
113
+ // measured at 7 of 71 reflow widths of agent-test-dir-prose.test.mjs's
114
+ // untouched header, against 0 with it.
115
+ //
116
+ // ITS CEILING: an instruction wrapped across two `//` continuation lines stays
117
+ // green. That is character-identical to wrapped prose about the runner, so no
118
+ // regex separates them; reword such a comment when you meet one.
119
+ //
120
+ // It stays a REGEX with its slashes escaped for a second reason: written as a
121
+ // plain string literal the pattern would occur in this file, and the scan would
122
+ // report itself.
123
+ test("no suite comment tells the reader to run it with the worktree runner", () => {
124
+ const dir = import.meta.dirname;
125
+ const offenders = readdirSync(dir)
126
+ .filter((f) => f.endsWith(".test.mjs"))
127
+ .filter((f) => /agent-test\s+(?!\/\/)\S*(?:\/|\.test\.mjs)/.test(readFileSync(join(dir, f), "utf8")));
128
+ assert.deepEqual(offenders, [], `name \`node --test <path>\` instead: ${offenders.join(", ")}`);
129
+ });
@@ -0,0 +1,312 @@
1
+ import { test } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { readFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+
6
+ // `board.html` is served as ONE self-contained file — board.mjs stages it with a
7
+ // single copyFileSync and createBoardServer routes only `/`, `/board.html` and
8
+ // `/board.json` — so its script is inline and there is nothing to import. The
9
+ // decision under test is lifted out of the SOURCE TEXT and evaluated instead,
10
+ // the same technique select-dimensions.test.mjs uses against scripts/review-core.mjs.
11
+ //
12
+ // Extraction to a module is deliberately NOT the shape here: it would need a
13
+ // second staged file and a fourth route, and a page that renders blank whenever
14
+ // the staging of that second file fails. Coupling to the literal spelling is the
15
+ // cheaper risk, because it breaks loudly, here.
16
+ const HTML = readFileSync(join(import.meta.dirname, "board.html"), "utf8");
17
+
18
+ // A lift reads a COPY. Three guards below keep that copy tied to the page: this
19
+ // one, so a second declaration cannot shadow the lifted one at runtime (a
20
+ // duplicate placed AFTER the real declaration wins by hoisting and is otherwise
21
+ // invisible to every lift); the call-site pin, so the page still routes through
22
+ // what is pinned; and the parse check, so the script the browser gets is valid.
23
+ for (const [name, re] of [
24
+ ["spendView", /^function\s+spendView\s*\(/gm],
25
+ ["k", /^const k = /gm],
26
+ ]) {
27
+ test(`board.html declares ${name} exactly once at top level`, () => {
28
+ assert.equal(HTML.match(re)?.length, 1,
29
+ `${name} must be declared exactly once — a second top-level declaration wins at runtime and the lift below would still read the first`);
30
+ });
31
+ }
32
+
33
+ // Slice to renderSpend's own body before matching, and drop comment lines: a
34
+ // whole-file assert.match is satisfied by any mention anywhere, including a
35
+ // commented-out one.
36
+ // Parameter names are matched as `\w+` throughout, never as the literal `sp`,
37
+ // and the whitespace around a declaration's name and paren is matched as `\s`,
38
+ // never as the literal single space. Neither a rename nor a reformat is a
39
+ // defect, and a lift that misses because of one throws where node registers no
40
+ // test at all — the file's whole total drops in silence rather than reporting a
41
+ // named failure. The duplicate guard above is deliberately `\s`-tolerant in the
42
+ // same places: loosening only that one lets a reformatted declaration pass the
43
+ // count and then die in the lift.
44
+ const renderSpend = HTML.match(/^function\s+renderSpend\s*\((\w+)\)\s*\{[\s\S]*?^\}$/m);
45
+ const renderSpendBody = renderSpend
46
+ ? renderSpend[0].split("\n").filter((l) => !/^\s*\/\//.test(l)).join("\n")
47
+ : "";
48
+
49
+ test("renderSpend routes through spendView rather than re-deriving the branch", () => {
50
+ assert.ok(renderSpend, "board.html no longer declares renderSpend as a top-level function — update this test");
51
+ // Without this the whole decision can be disconnected in one token and every
52
+ // case below still passes, against a function the page never calls.
53
+ // The call, not the name it is bound to — a renamed local is not a defect.
54
+ assert.match(renderSpendBody, /=\s*spendView\(\w+\);/);
55
+ // The tri-state must not be re-tested in the renderer; that is what the split
56
+ // removed. The decision's own fields may be read freely; the raw argument
57
+ // reaches exactly one place, the spendView call, and nowhere else. Matching
58
+ // `if (…)` shapes instead pins one spelling of a re-derivation: a pattern
59
+ // anchored on the argument being followed by `.` or `)` is evaded by
60
+ // `if (sp && sp.error)`, by `if (sp?.error)`, and by `const { error } = sp`.
61
+ const bodySansCall = renderSpendBody
62
+ .slice(renderSpendBody.indexOf("{") + 1) // drop the signature
63
+ .replace(/=\s*spendView\(\w+\);/, ""); // and the one legitimate use
64
+ assert.doesNotMatch(bodySansCall, new RegExp(`\\b${renderSpend[1]}\\b`));
65
+ });
66
+
67
+ // The test above pins that the decision is REACHED; these pin that each field
68
+ // lands in its own slot. Without them the panel can be miswired one token at a
69
+ // time and every case below still passes, because those only ever look at what
70
+ // spendView RETURNS: drop the hidden branch and a `kind:"hidden"` decision
71
+ // appends an empty `spend-wrap` every tick at run start — the #371 behaviour
72
+ // itself, a box where the panel must render nothing — or swap the two column
73
+ // lists, or the two header strings, and nothing goes red.
74
+ //
75
+ // Each column is pinned by ONE match that carries its heading and its rows
76
+ // together, and the backreference on the host local is the whole of it: a pin
77
+ // on the heading plus a separate pin on the list does not pin that the two
78
+ // belong to the same column, because each is satisfied by the OTHER column's
79
+ // call. Measured on the two-pin form: swapping the two lists, swapping the two
80
+ // headings, and feeding both calls the same host each left this file fully
81
+ // green, and a role column rendering the tool list is what the block exists to
82
+ // catch. The host stays `\w+` — renaming the local is not a defect; what is
83
+ // pinned is that the local a heading is appended to is the local its rows go
84
+ // to. Adjacency of those two statements is part of the pin: a wrapped
85
+ // `append(` survives the collapse below — the optional comma is the trailing
86
+ // one such a wrap picks up — but a statement spliced between a heading and its
87
+ // rows reds it, and that is a restructure worth reading, not a reflow.
88
+ //
89
+ // Left unpinned on purpose: the two `spendRows` option objects. Swapping those
90
+ // is green here, and it is the one wiring break that cannot pass for correct on
91
+ // the page — the callbacks read `.tool`/`.calls` off role rows and `.role`/
92
+ // `.agents` off tool rows, so every label in the column reads `undefined`,
93
+ // where a column silently fed the other list looks like a plausible panel.
94
+ // Pinning them would tie this file to the spelling of four callbacks.
95
+ //
96
+ // Matched against a whitespace-collapsed body: where a line breaks is not
97
+ // wiring, and a pin that reds on a reflow is a false alarm that trains the next
98
+ // reader to loosen it. `flat` is the idiom the *-prose.test.mjs files here use,
99
+ // plus paren-adjacent trimming, because the reflow a long call actually gets is
100
+ // a wrap straight after `(` — which collapsing alone leaves as `spendRows( host,`
101
+ // and every pin below would then miss. Spacing after a comma is left as the one
102
+ // space the collapse produces; the pins are written with it.
103
+ const renderSpendFlat = renderSpendBody
104
+ .replace(/\s+/g, " ").replace(/\( /g, "(").replace(/ \)/g, ")");
105
+ for (const [claim, re] of [
106
+ ["the hidden decision appends nothing", /if \(\w+\.kind === "hidden"\) return;/],
107
+ ["a text-only decision reaches the DOM", /el\("div", "spend-wrap", \w+\.text\)/],
108
+ ["the lede string fills the lede slot", /el\("span", "lede", \w+\.lede\)/],
109
+ ["the note string fills the note slot", /el\("span", "note", \w+\.note\)/],
110
+ ["the role list fills the column headed `by role`", /(\w+)\.append\(el\("h3", null, "by role"\),?\); spendRows\(\1, \w+\.roles,/],
111
+ ["the tool list fills the column headed by the tool heading", /(\w+)\.append\(el\("h3", null, \w+\.toolHeading\),?\); spendRows\(\1, \w+\.tools,/],
112
+ ]) {
113
+ test(`renderSpend wires the decision through: ${claim}`, () => {
114
+ assert.match(renderSpendFlat, re);
115
+ });
116
+ }
117
+
118
+ // Both the parse check right below and the K_SRC/VIEW_SRC lifts further down
119
+ // each read board.html's inline script via a single (non-global) match, so
120
+ // both assume the page carries exactly one <script> block: a second block —
121
+ // decoy or real, placed before OR after the renderer's own — is silently
122
+ // invisible to whichever occurrence that match happens to land on, and the
123
+ // duplicate-declaration guards above only ever catch a second `k`/`spendView`
124
+ // specifically, not every way a second block could misdirect these reads.
125
+ // Named as its own test and placed before both reads: asserting this inline,
126
+ // mixed into either read as a bare top-level statement, would throw during
127
+ // module load on failure and drop this whole file's test count to zero
128
+ // instead of reporting a named failure.
129
+ test("board.html carries exactly one <script> block", () => {
130
+ const blocks = [...HTML.matchAll(/<script>\n[\s\S]*?\n<\/script>/g)];
131
+ assert.equal(blocks.length, 1,
132
+ "board.html's parse check and its K_SRC/VIEW_SRC lifts below all assume exactly one " +
133
+ "<script> block — if a second is genuinely wanted, those reads need to become " +
134
+ "block-scoped rather than whole-file, and this assertion updated to match");
135
+ });
136
+
137
+ test("board.html's inline script parses", () => {
138
+ // An extraction is a restructure of this file's script; a broken one would not
139
+ // fail any other test in the suite, it would blank the page at runtime.
140
+ const m = HTML.match(/<script>\n([\s\S]*?)\n<\/script>/);
141
+ assert.ok(m, "board.html no longer carries its renderer in a bare inline <script> — update this test");
142
+ assert.doesNotThrow(() => new Function(`return function(){${m[1]}}`));
143
+ });
144
+
145
+ // `spendView` closes over `k`, a module-level const declared above it, so the
146
+ // lift takes both. Left out, `k` is a ReferenceError rather than a wrong answer —
147
+ // it fails loud rather than pinning a stale result.
148
+ const K_SRC = HTML.match(/^const k = .*;$/m);
149
+ const VIEW_SRC = HTML.match(/^function\s+spendView\s*\(\w+\)\s*\{[\s\S]*?^\}$/m);
150
+
151
+ test("board.html still declares k and spendView in the shape this file lifts", () => {
152
+ // Named, and outside the lift itself: asserting inside it throws before node
153
+ // registers anything, which drops the file's total to zero and reports one
154
+ // file-level error instead of telling you which claim stopped holding.
155
+ assert.ok(K_SRC, "board.html no longer declares `k` as a one-line top-level const — update this test");
156
+ assert.ok(VIEW_SRC, "board.html no longer declares spendView as a top-level function — update this test");
157
+ });
158
+
159
+ const spendView = K_SRC && VIEW_SRC
160
+ ? new Function(`${K_SRC[0]}\n${VIEW_SRC[0]}\nreturn spendView;`)()
161
+ : () => { throw new Error("spendView could not be lifted from board.html — see the shape test above"); };
162
+
163
+ // A run whose transcripts all read fine. Fields are the ones gatherSpend returns,
164
+ // `ok: true` included — it is the tag the view routes on, not decoration (#959).
165
+ const ok = (o = {}) => ({
166
+ ok: true,
167
+ totals: { cacheWrite: 2_000_000, cacheRead: 500_000, output: 12_000, agents: 4 },
168
+ roles: [{ role: "reviewer", agents: 2, cacheWrite: 1_500_000, pct: 75 }],
169
+ tools: [{ tool: "Bash", calls: 9, cacheWrite: 400_000, pct: 40 }],
170
+ reviewPct: 75,
171
+ attributedPct: 60,
172
+ skipped: 0,
173
+ ...o,
174
+ });
175
+
176
+ test("no spend yet hides the panel", () => {
177
+ // Normal at run start: gatherSpend returns null when there is no transcript
178
+ // dir to read and nothing was skipped.
179
+ assert.deepEqual(spendView(null), { kind: "hidden" });
180
+ assert.deepEqual(spendView(undefined), { kind: "hidden" });
181
+ });
182
+
183
+ test("an error is shown, never hidden", () => {
184
+ // The operator has to act on this one, and stderr is not a channel: the board
185
+ // is launched backgrounded and the operator is watching the page.
186
+ assert.deepEqual(spendView({ ok: false, error: "no transcript dir for cwd /x" }),
187
+ { kind: "error", text: "spend unavailable: no transcript dir for cwd /x" });
188
+ });
189
+
190
+ test("a success object with no cache-write but a non-zero skipped count reports the skip, not nothing (#371)", () => {
191
+ // THE REGRESSION THIS FILE EXISTS FOR. renderSpend used to return early on a
192
+ // falsy cacheWrite and swallow `skipped` with it, so a run whose transcripts
193
+ // were unreadable rendered identically to a run that had not started. The fix
194
+ // shipped with nothing to pin it.
195
+ assert.deepEqual(spendView(ok({ totals: { cacheWrite: 0, cacheRead: 0, output: 0, agents: 0 }, skipped: 3 })),
196
+ { kind: "note", text: "3 transcripts skipped; no spend recorded yet" });
197
+ // Same conflation one step earlier: totals absent entirely rather than zeroed.
198
+ assert.deepEqual(spendView({ ok: true, skipped: 1 }),
199
+ { kind: "note", text: "1 transcript skipped; no spend recorded yet" });
200
+ });
201
+
202
+ test("no cache-write and nothing skipped is the one legitimate hide", () => {
203
+ // Zeroes would read as "this run was free", a worse lie than absence. With no
204
+ // skipped count there is nothing to report, so absence is correct here.
205
+ assert.deepEqual(spendView(ok({ totals: { cacheWrite: 0, cacheRead: 0, output: 0, agents: 0 }, skipped: 0 })),
206
+ { kind: "hidden" });
207
+ });
208
+
209
+ test("a funded run renders the panel, with both headline strings", () => {
210
+ const v = spendView(ok());
211
+ assert.equal(v.kind, "panel");
212
+ assert.equal(v.lede, "2.0M cache-write · 500k cache-read · 12k output · 4 agents · review 75%");
213
+ assert.equal(v.note, "ranked on cache-creation; tool split is attributed, not billed");
214
+ assert.equal(v.toolHeading, "by tool — 60% of cache-write attributed");
215
+ assert.deepEqual(v.roles, [{ role: "reviewer", agents: 2, cacheWrite: 1_500_000, pct: 75 }]);
216
+ assert.deepEqual(v.tools, [{ tool: "Bash", calls: 9, cacheWrite: 400_000, pct: 40 }]);
217
+ });
218
+
219
+ test("a funded run still carries its skipped count into the panel note", () => {
220
+ // The skip does not stop mattering once there is spend to show: the count is
221
+ // live every tick, and the note is the only place it reaches the operator.
222
+ assert.equal(spendView(ok({ skipped: 2 })).note,
223
+ "2 transcripts skipped; ranked on cache-creation; tool split is attributed, not billed");
224
+ });
225
+
226
+ test("a fully unattributed run says 0%, and only an absent figure falls back", () => {
227
+ // The guard is `!= null`, not truthiness: 0% attributed is a real measurement
228
+ // and reads differently from "this build does not compute one".
229
+ assert.equal(spendView(ok({ attributedPct: 0 })).toolHeading, "by tool — 0% of cache-write attributed");
230
+ assert.equal(spendView(ok({ attributedPct: null })).toolHeading, "by tool");
231
+ });
232
+
233
+ test("the tool column is capped and both columns tolerate a missing list", () => {
234
+ const many = Array.from({ length: 12 }, (_, i) => ({ tool: `t${i}`, calls: 1, cacheWrite: 1, pct: 1 }));
235
+ assert.equal(spendView(ok({ tools: many })).tools.length, 8);
236
+ const bare = spendView(ok({ roles: undefined, tools: undefined }));
237
+ assert.deepEqual(bare.roles, []);
238
+ assert.deepEqual(bare.tools, []);
239
+ });
240
+
241
+ test("#916: a damaged-line count reaches the panel note, distinctly from a skip", () => {
242
+ // Second tally, second phrase. `skipped` means the transcript contributed
243
+ // nothing; `damaged` means it contributed but the torn line's own tool_use
244
+ // blocks and output_tokens snapshot may be missing — cache_creation/
245
+ // cache_read repeat on every line of a turn and survive a mid-turn tear,
246
+ // so the phrase hedges rather than asserting the numbers beside it are wrong.
247
+ assert.equal(spendView(ok({ damaged: 1 })).note,
248
+ "1 damaged transcript line — spend may be incomplete; ranked on cache-creation; tool split is attributed, not billed");
249
+ // Both in one tick, plural wording, in the order the note lists them:
250
+ // most spend lost first. A phrase spliced into the wrong slot reds here.
251
+ assert.equal(spendView(ok({ skipped: 1, damaged: 3 })).note,
252
+ "1 transcript skipped; 3 damaged transcript lines — spend may be incomplete; ranked on cache-creation; tool split is attributed, not billed");
253
+ });
254
+
255
+ test("#916: a run whose only turn WAS the damaged line reports the damage, not nothing", () => {
256
+ // The worst case in the ticket, and the one measured on the tree before this
257
+ // fix: a transcript holding a single torn line and nothing else returned
258
+ // `kind: "hidden"` — the panel rendered NOTHING for a run whose entire spend
259
+ // had been destroyed, a fault presented as an idle run. cacheWrite is 0
260
+ // because the damaged line was the only cache-creation turn there was, so
261
+ // `skipped` is 0 and this branch is reachable by
262
+ // `damaged` alone.
263
+ assert.deepEqual(spendView(ok({ totals: { cacheWrite: 0, cacheRead: 0, output: 0, agents: 1 }, skipped: 0, damaged: 1 })),
264
+ { kind: "note", text: "1 damaged transcript line; no spend recorded yet" });
265
+ });
266
+
267
+ test("#916: a clean empty run with damaged zero is still the one legitimate hide", () => {
268
+ // The no-false-positive half at the view layer: an unguarded push renders
269
+ // "0 damaged transcript lines; no spend recorded yet" over a run that has
270
+ // simply not started, which is the reverse of the conflation this panel
271
+ // removes. The funded branch's copy of that mutation reds the plain-note test
272
+ // above; this is the branch that one cannot see.
273
+ assert.deepEqual(spendView(ok({ totals: { cacheWrite: 0, cacheRead: 0, output: 0, agents: 0 }, skipped: 0, damaged: 0 })),
274
+ { kind: "hidden" });
275
+ });
276
+
277
+ test("an error with no usable message still renders the error panel (#959)", () => {
278
+ // The case #371 pinned as broken and #959 fixed. gatherSpend's outer catch
279
+ // returns `{ ok: false, error: e.message }`, and `e.message` is "" for an
280
+ // error thrown without one and `undefined` for a thrown non-Error — two
281
+ // shapes that, under the old truthiness discriminant, missed the error branch,
282
+ // found no totals, and HID the panel: a fault rendered as an idle run.
283
+ //
284
+ // Both are one case now, because the tag decides and the message only words
285
+ // the text. That is the whole value of the reshape over a presence check,
286
+ // which would have fixed "" and left `undefined` hidden.
287
+ const shown = { kind: "error", text: "spend unavailable: no reason given" };
288
+ assert.deepEqual(spendView({ ok: false, error: "" }), shown);
289
+ assert.deepEqual(spendView({ ok: false, error: undefined }), shown);
290
+ assert.deepEqual(spendView({ ok: false }), shown);
291
+ });
292
+
293
+ test("the TAG decides the branch, never the presence or truthiness of another field (#959)", () => {
294
+ // What makes the reshape more than a fixed discriminant: nothing but `ok`
295
+ // says which case a payload is. A success payload that happens to carry an
296
+ // `error` key is still a success, so no future reader can reintroduce
297
+ // "the error field means it failed" and have the suite agree.
298
+ assert.equal(spendView(ok({ error: "left over from somewhere" })).kind, "panel");
299
+ });
300
+
301
+ test("an untagged payload is treated as an error, never as a success (#959)", () => {
302
+ // The wrongly-REFUSE direction, decided on purpose. `!sp.ok` means a stale
303
+ // `board.json` written by an older board.mjs renders "spend unavailable"
304
+ // rather than its panel — a visible wrong answer that self-heals on the next
305
+ // tick (~15s). The alternative bias, `sp.ok === false`, would route a legacy
306
+ // `{ error: "…" }` back to hidden, which is the invisible wrong answer this
307
+ // whole ticket exists to remove. Loud and temporary beats silent.
308
+ assert.equal(spendView({ totals: { cacheWrite: 2_000_000, cacheRead: 1, output: 1, agents: 1 }, reviewPct: 50 }).kind, "error");
309
+ // A legacy error payload keeps its message rather than losing it to the fallback.
310
+ assert.deepEqual(spendView({ error: "no transcript dir for cwd /x" }),
311
+ { kind: "error", text: "spend unavailable: no transcript dir for cwd /x" });
312
+ });