@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,384 @@
1
+ // Regression gate for #484: `echo` expands backslash escapes in its operand,
2
+ // so every fleet script that reported caller-supplied text through
3
+ // `die() { echo "$NAME: $1" >&2; … }` could truncate its own refusal.
4
+ //
5
+ // The mechanism, measured rather than inferred (dash on CI's ubuntu-latest and
6
+ // macOS `sh` both do this):
7
+ //
8
+ // $ sh -c 'a="x \cy"; echo "n: $a"' | od -c
9
+ // 0000000 n : x
10
+ //
11
+ // `\c` truncates the line AND swallows the newline, so the next stderr line
12
+ // collides with it. `\t \n \b \f \r \v \\ \0` mangle in their own ways.
13
+ //
14
+ // The trap this file exists to avoid: **unknown escapes like `\s` pass through
15
+ // unharmed.** A fixture spelled `back\slash` exercises the safe member of the
16
+ // class, reads as coverage, and catches nothing — `no-undo-audit.test.mjs` had
17
+ // exactly such a fixture and was blind to five live defects (#480). Every
18
+ // fixture below therefore uses `\c`, the member that actually truncates.
19
+ //
20
+ // Two directions are pinned, because a suite that only feeds valid input pins
21
+ // neither:
22
+ // - REJECT: a `\c` message must arrive verbatim (the bug).
23
+ // - ACCEPT: a `%`-carrying message must arrive verbatim too (the fix's own
24
+ // regression risk — `printf "$msg\n"` would eat it; `printf '%s\n' "$msg"`
25
+ // does not).
26
+ //
27
+ // Zero deps: `node --test plugin/scripts/printf-die-sweep.test.mjs`.
28
+
29
+ import { test } from "node:test";
30
+ import assert from "node:assert/strict";
31
+ import { execFileSync, spawnSync } from "node:child_process";
32
+ import { mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, writeFileSync, mkdirSync } from "node:fs";
33
+ import { tmpdir } from "node:os";
34
+ import { join } from "node:path";
35
+ import { fileURLToPath } from "node:url";
36
+
37
+ const DIR = fileURLToPath(new URL(".", import.meta.url));
38
+
39
+ // Pin identity and cut the developer's ~/.gitconfig out of the fixture, so a
40
+ // local `pull.rebase` or hook cannot change what these repos look like.
41
+ const ENV = {
42
+ ...process.env,
43
+ GIT_DIR: undefined,
44
+ GIT_WORK_TREE: undefined,
45
+ GIT_TEMPLATE_DIR: undefined,
46
+ GIT_INDEX_FILE: undefined,
47
+ GIT_AUTHOR_NAME: "t",
48
+ GIT_AUTHOR_EMAIL: "t@example.com",
49
+ GIT_COMMITTER_NAME: "t",
50
+ GIT_COMMITTER_EMAIL: "t@example.com",
51
+ GIT_CONFIG_GLOBAL: "/dev/null",
52
+ GIT_CONFIG_SYSTEM: "/dev/null",
53
+ };
54
+
55
+ const git = (cwd, ...args) =>
56
+ execFileSync("git", args, { cwd, env: ENV, encoding: "utf8" }).trim();
57
+
58
+ /**
59
+ * Bare origin + working clone with one commit on main. Returns the clone dir.
60
+ *
61
+ * realpath'd: on macOS `$TMPDIR` sits under the `/var` → `/private/var`
62
+ * symlink, and `git worktree list --porcelain` reports the RESOLVED path. An
63
+ * unresolved fixture path never matches what the scripts print, which reads as
64
+ * a truncation failure and hides whether the escaping is right.
65
+ */
66
+ function repo(t) {
67
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "printf-die-")));
68
+ t.after(() => rmSync(root, { recursive: true, force: true }));
69
+ const origin = join(root, "origin.git");
70
+ const work = join(root, "work");
71
+ execFileSync("git", ["init", "-q", "--bare", "-b", "main", origin], { env: ENV });
72
+ execFileSync("git", ["clone", "-q", origin, work], { env: ENV });
73
+ writeFileSync(join(work, "f.txt"), "x\n");
74
+ git(work, "add", "f.txt");
75
+ git(work, "commit", "-q", "-m", "init");
76
+ git(work, "push", "-q", "origin", "main");
77
+ return work;
78
+ }
79
+
80
+ const run = (cwd, script, args, extraEnv = {}) =>
81
+ spawnSync("sh", [join(DIR, script), ...args], {
82
+ cwd,
83
+ env: { ...ENV, ...extraEnv },
84
+ encoding: "utf8",
85
+ });
86
+
87
+ // One reachable `die()` per script, chosen so the message interpolates text the
88
+ // CALLER supplied — the only text that can carry a backslash. `$NAME: ` is
89
+ // prefixed by `die` itself, so asserting the whole line also pins the prefix.
90
+ //
91
+ // `exit` codes are asserted because they are part of each script's contract and
92
+ // a `printf` substitution must not disturb them: eight scripts refuse at 2,
93
+ // `derive-testcmd.sh` at 1. The ticket does not mention that asymmetry.
94
+ const CASES = [
95
+ {
96
+ // The `\c` sits in the BRANCH slot, not the sha slot. Both reach `die()`,
97
+ // but only the branch reaches verify-sha.sh's fetch trace — the one line
98
+ // in these scripts where raw argv is printed before any git command has
99
+ // accepted it. With the escape in the sha slot the suite was green over
100
+ // that line: the sha is read after the fetch, so it can never get there.
101
+ // `trace` below is what pins it.
102
+ script: "verify-sha.sh",
103
+ args: ["back\\clue", "deadbee"],
104
+ exit: 2,
105
+ line: "verify-sha: cannot fetch origin/back\\clue",
106
+ trace: "$ git fetch --quiet origin back\\clue",
107
+ },
108
+ {
109
+ script: "drop-merged-label.sh",
110
+ args: ["back\\clue"],
111
+ exit: 2,
112
+ line: "drop-merged-label: pr must be a number, got 'back\\clue'",
113
+ },
114
+ {
115
+ script: "inflight.sh",
116
+ args: ["back\\clue"],
117
+ exit: 2,
118
+ line: "inflight: issue must be a number, got 'back\\clue'",
119
+ },
120
+ {
121
+ script: "claim-ticket.sh",
122
+ args: ["back\\clue", "slug", "fix"],
123
+ exit: 2,
124
+ line: "claim-ticket: issue must be a number, got 'back\\clue'",
125
+ },
126
+ {
127
+ script: "worktree-audit.sh",
128
+ args: [],
129
+ env: { BASE_REF: "origin/back\\clue" },
130
+ exit: 2,
131
+ line: "worktree-audit: origin/back\\clue does not resolve",
132
+ },
133
+ {
134
+ script: "release-ticket.sh",
135
+ args: ["back\\clue", "slug", "fix"],
136
+ exit: 2,
137
+ line: "release-ticket: issue must be a number, got 'back\\clue'",
138
+ },
139
+ {
140
+ script: "reap.sh",
141
+ args: [],
142
+ env: { BASE_REF: "origin/back\\clue" },
143
+ exit: 2,
144
+ line: "reap: origin/back\\clue does not resolve",
145
+ },
146
+ {
147
+ script: "prove-merge.sh",
148
+ args: ["back\\clue", "deadbee", "deadbee"],
149
+ exit: 2,
150
+ line: "prove-merge: cannot resolve back\\clue to a commit in this repository",
151
+ },
152
+ {
153
+ // The one script that refuses at 1, not 2.
154
+ script: "derive-testcmd.sh",
155
+ args: ["back\\clue-nope", "test"],
156
+ exit: 1,
157
+ line: "derive-testcmd: back\\clue-nope is not a git repository",
158
+ },
159
+ ];
160
+
161
+ for (const c of CASES) {
162
+ test(`${c.script}: die() reports a \\c-carrying message verbatim`, (t) => {
163
+ const w = repo(t);
164
+ // The fixture is only useful if it really carries the escape that breaks.
165
+ // `\s` would pass through `echo` unharmed and pin nothing.
166
+ assert.ok(
167
+ c.line.includes("\\c"),
168
+ "fixture must carry a `\\c`, the escape that truncates — not an inert one",
169
+ );
170
+ const r = run(w, c.script, c.args, c.env);
171
+ assert.equal(
172
+ r.status,
173
+ c.exit,
174
+ `${c.script} must still refuse at ${c.exit}; got ${r.status}, stderr ${JSON.stringify(r.stderr)}`,
175
+ );
176
+ // Whole line, anchored, WITH its newline: `echo` drops both the tail and
177
+ // the trailing newline at the `\c`, so a substring match on the surviving
178
+ // head would pass against the very defect this pins.
179
+ assert.ok(
180
+ r.stderr.includes(`${c.line}\n`),
181
+ `\`echo\` truncates this refusal at the \`\\c\` — it must arrive verbatim and newline-terminated.\nwant: ${JSON.stringify(`${c.line}\n`)}\ngot: ${JSON.stringify(r.stderr)}`,
182
+ );
183
+ // A trace line ABOVE the refusal, where the script names the command it is
184
+ // about to run. Only verify-sha.sh has one carrying unvalidated argv, and
185
+ // the newline is the half that matters most: `echo` eats it, so git's own
186
+ // `fatal:` lands welded to the tail of the trace and stops anchoring `^`.
187
+ if (c.trace) {
188
+ assert.ok(
189
+ r.stderr.includes(`${c.trace}\n`),
190
+ `the trace line must name the command verbatim and keep its newline.\nwant: ${JSON.stringify(`${c.trace}\n`)}\ngot: ${JSON.stringify(r.stderr)}`,
191
+ );
192
+ }
193
+ });
194
+ }
195
+
196
+ // The other direction. `printf` treats its FIRST argument as a format string,
197
+ // which `echo` never did, so the fix introduces a hazard of its own: a message
198
+ // holding `%s` or `%d` is silently rewritten by `printf "$msg\n"` — measured,
199
+ // `100% done %s %d` comes out as `100 0one 0`. `printf '%s\n' "$msg"` is
200
+ // immune. Nothing else in the suite feeds a `%`, so without this the fix could
201
+ // regress to the format-string form and stay green.
202
+ test("a %-carrying message is passed through, not interpreted as a format", (t) => {
203
+ const w = repo(t);
204
+ const r = run(w, "drop-merged-label.sh", ["100% done %s %d"]);
205
+ assert.equal(r.status, 2);
206
+ assert.ok(
207
+ r.stderr.includes("drop-merged-label: pr must be a number, got '100% done %s %d'\n"),
208
+ `the message must survive verbatim — \`printf "$msg\\n"\` would consume the %-specifiers; got ${JSON.stringify(r.stderr)}`,
209
+ );
210
+ });
211
+
212
+ // A plain message must still work — and this is the only case in the suite that
213
+ // notices if drop-merged-label.sh stops refusing ordinary input at all.
214
+ // Measured: widening its numeric guard's class (`*[!0-9]*` → `*[!0-9a-z]*`)
215
+ // reds this test ALONE, because `back\clue` and `100% done %s %d` fall outside
216
+ // any widened class and go on being refused, while `notanumber` does not.
217
+ //
218
+ // The "refuses everything" direction this was written for is already covered
219
+ // twice over — that mutant reds the `\c` and the `%` test as well — so it is
220
+ // the ordinary-input reachability above, not the accept direction, that makes
221
+ // this worth its fixture (#707 review).
222
+ test("an ordinary message with no escapes is unaffected", (t) => {
223
+ const w = repo(t);
224
+ const r = run(w, "drop-merged-label.sh", ["notanumber"]);
225
+ assert.equal(r.status, 2);
226
+ assert.ok(
227
+ r.stderr.includes("drop-merged-label: pr must be a number, got 'notanumber'\n"),
228
+ `got ${JSON.stringify(r.stderr)}`,
229
+ );
230
+ });
231
+
232
+ // ---------------------------------------------------------------------------
233
+ // Path-carrying sites: the same class, reached through operator output rather
234
+ // than through `die()`. A worktree path is caller-supplied and a backslash is
235
+ // legal in one, which is what makes these reachable at all.
236
+ // ---------------------------------------------------------------------------
237
+
238
+ test("worktree-audit: a worktree path holding a backslash reaches the status line whole", (t) => {
239
+ const w = repo(t);
240
+ const wt = join(w, "back\\clue-wt");
241
+ git(w, "worktree", "add", "-q", "-b", "fix/1-thing", wt);
242
+ const r = run(w, "worktree-audit.sh", []);
243
+ assert.equal(r.status, 0, `stderr: ${r.stderr}`);
244
+ assert.ok(
245
+ r.stderr.includes(`${wt} branch=fix/1-thing`),
246
+ `\`echo\` truncates the status line at the \`\\c\` — the path must arrive verbatim; got ${JSON.stringify(r.stderr)}`,
247
+ );
248
+ });
249
+
250
+ test("worktree-audit: a worktree gone from disk is named verbatim as MISSING", (t) => {
251
+ const w = repo(t);
252
+ const wt = join(w, "back\\clue-gone");
253
+ git(w, "worktree", "add", "-q", "-b", "fix/2-thing", wt);
254
+ rmSync(wt, { recursive: true, force: true });
255
+ const r = run(w, "worktree-audit.sh", []);
256
+ // Status first, as the test above already does. Without it an unrelated
257
+ // early refusal — the script dying before it ever reaches this line — is
258
+ // reported under the escaping headline below, naming a cause it did not have.
259
+ assert.equal(r.status, 0, `stderr: ${r.stderr}`);
260
+ assert.ok(
261
+ r.stderr.includes(`MISSING on disk: ${wt}\n`),
262
+ `the missing path must arrive verbatim; got ${JSON.stringify(r.stderr)}`,
263
+ );
264
+ });
265
+
266
+ // `keep()`'s reason is the one line reap.sh's refusals converge on, and a
267
+ // worktree path is interpolated into it from more than one of them — which is
268
+ // the property this test rests on: the escaping belongs in `keep()`, where every
269
+ // such reason passes through `jfield` once, and not at any call site, where it
270
+ // would have to be repeated and would be forgotten at the next one added.
271
+ //
272
+ // No count in this prose, deliberately, and that is this comment's own history
273
+ // rather than a rule imported from elsewhere. It shipped two counts and a list
274
+ // of sites cited by line number; the line numbers had drifted off what they
275
+ // pointed at before anyone noticed, and the counts then went stale again the
276
+ // next time a call site was added — silently, because nothing goes red when a
277
+ // number in a comment stops being true. Name the property, and re-derive the
278
+ // numbers from the tree at the moment you need them (#129):
279
+ // grep -c 'keep "\$b"' reap.sh
280
+ // grep 'keep "\$b"' reap.sh | grep -c '\$wt'
281
+ // reap only considers a branch whose
282
+ // upstream reads `[gone]`, so the fixture has to push the branch and then
283
+ // delete it on origin — reap's own `fetch --prune` is what marks it gone.
284
+ test("reap: a KEEP reason holding a backslashed path reaches the operator whole", (t) => {
285
+ const w = repo(t);
286
+ const wt = join(w, "back\\clue-dirty");
287
+ git(w, "worktree", "add", "-q", "-b", "fix/3-thing", wt);
288
+ // Pushed with -u so the branch has an upstream, then deleted on origin so
289
+ // that upstream becomes `[gone]`. No commit of its own: reap must get PAST
290
+ // the unmerged check to reach a reason that names the worktree.
291
+ git(wt, "push", "-q", "-u", "origin", "fix/3-thing");
292
+ git(w, "push", "-q", "origin", "--delete", "fix/3-thing");
293
+ writeFileSync(join(wt, "g.txt"), "uncommitted\n"); // dirty → `dirty worktree $wt`
294
+ const r = run(w, "reap.sh", []);
295
+ assert.equal(r.status, 0, `stderr: ${r.stderr}`);
296
+ assert.ok(
297
+ r.stderr.includes(`KEEP fix/3-thing — dirty worktree ${wt}\n`),
298
+ `\`echo\` truncates the KEEP line at the \`\\c\` — the worktree path must arrive verbatim; got ${JSON.stringify(r.stderr)}`,
299
+ );
300
+ });
301
+
302
+ test("claim-ticket: the dry-run plan names a backslashed worktree path verbatim", (t) => {
303
+ const w = repo(t);
304
+ // A claim needs the repository's Recipe cache (ADR 0015); the smallest
305
+ // proven one, untracked in the checkout's own `.fleet/`.
306
+ mkdirSync(join(w, ".fleet"), { recursive: true });
307
+ writeFileSync(join(w, ".fleet", "recipe.json"), JSON.stringify({
308
+ install: "true", test: "true", derivedAt: git(w, "rev-parse", "HEAD").trim(), installClean: true, testCount: 1,
309
+ }));
310
+ const r = run(w, "claim-ticket.sh", ["7", "back\\clue", "fix"]);
311
+ assert.equal(r.status, 0, `stderr: ${r.stderr}`);
312
+ assert.ok(
313
+ r.stderr.includes("would: git worktree add --no-track .worktrees/7-back\\clue -b fix/7-back\\clue origin/main\n"),
314
+ `the planned path and branch must arrive verbatim — \`echo\` truncates both at the \`\\c\`; got ${JSON.stringify(r.stderr)}`,
315
+ );
316
+ });
317
+
318
+ // ---------------------------------------------------------------------------
319
+ // The fix's own regression risk, at every site at once.
320
+ //
321
+ // The fixtures above are behavioural and cost a git repo each, so they pin one
322
+ // line per script. This pins the invariant the whole sweep rests on across all
323
+ // of them, statically: `printf` must be handed a LITERAL format, never one
324
+ // built by interpolation.
325
+ //
326
+ // Why a static test is the only thing that can catch it: `printf "$msg\n"` is
327
+ // the regression that reopens BOTH halves of #484, and every `\c` fixture above
328
+ // stays green over it. Measured on /bin/sh and /bin/dash — POSIX printf expands
329
+ // `\c` only under `%b`, never in the format it was handed, so
330
+ // `printf "$NAME: back\clue\n"` prints `back\clue` intact while
331
+ // `printf '%s\n' "back\clue"` does too. Only a `%`-carrying message tells them
332
+ // apart, and feeding one to all ~35 sites would need a fixture per site. Under
333
+ // that mutation the die() sites of verify-sha.sh and inflight.sh were reverted
334
+ // and the full suite stayed green.
335
+ //
336
+ // Not delegated to shellcheck: SC2059 is exactly this check, but it reports at
337
+ // `info`, and CI runs `shellcheck -x -S warning`, which filters it out before
338
+ // it is printed. Raising that floor is a change to a workflow file this ticket
339
+ // has no business in.
340
+ //
341
+ // It does NOT catch a revert to `echo` — nothing static can, since two thirds
342
+ // of the `echo` calls in these scripts interpolate values that are safe by
343
+ // construction (numbers, SHAs, refs git already accepted). That direction is
344
+ // what the behavioural fixtures above, and the per-script path fixtures in
345
+ // inflight.test.mjs and release-ticket.test.mjs, are for.
346
+ test("every printf in the fleet scripts is handed a literal format string", () => {
347
+ // The format argument is the first token after `printf`: a single-quoted run
348
+ // (literal through and through), a double-quoted run honouring `\"`, or a
349
+ // bare word. Full-line comments are skipped — several of them quote the very
350
+ // form being banned.
351
+ const FORMAT = /(?:^|[;&|(){}\s])printf[ \t]+('[^']*'|"(?:[^"\\]|\\.)*"|[^\s;&|)]+)/g;
352
+ // Single quotes cannot interpolate at all. Anything else does the moment it
353
+ // carries an unescaped `$` or a backtick — `"\$arg"` is a literal dollar and
354
+ // stays legal, which is what the agent-test runner claim-ticket.sh writes
355
+ // through a heredoc relies on.
356
+ const interpolates = (tok) => {
357
+ if (tok.startsWith("'")) return false;
358
+ const body = tok.startsWith('"') ? tok.slice(1, -1) : tok;
359
+ return /(?:^|[^\\])[$`]/.test(body);
360
+ };
361
+
362
+ const scripts = readdirSync(DIR).filter((n) => n.endsWith(".sh")).sort();
363
+ // A glob that matches nothing passes every assertion below it. Same failure
364
+ // as `tests 0`, and the same reading rule: no scripts is a broken test.
365
+ assert.ok(scripts.length >= 9, `expected the fleet scripts, found ${scripts.length}`);
366
+
367
+ const bad = [];
368
+ let checked = 0;
369
+ for (const name of scripts) {
370
+ readFileSync(join(DIR, name), "utf8").split("\n").forEach((line, i) => {
371
+ if (/^\s*#/.test(line)) return;
372
+ for (const m of line.matchAll(FORMAT)) {
373
+ checked++;
374
+ if (interpolates(m[1])) bad.push(`${name}:${i + 1} ${m[1]}`);
375
+ }
376
+ });
377
+ }
378
+ assert.ok(checked >= 100, `expected to find the sweep's printf calls, found ${checked}`);
379
+ assert.deepEqual(
380
+ bad,
381
+ [],
382
+ `these printf calls build their format by interpolation, which consumes any \`%\` in the message and re-opens #484:\n ${bad.join("\n ")}`,
383
+ );
384
+ });
@@ -0,0 +1,39 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { between } from "./prose-pin.mjs";
4
+ import { stripComments } from "./strip-comments.mjs";
5
+
6
+ // #1552. The extract-then-compile idiom — read a workflow's source, strip its
7
+ // comments so a block-commented call cannot render as live text, find a
8
+ // template literal's start/end anchors, trim its wrapping backticks, and
9
+ // compile it with `new Function` — existed independently in three test files
10
+ // (review-pr-specialist-scratch.test.mjs, review-pr-refuter-scratch.test.mjs,
11
+ // injection-control-prose.test.mjs), each around a different anchor pair. One
12
+ // of the three (review-pr-specialist-scratch.test.mjs) already delegated the
13
+ // anchor-finding half to prose-pin.mjs's `between()`; the other two
14
+ // reimplemented the same `indexOf`/`assert.notEqual` pair by hand. Only the
15
+ // extraction MACHINERY moves here; the prompt RULE PROSE itself stays inline
16
+ // in review-core.mjs per #496's brief against a shared source for
17
+ // the rules themselves.
18
+ const REPO = join(import.meta.dirname, "..");
19
+
20
+ // `file` is relative to the plugin root (e.g. "scripts/review-core.mjs").
21
+ // Extraction runs against the comment-stripped text, not the raw source: a
22
+ // block-commented `agent(...)` call still contains the whole template, so
23
+ // extracting from raw source would render dead text and report every
24
+ // criterion satisfied — the vacuity class strip-comments.mjs exists for.
25
+ export function workflowCode(file) {
26
+ return stripComments(readFileSync(join(REPO, file), "utf8"));
27
+ }
28
+
29
+ // Extracts the template literal between `start` and `end` out of `file` (via
30
+ // prose-pin.mjs's `between()`, which owns the bounded-slice extraction and
31
+ // both failure messages), trims the wrapping backticks, and compiles the
32
+ // result into a renderer bound to `scope`'s free names. Compiling is half the
33
+ // assertion: an unescaped `${` in the prescribed array expansion either
34
+ // throws here or silently interpolates away the very spelling the rule
35
+ // exists to teach.
36
+ export function promptRenderer({ file, start, end, scope, what }) {
37
+ const slice = between(workflowCode(file), start, end, what);
38
+ return new Function(...scope, "return `" + slice.slice(1, slice.lastIndexOf("`")) + "`");
39
+ }
@@ -0,0 +1,68 @@
1
+ // #1552. prompt-renderer.mjs's `workflowCode()` runs the file it reads through
2
+ // `stripComments()` before extraction — its own header comment (lines 17-21)
3
+ // documents this as the defense against a block-commented dead `agent()` call
4
+ // being extracted and rendered as live text, the exact vacuity class
5
+ // strip-comments.mjs exists for (measured twice on the pre-cutover review
6
+ // host before this module existed, per the comment above `workflowCode`).
7
+ // Nothing pinned that wrapper: review-core-cwd-isolation.test.mjs and
8
+ // injection-control-prose.test.mjs both extract from `review-core.mjs`,
9
+ // which carries no dead duplicate today, so neither can red if the
10
+ // `stripComments()` call is dropped. This file pins the guard directly with
11
+ // a synthetic fixture, once, for both consumers.
12
+ import { test } from "node:test";
13
+ import assert from "node:assert/strict";
14
+ import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
15
+ import { tmpdir } from "node:os";
16
+ import { join, relative } from "node:path";
17
+ import { promptRenderer, workflowCode } from "./prompt-renderer.mjs";
18
+
19
+ const REPO = join(import.meta.dirname, "..");
20
+
21
+ // A dead `agent()` call, block-commented on one line (matching
22
+ // strip-comments.mjs's line-based stripping), sits BEFORE the live one — the
23
+ // same first-occurrence hazard `between()`'s "no longer contains" pin never
24
+ // catches, since the dead text satisfies indexOf just as well as the live
25
+ // text and comes first.
26
+ const TEMPLATE_START = "`Try to REFUTE this finding from PR #";
27
+ const TEMPLATE_END = "{ label: `verify:";
28
+ const FIXTURE = [
29
+ "/* agent(`Try to REFUTE this finding from PR #999`, { label: `verify:dead` }); */",
30
+ "agent(`Try to REFUTE this finding from PR #1`, { label: `verify:live` });",
31
+ "",
32
+ ].join("\n");
33
+
34
+ function withFixture(fn) {
35
+ const dir = mkdtempSync(join(tmpdir(), "prompt-renderer-test-"));
36
+ try {
37
+ const file = join(dir, "fixture-workflow.js");
38
+ writeFileSync(file, FIXTURE, "utf8");
39
+ return fn(relative(REPO, file));
40
+ } finally {
41
+ rmSync(dir, { recursive: true, force: true });
42
+ }
43
+ }
44
+
45
+ test("workflowCode() strips a block-commented dead call before extraction, so a stale earlier occurrence cannot win", () => {
46
+ withFixture((relFile) => {
47
+ const code = workflowCode(relFile);
48
+ assert.ok(!code.includes("PR #999"), "the block-commented dead PR #999 call survived stripComments() — extraction would prefer it over the live call below it");
49
+ assert.ok(code.includes("PR #1"), "the live PR #1 call was stripped along with the dead comment — stripComments() over-blanked");
50
+ });
51
+ });
52
+
53
+ test("promptRenderer() renders the live occurrence, not a block-commented dead one that appears first", () => {
54
+ withFixture((relFile) => {
55
+ const RENDER = promptRenderer({
56
+ file: relFile,
57
+ start: TEMPLATE_START,
58
+ end: TEMPLATE_END,
59
+ scope: [],
60
+ what: "fixture template",
61
+ });
62
+ assert.equal(
63
+ RENDER(),
64
+ "Try to REFUTE this finding from PR #1",
65
+ "promptRenderer() extracted the block-commented dead template instead of the live one — workflowCode() is no longer stripping comments before extraction",
66
+ );
67
+ });
68
+ });