@feigi/fleet-ctl 3.23.36 → 3.23.38

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 (205) hide show
  1. package/package.json +1 -1
  2. package/scripts/cell-readout.mjs +38 -11
  3. package/scripts/main-checkout.mjs +1 -1
  4. package/scripts/member-write-guard.mjs +1 -1
  5. package/scripts/repo-root.mjs +1 -1
  6. package/skills/run-team/references/reaping.md +1 -1
  7. package/scripts/agent-test-dir-prose.test.mjs +0 -59
  8. package/scripts/agent-test.test.mjs +0 -1640
  9. package/scripts/ambient-git-vars-mjs-prose.test.mjs +0 -397
  10. package/scripts/ambient-git-vars-prose.test.mjs +0 -192
  11. package/scripts/ancestry-check-position-prose.test.mjs +0 -175
  12. package/scripts/apply-ruleset.test.mjs +0 -421
  13. package/scripts/arg-header-probes-prose.test.mjs +0 -394
  14. package/scripts/arg.test.mjs +0 -1354
  15. package/scripts/board-cli.test.mjs +0 -710
  16. package/scripts/board-identity.test.mjs +0 -429
  17. package/scripts/board-liveness-banner.test.mjs +0 -119
  18. package/scripts/board-prev-shape.test.mjs +0 -228
  19. package/scripts/board-tryparse-null.test.mjs +0 -119
  20. package/scripts/board.test.mjs +0 -3121
  21. package/scripts/brief-after-cut-prose.test.mjs +0 -53
  22. package/scripts/candidates-exit3-prose.test.mjs +0 -302
  23. package/scripts/candidates.test.mjs +0 -2312
  24. package/scripts/caveat-unification-prose.test.mjs +0 -98
  25. package/scripts/cell-readout.test.mjs +0 -615
  26. package/scripts/ci-comment-rot-prose.test.mjs +0 -2025
  27. package/scripts/ci-completes-premise-prose.test.mjs +0 -257
  28. package/scripts/ci-state-prose.test.mjs +0 -113
  29. package/scripts/ci-state.test.mjs +0 -1933
  30. package/scripts/ci-vacuous-green.test.mjs +0 -368
  31. package/scripts/citation-sweep-prose.test.mjs +0 -1712
  32. package/scripts/claim-lifecycle.test.mjs +0 -187
  33. package/scripts/claim-ticket.test.mjs +0 -1122
  34. package/scripts/closing-keyword-prose.test.mjs +0 -193
  35. package/scripts/cockpit-launch-idempotent-prose.test.mjs +0 -165
  36. package/scripts/cockpit-tick-nonblocking.test.mjs +0 -210
  37. package/scripts/compute-board.test.mjs +0 -1214
  38. package/scripts/compute-spend.test.mjs +0 -517
  39. package/scripts/consumer-technology-prose.test.mjs +0 -126
  40. package/scripts/cross-repo-citation-prose.test.mjs +0 -155
  41. package/scripts/cwd-isolation-pins.mjs +0 -83
  42. package/scripts/dedupe-guard-prose.test.mjs +0 -243
  43. package/scripts/delete-merged-branch.test.mjs +0 -576
  44. package/scripts/derive-testcmd.test.mjs +0 -595
  45. package/scripts/diff-stats.test.mjs +0 -404
  46. package/scripts/dispatch-block-golden-prose.test.mjs +0 -1130
  47. package/scripts/dispatch-block-pins-prose.test.mjs +0 -615
  48. package/scripts/dispositions-check.test.mjs +0 -936
  49. package/scripts/dispositions-gate-prose.test.mjs +0 -129
  50. package/scripts/drop-merged-label.test.mjs +0 -479
  51. package/scripts/exec-stub.mjs +0 -93
  52. package/scripts/exec-stub.test.mjs +0 -69
  53. package/scripts/expected-jobs-prose.test.mjs +0 -80
  54. package/scripts/fan-out-authorization-prose.test.mjs +0 -80
  55. package/scripts/filing-bar-seat-prose.test.mjs +0 -242
  56. package/scripts/filing-claim-bar-prose.test.mjs +0 -166
  57. package/scripts/finisher-died-prose.test.mjs +0 -31
  58. package/scripts/finisher-dispatch-premise-prose.test.mjs +0 -312
  59. package/scripts/finisher-halt-prose.test.mjs +0 -106
  60. package/scripts/finisher-name-prose.test.mjs +0 -134
  61. package/scripts/finisher-own-tree-prose.test.mjs +0 -299
  62. package/scripts/finisher-pin-race-prose.test.mjs +0 -339
  63. package/scripts/finisher-test-verdict-prose.test.mjs +0 -102
  64. package/scripts/fix-applier-correction-rules-prose.test.mjs +0 -202
  65. package/scripts/fix-applier-result-file-prose.test.mjs +0 -149
  66. package/scripts/fleet-bootstrap.test.mjs +0 -75
  67. package/scripts/fleet-heartbeat.test.mjs +0 -450
  68. package/scripts/fleet-provenance.test.mjs +0 -138
  69. package/scripts/fleet-run.test.mjs +0 -90
  70. package/scripts/fleet-state.test.mjs +0 -460
  71. package/scripts/fleet-tick-prose.test.mjs +0 -300
  72. package/scripts/fleet-tick.test.mjs +0 -2444
  73. package/scripts/force-with-lease-reason-prose.test.mjs +0 -184
  74. package/scripts/frontmatter-check.test.mjs +0 -436
  75. package/scripts/git-env.test.mjs +0 -149
  76. package/scripts/git-status-untracked-mode-sweep.test.mjs +0 -216
  77. package/scripts/gone-walk.test.mjs +0 -213
  78. package/scripts/gp-sep-invariant-prose.test.mjs +0 -188
  79. package/scripts/head-moved-after-label-prose.test.mjs +0 -233
  80. package/scripts/immutable-body-claim-prose.test.mjs +0 -204
  81. package/scripts/implementer-model-tier.test.mjs +0 -235
  82. package/scripts/inflight-citation-prose.test.mjs +0 -144
  83. package/scripts/inflight-exit2-prose.test.mjs +0 -81
  84. package/scripts/inflight-probe-guard-prose.test.mjs +0 -109
  85. package/scripts/inflight-scan-scope-prose.test.mjs +0 -57
  86. package/scripts/inflight.test.mjs +0 -2882
  87. package/scripts/injection-control-prose.test.mjs +0 -404
  88. package/scripts/install-root-audit.test.mjs +0 -464
  89. package/scripts/instrument-check-prose.test.mjs +0 -235
  90. package/scripts/instruments.test.mjs +0 -787
  91. package/scripts/is-cli.test.mjs +0 -99
  92. package/scripts/issue-tracker-prose.test.mjs +0 -71
  93. package/scripts/json.test.mjs +0 -364
  94. package/scripts/ledger-dispatch.test.mjs +0 -927
  95. package/scripts/ledger-grammar.test.mjs +0 -227
  96. package/scripts/ledger-read-require-file.test.mjs +0 -197
  97. package/scripts/ledger-rotate.test.mjs +0 -142
  98. package/scripts/ledger.test.mjs +0 -3436
  99. package/scripts/line-distance-prose.test.mjs +0 -245
  100. package/scripts/liveness-rationale-prose.test.mjs +0 -83
  101. package/scripts/locale-pin-prose.test.mjs +0 -189
  102. package/scripts/main-checkout.test.mjs +0 -332
  103. package/scripts/member-outcome-prose.test.mjs +0 -167
  104. package/scripts/member-outcomes-header.test.mjs +0 -129
  105. package/scripts/member-outcomes-prose.test.mjs +0 -63
  106. package/scripts/member-outcomes.test.mjs +0 -638
  107. package/scripts/member-prompt-prose.test.mjs +0 -165
  108. package/scripts/member-record.test.mjs +0 -541
  109. package/scripts/member-write-guard.test.mjs +0 -214
  110. package/scripts/merge-commit-probe-prose.test.mjs +0 -122
  111. package/scripts/merge-gate.test.mjs +0 -613
  112. package/scripts/muted-git-guard-sweep.test.mjs +0 -493
  113. package/scripts/net-ssh-precedence-prose.test.mjs +0 -91
  114. package/scripts/net-watchdog-prose.test.mjs +0 -79
  115. package/scripts/net.test.mjs +0 -211
  116. package/scripts/no-ci-gate-prose.test.mjs +0 -108
  117. package/scripts/no-undo-audit.test.mjs +0 -3961
  118. package/scripts/no-wave.test.mjs +0 -138
  119. package/scripts/node-floor-sweep.test.mjs +0 -611
  120. package/scripts/pointer-target-prose.test.mjs +0 -186
  121. package/scripts/pr-cost.test.mjs +0 -521
  122. package/scripts/pr-overlap.test.mjs +0 -692
  123. package/scripts/printf-die-sweep.test.mjs +0 -384
  124. package/scripts/prompt-renderer.mjs +0 -40
  125. package/scripts/prompt-renderer.test.mjs +0 -68
  126. package/scripts/prose-pin.mjs +0 -807
  127. package/scripts/prose-pin.test.mjs +0 -1034
  128. package/scripts/prove-merge.test.mjs +0 -995
  129. package/scripts/pull-table-relabel-prose.test.mjs +0 -60
  130. package/scripts/quiet-payload-prose.test.mjs +0 -222
  131. package/scripts/reap-cherry-check-prose.test.mjs +0 -80
  132. package/scripts/reap.test.mjs +0 -4432
  133. package/scripts/reaping-prose.test.mjs +0 -239
  134. package/scripts/reaping-reap-authorizers-prose.test.mjs +0 -112
  135. package/scripts/reaping-release-authorizers-prose.test.mjs +0 -85
  136. package/scripts/recipe-derivation-prose.test.mjs +0 -112
  137. package/scripts/recipe-prove.test.mjs +0 -1042
  138. package/scripts/refuter-scratch-prose.test.mjs +0 -135
  139. package/scripts/release-label-required-prose.test.mjs +0 -71
  140. package/scripts/release-label-split-prose.test.mjs +0 -184
  141. package/scripts/release-ticket-reap-pairing-prose.test.mjs +0 -63
  142. package/scripts/release-ticket.test.mjs +0 -5099
  143. package/scripts/renovate-release-contract.test.mjs +0 -379
  144. package/scripts/repo-root.test.mjs +0 -873
  145. package/scripts/reporter-output-rule-prose.test.mjs +0 -208
  146. package/scripts/review-agent-report-only.test.mjs +0 -49
  147. package/scripts/review-core-booking.test.mjs +0 -35
  148. package/scripts/review-core-cwd-isolation.test.mjs +0 -374
  149. package/scripts/review-core-reads.test.mjs +0 -478
  150. package/scripts/review-core-refuter-scratch.test.mjs +0 -148
  151. package/scripts/review-core-scratch-refusal.test.mjs +0 -64
  152. package/scripts/review-core-shared-test-run.test.mjs +0 -275
  153. package/scripts/review-core-snapshot-path.test.mjs +0 -830
  154. package/scripts/review-core-specialist-scratch.test.mjs +0 -191
  155. package/scripts/review-core-testcmd.test.mjs +0 -335
  156. package/scripts/review-core-unrun.test.mjs +0 -566
  157. package/scripts/review-core-unverified-discriminant.test.mjs +0 -208
  158. package/scripts/review-eval-resolver-path.test.mjs +0 -55
  159. package/scripts/review-host-fixture.mjs +0 -89
  160. package/scripts/review-in-run-retry.test.mjs +0 -211
  161. package/scripts/review-no-vendor-dispatch.test.mjs +0 -45
  162. package/scripts/review-path-default.test.mjs +0 -796
  163. package/scripts/review-runner-spawns.test.mjs +0 -95
  164. package/scripts/review-runner.test.mjs +0 -166
  165. package/scripts/review-tier-audit.test.mjs +0 -140
  166. package/scripts/run-artifact-pr-prose.test.mjs +0 -341
  167. package/scripts/run-merge-bot-prose.test.mjs +0 -1413
  168. package/scripts/run-team-local-hook.test.mjs +0 -442
  169. package/scripts/scratch-partition-invariant-prose.test.mjs +0 -74
  170. package/scripts/scripts-path-citation-sweep.test.mjs +0 -73
  171. package/scripts/section-between-guard-prose.test.mjs +0 -379
  172. package/scripts/select-dimensions.test.mjs +0 -674
  173. package/scripts/shared-refusal.test.mjs +0 -388
  174. package/scripts/shell-traps-prose.test.mjs +0 -504
  175. package/scripts/shortlist.test.mjs +0 -380
  176. package/scripts/slow-transport.mjs +0 -72
  177. package/scripts/snapshot-repo.test.mjs +0 -1006
  178. package/scripts/snapshot-runner-audience-prose.test.mjs +0 -130
  179. package/scripts/spend-view.test.mjs +0 -312
  180. package/scripts/staleness-qualifier-prose.test.mjs +0 -251
  181. package/scripts/staleness-verdict-prose.test.mjs +0 -142
  182. package/scripts/staleness.test.mjs +0 -893
  183. package/scripts/stalled-member-liveness-prose.test.mjs +0 -219
  184. package/scripts/stash-prohibition-prose.test.mjs +0 -313
  185. package/scripts/strip-comments.mjs +0 -44
  186. package/scripts/temp-dir.mjs +0 -47
  187. package/scripts/ticket-router.test.mjs +0 -981
  188. package/scripts/tier-check.test.mjs +0 -828
  189. package/scripts/tier-outcomes-header.test.mjs +0 -518
  190. package/scripts/tier-outcomes.test.mjs +0 -572
  191. package/scripts/tier-roles.test.mjs +0 -535
  192. package/scripts/tracker-block-copy-prose.test.mjs +0 -288
  193. package/scripts/triage-labels-gloss-prose.test.mjs +0 -97
  194. package/scripts/unattended-git-sweep.test.mjs +0 -142
  195. package/scripts/verify-sha-exit2-prose.test.mjs +0 -269
  196. package/scripts/verify-sha.test.mjs +0 -692
  197. package/scripts/watcher-degraded-block.test.mjs +0 -369
  198. package/scripts/watcher-key-prose.test.mjs +0 -106
  199. package/scripts/within-run-pair-prose.test.mjs +0 -212
  200. package/scripts/worktree-audit.test.mjs +0 -1408
  201. package/scripts/worktree-head-prose.test.mjs +0 -276
  202. package/scripts/worktree-listing-sweep.test.mjs +0 -217
  203. package/scripts/worktree-model-prose.test.mjs +0 -216
  204. package/scripts/worktree-porcelain.mjs +0 -35
  205. package/scripts/worktree-porcelain.test.mjs +0 -102
@@ -1,504 +0,0 @@
1
- // #854. `run-team/SKILL.md`'s **Shell traps** section is the single seat for the
2
- // zsh family, and the one thing a pin here has to stop is the rule being written
3
- // BACKWARDS. The ticket was filed naming `for x in $(…)` as the hazard — that is
4
- // the form that works — and a member acted on the uncorrected version and
5
- // reported a working bounded poll as broken. A string-matching pin cannot tell
6
- // the two directions apart: both spellings contain the same words.
7
- //
8
- // So this file RUNS them. It lifts the forms the document calls hazardous and
9
- // safe and executes each under zsh, asserting the document's own claim about
10
- // iteration counts. Invert the section and the test reddens because zsh
11
- // disagrees with it, not because a string moved. Same discipline as
12
- // watcher-degraded-block.test.mjs, one document over.
13
- //
14
- // It also runs `run-merge-bot.md`'s **Then stay armed** monitor, lifted from the
15
- // fence rather than copied, because that block carried a live instance of this
16
- // exact defect until this ticket.
17
- //
18
- // THE CEILING: the document's whole contract — the rule's direction included —
19
- // is asserted without a shell, so CI enforces it on ubuntu-latest, which ships
20
- // no zsh. The MEASUREMENTS behind it are zsh-only and announce themselves as
21
- // skipped there rather than passing; the monitor's sh and bash arms still run.
22
- // So a green on ubuntu proves the text, and a green here proves the text and
23
- // the shell agree. Nothing in this file contacts GitHub: the monitor's `gh` is
24
- // a stub, and `sleep` is a no-op, so this measures loop mechanics and not
25
- // timing.
26
- import { test } from "node:test";
27
- import assert from "node:assert/strict";
28
- import { execFileSync } from "node:child_process";
29
- import { mkdirSync, writeFileSync, readFileSync } from "node:fs";
30
- import { tempDir } from "./temp-dir.mjs";
31
- import { join } from "node:path";
32
- import { writeExecStub } from "./exec-stub.mjs";
33
-
34
- const SKILLS = join(import.meta.dirname, "..", "skills");
35
- const SKILL = readFileSync(join(SKILLS, "run-team", "SKILL.md"), "utf8");
36
- const MERGE_BOT = readFileSync(join(import.meta.dirname, "..", "commands", "run-merge-bot.md"), "utf8");
37
-
38
- const DIR = tempDir("shell-traps-");
39
- const BIN = join(DIR, "bin");
40
- mkdirSync(BIN);
41
-
42
- const stub = (name, body) => writeExecStub(join(BIN, name), body);
43
-
44
- const hasShell = (s) => {
45
- try {
46
- execFileSync(s, ["-c", "exit 0"], { stdio: "ignore" });
47
- return true;
48
- } catch {
49
- return false;
50
- }
51
- };
52
-
53
- // Runs a script and returns stdout. `env` is merged so the monitor case can
54
- // point its stub at a per-case call counter.
55
- const sh = (shell, script, env = {}) => {
56
- const p = join(DIR, "case.sh");
57
- writeFileSync(p, script);
58
- return execFileSync(shell, [p], {
59
- encoding: "utf8",
60
- env: { ...process.env, ...env, PATH: `${BIN}:${process.env.PATH}` },
61
- });
62
- };
63
-
64
- // Slice to the section, so a sentence elsewhere in a 3000-line file can never
65
- // stand in for one here. Anchored on the heading text, never on an offset.
66
- const section = (doc, heading) => {
67
- const start = doc.indexOf(`\n## ${heading}\n`);
68
- assert.notEqual(start, -1, `run-team/SKILL.md no longer has a '## ${heading}' section — this ticket put it there`);
69
- const rest = doc.slice(start + 1);
70
- const end = rest.indexOf("\n## ", 1);
71
- return end === -1 ? rest : rest.slice(0, end);
72
- };
73
-
74
- const TRAPS = section(SKILL, "Shell traps");
75
-
76
- // The three-value list the section's own table is measured against.
77
- const LIST = "849\\n850\\n852\\n";
78
-
79
- // A literal phrase as a regex that tolerates re-wrapping: every run of
80
- // whitespace matches any run. The CLAIM is what these tests pin; where the
81
- // editor's line breaks fall is not, and a pin that reddens on a reflow is one
82
- // the next reader weakens instead of reading.
83
- const phrase = (s) => new RegExp(s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\s+/g, "\\s+"));
84
-
85
- test("the section exists and is the only place the zsh loop family is stated, in either document", () => {
86
- // The mechanism sentence lives once. The two seats that consume it cite the
87
- // section instead of restating it — that is #854's placement ruling, and the
88
- // drift it prevents is a second copy going stale against the first, whether
89
- // that copy lands back in SKILL.md or in run-merge-bot.md, the document this
90
- // ticket edits most heavily and whose own brief bullet was replaced by a
91
- // pointer.
92
- const mechanism = phrase("word-splits an unquoted command substitution's result; it does NOT split an unquoted parameter expansion");
93
- assert.match(TRAPS, mechanism, "the Shell traps section dropped the mechanism sentence");
94
-
95
- const elsewhere = SKILL.replace(TRAPS, "") + MERGE_BOT;
96
- assert.ok(
97
- !/zsh has no `PIPESTATUS`/.test(elsewhere),
98
- "a second copy of the PIPESTATUS trap is back outside Shell traps — #854 collapsed them into one seat",
99
- );
100
- assert.ok(
101
- !/is a READ-ONLY variable in zsh/.test(elsewhere),
102
- "a second copy of the read-only-`status` trap is back outside Shell traps",
103
- );
104
- });
105
-
106
- test("both consumer seats reach the section instead of restating it", () => {
107
- // Phase 3 writes the CI watcher's loop; the merge-bot brief is where a bot
108
- // gets the same traps. The ticket's ruling is that neither carries its own
109
- // copy, so each has to name the section.
110
- const watcher = SKILL.slice(SKILL.indexOf("**Guard every probe, not just the ones with a verdict field.**"));
111
- const watcherPara = watcher.slice(0, watcher.indexOf("\n\n**Judge `ci-state`"));
112
- // The citation is the section NAME, in whatever emphasis the sentence wants.
113
- // Pinning `**Shell traps**` exactly would fail on a bold span that opens
114
- // earlier in the clause, which is a rewording rather than a lost pointer.
115
- assert.match(
116
- watcherPara,
117
- /\bShell traps\b/,
118
- "phase 3's monitor paragraph no longer points at Shell traps — it either lost the pointer or grew its own copy of the mechanism",
119
- );
120
-
121
- // The brief's one bullet since #1806 retired the gate traps into
122
- // merge-gate.mjs: sliced to that paragraph alone.
123
- const at = SKILL.indexOf("**Put the shell traps in the bot's brief");
124
- assert.notEqual(at, -1, "the merge bot's shell-traps brief paragraph moved — re-anchor this test");
125
- const briefPara = SKILL.slice(at, SKILL.indexOf("\n\n", at));
126
- assert.match(
127
- briefPara,
128
- /\bShell traps\b/,
129
- "the merge bot's brief no longer points at Shell traps, so a dispatched bot never receives them",
130
- );
131
- });
132
-
133
- // CI runs ubuntu-latest, which ships no zsh. So the document's whole contract
134
- // is asserted in tests that need no shell — including the rule's DIRECTION,
135
- // which is the one thing #854 exists to keep straight — and only the
136
- // measurements behind it are shell-gated, announced with `t.skip` rather than
137
- // returning green on a cell that never ran.
138
- const needs = (t, shell) => {
139
- if (hasShell(shell)) return true;
140
- t.skip(`no ${shell} on PATH — this cell measures a ${shell}-specific behaviour and cannot run here`);
141
- return false;
142
- };
143
-
144
- test("the section states the rule in the corrected direction", () => {
145
- // The half the original ticket got backwards, and the half that matters most:
146
- // a reader who takes `$(…)` for the hazard avoids the form that works and
147
- // keeps the one that collapses. Both directions are pinned, because dropping
148
- // either one leaves a reader able to infer the wrong discriminator.
149
- assert.match(
150
- TRAPS,
151
- phrase("hazard is the **assigned-variable** form, never `$(…)`"),
152
- "Shell traps no longer names the assigned-variable form as the hazard — #854's whole correction is that direction",
153
- );
154
- assert.match(TRAPS, phrase("`$(…)` splits. Leave it alone."), "Shell traps stopped blessing the command-substitution form");
155
- assert.match(
156
- TRAPS,
157
- phrase("Capture-then-loop needs `while IFS= read -r` fed by a heredoc"),
158
- "Shell traps no longer prescribes the heredoc-fed `while IFS= read -r` remedy",
159
- );
160
- assert.match(
161
- TRAPS,
162
- phrase("`</dev/null` every command inside a `while read` loop"),
163
- "Shell traps dropped the `</dev/null` rule — the remedy it prescribes is unsafe without it",
164
- );
165
- });
166
-
167
- test("zsh agrees with the table: the assigned-variable form collapses", (t) => {
168
- if (!needs(t, "zsh")) return;
169
- // The hazard row, run for real rather than quoted. This is what a string pin
170
- // cannot do: if the section is ever reworded to bless the broken form, the
171
- // measurement it claims stops holding and this reddens on the shell's own
172
- // behaviour instead of on a diff.
173
- const out = sh("zsh", `prs=$(printf '${LIST}')\ni=0; for pr in $prs; do i=$((i+1)); done; echo "$i"`);
174
- assert.equal(
175
- out.trim(),
176
- "1",
177
- "zsh no longer collapses `for pr in $prs` — the section's hazard row is now false and the rule needs re-measuring",
178
- );
179
- });
180
-
181
- test("zsh agrees with the table: both command-substitution rows split", (t) => {
182
- if (!needs(t, "zsh")) return;
183
- const inline = sh("zsh", `i=0; for pr in $(printf '${LIST}'); do i=$((i+1)); done; echo "$i"`);
184
- assert.equal(inline.trim(), "3", "zsh no longer splits an inline command substitution — the section's safe row is now false");
185
- const seq = sh("zsh", `j=0; for _ in $(seq 1 60); do j=$((j+1)); done; echo "$j"`);
186
- assert.equal(seq.trim(), "60", "the bounded-poll row is false — `for _ in $(seq 1 60)` no longer runs 60 times");
187
- });
188
-
189
- test("bash and sh split BOTH forms — which is why the bug hides", (t) => {
190
- // The table's third column. Without it the section reads as a fact about
191
- // loops rather than about zsh, and the reason a bash-tested loop ships broken
192
- // goes unstated.
193
- let ran = 0;
194
- for (const shell of ["sh", "bash"]) {
195
- if (!hasShell(shell)) continue;
196
- ran++;
197
- const out = execFileSync(shell, ["-c", `prs=$(printf '${LIST}'); i=0; for pr in $prs; do i=$((i+1)); done; echo "$i"`], {
198
- encoding: "utf8",
199
- });
200
- assert.equal(out.trim(), "3", `${shell} no longer splits a bare parameter expansion; the table's bash/sh column is wrong`);
201
- }
202
- if (!ran) t.skip("neither sh nor bash on PATH");
203
- });
204
-
205
- test("the prescribed remedy is line-exact where `$(printf …)` is not", (t) => {
206
- if (!needs(t, "zsh")) return;
207
- // Why the remedy is `while IFS= read -r` and not "either form": the inline
208
- // one splits on every whitespace character, so it is safe for PR numbers and
209
- // wrong for anything that can contain a space. Measured, not asserted.
210
- const blob = `blob=$(printf 'two words\\nsecond\\n')`;
211
- const viaSubst = sh("zsh", `${blob}\ni=0; for x in $(printf '%s\\n' "$blob"); do i=$((i+1)); done; echo "$i"`);
212
- const viaRead = sh("zsh", `${blob}\ni=0; while IFS= read -r x; do i=$((i+1)); done <<EOF\n$blob\nEOF\necho "$i"`);
213
- assert.equal(viaSubst.trim(), "3", "`$(printf …)` stopped splitting on the space inside a value; the section's caveat is stale");
214
- assert.equal(viaRead.trim(), "2", "`while IFS= read -r` stopped being line-exact; the prescribed remedy no longer holds");
215
- });
216
-
217
- test("an inner command without `</dev/null` eats the loop's stdin", (t) => {
218
- if (!needs(t, "zsh")) return;
219
- // The half nothing in this repo carried before #854, and the reason it
220
- // matters: the failure signature is IDENTICAL to the word-split bug, so a
221
- // reader who fixes the loop correctly and omits this sees no change and
222
- // concludes the fix did not work.
223
- const loop = (inner) => `i=0; while IFS= read -r n; do i=$((i+1)); ${inner}; done <<EOF\n849\n850\n852\nEOF\necho "$i"`;
224
- assert.equal(sh("zsh", loop("cat >/dev/null")).trim(), "1", "an unredirected inner reader no longer eats the loop's stdin; re-measure the rule");
225
- assert.equal(sh("zsh", loop("cat >/dev/null </dev/null")).trim(), "3", "`</dev/null` no longer protects the loop's stdin");
226
- });
227
-
228
- test("the probe-could-not-look rule is stated as its own instruction", () => {
229
- // #854's third ruling. It is a sentence, not a clause hanging off the loop
230
- // rule, because a monitor that `continue`s on an unreadable probe is blind
231
- // whether or not its loop iterates.
232
- assert.match(
233
- TRAPS,
234
- phrase("**A probe that could not look emits an event; it never `continue`s.**"),
235
- "Shell traps lost the probe-could-not-look instruction",
236
- );
237
- assert.match(
238
- TRAPS,
239
- /transition event, not silence/,
240
- "the probe rule no longer routes to phase 3's full statement, so the sentence is all a reader gets",
241
- );
242
- });
243
-
244
- // --- run-merge-bot.md's monitor, lifted from the fence and executed ----------
245
-
246
- // Anchored on what the block contains, never on its ordinal. Exactly one fence
247
- // in that document emits the label event.
248
- const monitorBlocks = [...MERGE_BOT.matchAll(/```bash\n([\s\S]*?)```/g)]
249
- .map((m) => m[1])
250
- .filter((b) => b.includes("ready-to-merge label added"));
251
- assert.equal(
252
- monitorBlocks.length,
253
- 1,
254
- `expected exactly one bash block emitting the ready-to-merge event, found ${monitorBlocks.length} — update this test`,
255
- );
256
- const MONITOR = monitorBlocks[0];
257
-
258
- const WATCH_LOOP = "while true; do";
259
- assert.ok(MONITOR.includes(WATCH_LOOP), `the monitor no longer opens with '${WATCH_LOOP}'; the harness caps the run on that line — update this test`);
260
-
261
- // `gh` returns 849,850 on the seed call and 849,850,852 after it: one PR whose
262
- // label genuinely appeared after arming. `sleep` is a no-op so the cap is the
263
- // tick count, not wall time.
264
- stub(
265
- "gh",
266
- `#!/bin/sh
267
- c="$CALLS/n"
268
- n=$(cat "$c" 2>/dev/null || echo 0); n=$((n+1)); echo "$n" >"$c"
269
- if [ "$n" -le 1 ]; then printf '849\\n850\\n'; else printf '849\\n850\\n852\\n'; fi
270
- `,
271
- );
272
- stub("sleep", "#!/bin/sh\nexit 0\n");
273
-
274
- const runMonitor = (shell, body, ticks = 2) => {
275
- const calls = tempDir("shell-traps-calls-");
276
- const capped = body.replace(WATCH_LOOP, `tick=0\nwhile tick=$((tick+1)); [ "$tick" -le ${ticks} ]; do`);
277
- return sh(shell, capped, { CALLS: calls });
278
- };
279
-
280
- const events = (out) => out.split("\n").filter((l) => l.includes("ready-to-merge label added")).map((l) => l.trim());
281
-
282
- // A loop whose operand is a bare parameter — `for n in $cur`, `for n in ${cur}`.
283
- // `$(` is deliberately excluded: that is the form that splits, and refusing it
284
- // would be this ticket's own inversion re-committed as a test.
285
- const COLLAPSING_LOOP = /for\s+\w+\s+in\s+\$\{?\w/;
286
-
287
- // Line continuations are folded to a space FIRST: a backslash-newline breaks
288
- // the regex's `\s+` run (the literal `\` is not whitespace), so a wrapped
289
- // `for n in \` / ` $cur` reads as safe when it collapses under zsh exactly
290
- // like the unwrapped form. Comments are stripped second: both blocks NAME the
291
- // forbidden form in a comment so the next editor sees the rule at the line it
292
- // applies to, and matching that would make the fix look like the defect.
293
- // Removing text can only delete matches, never create one, so the crude sweep
294
- // is safe here even where it clips the tail of a string containing `#`.
295
- const code = (block) => block.replace(/\\\n/g, " ").replace(/(^|\s)#.*$/gm, "$1");
296
-
297
- test("no prescriptive loop in either document iterates a bare parameter", () => {
298
- // The behavioural tests above catch this only where zsh exists, and CI runs
299
- // ubuntu-latest, which ships none: measured, reverting the monitor to `for n
300
- // in $cur` leaves the whole suite GREEN on a zsh-less runner, because sh and
301
- // bash split it correctly. That is the same "the bug hides in whichever shell
302
- // you tested in" mechanism one level up, aimed at the pin instead of the
303
- // runbook — so the shape gets an assertion that needs no shell at all.
304
- const blocks = [
305
- ["run-merge-bot.md's stay-armed monitor", MONITOR],
306
- ["run-team/SKILL.md's degraded-watcher block", (() => {
307
- const b = [...SKILL.matchAll(/```sh\n([\s\S]*?)```/g)].map((m) => m[1]).filter((x) => x.includes("WATCHER DEGRADED"));
308
- assert.equal(b.length, 1, `expected exactly one sh block emitting WATCHER DEGRADED, found ${b.length} — update this test`);
309
- return b[0];
310
- })()],
311
- ];
312
- for (const [name, block] of blocks) {
313
- const hit = code(block).match(COLLAPSING_LOOP);
314
- assert.equal(
315
- hit,
316
- null,
317
- `${name} iterates a bare parameter (\`${hit?.[0]}\`). Under zsh that runs ONCE with the whole list glued into one value — measured. Feed it from a heredoc with \`while IFS= read -r\`, or iterate \`$(printf '%s\\n' "$var")\`; see run-team/SKILL.md's Shell traps.`,
318
- );
319
- }
320
- });
321
-
322
- test("the stay-armed monitor reports the ONE new PR, under zsh as well as sh", () => {
323
- for (const shell of ["sh", "bash", "zsh"]) {
324
- if (!hasShell(shell)) continue;
325
- const got = events(runMonitor(shell, MONITOR));
326
- assert.deepEqual(
327
- got,
328
- ["ready-to-merge label added: PR #852"],
329
- // Two different regressions land here and the message has to tell them
330
- // apart, or it teaches the wrong discriminator — this ticket's own
331
- // failure mode. ONE event naming several numbers is the #854 collapse:
332
- // the loop iterated once over the whole list. SEVERAL events, or one
333
- // naming an already-handled PR, is the `seen` seed missing instead.
334
- `${shell}: expected exactly one event naming PR #852, got ${JSON.stringify(got)}. One event naming several numbers = the #854 loop collapse; extra events naming 849/850 = the \`seen\` seed is gone.`,
335
- );
336
- }
337
- });
338
-
339
- // Restores the two-phase stub the tests above rely on, so a case that swaps it
340
- // for a fixed one cannot leak into whatever runs next.
341
- const restoreGh = () =>
342
- stub(
343
- "gh",
344
- `#!/bin/sh
345
- c="$CALLS/n"
346
- n=$(cat "$c" 2>/dev/null || echo 0); n=$((n+1)); echo "$n" >"$c"
347
- if [ "$n" -le 1 ]; then printf '849\\n850\\n'; else printf '849\\n850\\n852\\n'; fi
348
- `,
349
- );
350
-
351
- const SHELLS = ["sh", "bash", "zsh"].filter(hasShell);
352
-
353
- test("the monitor stays silent when no label appeared", (t) => {
354
- if (!SHELLS.length) return t.skip("no shell on PATH");
355
- // The positive control's other half: a monitor that fires on an unchanged
356
- // list is noise, and the seeded `seen` is what prevents it. Without this, a
357
- // loop that emitted an event per tick would pass the test above on tick 1.
358
- // Every shell, not just zsh — the seed is not a zsh concern.
359
- stub("gh", "#!/bin/sh\nprintf '849\\n850\\n'\n");
360
- try {
361
- for (const shell of SHELLS) {
362
- assert.deepEqual(events(runMonitor(shell, MONITOR, 3)), [], `${shell}: the monitor re-fires on an unchanged labeled set`);
363
- }
364
- } finally {
365
- restoreGh();
366
- }
367
- });
368
-
369
- test("the monitor does not fire on an empty labeled set", (t) => {
370
- if (!SHELLS.length) return t.skip("no shell on PATH");
371
- // The blank-line guard. A heredoc fed an empty `cur` still delivers one empty
372
- // line, so without `[ -n "$n" ]` the block emits `PR #` — an event naming no
373
- // PR, which is the same class of garbage the collapse produced.
374
- stub("gh", "#!/bin/sh\nexit 0\n");
375
- try {
376
- for (const shell of SHELLS) {
377
- const out = runMonitor(shell, MONITOR, 2);
378
- assert.deepEqual(events(out), [], `${shell}: an empty labeled set produced an event:\n${out}`);
379
- }
380
- } finally {
381
- restoreGh();
382
- }
383
- });
384
-
385
- test("a failed poll is skipped without losing `seen` — the seed/tick guard is load-bearing", (t) => {
386
- if (!SHELLS.length) return t.skip("no shell on PATH");
387
- // #854 silently made `if cur=$(poll)` (and the seed's mirror of it) load-
388
- // bearing for the FIRST time by moving `| tr` out of `poll()` and onto the
389
- // call sites. Nothing pinned that before this test: fold `| tr` back INTO
390
- // `poll()` — a "natural tidy-up", since `tr` now appears twice at the call
391
- // sites — and `poll`'s exit status becomes `tr`'s, which is 0 regardless of
392
- // whether the `gh` call underneath it failed. The guard stops guarding: a
393
- // failed poll then reads as an empty labeled set, `seen` gets reassigned to
394
- // blank, and the next successful poll fires one event per already-seen PR
395
- // instead of staying silent on the ones it already reported.
396
- stub(
397
- "gh",
398
- `#!/bin/sh
399
- c="$CALLS/n"
400
- n=$(cat "$c" 2>/dev/null || echo 0); n=$((n+1)); echo "$n" >"$c"
401
- if [ "$n" -eq 1 ]; then printf '849\\n850\\n'
402
- elif [ "$n" -eq 2 ]; then exit 1
403
- else printf '849\\n850\\n852\\n'
404
- fi
405
- `,
406
- );
407
- try {
408
- for (const shell of SHELLS) {
409
- const out = runMonitor(shell, MONITOR, 2);
410
- assert.deepEqual(
411
- events(out),
412
- ["ready-to-merge label added: PR #852"],
413
- `${shell}: a poll that fails on one tick must not fire an event on that tick, and must not lose \`seen\` — expected exactly one event (PR #852) on the next successful poll, not a replay of 849/850:\n${out}`,
414
- );
415
- }
416
- } finally {
417
- restoreGh();
418
- }
419
- });
420
-
421
- // #2108. A stub `gh` that stops at `--limit` the way gh does — 30 when the
422
- // flag is absent, exit 0, no warning — holding `totals[k]` labelled PRs
423
- // (numbered from 1) on its k-th call and the last entry thereafter.
424
- const cappingGh = (totals) =>
425
- stub(
426
- "gh",
427
- `#!/bin/sh
428
- c="$CALLS/n"
429
- n=$(cat "$c" 2>/dev/null || echo 0); n=$((n+1)); echo "$n" >"$c"
430
- limit=30
431
- while [ $# -gt 0 ]; do [ "$1" = --limit ] && limit=$2; shift; done
432
- total=$(echo "${totals.join(" ")}" | awk -v k="$n" '{ print (k <= NF) ? $k : $NF }')
433
- i=0; while [ "$i" -lt "$total" ] && [ "$i" -lt "$limit" ]; do i=$((i+1)); echo "$i"; done
434
- `,
435
- );
436
-
437
- test("#2108: a poll that fills its --limit says so once, clears once, and fires no label event for it", (t) => {
438
- if (!SHELLS.length) return t.skip("no shell on PATH");
439
- // Two runs. 250 labelled on the seed and tick 1, then 5: the cap sustained
440
- // across polls must still speak once. 250 on the seed alone, then 5: a
441
- // monitor that arms on a capped seed must say so at arming, not wait for a
442
- // capped tick that never comes. Every one of the 5 is already in `seen`, so
443
- // the only lines either run may print are the cap's own pair.
444
- for (const [totals, ticks] of [[[250, 250, 5], 3], [[250, 5], 1]]) {
445
- cappingGh(totals);
446
- try {
447
- for (const shell of SHELLS) {
448
- const lines = runMonitor(shell, MONITOR, ticks).split("\n");
449
- const said = (s) => lines.filter((l) => l.includes(s)).length;
450
- const run = `${shell}, totals ${totals.join("/")}`;
451
- assert.equal(said("hit its --limit 200"), 1, `${run}: a full page must be reported exactly once:\n${lines.join("\n")}`);
452
- assert.equal(said("under its --limit 200"), 1, `${run}: a poll back under the cap must clear the latch exactly once:\n${lines.join("\n")}`);
453
- assert.deepEqual(events(lines.join("\n")), [], `${run}: the cap's lines were read as label events`);
454
- }
455
- } finally {
456
- restoreGh();
457
- }
458
- }
459
- });
460
-
461
- test("#2108: a labelled set past gh's bare default of 30 is read whole, and says nothing about a cap", (t) => {
462
- if (!SHELLS.length) return t.skip("no shell on PATH");
463
- // The input the guard must ACCEPT. 35 seeded, then #36 labelled: a poll cut
464
- // at 30 would never see #36, and 36 is far under the explicit limit.
465
- cappingGh([35, 36]);
466
- try {
467
- for (const shell of SHELLS) {
468
- const out = runMonitor(shell, MONITOR, 2);
469
- assert.deepEqual(events(out), ["ready-to-merge label added: PR #36"], `${shell}: the poll no longer reads past gh's default of 30:\n${out}`);
470
- assert.doesNotMatch(out, /--limit/, `${shell}: a poll under its limit reported a cap:\n${out}`);
471
- }
472
- } finally {
473
- restoreGh();
474
- }
475
- });
476
-
477
- test("#2108: a poll one short of its explicit --limit is read whole, and says nothing about a cap", (t) => {
478
- if (!SHELLS.length) return t.skip("no shell on PATH");
479
- // The input the guard must ACCEPT: 199 is a whole answer, not a capped one,
480
- // and every one of them fires its own label event — unlike the 35/36 case
481
- // above, which only clears gh's bare default of 30 and never approaches the
482
- // 200 this monitor actually asks for.
483
- cappingGh([0, 199]);
484
- try {
485
- for (const shell of SHELLS) {
486
- const out = runMonitor(shell, MONITOR, 2);
487
- assert.equal(events(out).length, 199, `${shell}: a poll one short of its limit reported fewer label events than PRs returned:\n${out}`);
488
- assert.doesNotMatch(out, /--limit/, `${shell}: a poll under its limit reported a cap:\n${out}`);
489
- }
490
- } finally {
491
- restoreGh();
492
- }
493
- });
494
-
495
- test("run-merge-bot.md's bounded poll is left alone — it is not an instance", () => {
496
- // The ticket's filer retracted the claim that step 1's poll was a second
497
- // instance of this bug, and a later reader "fixing" it would be acting on the
498
- // retracted version. Pin the form so that edit has to argue with a test.
499
- assert.match(
500
- MERGE_BOT,
501
- phrase("for _ in $(seq 1 60); do"),
502
- "step 1's bounded poll was rewritten — it is a command substitution, it splits correctly (60 iterations, measured), and #854's filer retracted the claim that it was broken",
503
- );
504
- });