@feigi/fleet-ctl 3.23.35 → 3.23.37

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 (204) hide show
  1. package/package.json +1 -1
  2. package/scripts/main-checkout.mjs +1 -1
  3. package/scripts/member-write-guard.mjs +1 -1
  4. package/scripts/repo-root.mjs +1 -1
  5. package/skills/run-team/references/reaping.md +1 -1
  6. package/scripts/agent-test-dir-prose.test.mjs +0 -59
  7. package/scripts/agent-test.test.mjs +0 -1640
  8. package/scripts/ambient-git-vars-mjs-prose.test.mjs +0 -397
  9. package/scripts/ambient-git-vars-prose.test.mjs +0 -192
  10. package/scripts/ancestry-check-position-prose.test.mjs +0 -175
  11. package/scripts/apply-ruleset.test.mjs +0 -421
  12. package/scripts/arg-header-probes-prose.test.mjs +0 -394
  13. package/scripts/arg.test.mjs +0 -1354
  14. package/scripts/board-cli.test.mjs +0 -710
  15. package/scripts/board-identity.test.mjs +0 -429
  16. package/scripts/board-liveness-banner.test.mjs +0 -119
  17. package/scripts/board-prev-shape.test.mjs +0 -228
  18. package/scripts/board-tryparse-null.test.mjs +0 -119
  19. package/scripts/board.test.mjs +0 -3121
  20. package/scripts/brief-after-cut-prose.test.mjs +0 -53
  21. package/scripts/candidates-exit3-prose.test.mjs +0 -302
  22. package/scripts/candidates.test.mjs +0 -2312
  23. package/scripts/caveat-unification-prose.test.mjs +0 -98
  24. package/scripts/cell-readout.test.mjs +0 -615
  25. package/scripts/ci-comment-rot-prose.test.mjs +0 -2025
  26. package/scripts/ci-completes-premise-prose.test.mjs +0 -257
  27. package/scripts/ci-state-prose.test.mjs +0 -113
  28. package/scripts/ci-state.test.mjs +0 -1933
  29. package/scripts/ci-vacuous-green.test.mjs +0 -368
  30. package/scripts/citation-sweep-prose.test.mjs +0 -1712
  31. package/scripts/claim-lifecycle.test.mjs +0 -187
  32. package/scripts/claim-ticket.test.mjs +0 -1122
  33. package/scripts/closing-keyword-prose.test.mjs +0 -193
  34. package/scripts/cockpit-launch-idempotent-prose.test.mjs +0 -165
  35. package/scripts/cockpit-tick-nonblocking.test.mjs +0 -210
  36. package/scripts/compute-board.test.mjs +0 -1214
  37. package/scripts/compute-spend.test.mjs +0 -517
  38. package/scripts/consumer-technology-prose.test.mjs +0 -126
  39. package/scripts/cross-repo-citation-prose.test.mjs +0 -155
  40. package/scripts/cwd-isolation-pins.mjs +0 -83
  41. package/scripts/dedupe-guard-prose.test.mjs +0 -243
  42. package/scripts/delete-merged-branch.test.mjs +0 -576
  43. package/scripts/derive-testcmd.test.mjs +0 -595
  44. package/scripts/diff-stats.test.mjs +0 -404
  45. package/scripts/dispatch-block-golden-prose.test.mjs +0 -1130
  46. package/scripts/dispatch-block-pins-prose.test.mjs +0 -615
  47. package/scripts/dispositions-check.test.mjs +0 -936
  48. package/scripts/dispositions-gate-prose.test.mjs +0 -129
  49. package/scripts/drop-merged-label.test.mjs +0 -479
  50. package/scripts/exec-stub.mjs +0 -93
  51. package/scripts/exec-stub.test.mjs +0 -69
  52. package/scripts/expected-jobs-prose.test.mjs +0 -80
  53. package/scripts/fan-out-authorization-prose.test.mjs +0 -80
  54. package/scripts/filing-bar-seat-prose.test.mjs +0 -242
  55. package/scripts/filing-claim-bar-prose.test.mjs +0 -166
  56. package/scripts/finisher-died-prose.test.mjs +0 -31
  57. package/scripts/finisher-dispatch-premise-prose.test.mjs +0 -312
  58. package/scripts/finisher-halt-prose.test.mjs +0 -106
  59. package/scripts/finisher-name-prose.test.mjs +0 -134
  60. package/scripts/finisher-own-tree-prose.test.mjs +0 -299
  61. package/scripts/finisher-pin-race-prose.test.mjs +0 -339
  62. package/scripts/finisher-test-verdict-prose.test.mjs +0 -102
  63. package/scripts/fix-applier-correction-rules-prose.test.mjs +0 -202
  64. package/scripts/fix-applier-result-file-prose.test.mjs +0 -149
  65. package/scripts/fleet-bootstrap.test.mjs +0 -75
  66. package/scripts/fleet-heartbeat.test.mjs +0 -450
  67. package/scripts/fleet-provenance.test.mjs +0 -138
  68. package/scripts/fleet-run.test.mjs +0 -90
  69. package/scripts/fleet-state.test.mjs +0 -460
  70. package/scripts/fleet-tick-prose.test.mjs +0 -300
  71. package/scripts/fleet-tick.test.mjs +0 -2444
  72. package/scripts/force-with-lease-reason-prose.test.mjs +0 -184
  73. package/scripts/frontmatter-check.test.mjs +0 -436
  74. package/scripts/git-env.test.mjs +0 -149
  75. package/scripts/git-status-untracked-mode-sweep.test.mjs +0 -216
  76. package/scripts/gone-walk.test.mjs +0 -213
  77. package/scripts/gp-sep-invariant-prose.test.mjs +0 -188
  78. package/scripts/head-moved-after-label-prose.test.mjs +0 -233
  79. package/scripts/immutable-body-claim-prose.test.mjs +0 -204
  80. package/scripts/implementer-model-tier.test.mjs +0 -235
  81. package/scripts/inflight-citation-prose.test.mjs +0 -144
  82. package/scripts/inflight-exit2-prose.test.mjs +0 -81
  83. package/scripts/inflight-probe-guard-prose.test.mjs +0 -109
  84. package/scripts/inflight-scan-scope-prose.test.mjs +0 -57
  85. package/scripts/inflight.test.mjs +0 -2882
  86. package/scripts/injection-control-prose.test.mjs +0 -404
  87. package/scripts/install-root-audit.test.mjs +0 -464
  88. package/scripts/instrument-check-prose.test.mjs +0 -235
  89. package/scripts/instruments.test.mjs +0 -787
  90. package/scripts/is-cli.test.mjs +0 -99
  91. package/scripts/issue-tracker-prose.test.mjs +0 -71
  92. package/scripts/json.test.mjs +0 -364
  93. package/scripts/ledger-dispatch.test.mjs +0 -927
  94. package/scripts/ledger-grammar.test.mjs +0 -227
  95. package/scripts/ledger-read-require-file.test.mjs +0 -197
  96. package/scripts/ledger-rotate.test.mjs +0 -142
  97. package/scripts/ledger.test.mjs +0 -3436
  98. package/scripts/line-distance-prose.test.mjs +0 -245
  99. package/scripts/liveness-rationale-prose.test.mjs +0 -83
  100. package/scripts/locale-pin-prose.test.mjs +0 -189
  101. package/scripts/main-checkout.test.mjs +0 -332
  102. package/scripts/member-outcome-prose.test.mjs +0 -167
  103. package/scripts/member-outcomes-header.test.mjs +0 -129
  104. package/scripts/member-outcomes-prose.test.mjs +0 -63
  105. package/scripts/member-outcomes.test.mjs +0 -638
  106. package/scripts/member-prompt-prose.test.mjs +0 -165
  107. package/scripts/member-record.test.mjs +0 -541
  108. package/scripts/member-write-guard.test.mjs +0 -214
  109. package/scripts/merge-commit-probe-prose.test.mjs +0 -122
  110. package/scripts/merge-gate.test.mjs +0 -613
  111. package/scripts/muted-git-guard-sweep.test.mjs +0 -493
  112. package/scripts/net-ssh-precedence-prose.test.mjs +0 -91
  113. package/scripts/net-watchdog-prose.test.mjs +0 -79
  114. package/scripts/net.test.mjs +0 -211
  115. package/scripts/no-ci-gate-prose.test.mjs +0 -108
  116. package/scripts/no-undo-audit.test.mjs +0 -3961
  117. package/scripts/no-wave.test.mjs +0 -138
  118. package/scripts/node-floor-sweep.test.mjs +0 -611
  119. package/scripts/pointer-target-prose.test.mjs +0 -186
  120. package/scripts/pr-cost.test.mjs +0 -521
  121. package/scripts/pr-overlap.test.mjs +0 -692
  122. package/scripts/printf-die-sweep.test.mjs +0 -384
  123. package/scripts/prompt-renderer.mjs +0 -40
  124. package/scripts/prompt-renderer.test.mjs +0 -68
  125. package/scripts/prose-pin.mjs +0 -807
  126. package/scripts/prose-pin.test.mjs +0 -1034
  127. package/scripts/prove-merge.test.mjs +0 -995
  128. package/scripts/pull-table-relabel-prose.test.mjs +0 -60
  129. package/scripts/quiet-payload-prose.test.mjs +0 -222
  130. package/scripts/reap-cherry-check-prose.test.mjs +0 -80
  131. package/scripts/reap.test.mjs +0 -4432
  132. package/scripts/reaping-prose.test.mjs +0 -239
  133. package/scripts/reaping-reap-authorizers-prose.test.mjs +0 -112
  134. package/scripts/reaping-release-authorizers-prose.test.mjs +0 -85
  135. package/scripts/recipe-derivation-prose.test.mjs +0 -112
  136. package/scripts/recipe-prove.test.mjs +0 -1042
  137. package/scripts/refuter-scratch-prose.test.mjs +0 -135
  138. package/scripts/release-label-required-prose.test.mjs +0 -71
  139. package/scripts/release-label-split-prose.test.mjs +0 -184
  140. package/scripts/release-ticket-reap-pairing-prose.test.mjs +0 -63
  141. package/scripts/release-ticket.test.mjs +0 -5099
  142. package/scripts/renovate-release-contract.test.mjs +0 -379
  143. package/scripts/repo-root.test.mjs +0 -873
  144. package/scripts/reporter-output-rule-prose.test.mjs +0 -208
  145. package/scripts/review-agent-report-only.test.mjs +0 -49
  146. package/scripts/review-core-booking.test.mjs +0 -35
  147. package/scripts/review-core-cwd-isolation.test.mjs +0 -374
  148. package/scripts/review-core-reads.test.mjs +0 -478
  149. package/scripts/review-core-refuter-scratch.test.mjs +0 -148
  150. package/scripts/review-core-scratch-refusal.test.mjs +0 -64
  151. package/scripts/review-core-shared-test-run.test.mjs +0 -275
  152. package/scripts/review-core-snapshot-path.test.mjs +0 -830
  153. package/scripts/review-core-specialist-scratch.test.mjs +0 -191
  154. package/scripts/review-core-testcmd.test.mjs +0 -335
  155. package/scripts/review-core-unrun.test.mjs +0 -566
  156. package/scripts/review-core-unverified-discriminant.test.mjs +0 -208
  157. package/scripts/review-eval-resolver-path.test.mjs +0 -55
  158. package/scripts/review-host-fixture.mjs +0 -89
  159. package/scripts/review-in-run-retry.test.mjs +0 -211
  160. package/scripts/review-no-vendor-dispatch.test.mjs +0 -45
  161. package/scripts/review-path-default.test.mjs +0 -796
  162. package/scripts/review-runner-spawns.test.mjs +0 -95
  163. package/scripts/review-runner.test.mjs +0 -166
  164. package/scripts/review-tier-audit.test.mjs +0 -140
  165. package/scripts/run-artifact-pr-prose.test.mjs +0 -341
  166. package/scripts/run-merge-bot-prose.test.mjs +0 -1413
  167. package/scripts/run-team-local-hook.test.mjs +0 -442
  168. package/scripts/scratch-partition-invariant-prose.test.mjs +0 -74
  169. package/scripts/scripts-path-citation-sweep.test.mjs +0 -73
  170. package/scripts/section-between-guard-prose.test.mjs +0 -379
  171. package/scripts/select-dimensions.test.mjs +0 -674
  172. package/scripts/shared-refusal.test.mjs +0 -388
  173. package/scripts/shell-traps-prose.test.mjs +0 -504
  174. package/scripts/shortlist.test.mjs +0 -380
  175. package/scripts/slow-transport.mjs +0 -72
  176. package/scripts/snapshot-repo.test.mjs +0 -1006
  177. package/scripts/snapshot-runner-audience-prose.test.mjs +0 -130
  178. package/scripts/spend-view.test.mjs +0 -312
  179. package/scripts/staleness-qualifier-prose.test.mjs +0 -251
  180. package/scripts/staleness-verdict-prose.test.mjs +0 -142
  181. package/scripts/staleness.test.mjs +0 -893
  182. package/scripts/stalled-member-liveness-prose.test.mjs +0 -219
  183. package/scripts/stash-prohibition-prose.test.mjs +0 -313
  184. package/scripts/strip-comments.mjs +0 -44
  185. package/scripts/temp-dir.mjs +0 -47
  186. package/scripts/ticket-router.test.mjs +0 -981
  187. package/scripts/tier-check.test.mjs +0 -828
  188. package/scripts/tier-outcomes-header.test.mjs +0 -518
  189. package/scripts/tier-outcomes.test.mjs +0 -572
  190. package/scripts/tier-roles.test.mjs +0 -535
  191. package/scripts/tracker-block-copy-prose.test.mjs +0 -288
  192. package/scripts/triage-labels-gloss-prose.test.mjs +0 -97
  193. package/scripts/unattended-git-sweep.test.mjs +0 -142
  194. package/scripts/verify-sha-exit2-prose.test.mjs +0 -269
  195. package/scripts/verify-sha.test.mjs +0 -692
  196. package/scripts/watcher-degraded-block.test.mjs +0 -369
  197. package/scripts/watcher-key-prose.test.mjs +0 -106
  198. package/scripts/within-run-pair-prose.test.mjs +0 -212
  199. package/scripts/worktree-audit.test.mjs +0 -1408
  200. package/scripts/worktree-head-prose.test.mjs +0 -276
  201. package/scripts/worktree-listing-sweep.test.mjs +0 -217
  202. package/scripts/worktree-model-prose.test.mjs +0 -216
  203. package/scripts/worktree-porcelain.mjs +0 -35
  204. package/scripts/worktree-porcelain.test.mjs +0 -102
@@ -1,613 +0,0 @@
1
- // Regression gate for merge-gate.mjs (#1800), the merge bot's pre-merge
2
- // conjunction — spec docs/specs/2026-09-24-slot-based-fleet-loop-design.md
3
- // § 5, whose exit-vocabulary table every row below is named after.
4
- //
5
- // Zero deps: `node --test plugin/scripts/merge-gate.test.mjs`.
6
- //
7
- // `gh` is stubbed on PATH. ci-state.mjs and instruments.sh are resolved beside
8
- // merge-gate.mjs itself (its SCRIPT_DIR), so each fixture runs a COPY of the
9
- // gate out of a stub scripts directory holding stub siblings — the pattern
10
- // fleet-tick.test.mjs uses for candidates.mjs — with every module the gate
11
- // imports copied alongside. All three stubs append to one call log, which is
12
- // how the "ci-state runs on every call, with --declare-no-ci" and "read-only"
13
- // assertions are made. The cwd is a real `git init`-ed repository, because
14
- // the gate derives instruments.sh's `--repo` from `git rev-parse
15
- // --git-common-dir`.
16
- //
17
- // Each row gets a case that proves it blocks ON ITS OWN, the discipline
18
- // drop-merged-label.test.mjs states: every input except the one under test is
19
- // held at the mergeable baseline, so deleting a check fails the case named
20
- // after it, not merely some case somewhere.
21
-
22
- import { after, test } from "node:test";
23
- import assert from "node:assert/strict";
24
- import { spawnSync } from "node:child_process";
25
- import { mkdtempSync, mkdirSync, readFileSync, writeFileSync, rmSync, realpathSync } from "node:fs";
26
- import { tmpdir } from "node:os";
27
- import { join } from "node:path";
28
- import { fileURLToPath } from "node:url";
29
-
30
- const SCRIPT = fileURLToPath(new URL("./merge-gate.mjs", import.meta.url));
31
- // Every non-builtin module the copied gate imports. An unlisted one is a
32
- // module-not-found at startup — Node's exit 1, which is this gate's
33
- // "blocked". Add a row whenever merge-gate.mjs gains an import.
34
- const SIBLING_MODULES = ["arg.mjs", "git-env.mjs"].map((m) => [m, fileURLToPath(new URL(`./${m}`, import.meta.url))]);
35
-
36
- const PRE = "a".repeat(40);
37
- const POST = "b".repeat(40);
38
- const THIRD = "c".repeat(40);
39
- const DIGEST = "d".repeat(64);
40
-
41
- const PR_VIEW = { labels: [{ name: "patch" }, { name: "ready-to-merge" }], reviewDecision: "APPROVED", headRefOid: PRE };
42
-
43
- // Shaped like ci-state.mjs's own payload (its `payload` literal, plus
44
- // `jobs`/`missing` outside --quiet), green at exit 0.
45
- const CI_GREEN = {
46
- pr: 42,
47
- branch: "fix/42",
48
- prHead: PRE,
49
- runId: 7,
50
- attempt: 1,
51
- runHeadSha: PRE,
52
- status: "completed",
53
- conclusion: "success",
54
- behind: 0,
55
- verdict: "green",
56
- reasons: [],
57
- jobs: [{ name: "check", status: "completed", conclusion: "success" }],
58
- missing: [],
59
- };
60
- const ci = (patch) => JSON.stringify({ ...CI_GREEN, ...patch });
61
-
62
- const CI_STATE_STUB = `import { appendFileSync, readFileSync } from "node:fs";
63
- appendFileSync(process.env.CALL_LOG, "ci-state.mjs " + process.argv.slice(2).join(" ") + "\\n");
64
- process.stderr.write(process.env.CI_STDERR ?? "");
65
- process.stdout.write(readFileSync(process.env.CI_STDOUT_FILE));
66
- process.exitCode = Number(process.env.CI_EXIT);
67
- `;
68
-
69
- const INSTRUMENTS_STUB = `printf 'instruments.sh %s\\n' "$*" >> "$CALL_LOG"
70
- [ -z "$INSTR_STDOUT" ] || printf '%s\\n' "$INSTR_STDOUT"
71
- exit "$INSTR_EXIT"
72
- `;
73
-
74
- const GH_STUB = `#!/bin/sh
75
- printf 'gh %s\\n' "$*" >> "$CALL_LOG"
76
- case "$1 $2" in
77
- "pr view") cat "$PR_VIEW_FILE"; exit "$PR_VIEW_EXIT" ;;
78
- *) echo "gh: unstubbed call: $*" >&2; exit 1 ;;
79
- esac
80
- `;
81
-
82
- function mktemp(t, prefix) {
83
- const d = realpathSync(mkdtempSync(join(tmpdir(), prefix)));
84
- t.after(() => rmSync(d, { recursive: true, force: true }));
85
- return d;
86
- }
87
-
88
- // One `gh` stub for the whole file, on every fixture's PATH. macOS scans a
89
- // newly created executable inode on its first direct exec (~1-2s, measured in
90
- // #2249), so a fresh stub per gate() call cost the file one scan per case. The
91
- // stub is stateless — CALL_LOG, PR_VIEW_FILE and PR_VIEW_EXIT come from each
92
- // call's env — so sharing it changes nothing a case asserts; everything else
93
- // stays per call.
94
- const BIN = realpathSync(mkdtempSync(join(tmpdir(), "merge-gate-bin-")));
95
- after(() => rmSync(BIN, { recursive: true, force: true }));
96
- writeFileSync(join(BIN, "gh"), GH_STUB, { mode: 0o755 });
97
-
98
- function git(cwd, ...args) {
99
- const r = spawnSync("git", args, { cwd, encoding: "utf8", env: cleanEnv() });
100
- assert.equal(r.status, 0, `fixture: git ${args.join(" ")} failed: ${r.stderr}`);
101
- return r.stdout;
102
- }
103
-
104
- // The runner's own ambient GIT_DIR/GIT_WORK_TREE must not reach a fixture;
105
- // the one case that wants one sets it explicitly.
106
- function cleanEnv() {
107
- const env = { ...process.env };
108
- delete env.GIT_DIR;
109
- delete env.GIT_WORK_TREE;
110
- return env;
111
- }
112
-
113
- /**
114
- * Runs a copy of the gate against stubbed readings. Every option defaults to
115
- * the mergeable baseline, so a case names only the one reading it changes.
116
- */
117
- function gate(
118
- t,
119
- {
120
- argv = ["--pr", "42", "--pre", PRE],
121
- prView = JSON.stringify(PR_VIEW),
122
- prViewExit = 0,
123
- ciOut = JSON.stringify(CI_GREEN),
124
- ciExit = 0,
125
- ciStderr = "",
126
- instrOut = DIGEST,
127
- instrExit = 0,
128
- cwd = null,
129
- env = {},
130
- realInstruments = false,
131
- instrPre = null,
132
- } = {},
133
- ) {
134
- const root = mktemp(t, "merge-gate-");
135
- const scripts = join(root, "scripts");
136
- mkdirSync(scripts);
137
- const script = join(scripts, "merge-gate.mjs");
138
- writeFileSync(script, readFileSync(SCRIPT));
139
- for (const [name, path] of SIBLING_MODULES) writeFileSync(join(scripts, name), readFileSync(path));
140
- writeFileSync(join(scripts, "ci-state.mjs"), CI_STATE_STUB);
141
- // The cross-workspace cases run the REAL instruments.sh beside the copied
142
- // gate — the two-tree contract lives in that script, and a stub can only
143
- // echo a verdict, never produce one. The stub stays the default: every
144
- // other case here holds the instruments leg at mergeable and varies one
145
- // input.
146
- writeFileSync(
147
- join(scripts, "instruments.sh"),
148
- realInstruments
149
- ? readFileSync(fileURLToPath(new URL("./instruments.sh", import.meta.url)))
150
- : INSTRUMENTS_STUB,
151
- );
152
- const log = join(root, "calls.log");
153
- writeFileSync(log, "");
154
- writeFileSync(join(root, "pr-view.json"), prView);
155
- writeFileSync(join(root, "ci.out"), ciOut);
156
-
157
- const repo = join(root, "repo");
158
- mkdirSync(repo);
159
- git(repo, "init", "-q");
160
- // A hook for the real-instruments cases: run before the gate, with the
161
- // fixture's workspace repo and scripts dir in hand — this is where a
162
- // baseline gets pinned over a tree the workspace does not carry.
163
- if (instrPre) instrPre({ repo, scripts, root });
164
-
165
- const res = spawnSync(process.execPath, [script, ...argv], {
166
- cwd: cwd ?? repo,
167
- encoding: "utf8",
168
- env: {
169
- ...cleanEnv(),
170
- PATH: `${BIN}:${process.env.PATH}`,
171
- CALL_LOG: log,
172
- PR_VIEW_FILE: join(root, "pr-view.json"),
173
- PR_VIEW_EXIT: String(prViewExit),
174
- CI_STDOUT_FILE: join(root, "ci.out"),
175
- CI_EXIT: String(ciExit),
176
- CI_STDERR: ciStderr,
177
- INSTR_STDOUT: instrOut,
178
- INSTR_EXIT: String(instrExit),
179
- ...env,
180
- },
181
- });
182
- return {
183
- code: res.status,
184
- stdout: res.stdout,
185
- stderr: res.stderr,
186
- json: res.stdout.trim() ? JSON.parse(res.stdout) : null,
187
- calls: readFileSync(log, "utf8").split("\n").filter(Boolean),
188
- root,
189
- repo,
190
- };
191
- }
192
-
193
- const CI_CALL = "ci-state.mjs --pr 42 --declare-no-ci";
194
-
195
- // Exit code, verdict, reason — and ci-state called exactly once, with
196
- // --declare-no-ci, which the AC requires on every call whatever the verdict.
197
- function assertRow(r, code, verdict, reason) {
198
- assert.equal(r.code, code, `exit ${r.code}, expected ${code}\nstdout: ${r.stdout}\nstderr: ${r.stderr}`);
199
- assert.equal(r.json.verdict, verdict);
200
- assert.equal(r.json.reason, reason);
201
- assert.deepEqual(r.calls.filter((c) => c.startsWith("ci-state.mjs")), [CI_CALL], "ci-state must run once per call, with --declare-no-ci");
202
- }
203
-
204
- // --- exit 0 ----------------------------------------------------------------
205
-
206
- test("every check holds → 0 mergeable, one JSON line with every field, three read-only calls in spec order", (t) => {
207
- const r = gate(t);
208
- assertRow(r, 0, "mergeable", null);
209
- assert.equal(r.stdout.split("\n").length, 2, "stdout must be exactly one line");
210
- assert.deepEqual(r.json, {
211
- pr: 42,
212
- verdict: "mergeable",
213
- reason: null,
214
- head: PRE,
215
- pre: PRE,
216
- post: null,
217
- behind: 0,
218
- instruments: DIGEST,
219
- ci: CI_GREEN,
220
- });
221
- // The whole call log: nothing merges, labels or rebases, and the three
222
- // reads run in the order the spec names.
223
- assert.deepEqual(r.calls, [
224
- `instruments.sh --repo ${r.repo}`,
225
- "gh pr view 42 --json labels,reviewDecision,headRefOid",
226
- CI_CALL,
227
- ]);
228
- });
229
-
230
- test("the rebased path: head and ci-state both on --post → 0", (t) => {
231
- const r = gate(t, {
232
- argv: ["--pr", "42", "--pre", PRE, "--post", POST],
233
- prView: JSON.stringify({ ...PR_VIEW, headRefOid: POST }),
234
- ciOut: ci({ prHead: POST, runHeadSha: POST }),
235
- });
236
- assertRow(r, 0, "mergeable", null);
237
- assert.equal(r.json.post, POST);
238
- assert.equal(r.json.head, POST);
239
- });
240
-
241
- test("the no-rebase path: --post equal to --pre → 0", (t) => {
242
- const r = gate(t, { argv: ["--pr", "42", "--pre", PRE, "--post", PRE] });
243
- assertRow(r, 0, "mergeable", null);
244
- });
245
-
246
- test("no-ci verdict with the label present → 0, the arm that cleared visible in ci.verdict", (t) => {
247
- const r = gate(t, {
248
- ciOut: JSON.stringify({
249
- pr: 42,
250
- branch: "fix/42",
251
- prHead: PRE,
252
- runId: null,
253
- attempt: null,
254
- runHeadSha: null,
255
- status: null,
256
- conclusion: null,
257
- behind: 0,
258
- verdict: "no-ci",
259
- reasons: ["no workflows configured under .github/workflows/ — --declare-no-ci passed, gating on the caller's verified suite run instead"],
260
- }),
261
- });
262
- assertRow(r, 0, "mergeable", null);
263
- assert.equal(r.json.ci.verdict, "no-ci");
264
- });
265
-
266
- test("ci-state's stderr noise never reaches the parse, and is passed through", (t) => {
267
- const noise = '$ gh run view 7\n{"verdict":"not-green"}\nci-state: verdict=green\n';
268
- const r = gate(t, { ciStderr: noise });
269
- assertRow(r, 0, "mergeable", null);
270
- assert.ok(r.stderr.includes(noise), "the child's diagnostics must reach the gate's stderr");
271
- });
272
-
273
- // --- exit 1: blocked ---------------------------------------------------------
274
-
275
- test("ready-to-merge absent → 1 label-pulled", (t) => {
276
- const r = gate(t, { prView: JSON.stringify({ ...PR_VIEW, labels: [{ name: "patch" }] }) });
277
- assertRow(r, 1, "blocked", "label-pulled");
278
- });
279
-
280
- test("reviewDecision CHANGES_REQUESTED → 1 changes-requested", (t) => {
281
- const r = gate(t, { prView: JSON.stringify({ ...PR_VIEW, reviewDecision: "CHANGES_REQUESTED" }) });
282
- assertRow(r, 1, "blocked", "changes-requested");
283
- });
284
-
285
- // The two gh-read cases hold ci-state's own head read on --pre, so the gh
286
- // read's check is the only one that can block them; the ci-state read's check
287
- // has its own case below.
288
- test("headRefOid outside {pre, post} → 1 head-moved-after-label", (t) => {
289
- const r = gate(t, {
290
- argv: ["--pr", "42", "--pre", PRE, "--post", POST],
291
- prView: JSON.stringify({ ...PR_VIEW, headRefOid: THIRD }),
292
- });
293
- assertRow(r, 1, "blocked", "head-moved-after-label");
294
- assert.equal(r.json.head, THIRD);
295
- });
296
-
297
- test("--post omitted: a head that moved off --pre is not excused by any other SHA → 1 head-moved-after-label", (t) => {
298
- const r = gate(t, { prView: JSON.stringify({ ...PR_VIEW, headRefOid: POST }) });
299
- assertRow(r, 1, "blocked", "head-moved-after-label");
300
- });
301
-
302
- test("ci-state's own head read outside {pre, post} → 1 head-moved-after-label, even with gh's read on --pre", (t) => {
303
- // A push between the gate's gh pr view and ci-state's own head read: its
304
- // CI would be judged while the label's audit belongs to the tree before it.
305
- const r = gate(t, { ciOut: ci({ prHead: THIRD, runHeadSha: THIRD }) });
306
- assertRow(r, 1, "blocked", "head-moved-after-label");
307
- });
308
-
309
- test("ci-state exit 1 (in progress, no conclusion) → 1 ci:<first reason>, runId and status carried for the wait", (t) => {
310
- const reasons = ["run status is in_progress, not completed", "job check is in_progress, not success"];
311
- const r = gate(t, {
312
- ciOut: ci({ status: "in_progress", conclusion: null, verdict: "not-green", reasons }),
313
- ciExit: 1,
314
- });
315
- assertRow(r, 1, "blocked", `ci:${reasons[0]}`);
316
- assert.equal(r.json.ci.status, "in_progress");
317
- assert.equal(r.json.ci.runId, 7);
318
- });
319
-
320
- test("green with behind 3 → 1 behind:3", (t) => {
321
- const r = gate(t, { ciOut: ci({ behind: 3 }) });
322
- assertRow(r, 1, "blocked", "behind:3");
323
- assert.equal(r.json.behind, 3);
324
- });
325
-
326
- // --- exit 2: could not evaluate -----------------------------------------------
327
-
328
- test("ci-state rate-limited payload → 2 rate-limited", (t) => {
329
- const r = gate(t, {
330
- ciOut: JSON.stringify({ pr: 42, verdict: "rate-limited", reasons: ["gh run list was refused by the GitHub API rate limit — no CI state was read."] }),
331
- ciExit: 2,
332
- });
333
- assertRow(r, 2, "unknown", "rate-limited");
334
- assert.equal(r.json.ci.verdict, "rate-limited");
335
- assert.equal(r.json.behind, null);
336
- });
337
-
338
- test("ci-state {} payload → 2 ci-unreadable", (t) => {
339
- const r = gate(t, { ciOut: "{}\n", ciExit: 2 });
340
- assertRow(r, 2, "unknown", "ci-unreadable");
341
- });
342
-
343
- test("ci-state zero-byte payload → 2 ci-unreadable", (t) => {
344
- const r = gate(t, { ciOut: "", ciExit: 2 });
345
- assertRow(r, 2, "unknown", "ci-unreadable");
346
- assert.equal(r.json.ci, null);
347
- });
348
-
349
- test("ci-state unparseable payload → 2 ci-unreadable", (t) => {
350
- const r = gate(t, { ciOut: '{"pr":42,"verdict":"gre', ciExit: 2 });
351
- assertRow(r, 2, "unknown", "ci-unreadable");
352
- assert.equal(r.json.ci, null);
353
- });
354
-
355
- test("an exit code its payload does not back → 2 ci-unreadable, never a verdict", (t) => {
356
- // Exit 0 with nothing to gate on is the vacuous pass; exit 1 with no
357
- // payload is Node's own crash code, not ci-state's not-green; and a code
358
- // contradicting the verdict it printed has answered nothing.
359
- const shapes = [
360
- ["exit 0, {}", "{}\n", 0],
361
- ["exit 0, zero bytes", "", 0],
362
- ["exit 1, zero bytes (a crashed ci-state)", "", 1],
363
- ["exit 0, not-green verdict", ci({ verdict: "not-green", reasons: ["run status is queued, not completed"] }), 0],
364
- ["exit 1, green verdict", ci({}), 1],
365
- ["exit 0, green verdict with no behind field", JSON.stringify({ ...CI_GREEN, behind: undefined }), 0],
366
- ["exit 0, green verdict with no prHead", JSON.stringify({ ...CI_GREEN, prHead: undefined }), 0],
367
- ];
368
- for (const [what, ciOut, ciExit] of shapes) {
369
- const r = gate(t, { ciOut, ciExit });
370
- assert.equal(r.code, 2, `${what}: exit ${r.code}\n${r.stdout}`);
371
- assert.equal(r.json.reason, "ci-unreadable", what);
372
- }
373
- });
374
-
375
- test("green with behind null → 2 behind-unknown", (t) => {
376
- const r = gate(t, { ciOut: ci({ behind: null }) });
377
- assertRow(r, 2, "unknown", "behind-unknown");
378
- });
379
-
380
- // An unusable payload that ALSO happens to carry a `behind: null` field must
381
- // still read as ci-unreadable, not behind-unknown: readCi()'s `validated` is
382
- // null whenever `usable` is false, so decide() cannot fall through to a
383
- // `behind` read on an unvalidated shape no matter which check runs first.
384
- test("an unusable payload that also carries behind:null → 2 ci-unreadable, never behind-unknown", (t) => {
385
- const r = gate(t, { ciOut: ci({ verdict: "not-green", reasons: ["queued"], behind: null }), ciExit: 0 });
386
- assertRow(r, 2, "unknown", "ci-unreadable");
387
- });
388
-
389
- test("instruments.sh exit 1 → 2 instrument-set-changed, the digest it printed carried", (t) => {
390
- const changed = "e".repeat(64);
391
- const r = gate(t, { instrOut: changed, instrExit: 1 });
392
- assertRow(r, 2, "unknown", "instrument-set-changed");
393
- assert.equal(r.json.instruments, changed);
394
- });
395
-
396
- test("instruments.sh exit 2 → 2 instruments-unanswerable", (t) => {
397
- const r = gate(t, { instrOut: "", instrExit: 2 });
398
- assertRow(r, 2, "unknown", "instruments-unanswerable");
399
- assert.equal(r.json.instruments, null);
400
- });
401
-
402
- test("instruments.sh exit 0 that printed no digest → 2 instruments-unanswerable", (t) => {
403
- const r = gate(t, { instrOut: "", instrExit: 0 });
404
- assertRow(r, 2, "unknown", "instruments-unanswerable");
405
- });
406
-
407
- test("no git checkout to name the instrument set from → 2 instruments-unanswerable, instruments.sh never run", (t) => {
408
- const outside = mktemp(t, "merge-gate-nogit-");
409
- const r = gate(t, { cwd: outside, env: { GIT_CEILING_DIRECTORIES: outside } });
410
- assertRow(r, 2, "unknown", "instruments-unanswerable");
411
- assert.equal(r.calls.filter((c) => c.startsWith("instruments.sh")).length, 0);
412
- });
413
-
414
- test("gh pr view exits non-zero → 2 pr-unreadable", (t) => {
415
- const r = gate(t, { prView: "", prViewExit: 1 });
416
- assertRow(r, 2, "unknown", "pr-unreadable");
417
- assert.equal(r.json.head, null);
418
- });
419
-
420
- test("gh pr view misparses → 2 pr-unreadable", (t) => {
421
- const shapes = [
422
- ["non-JSON body at exit 0", "<html>502 Bad Gateway</html>"],
423
- ["labels missing", JSON.stringify({ reviewDecision: "APPROVED", headRefOid: PRE })],
424
- ["headRefOid empty", JSON.stringify({ ...PR_VIEW, headRefOid: "" })],
425
- ["reviewDecision missing", JSON.stringify({ labels: PR_VIEW.labels, headRefOid: PRE })],
426
- ];
427
- for (const [what, prView] of shapes) {
428
- const r = gate(t, { prView });
429
- assert.equal(r.code, 2, `${what}: exit ${r.code}\n${r.stdout}`);
430
- assert.equal(r.json.reason, "pr-unreadable", what);
431
- }
432
- });
433
-
434
- test("only CHANGES_REQUESTED blocks: reviewDecision \"\" (no review required), null and REVIEW_REQUIRED → 0", (t) => {
435
- for (const reviewDecision of ["", null, "REVIEW_REQUIRED"]) {
436
- const r = gate(t, { prView: JSON.stringify({ ...PR_VIEW, reviewDecision }) });
437
- assert.equal(r.code, 0, `${JSON.stringify(reviewDecision)}: ${r.stdout}`);
438
- }
439
- });
440
-
441
- // --- precedence ----------------------------------------------------------------
442
-
443
- test("the first failing row is the reason, and the JSON still carries every reading", (t) => {
444
- const notGreen = ci({ status: "in_progress", verdict: "not-green", reasons: ["run status is in_progress, not completed"] });
445
- const r = gate(t, {
446
- prView: JSON.stringify({ ...PR_VIEW, labels: [] }),
447
- ciOut: notGreen,
448
- ciExit: 1,
449
- instrOut: "e".repeat(64),
450
- instrExit: 1,
451
- });
452
- assertRow(r, 1, "blocked", "label-pulled");
453
- assert.equal(r.json.instruments, "e".repeat(64));
454
- assert.deepEqual(r.json.ci, JSON.parse(notGreen));
455
- assert.equal(r.json.head, PRE);
456
- });
457
-
458
- // --- --repo: the main checkout, whatever the cwd or the environment says ------
459
-
460
- test("from a linked worktree, instruments.sh audits the main checkout (--git-common-dir), not the worktree", (t) => {
461
- // The run's baseline lives in the main checkout's .fleet/, which a
462
- // worktree does not carry: --show-toplevel there would exit 2 forever.
463
- const probe = gate(t);
464
- const main = probe.repo;
465
- git(main, "-c", "user.email=t@example.com", "-c", "user.name=t", "commit", "-q", "--allow-empty", "-m", "init");
466
- const wt = join(probe.root, "wt");
467
- git(main, "worktree", "add", "-q", wt);
468
- const r = gate(t, { cwd: wt });
469
- assertRow(r, 0, "mergeable", null);
470
- assert.deepEqual(r.calls.filter((c) => c.startsWith("instruments.sh")), [`instruments.sh --repo ${main}`]);
471
- });
472
-
473
- test("an ambient GIT_DIR cannot move the audited instrument set into another repository", (t) => {
474
- const other = mktemp(t, "merge-gate-other-");
475
- git(other, "init", "-q");
476
- const r = gate(t, { env: { GIT_DIR: join(other, ".git") } });
477
- assertRow(r, 0, "mergeable", null);
478
- assert.deepEqual(r.calls.filter((c) => c.startsWith("instruments.sh")), [`instruments.sh --repo ${r.repo}`]);
479
- });
480
-
481
- // --- interface ------------------------------------------------------------------
482
-
483
- test("--declare-no-ci is not on the gate's surface: refused by name, nothing run", (t) => {
484
- const r = gate(t, { argv: ["--pr", "42", "--pre", PRE, "--declare-no-ci"] });
485
- assert.equal(r.code, 2);
486
- assert.match(r.stderr, /unknown flag --declare-no-ci/);
487
- assert.equal(r.stdout, "");
488
- assert.deepEqual(r.calls, []);
489
- });
490
-
491
- test("usage: --pr and --pre are both required, refused before any read", (t) => {
492
- for (const argv of [["--pre", PRE], ["--pr", "42"], []]) {
493
- const r = gate(t, { argv });
494
- assert.equal(r.code, 2, argv.join(" "));
495
- assert.match(r.stderr, /usage: merge-gate\.mjs --pr <n> --pre <sha>/);
496
- assert.deepEqual(r.calls, []);
497
- }
498
- });
499
-
500
- test("usage: an abbreviated SHA is refused, a full uppercase one is accepted", (t) => {
501
- // Abbreviated can never equal gh's full headRefOid, so accepting it would
502
- // skip every PR as head-moved-after-label.
503
- for (const argv of [["--pr", "42", "--pre", PRE.slice(0, 7)], ["--pr", "42", "--pre", PRE, "--post", "HEAD"]]) {
504
- const r = gate(t, { argv });
505
- assert.equal(r.code, 2, argv.join(" "));
506
- assert.match(r.stderr, /needs a full 40-character commit SHA/);
507
- assert.deepEqual(r.calls, []);
508
- }
509
- const upper = gate(t, { argv: ["--pr", "42", "--pre", PRE.toUpperCase()] });
510
- assertRow(upper, 0, "mergeable", null);
511
- assert.equal(upper.json.pre, PRE);
512
- });
513
-
514
- test("--out writes the same line, creating missing directories, whatever the verdict", (t) => {
515
- for (const [label, code] of [["ready-to-merge", 0], ["patch", 1]]) {
516
- const dir = mktemp(t, "merge-gate-out-");
517
- const out = join(dir, "pr42", "merge-bot-3", "ci.json");
518
- const r = gate(t, {
519
- argv: ["--pr", "42", "--pre", PRE, "--out", out],
520
- prView: JSON.stringify({ ...PR_VIEW, labels: [{ name: label }] }),
521
- });
522
- assert.equal(r.code, code, r.stderr);
523
- assert.equal(readFileSync(out, "utf8"), r.stdout);
524
- }
525
- });
526
-
527
- test("--out that cannot be written → 2, and no verdict on stdout the file does not carry", (t) => {
528
- const dir = mktemp(t, "merge-gate-out-");
529
- writeFileSync(join(dir, "file"), "");
530
- const r = gate(t, { argv: ["--pr", "42", "--pre", PRE, "--out", join(dir, "file", "ci.json")] });
531
- assert.equal(r.code, 2);
532
- assert.equal(r.stdout, "");
533
- assert.match(r.stderr, /cannot write --out/);
534
- });
535
-
536
- // --- #2284: the instruments root and the gh root are different checkouts ----
537
- //
538
- // The live incident: a fleet running in a consumer repo that does not track
539
- // `plugin/…`. Every leg but instruments was green; instruments.sh hashed the
540
- // workspace tree, found no tracked instrument, refused on the empty set, and
541
- // the gate exited 2 `instruments-unanswerable` forever — labelled PRs that
542
- // could never merge. The fix records the audited root inside the baseline at
543
- // pin time, so the SAME `--repo <workspace>` call the gate already makes
544
- // reads one tree's home and another tree's bytes. These cases run the REAL
545
- // instruments.sh beside the copied gate: the contract being proven is the two
546
- // scripts' handoff across that seam, and a stubbed child proves only the row
547
- // table — it can echo an exit code, never derive one from two trees.
548
-
549
- // A checkout that carries the instrument set — the plugin's own repo, or an
550
- // install's cache — separate from every gate fixture's workspace repo.
551
- function pluginTree(t) {
552
- const dir = mktemp(t, "merge-gate-plugin-");
553
- git(dir, "init", "-q", "-b", "main");
554
- mkdirSync(join(dir, "plugin", "scripts"), { recursive: true });
555
- writeFileSync(join(dir, "plugin", "scripts", "probe.sh"), "echo probe\n");
556
- git(dir, "-c", "user.email=t@example.com", "-c", "user.name=t", "add", "-A");
557
- git(dir, "-c", "user.email=t@example.com", "-c", "user.name=t", "commit", "-qm", "fixture");
558
- return dir;
559
- }
560
-
561
- // The phase-0 pin a controller runs from the plugin-less workspace: the
562
- // baseline lands in the WORKSPACE's .fleet/, the digest covers the PLUGIN's
563
- // tree, and the second line records which tree that was.
564
- function pinAcrossSeam({ repo, scripts }, plugin) {
565
- const r = spawnSync("sh", [join(scripts, "instruments.sh"), "--pin", "--audit", plugin], {
566
- cwd: repo,
567
- encoding: "utf8",
568
- env: cleanEnv(),
569
- });
570
- assert.equal(r.status, 0, `fixture pin failed: ${r.stderr}`);
571
- return r.stdout.trim();
572
- }
573
-
574
- test("a plugin-less workspace reaches a verdict: the gate audits the root the baseline records, gh legs on the workspace", (t) => {
575
- const plugin = pluginTree(t);
576
- let digest = null;
577
- const r = gate(t, {
578
- realInstruments: true,
579
- instrPre: (ws) => {
580
- digest = pinAcrossSeam(ws, plugin);
581
- },
582
- });
583
- assertRow(r, 0, "mergeable", null);
584
- assert.equal(
585
- r.json.instruments,
586
- digest,
587
- "the JSON carries the digest of the plugin tree — the workspace has no instruments to digest",
588
- );
589
- });
590
-
591
- test("tampering the recorded plugin tree still closes the gate across the seam: 2 instrument-set-changed", (t) => {
592
- const plugin = pluginTree(t);
593
- const r = gate(t, {
594
- realInstruments: true,
595
- instrPre: (ws) => {
596
- pinAcrossSeam(ws, plugin);
597
- writeFileSync(join(plugin, "plugin", "scripts", "probe.sh"), "echo TAMPERED\n");
598
- },
599
- });
600
- assertRow(r, 2, "unknown", "instrument-set-changed");
601
- });
602
-
603
- test("a plugin-less workspace with NO pin of any kind keeps its exit 2 — the refusal that says WHICH flag to pass", (t) => {
604
- // The incident shape stays a refusal, never a silent pass: with no
605
- // baseline there is no recorded root, the instruments leg answers nothing,
606
- // and the gate lands on instruments-unanswerable. What changed is WHERE a
607
- // run discovers this: the SKILL's phase-0 pin refuses once and names the
608
- // empty tree, instead of dispatching finishers and merge bots into this
609
- // leg forever.
610
- const r = gate(t, { realInstruments: true });
611
- assertRow(r, 2, "unknown", "instruments-unanswerable");
612
- assert.equal(r.json.instruments, null);
613
- });