@feigi/fleet-ctl 0.0.0 → 3.16.3

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 (153) hide show
  1. package/agents/{fleet-implementer.agent.md → fleet-implementer-slow-high.agent.md} +23 -2
  2. package/agents/fleet-implementer-slow-medium.agent.md +231 -0
  3. package/agents/fleet-implementer-smol-high.agent.md +231 -0
  4. package/agents/{fleet-implementer-alt.agent.md → fleet-implementer-task-high.agent.md} +23 -2
  5. package/agents/fleet-implementer-task-max.agent.md +231 -0
  6. package/agents/fleet-review-comments.agent.md +4 -2
  7. package/agents/fleet-review-correctness.agent.md +2 -1
  8. package/agents/fleet-review-runner.agent.md +14 -10
  9. package/agents/fleet-review-silent-failure.agent.md +4 -3
  10. package/agents/fleet-review-simplify.agent.md +2 -1
  11. package/agents/fleet-review-snapshot.agent.md +2 -1
  12. package/agents/fleet-review-test-run.agent.md +29 -0
  13. package/agents/fleet-review-tests.agent.md +10 -5
  14. package/agents/fleet-review-types.agent.md +4 -2
  15. package/agents/fleet-review-verifier.agent.md +4 -3
  16. package/commands/review-and-fix.md +7 -6
  17. package/commands/run-merge-bot.md +14 -4
  18. package/package.json +4 -2
  19. package/scripts/agent-test.test.mjs +36 -32
  20. package/scripts/ambient-git-vars-mjs-prose.test.mjs +23 -13
  21. package/scripts/apply-ruleset.test.mjs +4 -3
  22. package/scripts/arg-header-probes-prose.test.mjs +1 -0
  23. package/scripts/arg.test.mjs +18 -18
  24. package/scripts/board-cli.test.mjs +18 -21
  25. package/scripts/board-identity.test.mjs +9 -9
  26. package/scripts/board-liveness-banner.test.mjs +6 -6
  27. package/scripts/board-prev-shape.test.mjs +12 -13
  28. package/scripts/board-tryparse-null.test.mjs +7 -7
  29. package/scripts/board.mjs +4 -7
  30. package/scripts/board.test.mjs +57 -61
  31. package/scripts/candidates.test.mjs +228 -17
  32. package/scripts/ci-completes-premise-prose.test.mjs +1 -1
  33. package/scripts/ci-state-prose.test.mjs +2 -2
  34. package/scripts/ci-state.mjs +389 -187
  35. package/scripts/ci-state.test.mjs +458 -165
  36. package/scripts/citation-sweep-prose.test.mjs +59 -1
  37. package/scripts/claim-lifecycle.test.mjs +2 -1
  38. package/scripts/claim-ticket.test.mjs +35 -34
  39. package/scripts/closing-keyword-prose.test.mjs +1 -1
  40. package/scripts/cockpit-tick-nonblocking.test.mjs +8 -8
  41. package/scripts/compute-board.mjs +13 -3
  42. package/scripts/compute-board.test.mjs +64 -1
  43. package/scripts/compute-spend.mjs +46 -8
  44. package/scripts/compute-spend.test.mjs +64 -10
  45. package/scripts/cross-repo-citation-prose.test.mjs +18 -19
  46. package/scripts/delete-merged-branch.sh +218 -0
  47. package/scripts/delete-merged-branch.test.mjs +576 -0
  48. package/scripts/derive-testcmd.sh +18 -7
  49. package/scripts/derive-testcmd.test.mjs +9 -8
  50. package/scripts/diff-stats.mjs +2 -2
  51. package/scripts/diff-stats.test.mjs +7 -11
  52. package/scripts/dispatch-block-golden-prose.test.mjs +111 -6
  53. package/scripts/dispatch-block-pins-prose.test.mjs +5 -5
  54. package/scripts/dispositions-check.mjs +507 -0
  55. package/scripts/dispositions-check.test.mjs +843 -0
  56. package/scripts/dispositions-gate-prose.test.mjs +114 -0
  57. package/scripts/drop-merged-label.test.mjs +3 -4
  58. package/scripts/exec-stub.mjs +93 -0
  59. package/scripts/exec-stub.test.mjs +69 -0
  60. package/scripts/filing-bar-seat-prose.test.mjs +1 -1
  61. package/scripts/finisher-test-verdict-prose.test.mjs +102 -0
  62. package/scripts/fix-applier-correction-rules-prose.test.mjs +11 -10
  63. package/scripts/fleet-bootstrap +5 -20
  64. package/scripts/fleet-bootstrap.test.mjs +75 -0
  65. package/scripts/fleet-heartbeat.mjs +2 -2
  66. package/scripts/fleet-provenance +15 -24
  67. package/scripts/fleet-provenance.test.mjs +86 -12
  68. package/scripts/fleet-run.test.mjs +5 -5
  69. package/scripts/fleet-state.mjs +33 -11
  70. package/scripts/fleet-state.test.mjs +90 -3
  71. package/scripts/fleet-tick.mjs +346 -70
  72. package/scripts/fleet-tick.test.mjs +566 -16
  73. package/scripts/force-with-lease-reason-prose.test.mjs +1 -1
  74. package/scripts/frontmatter-check.mjs +3 -2
  75. package/scripts/frontmatter-check.test.mjs +6 -6
  76. package/scripts/immutable-body-claim-prose.test.mjs +53 -262
  77. package/scripts/implementer-model-tier.test.mjs +98 -506
  78. package/scripts/inflight.test.mjs +18 -127
  79. package/scripts/is-cli.mjs +26 -0
  80. package/scripts/is-cli.test.mjs +99 -0
  81. package/scripts/json.test.mjs +3 -3
  82. package/scripts/ledger-dispatch.test.mjs +368 -7
  83. package/scripts/ledger-grammar.mjs +85 -1
  84. package/scripts/ledger-grammar.test.mjs +86 -1
  85. package/scripts/ledger-read-require-file.test.mjs +7 -7
  86. package/scripts/ledger-rotate.test.mjs +142 -0
  87. package/scripts/ledger.mjs +181 -17
  88. package/scripts/ledger.test.mjs +12 -130
  89. package/scripts/main-checkout.mjs +312 -0
  90. package/scripts/main-checkout.test.mjs +332 -0
  91. package/scripts/member-outcomes-header.test.mjs +3 -3
  92. package/scripts/member-outcomes.mjs +4 -5
  93. package/scripts/member-outcomes.test.mjs +92 -18
  94. package/scripts/member-prompt-prose.test.mjs +17 -13
  95. package/scripts/member-record.mjs +8 -3
  96. package/scripts/member-record.test.mjs +5 -5
  97. package/scripts/member-write-guard.mjs +5 -5
  98. package/scripts/member-write-guard.test.mjs +6 -3
  99. package/scripts/no-undo-audit.sh +24 -21
  100. package/scripts/no-undo-audit.test.mjs +9 -13
  101. package/scripts/pointer-target-prose.test.mjs +1 -1
  102. package/scripts/pr-overlap.test.mjs +6 -9
  103. package/scripts/prompt-renderer.mjs +10 -9
  104. package/scripts/prose-pin.mjs +10 -11
  105. package/scripts/prove-merge.test.mjs +3 -3
  106. package/scripts/quiet-payload-prose.test.mjs +1 -1
  107. package/scripts/reap.test.mjs +3 -4
  108. package/scripts/release-label-split-prose.test.mjs +17 -2
  109. package/scripts/release-ticket.test.mjs +35 -44
  110. package/scripts/review-core-cwd-isolation.test.mjs +7 -6
  111. package/scripts/review-core-reads.test.mjs +1 -1
  112. package/scripts/review-core-scratch-refusal.test.mjs +64 -0
  113. package/scripts/review-core-shared-test-run.test.mjs +238 -0
  114. package/scripts/review-core-snapshot-path.test.mjs +59 -12
  115. package/scripts/review-core-specialist-scratch.test.mjs +12 -10
  116. package/scripts/review-core-testcmd.test.mjs +76 -45
  117. package/scripts/review-core-unrun.test.mjs +154 -168
  118. package/scripts/review-core.mjs +250 -56
  119. package/scripts/review-eval.mjs +11 -4
  120. package/scripts/review-host-fixture.mjs +12 -3
  121. package/scripts/review-in-run-retry.test.mjs +27 -3
  122. package/scripts/review-runner-spawns.test.mjs +5 -3
  123. package/scripts/review-runner.test.mjs +14 -3
  124. package/scripts/review-tier-audit.test.mjs +1 -1
  125. package/scripts/run-merge-bot-prose.test.mjs +29 -6
  126. package/scripts/scratch-partition-invariant-prose.test.mjs +1 -1
  127. package/scripts/section-between-guard-prose.test.mjs +4 -3
  128. package/scripts/select-dimensions.test.mjs +1 -1
  129. package/scripts/shell-traps-prose.test.mjs +6 -9
  130. package/scripts/shortlist.mjs +4 -1
  131. package/scripts/shortlist.test.mjs +30 -16
  132. package/scripts/snapshot-repo.test.mjs +177 -4
  133. package/scripts/stash-prohibition-prose.test.mjs +1 -1
  134. package/scripts/temp-dir.mjs +47 -0
  135. package/scripts/tier-check.mjs +95 -28
  136. package/scripts/tier-check.test.mjs +131 -29
  137. package/scripts/tier-outcomes-header.test.mjs +11 -54
  138. package/scripts/tier-outcomes.mjs +34 -12
  139. package/scripts/tier-outcomes.test.mjs +157 -4
  140. package/scripts/tier-roles.mjs +118 -29
  141. package/scripts/tier-roles.test.mjs +226 -61
  142. package/scripts/tracker-block-copy-prose.test.mjs +3 -3
  143. package/scripts/verify-sha.test.mjs +4 -5
  144. package/scripts/watcher-degraded-block.test.mjs +5 -8
  145. package/scripts/within-run-pair-prose.test.mjs +43 -75
  146. package/scripts/worktree-audit.test.mjs +2 -1
  147. package/skills/next-ticket/SKILL.md +2 -2
  148. package/skills/run-team/SKILL.md +433 -303
  149. package/skills/run-team/references/ci-and-staleness.md +7 -6
  150. package/skills/run-team/references/correction-tickets.md +3 -3
  151. package/skills/run-team/references/isolation.md +1 -1
  152. package/skills/sizing-a-ticket/SKILL.md +8 -8
  153. package/scripts/tier-guard-gate-prose.test.mjs +0 -216
@@ -23,11 +23,10 @@ import { mkdtempSync, mkdirSync, writeFileSync, chmodSync, appendFileSync, readF
23
23
  import { tmpdir } from "node:os";
24
24
  import { join, dirname } from "node:path";
25
25
  import { createServer } from "node:net";
26
- import { stripComments } from "./strip-comments.mjs";
27
26
  import { slowTransport, SSH_URL } from "./slow-transport.mjs";
27
+ import { writeExecStub } from "./exec-stub.mjs";
28
28
 
29
29
  const SCRIPT = join(import.meta.dirname, "inflight.sh");
30
- const THIS_FILE = import.meta.filename;
31
30
 
32
31
  // The stub shells out to jq. Without it every `gh issue view` would fail and
33
32
  // the suite would report exit 2 everywhere — which reads as a real red but
@@ -101,8 +100,7 @@ const REAL_HEAD = execFileSync("/bin/sh", ["-c", "command -v head"], { encoding:
101
100
  * not the shim itself.
102
101
  */
103
102
  function gitShim(bin, body) {
104
- writeFileSync(join(bin, "git"), `#!/bin/sh\n${body}\nexec '${REAL_GIT}' "$@"\n`);
105
- chmodSync(join(bin, "git"), 0o755);
103
+ writeExecStub(join(bin, "git"), `#!/bin/sh\n${body}\nexec '${REAL_GIT}' "$@"\n`);
106
104
  }
107
105
 
108
106
  // Every chmod-denial fixture below rests on the mode being ENFORCED, and root
@@ -159,8 +157,7 @@ function fixture(t, n, { linked = [], prs = [], issueErr = null, prErr = null, o
159
157
 
160
158
  const bin = join(root, "bin");
161
159
  mkdirSync(bin);
162
- writeFileSync(join(bin, "gh"), GH_STUB);
163
- chmodSync(join(bin, "gh"), 0o755);
160
+ writeExecStub(join(bin, "gh"), GH_STUB);
164
161
 
165
162
  // A filter that could not run at all. Written only when a case asks for it,
166
163
  // so every other case forks the real awk directly.
@@ -178,11 +175,10 @@ function fixture(t, n, { linked = [], prs = [], issueErr = null, prErr = null, o
178
175
  // `exit`, so they return 0 whether or not anything matched, which is what
179
176
  // makes any non-zero status readable as a failure.
180
177
  if (awkFailWhenProgramHas !== null) {
181
- writeFileSync(join(bin, "awk"), `#!/bin/sh
178
+ writeExecStub(join(bin, "awk"), `#!/bin/sh
182
179
  case "$*" in *'${awkFailWhenProgramHas}'*) exit 1 ;; esac
183
180
  exec '${REAL_AWK}' "$@"
184
181
  `);
185
- chmodSync(join(bin, "awk"), 0o755);
186
182
  }
187
183
 
188
184
  // The same shim shape for `tr`. `-d` addresses jrewritten and nothing else:
@@ -205,11 +201,10 @@ exec '${REAL_AWK}' "$@"
205
201
  // it into json.sh behind its own capture and `|| return 1`, and json.test.mjs
206
202
  // pins it there.)
207
203
  if (trFailWhenArgsHave !== null) {
208
- writeFileSync(join(bin, "tr"), `#!/bin/sh
204
+ writeExecStub(join(bin, "tr"), `#!/bin/sh
209
205
  case "$*" in *'${trFailWhenArgsHave}'*) exit 1 ;; esac
210
206
  exec '${REAL_TR}' "$@"
211
207
  `);
212
- chmodSync(join(bin, "tr"), 0o755);
213
208
  }
214
209
 
215
210
  // The same shim shape for `python3`, selected by program text. Probe 1 forks
@@ -222,11 +217,10 @@ exec '${REAL_TR}' "$@"
222
217
  // Exits 1 for the reason the awk shim does: it stands in for a fork that
223
218
  // could not happen, not for a program that ran and disagreed.
224
219
  if (python3FailWhenProgramHas !== null) {
225
- writeFileSync(join(bin, "python3"), `#!/bin/sh
220
+ writeExecStub(join(bin, "python3"), `#!/bin/sh
226
221
  case "$*" in *'${python3FailWhenProgramHas}'*) exit 1 ;; esac
227
222
  exec '${REAL_PYTHON3}' "$@"
228
223
  `);
229
- chmodSync(join(bin, "python3"), 0o755);
230
224
  }
231
225
 
232
226
  const repo = join(root, "repo");
@@ -1851,8 +1845,7 @@ test("probe 3: a refs-subdirectory walk whose `head` cannot run is unknown, neve
1851
1845
  //
1852
1846
  // Selected by the first argument for the reason the git shims are, and
1853
1847
  // `head -1` is the only `head` the script runs.
1854
- writeFileSync(join(bin, "head"), `#!/bin/sh\ncase "$1" in -1) exit 1 ;; esac\nexec '${REAL_HEAD}' "$@"\n`);
1855
- chmodSync(join(bin, "head"), 0o755);
1848
+ writeExecStub(join(bin, "head"), `#!/bin/sh\ncase "$1" in -1) exit 1 ;; esac\nexec '${REAL_HEAD}' "$@"\n`);
1856
1849
 
1857
1850
  // Measured with the guard deleted: exit 0, `taken:false`, `unknown:[]`, "no
1858
1851
  // local branch or worktree for #77". `$bad` takes the empty string the walk
@@ -1886,8 +1879,7 @@ test("probe 3: a refs-subdirectory find that cannot run at all is unknown, never
1886
1879
  // whether `find` printed a permission-denied hit or never ran at all, so a
1887
1880
  // crashed `find` and a clean tree left the same empty `$bad` and were
1888
1881
  // indistinguishable at the guard below.
1889
- writeFileSync(join(bin, "find"), "#!/bin/sh\nexit 127\n");
1890
- chmodSync(join(bin, "find"), 0o755);
1882
+ writeExecStub(join(bin, "find"), "#!/bin/sh\nexit 127\n");
1891
1883
 
1892
1884
  // Measured before the fix: exit 0, `taken:false`, `unknown:[]`, "no local
1893
1885
  // branch or worktree for #77" — a `find` that never ran reported a definite
@@ -2047,8 +2039,7 @@ test("probe 2: a transport that connects and then never answers still terminates
2047
2039
  const sshStub = (dir, name = "user-ssh-stub.sh") => {
2048
2040
  const log = join(dir, `${name}.log`);
2049
2041
  const stub = join(dir, name);
2050
- writeFileSync(stub, `#!/bin/sh\nprintf '%s\\n' "$*" >> '${log}'\nexit 1\n`);
2051
- chmodSync(stub, 0o755);
2042
+ writeExecStub(stub, `#!/bin/sh\nprintf '%s\\n' "$*" >> '${log}'\nexit 1\n`);
2052
2043
  return { stub, log };
2053
2044
  };
2054
2045
 
@@ -2476,8 +2467,7 @@ test("mktemp failing leaves probe 2 to answer, rather than abandoning the run",
2476
2467
  const { repo, env, bin } = fixture(t, 8, {
2477
2468
  remoteBranches: ["fix/8-thing"], detachedWorktreeUnder: "nospace",
2478
2469
  });
2479
- writeFileSync(join(bin, "mktemp"), "#!/bin/sh\nexit 1\n");
2480
- chmodSync(join(bin, "mktemp"), 0o755);
2470
+ writeExecStub(join(bin, "mktemp"), "#!/bin/sh\nexit 1\n");
2481
2471
  const r = spawnSync("sh", [SCRIPT, "8"], { cwd: repo, env, encoding: "utf8" });
2482
2472
  assert.equal(r.status, 1, "the probe that could still look found the ticket taken");
2483
2473
  const json = JSON.parse(r.stdout);
@@ -2504,14 +2494,13 @@ test("cleanup that cannot remove the capture file never rewrites the verdict", (
2504
2494
  // unremovable, which is what `rm -f` fails on (a read-only mount, perms
2505
2495
  // changed under the run). Writing the capture is unaffected: `2>` needs
2506
2496
  // permission on the file, not on the directory.
2507
- writeFileSync(join(bin, "mktemp"), `#!/bin/sh
2497
+ writeExecStub(join(bin, "mktemp"), `#!/bin/sh
2508
2498
  mkdir -p '${cap}' && chmod 755 '${cap}'
2509
2499
  f='${cap}'/cap.$$
2510
2500
  (umask 077; : > "$f") || exit 1
2511
2501
  chmod 555 '${cap}'
2512
2502
  printf '%s\\n' "$f"
2513
2503
  `);
2514
- chmodSync(join(bin, "mktemp"), 0o755);
2515
2504
  const r = spawnSync("sh", [SCRIPT, "8"], { cwd: repo, env, encoding: "utf8" });
2516
2505
  // Restored before the first assert, or a failure here leaves a fixture the
2517
2506
  // suite's own cleanup cannot remove.
@@ -2768,56 +2757,15 @@ test("probe 2: a credential helper that never answers is bounded like any other
2768
2757
  // separates this case from the vacuous one its comment above describes. See
2769
2758
  // the assertion at the bottom for why that is not decoration here.
2770
2759
  const helperRan = join(repo, "helper-ran");
2771
- // The `--fleet-warm` arm sits above the marker for the reason ledger.test.mjs
2772
- // records at its own GH_STUB: warming without it would let the warm-up write
2773
- // the marker itself, and the assertion below — the only thing standing
2774
- // between this case and the vacuity it already regressed into once — would
2775
- // read as satisfied on a helper that never ran. git passes a credential
2776
- // helper its operation and nothing else (measured, git 2.50.1: argv is
2777
- // exactly `get`), so no real invocation can take the arm.
2778
- writeFileSync(helper,
2779
- `#!/bin/sh\ncase " $* " in *" --fleet-warm "*) exit 0 ;; esac\n: > '${helperRan}'\nsleep 300\n`);
2780
- chmodSync(helper, 0o755);
2760
+ // Through `writeExecStub`, so the helper is a link to the inode exec-stub.mjs
2761
+ // already exec'd at import, and no first-exec OS scan lands inside the 5 s
2762
+ // budget the watchdog kills the fetch at. A freshly written helper measured
2763
+ // ~2.5 s idle and 5.5-12.9 s under load on that scan, and was killed mid-scan
2764
+ // having executed none of its own lines; `helper-ran` below is what catches
2765
+ // that degenerate run.
2766
+ writeExecStub(helper, `#!/bin/sh\n: > '${helperRan}'\nsleep 300\n`);
2781
2767
  git(repo, env, "config", "credential.helper", helper);
2782
2768
 
2783
- // Pay this helper's first-exec OS scan HERE, before the timed spawn, so it is
2784
- // spent outside the 5 s budget the watchdog kills the fetch at — #1199's
2785
- // finding and #1099's ruling on the remedy, reached again from a different
2786
- // file and a different collision (#1606).
2787
- //
2788
- // Measured on this case: the first execution of the freshly written helper
2789
- // costs ~2.5 s on an idle machine and 5.5-12.9 s under five concurrent copies
2790
- // of this suite, the fleet's normal condition, while a second execution stays
2791
- // at ~4 ms either way. The budget is 5 s. So unwarmed the scan never finished
2792
- // inside it, and the helper was killed mid-scan having executed NONE of its
2793
- // own lines — `helper-ran` absent in 15 of 15 runs, quiet and loaded alike.
2794
- //
2795
- // That is not the reported flake, it is worse and it is deterministic: with
2796
- // the helper never reaching `sleep 300`, nothing in the case stalled on a
2797
- // credential at all and it re-tested "an http origin that never answers" —
2798
- // exactly the vacuity the comment above says moving the 401 out of process
2799
- // had already fixed once. The 401 does arrive and git does spawn the helper;
2800
- // what never happened is the helper running. Warmed: 14 of 14 runs reach it,
2801
- // it really stalls, and net_kill_tree really reaps it (no survivor, and the
2802
- // caller's stdio closes within 1 ms of the script's own exit).
2803
- //
2804
- // Warming, not a longer bound: the 30 s backstop is 5x the observed run and
2805
- // raising it would only widen the window a helper can hide in. Warming, not a
2806
- // shared helper, because credential.helper takes a path and the per-case temp
2807
- // root is what keeps these fixtures isolated.
2808
- //
2809
- // "Warming, not a longer bound" is about the timed spawn's 30 s backstop
2810
- // below, not about this warm-up's own bound, which is 120 s. The warm-up
2811
- // runs the helper's `--fleet-warm` arm, which exits 0 above the marker write
2812
- // and the `sleep 300`, so no helper stall can hide in a longer warm-up
2813
- // bound: the only thing it can extend is the first-exec scan, and letting
2814
- // that finish is the whole point of warming. Killing it early is worse than
2815
- // useless — a warm-up killed mid-scan leaves the scan unpaid for the timed
2816
- // spawn, as PR #2224 measured (first execs 15-16 s under load ~25; one
2817
- // killed at 500 ms still took 14.5-15.0 s next time) (#2229). It stays
2818
- // finite only so a truly hung exec still ends the case.
2819
- spawnSync(helper, ["--fleet-warm"], { timeout: 120_000 });
2820
-
2821
2769
  const started = Date.now();
2822
2770
  const r = spawnSync("sh", [SCRIPT, "8"],
2823
2771
  { cwd: repo, env: { ...env, INFLIGHT_LS_REMOTE_TIMEOUT: "5" }, encoding: "utf8", timeout: 30_000 });
@@ -2835,63 +2783,6 @@ test("probe 2: a credential helper that never answers is bounded like any other
2835
2783
  assert.match(r.stderr, /did not finish within/);
2836
2784
  });
2837
2785
 
2838
- // The other half of the case above, and it needs a different technique. The
2839
- // `helper-ran` assertion is what catches the vacuity UNDER LOAD, where the
2840
- // scan runs 5.5-12.9 s and never fits the 5 s budget; it does not catch it on
2841
- // an idle machine, where the scan is ~2.5 s and the helper squeezes in warmed
2842
- // or not. Measured: deleting the warm-up line leaves this file green, 1 pass /
2843
- // 0 fail, on a quiet host — the exact hole #1199 hit, and its remedy is the
2844
- // same one ledger.test.mjs, arg.mjs's die() and candidates.mjs's EXCLUDE use.
2845
- //
2846
- // So the SHAPE is pinned as well, read back through stripComments() so a
2847
- // comment alone cannot satisfy it, and anchored at line starts under `/m` so an
2848
- // unrelated line inserted between the steps cannot still match.
2849
- //
2850
- // Anchored per STATEMENT, not per line (#2265): inside the warm-up call and
2851
- // the writeFileSync() call every token boundary is `\s*`, and a trailing comma
2852
- // is allowed wherever JS allows one, so wrapping either call across lines — a
2853
- // behavior-neutral reformat a formatter makes on its own — cannot red this pin
2854
- // the way deleting the call does. Only whitespace is free: every token, the
2855
- // timeout's floor included, is still literal and in order.
2856
- test("the credential helper's warm-up survives — deleting it would let a cold exec scan empty the case again (structural pin, #1606)", () => {
2857
- const src = stripComments(readFileSync(THIS_FILE, "utf8"));
2858
- const warmUp = /^\s*chmodSync\(helper, 0o755\);\s*^\s*git\(repo, env, "config", "credential\.helper", helper\);\s*^\s*spawnSync\(\s*helper,\s*\[\s*"--fleet-warm",?\s*\],\s*\{\s*timeout:\s*\d{3}_\d{3},?\s*\},?\s*\);\s*^\s*const started = Date\.now\(\);[\s\S]*?^\s*assert\.equal\(existsSync\(helperRan\), true,/m;
2859
- assert.match(
2860
- src,
2861
- warmUp,
2862
- "the helper must be warmed after it is written and configured and BEFORE the timed spawn, and the vacuity-guard assertion (assert.equal(existsSync(helperRan), true, ...)) must still exist below it — deleting either reopens #1606, and the suite stays green on an idle machine while it does",
2863
- );
2864
- // The input the pin must ACCEPT: the same four statements with the warm-up
2865
- // wrapped the way a formatter wraps it. Quoted lines joined, never a template
2866
- // literal — a template's lines would sit at line starts in THIS file's own
2867
- // source and satisfy the pin above with the real warm-up deleted.
2868
- assert.match(
2869
- [
2870
- " chmodSync(helper, 0o755);",
2871
- ' git(repo, env, "config", "credential.helper", helper);',
2872
- ' spawnSync(helper, ["--fleet-warm"], {',
2873
- " timeout: 120_000,",
2874
- " });",
2875
- " const started = Date.now();",
2876
- " assert.equal(existsSync(helperRan), true,",
2877
- ].join("\n"),
2878
- warmUp,
2879
- "wrapping the warm-up call across lines changes neither its order nor its presence, so the pin must not read it as deleted (#2265)",
2880
- );
2881
- // The arm's POSITION inside the helper body, not merely its presence. Below
2882
- // the marker write, the warm-up call itself would create `helper-ran` before
2883
- // any timed run ever executes (measured: a lone --fleet-warm invocation on
2884
- // the mutated order leaves the marker behind by itself): the vacuity
2885
- // assertion would then read as satisfied on a helper that never ran during
2886
- // the timed run. That is ledger.test.mjs's GH_STUB lesson, which had to be
2887
- // learned once already.
2888
- assert.match(
2889
- src,
2890
- /^\s*writeFileSync\(\s*helper,\s*`#!\/bin\/sh\\ncase " \$\* " in \*" --fleet-warm "\*\) exit 0 ;; esac\\n: > '\$\{helperRan\}'\\nsleep 300\\n`,?\s*\);/m,
2891
- "the --fleet-warm arm must sit ABOVE the marker write, or warming writes the marker itself and the vacuity guard above goes blind — anchored at line starts under `/m` so a coincidental match elsewhere in the file cannot satisfy it",
2892
- );
2893
- });
2894
-
2895
2786
  test("the euid-0 guard does not fire on a normal run, and the modes it guards really deny (#184, #660)", (t) => {
2896
2787
  // Mirrors release-ticket.test.mjs's own pin for the same class. The 8
2897
2788
  // `if (EUID0) return t.skip(NO_DENIAL)` guards above are by construction
@@ -0,0 +1,26 @@
1
+ // The "was this module run as the CLI?" guard every fleet script ends with:
2
+ //
3
+ // if (isCLI(import.meta.url)) main();
4
+ //
5
+ // Compared by realpath, never as strings. `import.meta.url` is the module's
6
+ // resolved file; `argv[1]` is whatever path the caller typed. Reached through
7
+ // a symlinked path (on macOS `/tmp` is one) or a relative one, the two differ
8
+ // as strings, main() is skipped, and the process exits 0 with no output —
9
+ // indistinguishable from a run that had nothing to say, and for a gate that is
10
+ // the code that means ok. Resolving both sides makes the answer independent of
11
+ // how node was invoked.
12
+ //
13
+ // A path that cannot be resolved (`node -`, a REPL, a module loaded by a
14
+ // wrapper that gave argv[1] no file) is not a CLI run: false, not a throw —
15
+ // the module may be nothing but imported.
16
+
17
+ import { realpathSync } from "node:fs";
18
+ import { fileURLToPath } from "node:url";
19
+
20
+ export function isCLI(metaUrl, argv1 = process.argv[1]) {
21
+ try {
22
+ return realpathSync(argv1) === realpathSync(fileURLToPath(metaUrl));
23
+ } catch {
24
+ return false;
25
+ }
26
+ }
@@ -0,0 +1,99 @@
1
+ // is-cli.mjs: the "was this module run as the CLI?" guard every script ends
2
+ // with. A string comparison of import.meta.url against argv[1] skipped main()
3
+ // whenever the script was reached through a symlinked path (on macOS `/tmp` is
4
+ // one) and exited 0 with no output — the code that reads as "nothing to do".
5
+ // The second half of this file runs every CLI script through a symlinked
6
+ // directory, one case per script, because the helper being right says nothing
7
+ // about a script that does not call it.
8
+
9
+ import { test } from "node:test";
10
+ import assert from "node:assert/strict";
11
+ import { spawnSync } from "node:child_process";
12
+ import { symlinkSync, writeFileSync } from "node:fs";
13
+ import { join, relative } from "node:path";
14
+ import { fileURLToPath, pathToFileURL } from "node:url";
15
+ import { tempDir } from "./temp-dir.mjs";
16
+ import { isCLI } from "./is-cli.mjs";
17
+
18
+ const SCRIPTS_DIR = fileURLToPath(new URL(".", import.meta.url));
19
+
20
+ function fixture() {
21
+ const dir = tempDir("is-cli-");
22
+ const file = join(dir, "real.mjs");
23
+ writeFileSync(file, "export {};\n");
24
+ return { dir, file, url: pathToFileURL(file).href };
25
+ }
26
+
27
+ test("isCLI accepts the module's own path, a relative path to it and a symlink to it", () => {
28
+ const { dir, file, url } = fixture();
29
+ const link = join(dir, "link.mjs");
30
+ symlinkSync(file, link);
31
+ assert.equal(isCLI(url, file), true);
32
+ assert.equal(isCLI(url, relative(process.cwd(), file)), true);
33
+ assert.equal(isCLI(url, link), true);
34
+ });
35
+
36
+ test("isCLI accepts a module reached through a symlinked directory", () => {
37
+ const { dir, file, url } = fixture();
38
+ const linkDir = join(dir, "dir-link");
39
+ symlinkSync(dir, linkDir);
40
+ assert.equal(isCLI(url, join(linkDir, "real.mjs")), true);
41
+ assert.equal(isCLI(pathToFileURL(join(linkDir, "real.mjs")).href, file), true);
42
+ });
43
+
44
+ test("isCLI refuses another module — an import, not a run", () => {
45
+ const { dir, url } = fixture();
46
+ const other = join(dir, "other.mjs");
47
+ writeFileSync(other, "export {};\n");
48
+ assert.equal(isCLI(url, other), false);
49
+ });
50
+
51
+ test("isCLI refuses, rather than throws, when argv[1] is missing or names nothing", () => {
52
+ const { dir, url } = fixture();
53
+ assert.equal(isCLI(url, null), false);
54
+ assert.equal(isCLI(url, ""), false);
55
+ assert.equal(isCLI(url, join(dir, "gone.mjs")), false);
56
+ assert.equal(isCLI(url, "-"), false);
57
+ });
58
+
59
+ test("isCLI defaults to the live process.argv[1]", () => {
60
+ const { url } = fixture();
61
+ assert.equal(isCLI(url), false);
62
+ assert.equal(isCLI(pathToFileURL(process.argv[1]).href), true);
63
+ });
64
+
65
+ // Each script refuses an unknown flag with exit 2 before it reads or writes
66
+ // anything; a skipped main() exits 0. The real-path run is the control: the
67
+ // symlinked run must match it, not merely be non-zero.
68
+ const CLI_SCRIPTS = [
69
+ "diff-stats", "fleet-heartbeat", "fleet-tick", "frontmatter-check", "main-checkout",
70
+ "member-outcomes", "tier-check", "tier-outcomes", "tier-roles", "board", "dispositions-check",
71
+ ];
72
+
73
+ for (const name of CLI_SCRIPTS) {
74
+ test(`${name}.mjs run through a symlinked path still runs main()`, () => {
75
+ const dir = tempDir("is-cli-run-");
76
+ const linkDir = join(dir, "scripts-link");
77
+ symlinkSync(SCRIPTS_DIR, linkDir);
78
+ const run = (script) => spawnSync(process.execPath, [script, "--bogus"], { cwd: dir, encoding: "utf8" });
79
+ const real = run(join(SCRIPTS_DIR, `${name}.mjs`));
80
+ const linked = run(join(linkDir, `${name}.mjs`));
81
+ assert.equal(real.status, 2, real.stderr);
82
+ assert.equal(linked.status, real.status, `via symlink: ${linked.stderr}`);
83
+ assert.equal(linked.stderr, real.stderr);
84
+ });
85
+ }
86
+
87
+ // The other direction: the control above cannot tell a guard that tests the
88
+ // path from one that is always true — both run main() under --bogus. Loading
89
+ // the script as a module must leave main() unrun: no output, exit 0.
90
+ for (const name of CLI_SCRIPTS) {
91
+ test(`${name}.mjs imported as a module does not run main()`, () => {
92
+ const dir = tempDir("is-cli-import-");
93
+ const url = pathToFileURL(join(SCRIPTS_DIR, `${name}.mjs`)).href;
94
+ const run = spawnSync(process.execPath, ["--input-type=module", "-e", `await import(${JSON.stringify(url)});`], { cwd: dir, encoding: "utf8" });
95
+ assert.equal(run.status, 0, run.stderr);
96
+ assert.equal(run.stdout, "");
97
+ assert.equal(run.stderr, "");
98
+ });
99
+ }
@@ -25,10 +25,11 @@
25
25
  import { test } from "node:test";
26
26
  import assert from "node:assert/strict";
27
27
  import { spawnSync } from "node:child_process";
28
- import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
28
+ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
29
29
  import { tmpdir } from "node:os";
30
30
  import { join } from "node:path";
31
31
  import { fileURLToPath } from "node:url";
32
+ import { writeExecStub } from "./exec-stub.mjs";
32
33
 
33
34
  const LIB = fileURLToPath(new URL("./json.sh", import.meta.url));
34
35
 
@@ -57,8 +58,7 @@ function drive(body, { args = [], input, break: broken, raw = false } = {}) {
57
58
  const stub = join(dir, broken);
58
59
  // Exit 1 and emit nothing — how BSD `tr` behaves on a byte that is not
59
60
  // valid UTF-8, the real-world failure this stands in for (#582).
60
- writeFileSync(stub, "#!/bin/sh\nexit 1\n");
61
- chmodSync(stub, 0o755);
61
+ writeExecStub(stub, "#!/bin/sh\nexit 1\n");
62
62
  env.PATH = `${dir}:${process.env.PATH}`;
63
63
  }
64
64
  const f = join(dir, "drive.sh");