@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,189 @@
1
+ // #1550. PR #1084 (implemented as #1530) added two directory-safety rules to
2
+ // the (since-retired) `review-pr` WORKFLOW's specialist prompt — chain the
3
+ // directory change into the command, and bracket a fixture's own git with
4
+ // `git rev-parse --show-toplevel` — mirroring what PR #1082 had already
5
+ // added to that same file's REFUTER prompt. `scripts/review-core.mjs`
6
+ // carried the same specialist dispatch prompt and, at the time, neither
7
+ // rule, while ordering the same kind of work: "Run any mutation or probe
8
+ // work inside your own copy of the snapshot." `review-core.mjs` is now the
9
+ // only surviving copy of this prompt.
10
+ //
11
+ // Naming the write area is not the same rule and does not close either failure
12
+ // mode. The specialist prompt already said scratch files go in its own
13
+ // directory "and nowhere else", and both measured failures happen with that
14
+ // sentence obeyed as written: a `cd` that silently fails leaves the following
15
+ // `;`-separated `git` running in whatever directory the agent was already in —
16
+ // the incident review-core-refuter-scratch.test.mjs records as commit
17
+ // 020d6ea reaching the checkout during the PR #488 fix-applier run — and an
18
+ // agent that BELIEVES it is already in its scratch copy and is wrong runs
19
+ // `git init` / `git commit` against the repository. A rule about where
20
+ // writes SHOULD go does not detect either.
21
+ //
22
+ // INLINED, NOT SHARED: #496's brief rules the shared-source route out — "the
23
+ // drift hazard is real and is its own ticket, not this one." That drift
24
+ // hazard is exactly what this pin exists to convert into a red: it failed to
25
+ // fire once already, which is why this ticket exists at all.
26
+ //
27
+ // WHY THESE PINS RENDER RATHER THAN GREP. Two reasons, and the second is the
28
+ // one a source-text pin cannot reach. The rules live inside a template
29
+ // literal, so their backticks are written escaped (`` \` ``); a pin written
30
+ // against the source has to tolerate that backslash, and then it passes just
31
+ // as happily on a prompt that shows the specialist a literal `\` instead of a
32
+ // code span. Rendering settles what the agent actually reads. And a bounded
33
+ // slice of the SOURCE would still be satisfied by dead text — the vacuity
34
+ // class strip-comments.mjs exists for — whereas a commented-out prompt does
35
+ // not render at all.
36
+ //
37
+ // THE SLICE IS THE PIN. Each rule appears more than once in this file (the
38
+ // verify/refuter prompt below carries its own, older copy), so every regex
39
+ // here would be satisfied by the refuter's copy alone if it were matched
40
+ // against the whole file — which is exactly the defect this ticket reports,
41
+ // so a pin that could pass on the refuter's copy would have passed before the
42
+ // fix. The extraction is bounded at both ends by the specialist `agent()`
43
+ // call's own template and its `review:` label, so the refuter prompt is
44
+ // outside it by construction. Both directions were measured: reverting the two
45
+ // rules out of the specialist prompt reds all three tests here with the
46
+ // refuter's copy untouched.
47
+ //
48
+ // THE CEILING, same as review-pr-refuter-scratch.test.mjs's: nothing here
49
+ // reaches the agent's own obedience. These pins settle what a specialist is
50
+ // TOLD, never where it actually writes.
51
+ import { test } from "node:test";
52
+ import assert from "node:assert/strict";
53
+ import { readFileSync } from "node:fs";
54
+ import { join } from "node:path";
55
+ import { stripComments } from "./strip-comments.mjs";
56
+ import { between } from "./prose-pin.mjs";
57
+
58
+ const REPO = join(import.meta.dirname, "..");
59
+ const SOURCE = readFileSync(join(REPO, "scripts", "review-core.mjs"), "utf8");
60
+ const CODE = stripComments(SOURCE);
61
+
62
+ const TEMPLATE_START = "`Review PR #${pr} (branch ${branch}) for: ";
63
+ const TEMPLATE_END = "label: `review:";
64
+
65
+ // The template's free names, in the order `render` binds them. `readRules`,
66
+ // `usableDiff` and `environmentNote` are stubs: what they return is not under
67
+ // test here, and binding them keeps a render that stops passing one from
68
+ // dropping a paragraph silently — it throws a ReferenceError instead.
69
+ const SCOPE = ["pr", "branch", "d", "snap", "worktree", "stats", "testCmd", "readRules", "usableDiff", "environmentNote"];
70
+
71
+ // `between` owns the bounded-slice extraction (and both failure messages);
72
+ // only the backtick trim below is specific to a template literal and stays
73
+ // here.
74
+ const SLICE = between(
75
+ CODE,
76
+ TEMPLATE_START,
77
+ TEMPLATE_END,
78
+ "review-core.mjs's specialist prompt (opening `Review PR #${pr} (branch ${branch}) for: `, labelled `review:`)",
79
+ );
80
+
81
+ const RENDER = new Function(...SCOPE, "return `" + SLICE.slice(1, SLICE.lastIndexOf("`")) + "`");
82
+
83
+ // One specialist's prompt. Every argument is fixed: these pins are about what
84
+ // the prompt SAYS, not about how it varies, so nothing here needs to.
85
+ const render = () =>
86
+ RENDER(
87
+ 7,
88
+ "feature/x",
89
+ { key: "correctness", prompt: "does it do what it says" },
90
+ { path: "/scr/run-1/snapshot-abc1234", head: "abc1234", runRoot: "/scr/run-1" },
91
+ "/repo/.worktrees/7-x",
92
+ null,
93
+ "node --test",
94
+ () => "READ RULES",
95
+ () => null,
96
+ () => "TEST ENVIRONMENT",
97
+ );
98
+
99
+ // The first of the two rules, in the prompt that was missing it. ONE
100
+ // contiguous regex rather than two assertions, for the reason
101
+ // refuter-scratch-prose.test.mjs states about the same wording: an unbounded
102
+ // gap lets a spliced sentence carve an exception INTO the rule and stay green.
103
+ // Both gaps are the literal punctuation the rendered prompt carries around
104
+ // "never" ("…`, " before it, a line break plus backtick after) rather than a
105
+ // free-text `.{0,N}` span — mutation-tested: an exception clause spliced into
106
+ // either gap (e.g. "never except during setup steps") reds this assertion.
107
+ //
108
+ // Both spellings are required, and the negative one is what carries the rule —
109
+ // `cd "$D" && git …` alone reads as a suggestion, and the observed failure is
110
+ // an agent writing the other form.
111
+ test("the rendered specialist prompt chains cd into the git command, never semicolon", () => {
112
+ assert.match(
113
+ render(),
114
+ /cd\s+"\$D"\s+&&\s+git\s+…`,\s+never\s+`cd\s+"\$D";\s+git\s+…/s,
115
+ "review-core.mjs's specialist prompt carries no cd-chaining rule — a silently failed `cd` leaves the following `git` " +
116
+ "running in the checkout, which is what produced commit 020d6ea during the PR #488 fix-applier run (#1550)",
117
+ );
118
+ });
119
+
120
+ // The second rule. Both halves, because they have OPPOSITE expected outcomes:
121
+ // a lone "resolves to your scratch path" guard is unsatisfiable before `git
122
+ // init` — a fresh scratch dir has no toplevel and exits 128 — and a guard that
123
+ // cannot pass on the clean path gets ignored. Naming a path alone does not
124
+ // catch the observed failure either, which was an agent BELIEVING it was
125
+ // already in scratch and being wrong. Gaps are the literal prose between the
126
+ // four clauses, typed out rather than left as a free-text `.{0,N}` span —
127
+ // mutation-tested: a short exception clause spliced into any of the first,
128
+ // third, or fourth gaps (e.g. "except in CI runners," right after the
129
+ // leading `:`, or "except during rebase," right after "not a failure;")
130
+ // reds this assertion; the same splices pass a `.{0,N}`-gapped version of
131
+ // this regex undetected.
132
+ //
133
+ // The realpath tail is part of the pin, not decoration on it, and carries the
134
+ // same typed gaps for the same reason. PR #1567 added that remedy to all four
135
+ // copies of this rule but the pin to only the refuter's two, so the clause sat
136
+ // unpinned in both specialist prompts: deleting it from both (measured, #1570)
137
+ // left this file and its review-pr sibling at 6/6 and the four refuter/prose
138
+ // pins at 41/41, all green. It is also the half that makes the rule
139
+ // satisfiable in the OTHER direction — `--show-toplevel` answers
140
+ // `/private/tmp/…` for a `/tmp` scratch dir on macOS, so a raw string compare
141
+ // reports a mismatch on the clean path, and a guard that cannot pass there
142
+ // gets ignored exactly as a lone `git init` half would.
143
+ //
144
+ // Both directions on the tail itself: an exception clause spliced into its
145
+ // leading gap ("…your scratch path, except in CI runners — compare resolved
146
+ // forms…") reds this assertion, where the `.{0,80}`-gapped spelling in
147
+ // review-pr-specialist-scratch.test.mjs lets it through; rewrapping the clause
148
+ // to one line and to a narrower column stays green, since every gap here is
149
+ // `\s+` (all measured).
150
+ test("the rendered specialist prompt requires a toplevel assertion around git init/commit, including the realpath remedy for macOS's /private/tmp symlink", () => {
151
+ assert.match(
152
+ render(),
153
+ /`git\s+rev-parse\s+--show-toplevel`:\s+before\s+`git\s+init`\s+it\s+must\s+NOT\s+resolve\s+to\s+the\s+repository,\s+and\s+a\s+fresh\s+scratch\s+dir's\s+`fatal:\s+not\s+a\s+git\s+repository`\s+\(exit\s+128\)\s+is\s+the\s+pass,\s+not\s+a\s+failure;\s+before\s+any\s+`git\s+commit`\s+it\s+must\s+resolve\s+to\s+your\s+scratch\s+path\s+—\s+compare\s+resolved\s+forms\s+\(`realpath`\),\s+since\s+`--show-toplevel`\s+can\s+report\s+`\/private\/tmp\/…`\s+for\s+a\s+`\/tmp`\s+scratch\s+dir\s+on\s+macOS/s,
154
+ "review-core.mjs's specialist prompt carries no toplevel assertion around a fixture's own git init/commit, or " +
155
+ "dropped the realpath remedy for macOS's /private vs /tmp symlink — an agent that wrongly believes it is " +
156
+ "already in its scratch copy runs `git init`/`git commit` against the repository, and a raw compare against " +
157
+ "`--show-toplevel` reads a `/private/tmp` answer for a `/tmp` scratch dir as a mismatch on the clean path (#1550, #1570)",
158
+ );
159
+ });
160
+
161
+ // The other direction, and the reason a prose pin on an ADDED rule needs one: a
162
+ // prompt that gains rules can displace the instructions those rules exist to
163
+ // make safe, and both of the added rules are written in terms of the
164
+ // specialist's own scratch area — "your scratch path" names nothing once the
165
+ // directory sentence goes, and a rule about a fixture's git is inert if the
166
+ // prompt no longer orders mutation work in a copy of its own.
167
+ //
168
+ // The scratch sentence and the first rule are asserted as one bounded span,
169
+ // with the gap between them typed as `\s+` — the rendered prompt carries
170
+ // exactly one space there, never a free-text `.{0,N}` — so a sentence spliced
171
+ // between them (mutation-tested: "Except for git fixtures, which may live
172
+ // anywhere.") reds this assertion instead of leaving both halves present and
173
+ // passing.
174
+ test("the added rules still sit on a prompt that names a write area and orders work in its own copy", () => {
175
+ const prompt = render();
176
+ assert.match(
177
+ prompt,
178
+ /Run any mutation or probe work inside your own copy of the snapshot\./,
179
+ "review-core.mjs's specialist is no longer told to do mutation or probe work in a copy of its own — the two " +
180
+ "directory rules now guard work the prompt never scopes to a copy at all",
181
+ );
182
+ assert.match(
183
+ prompt,
184
+ /Scratch\s+files\s+go\s+in\s+\/scr\/run-1\/correctness\/\s+and\s+nowhere\s+else\.\s+Chain\s+the\s+directory\s+change\s+into\s+the\s+command/s,
185
+ "review-core.mjs's specialist prompt no longer names the scratch directory immediately before the cd rule — " +
186
+ "either the write area is gone, leaving 'your scratch path' naming nothing, or a sentence between them carves " +
187
+ "an exception into it",
188
+ );
189
+ });
@@ -0,0 +1,288 @@
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
+ import { stripComments } from "./strip-comments.mjs";
6
+ import { between } from "./prose-pin.mjs";
7
+ import { resolveTestCmd, SNAPSHOT_SCHEMA } from "./review-core.mjs";
8
+
9
+ // The review host used to default `testCmd` to a literal string naming THIS
10
+ // repo's own test path — silent green everywhere else, since `worktree` is a
11
+ // caller-supplied argument and a glob matching nothing exits 0 reporting
12
+ // `tests 0` (#142). It is now READ from the repo under review's Recipe cache by
13
+ // the snapshot agent (see the "derives this repository's own test command"
14
+ // paragraph below), through derive-testcmd.sh — see derive-testcmd.test.mjs
15
+ // for that script's own coverage, exercised against fixture repos that are
16
+ // NOT this one, which is the guard #142's acceptance criteria required and an
17
+ // archive of this repo could not have been.
18
+ //
19
+ // This file covers what remains review-core.mjs's own responsibility:
20
+ // resolveTestCmd's resolution order and refusal, the snapshot agent's prompt
21
+ // and schema actually carrying the derivation, and the specialist prompt
22
+ // still handing testCmd over verbatim with the 'tests 0' rule.
23
+ const REPO = join(import.meta.dirname, "..");
24
+ const SOURCE = readFileSync(join(REPO, "scripts", "review-core.mjs"), "utf8");
25
+
26
+ // Every pin below runs against CODE, not SOURCE — the same policy, and now the
27
+ // same stripper, as `review-core-reads.test.mjs`. Written against raw source,
28
+ // this file's schema-declaration pin was VACUOUS: wrapping the real
29
+ // `testCmd: { type: "string" },` in a `/* */` block left the suite 9 pass / 0
30
+ // fail while `additionalProperties: false` silently dropped the field at
31
+ // runtime, breaking the very derivation #142 adds. The `^\s*` anchor those
32
+ // pins use rejects a leading `//` and nothing else. Measured, #142 review.
33
+ const CODE = stripComments(SOURCE);
34
+
35
+ test("an explicit override always wins, whatever the snapshot derived", () => {
36
+ assert.equal(resolveTestCmd("npm test --", { testCmd: "node --test" }), "npm test --");
37
+ assert.equal(resolveTestCmd("npm test --", null), "npm test --");
38
+ assert.equal(resolveTestCmd("npm test --", { testCmdError: "refused" }), "npm test --");
39
+ });
40
+
41
+ test("no override falls back to the snapshot agent's derivation", () => {
42
+ assert.equal(resolveTestCmd(undefined, { testCmd: "node --test" }), "node --test");
43
+ assert.equal(resolveTestCmd(null, { testCmd: "npm test --" }), "npm test --");
44
+ });
45
+
46
+ // The whole point of #142: neither an override nor a derivation must REFUSE
47
+ // the review, never fall back to a guessed default. The reason passed through
48
+ // is derive-testcmd.sh's own, which names the derivation step (ADR 0015).
49
+ test("no override and no derivation refuses, naming the snapshot agent's reason", () => {
50
+ assert.throws(
51
+ () => resolveTestCmd(undefined, { testCmdError: "derive-testcmd: no Recipe cache at /r/.fleet/recipe.json" }),
52
+ /no test command for this repository — derive-testcmd: no Recipe cache at \/r\/\.fleet\/recipe\.json/,
53
+ );
54
+ });
55
+
56
+ // With no reason from the snapshot agent, the refusal still has to tell its
57
+ // reader what to RUN — the derivation step — rather than only that nothing
58
+ // was derived: a controller or reviewer reading it has no other pointer.
59
+ test("no override, no snapshot at all, and no testCmdError still refuses, naming the derivation step", () => {
60
+ for (const snap of [null, {}]) {
61
+ assert.throws(
62
+ () => resolveTestCmd(undefined, snap),
63
+ /no test command for this repository — the snapshot agent read no Recipe cache; run the Recipe derivation step \(run-team phase 0/,
64
+ );
65
+ }
66
+ });
67
+
68
+ // A falsy-but-present override (`""`) is caller error, not "no override" —
69
+ // the `||`/truthiness check above only distinguishes explicit from absent,
70
+ // and this pins that an empty string does NOT silently pass through as a
71
+ // command. It falls to the snapshot the same as `undefined` would.
72
+ test("an empty-string override is not treated as an explicit command", () => {
73
+ assert.equal(resolveTestCmd("", { testCmd: "node --test" }), "node --test");
74
+ });
75
+
76
+ // The function is worthless if nothing calls it — pin the CALL SITE, not
77
+ // just the lifted copy. select-dimensions.test.mjs's #118 regression is this
78
+ // exact defect: replacing the call with a bare default left every test above
79
+ // green while the feature disconnected.
80
+ test("runReview actually calls resolveTestCmd once the snapshot is validated", () => {
81
+ assert.match(
82
+ CODE,
83
+ /^\s*const testCmd = resolveTestCmd\(A\.testCmd, snap\);$/m,
84
+ "the testCmd call site changed — the derivation may be disconnected",
85
+ );
86
+ // Textually after the snapshot's own validity guard, not before — snap must
87
+ // be known good (or the throw above already fired) before this reads it.
88
+ // Anchored on the guard's INVOCATION — not its declaration, and not one of
89
+ // its return messages. The declaration sits above every top-level statement
90
+ // in this file, so ordering against it is near-tautological: measured, it
91
+ // stays green with the resolveTestCmd call moved ahead of the guard, which
92
+ // is the one regression this assertion's message names. A message anchor is
93
+ // reword-fragile instead — #539 split the single "no tree" message into
94
+ // three, and the retired literal leaves guardAt at -1, which reds this
95
+ // assertion loudly rather than silently, but reds it all the same. The call
96
+ // site is the only anchor that is both reword-proof and order-sensitive.
97
+ const guardAt = CODE.indexOf("const missingReason = snapshotMissing(snap, runRootPrefix);");
98
+ const callAt = CODE.indexOf("const testCmd = resolveTestCmd(");
99
+ assert.ok(guardAt !== -1 && callAt !== -1 && callAt > guardAt, "resolveTestCmd is called before snap is validated");
100
+ });
101
+
102
+ // A hardcoded default anywhere in this file is the exact regression #142
103
+ // fixes — `A.testCmd || "<literal>"` is the shape it used to take.
104
+ test("no hardcoded testCmd default remains", () => {
105
+ assert.doesNotMatch(
106
+ CODE,
107
+ /A\.testCmd\s*\|\|\s*"/,
108
+ "a literal testCmd default reappeared — it must come from resolveTestCmd/derive-testcmd.sh instead",
109
+ );
110
+ });
111
+
112
+ // The snapshot agent's return schema gains testCmd/testCmdError the same way
113
+ // diffPath/diffLines/prHead were added: `additionalProperties: false` drops
114
+ // an undeclared field silently, so BOTH the prompt asking for it and the
115
+ // schema declaring it have to be pinned, or the feature disconnects in one
116
+ // token exactly like `review-pr-reads.test.mjs`'s "the snapshot agent asks for
117
+ // the diff facts AND declares them in its schema" records happening to the
118
+ // diff facts.
119
+ test("the snapshot agent is told to derive testCmd AND the schema declares it", () => {
120
+ const snapshot = between(CODE, "const snap = await agent(", "if (snap) {", "the snapshot agent dispatch");
121
+
122
+ assert.match(
123
+ snapshot,
124
+ /~\/\.fleet\/bin\/fleet-run derive-testcmd\.sh \$\{worktree\} test/,
125
+ "the snapshot agent no longer reads the Test entrypoint through derive-testcmd.sh via the Resolver",
126
+ );
127
+ // Deriving the command is half the job — it also has to RUN where the
128
+ // specialists are told to run it. `git archive` carries tracked files only,
129
+ // so `npm test --` (the derivation's first branch, for any repo whose
130
+ // scripts.test invokes a node_modules binary) exits 127 in the snapshot
131
+ // while passing in the worktree the derivation was run against. Measured on
132
+ // a synthetic repo during the #142 review: worktree exit 0, archive exit 127.
133
+ assert.match(
134
+ snapshot,
135
+ // `"$SNAP/node_modules"` since #1129: the destination is a per-run shell
136
+ // variable now, and the symlink has to land in the tree this run actually
137
+ // extracted — a link left at the old bare `${scratch}/snapshot` would
138
+ // provision node_modules for a directory no specialist is pointed at.
139
+ // Quote-tolerant on purpose. The needle's job is that the symlink lands in
140
+ // THIS run's destination — `$SNAP`, never the old bare `${scratch}/snapshot`
141
+ // — and `"$SNAP/node_modules"` and `"$SNAP"/node_modules` are the same word
142
+ // to any POSIX shell, `/node_modules` carrying no metacharacters. Pinning
143
+ // one of the two rejected a behaviour-identical rewrite as a #1129
144
+ // regression, which is how a pin teaches its next reader to weaken it.
145
+ //
146
+ // The `[ -n "$SNAP" ]` half is not decoration either: this is the only
147
+ // command in the block whose target no earlier line created, so it is the
148
+ // only one that would still act on an empty `$SNAP` — writing a symlink at
149
+ // `/node_modules`, outside the run root entirely.
150
+ // Order-agnostic between the two `[ ]` tests, for the same reason the
151
+ // quotes are optional: swapping them is behaviour-identical, so pinning
152
+ // one arrangement would red a correct change.
153
+ /if [^\n]*\[ -n "\$SNAP" \][^\n]*; then ln -s \$\{worktree\}\/node_modules "?\$SNAP"?\/node_modules"?/,
154
+ "the snapshot no longer provisions node_modules — a derived `npm test --` cannot run in it",
155
+ );
156
+ // These names live inside a template literal, so each backtick is a
157
+ // BACKSLASH-backtick in the source text — `\\?` matches it either way, the
158
+ // same idiom `review-pr-reads.test.mjs` uses for diffPath/prHead/diffLines.
159
+ const B = "\\\\?`";
160
+ assert.match(
161
+ snapshot,
162
+ new RegExp(`Report\\s+${B}testCmd${B}\\s*=\\s*its\\s+stdout\\s+ONLY\\s+if\\s+it\\s+exited\\s+0`),
163
+ "testCmd is not bound to the script's stdout and gated on its exit code",
164
+ );
165
+ assert.match(
166
+ snapshot,
167
+ new RegExp(`report\\s+${B}testCmdError${B}\\s*=\\s*its\\s+stderr`),
168
+ "testCmdError is not bound to the script's stderr on refusal",
169
+ );
170
+
171
+ // Scoped to `SNAPSHOT_SCHEMA.properties` directly — a real import now,
172
+ // never a second copy of its JSON re-parsed from source text. A field
173
+ // declared ANYWHERE else is undeclared as far as
174
+ // `additionalProperties: false` is concerned.
175
+ for (const field of ["testCmd", "testCmdError"]) {
176
+ assert.ok(
177
+ Object.prototype.hasOwnProperty.call(SNAPSHOT_SCHEMA.properties, field),
178
+ `${field} is not declared in SNAPSHOT_SCHEMA.properties — additionalProperties:false drops it`,
179
+ );
180
+ }
181
+ // Both stay OUT of `required`: a network or git failure inside
182
+ // derive-testcmd.sh must not abort a snapshot that is otherwise good —
183
+ // resolveTestCmd is what turns a missing derivation into a refusal, not a
184
+ // required-field validation error one layer down. `pathVerified` joins
185
+ // path+head instead (#140): unlike testCmd, its absence must abort. So does
186
+ // `repoVerified` (#1056) — whether the snapshot is a repository holding the
187
+ // reviewed tree decides what a suite run in there is evidence about.
188
+ // `environmentNote`'s strict `=== true` check already guarantees an omitted
189
+ // field reads as UNVERIFIED either way, so the risk `required` guards
190
+ // against is different: omitted from `required`, the snapshot agent could
191
+ // silently drop the field from its structured output — especially under
192
+ // omp's permissive schema-retry-exhaustion mode — and the caller would
193
+ // never find out the measurement was never taken.
194
+ assert.deepEqual(
195
+ SNAPSHOT_SCHEMA.required,
196
+ ["runRoot", "path", "head", "pathVerified", "repoVerified"],
197
+ "required must stay path+head+pathVerified+repoVerified only",
198
+ );
199
+ });
200
+
201
+ // The prompt is what specialists actually obey, so the reading rule has to be
202
+ // in it. Without this, a specialist that guesses a glob still reports
203
+ // `tests 0` as a pass — the exact failure the derivation alone does not cover.
204
+ test("the specialist prompt hands the command over verbatim and rules 'tests 0' a failure", () => {
205
+ // indexOf returns -1 when absent and slice(-1) is a truthy one-character
206
+ // string, so asserting on the slice passes with the prompt gone. Assert the
207
+ // index — and bound the END too: unbounded, this slice ran to EOF and the
208
+ // assertions below were satisfiable from the verifier prompt further down.
209
+ const prompt = between(CODE, "READ ONLY FROM THE SNAPSHOT", "Scratch files go in", "the specialist prompt");
210
+ // The worked example must INTERPOLATE testCmd, not restate it. A hardcoded
211
+ // copy drifts from the resolved value the moment either one changes, and a
212
+ // caller passing args.testCmd (or the derivation) would be handed the wrong
213
+ // command.
214
+ assert.match(
215
+ prompt,
216
+ /run exactly this[^\n]*\n\s*\$\{testCmd\}/,
217
+ "the prompt no longer hands specialists the interpolated command verbatim",
218
+ );
219
+ // Match the ruling itself, not the phrase `tests 0` — that appears in the
220
+ // surrounding explanation too, so a looser assertion passes with the rule
221
+ // deleted (observed: it did).
222
+ assert.match(
223
+ prompt,
224
+ /'tests 0' is a FAILED run/,
225
+ "the prompt no longer rules a zero-test run a failure",
226
+ );
227
+ // The RULING was pinned and the INSTRUCTION was not, so the sentence telling
228
+ // specialists not to swap the command out could be deleted with this suite
229
+ // green (#143). Everything around it explains why; this is the only clause
230
+ // that actually forbids anything.
231
+ assert.match(
232
+ prompt,
233
+ /Do not substitute a command of your own\./,
234
+ "the prompt no longer forbids substituting a command — only explains why one would be wrong",
235
+ );
236
+ });
237
+
238
+ // #143's second correction. The rationale above asserted, present tense and as
239
+ // fact about the run being described, that a bare runner "tears down a shared
240
+ // container mid-run for every sibling". Measured against this repo:
241
+ // this repo's Test entrypoint is a plain `node --test` run and
242
+ // `commands/review-and-fix.md` records that this repo has no
243
+ // compose file, no `globalSetup`, and no vitest — so no teardown can happen,
244
+ // and a specialist that checks the reason it was given finds it false.
245
+ //
246
+ // The rule is still worth carrying, because the review host reviews repos that DO
247
+ // have a stack. It has to be stated as a conditional about those repos rather
248
+ // than as a fact about this run.
249
+ test("the anti-substitution rationale is portable, not a present-tense claim about this run", () => {
250
+ const prompt = between(CODE, "READ ONLY FROM THE SNAPSHOT", "Scratch files go in", "the specialist prompt");
251
+ assert.doesNotMatch(
252
+ prompt,
253
+ /tears down a shared container mid-run for every sibling/,
254
+ "the prompt again asserts a container teardown as fact about a run that cannot have one (#143)",
255
+ );
256
+ // The conditional that replaced it, and the half that is NOT conditional: a
257
+ // zero-match glob exits 0 in every repo, so hedging that one would weaken a
258
+ // rule this repo has actually measured (#142).
259
+ assert.match(
260
+ prompt,
261
+ /In a repo that has a shared test stack/,
262
+ "the container rationale is no longer scoped to the repos it can happen in",
263
+ );
264
+ assert.match(
265
+ prompt,
266
+ /a guessed glob is\s+worse in every repo/,
267
+ "the zero-match-glob half is no longer stated as holding everywhere",
268
+ );
269
+ });
270
+
271
+ // The rule #143 widened, in the place specialists actually read. The classifier
272
+ // catches the zero-pass case on its own (`review-pr-unrun.test.mjs`), but the
273
+ // partial-tree case it CANNOT: `unrunReason` is pure and never learns how many
274
+ // tests the whole tree has, so the only reader positioned to notice is the agent
275
+ // that ran the command. If this instruction goes, that case has no other guard.
276
+ test("the prompt rules a no-work run unrun too: zero passes, and a count below the whole tree", () => {
277
+ const prompt = between(CODE, "READ ONLY FROM THE SNAPSHOT", "Scratch files go in", "the specialist prompt");
278
+ assert.match(
279
+ prompt,
280
+ /0 passes with no failures is\s+everything skipped/,
281
+ "the prompt no longer rules an all-skipped run a no-work run (#143)",
282
+ );
283
+ assert.match(
284
+ prompt,
285
+ /a count well below what the whole tree reports means you\s+ran a PARTIAL copy/,
286
+ "the prompt no longer rules a partial-tree run unrun — the case nothing downstream can catch (#143)",
287
+ );
288
+ });