@feigi/fleet-ctl 0.0.0 → 3.16.2

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 (152) 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/claim-lifecycle.test.mjs +2 -1
  37. package/scripts/claim-ticket.test.mjs +35 -34
  38. package/scripts/closing-keyword-prose.test.mjs +1 -1
  39. package/scripts/cockpit-tick-nonblocking.test.mjs +8 -8
  40. package/scripts/compute-board.mjs +13 -3
  41. package/scripts/compute-board.test.mjs +64 -1
  42. package/scripts/compute-spend.mjs +46 -8
  43. package/scripts/compute-spend.test.mjs +64 -10
  44. package/scripts/cross-repo-citation-prose.test.mjs +18 -19
  45. package/scripts/delete-merged-branch.sh +218 -0
  46. package/scripts/delete-merged-branch.test.mjs +576 -0
  47. package/scripts/derive-testcmd.sh +18 -7
  48. package/scripts/derive-testcmd.test.mjs +9 -8
  49. package/scripts/diff-stats.mjs +2 -2
  50. package/scripts/diff-stats.test.mjs +7 -11
  51. package/scripts/dispatch-block-golden-prose.test.mjs +111 -6
  52. package/scripts/dispatch-block-pins-prose.test.mjs +5 -5
  53. package/scripts/dispositions-check.mjs +507 -0
  54. package/scripts/dispositions-check.test.mjs +843 -0
  55. package/scripts/dispositions-gate-prose.test.mjs +114 -0
  56. package/scripts/drop-merged-label.test.mjs +3 -4
  57. package/scripts/exec-stub.mjs +93 -0
  58. package/scripts/exec-stub.test.mjs +69 -0
  59. package/scripts/filing-bar-seat-prose.test.mjs +1 -1
  60. package/scripts/finisher-test-verdict-prose.test.mjs +102 -0
  61. package/scripts/fix-applier-correction-rules-prose.test.mjs +11 -10
  62. package/scripts/fleet-bootstrap +5 -20
  63. package/scripts/fleet-bootstrap.test.mjs +75 -0
  64. package/scripts/fleet-heartbeat.mjs +2 -2
  65. package/scripts/fleet-provenance +15 -24
  66. package/scripts/fleet-provenance.test.mjs +86 -12
  67. package/scripts/fleet-run.test.mjs +5 -5
  68. package/scripts/fleet-state.mjs +33 -11
  69. package/scripts/fleet-state.test.mjs +90 -3
  70. package/scripts/fleet-tick.mjs +346 -70
  71. package/scripts/fleet-tick.test.mjs +566 -16
  72. package/scripts/force-with-lease-reason-prose.test.mjs +1 -1
  73. package/scripts/frontmatter-check.mjs +3 -2
  74. package/scripts/frontmatter-check.test.mjs +6 -6
  75. package/scripts/immutable-body-claim-prose.test.mjs +53 -262
  76. package/scripts/implementer-model-tier.test.mjs +98 -506
  77. package/scripts/inflight.test.mjs +18 -127
  78. package/scripts/is-cli.mjs +26 -0
  79. package/scripts/is-cli.test.mjs +99 -0
  80. package/scripts/json.test.mjs +3 -3
  81. package/scripts/ledger-dispatch.test.mjs +368 -7
  82. package/scripts/ledger-grammar.mjs +85 -1
  83. package/scripts/ledger-grammar.test.mjs +86 -1
  84. package/scripts/ledger-read-require-file.test.mjs +7 -7
  85. package/scripts/ledger-rotate.test.mjs +142 -0
  86. package/scripts/ledger.mjs +181 -17
  87. package/scripts/ledger.test.mjs +12 -130
  88. package/scripts/main-checkout.mjs +312 -0
  89. package/scripts/main-checkout.test.mjs +332 -0
  90. package/scripts/member-outcomes-header.test.mjs +3 -3
  91. package/scripts/member-outcomes.mjs +4 -5
  92. package/scripts/member-outcomes.test.mjs +92 -18
  93. package/scripts/member-prompt-prose.test.mjs +17 -13
  94. package/scripts/member-record.mjs +8 -3
  95. package/scripts/member-record.test.mjs +5 -5
  96. package/scripts/member-write-guard.mjs +5 -5
  97. package/scripts/member-write-guard.test.mjs +6 -3
  98. package/scripts/no-undo-audit.sh +24 -21
  99. package/scripts/no-undo-audit.test.mjs +9 -13
  100. package/scripts/pointer-target-prose.test.mjs +1 -1
  101. package/scripts/pr-overlap.test.mjs +6 -9
  102. package/scripts/prompt-renderer.mjs +10 -9
  103. package/scripts/prose-pin.mjs +10 -11
  104. package/scripts/prove-merge.test.mjs +3 -3
  105. package/scripts/quiet-payload-prose.test.mjs +1 -1
  106. package/scripts/reap.test.mjs +3 -4
  107. package/scripts/release-label-split-prose.test.mjs +17 -2
  108. package/scripts/release-ticket.test.mjs +35 -44
  109. package/scripts/review-core-cwd-isolation.test.mjs +7 -6
  110. package/scripts/review-core-reads.test.mjs +1 -1
  111. package/scripts/review-core-scratch-refusal.test.mjs +64 -0
  112. package/scripts/review-core-shared-test-run.test.mjs +238 -0
  113. package/scripts/review-core-snapshot-path.test.mjs +59 -12
  114. package/scripts/review-core-specialist-scratch.test.mjs +12 -10
  115. package/scripts/review-core-testcmd.test.mjs +76 -45
  116. package/scripts/review-core-unrun.test.mjs +154 -168
  117. package/scripts/review-core.mjs +250 -56
  118. package/scripts/review-eval.mjs +11 -4
  119. package/scripts/review-host-fixture.mjs +12 -3
  120. package/scripts/review-in-run-retry.test.mjs +27 -3
  121. package/scripts/review-runner-spawns.test.mjs +5 -3
  122. package/scripts/review-runner.test.mjs +14 -3
  123. package/scripts/review-tier-audit.test.mjs +1 -1
  124. package/scripts/run-merge-bot-prose.test.mjs +29 -6
  125. package/scripts/scratch-partition-invariant-prose.test.mjs +1 -1
  126. package/scripts/section-between-guard-prose.test.mjs +4 -3
  127. package/scripts/select-dimensions.test.mjs +1 -1
  128. package/scripts/shell-traps-prose.test.mjs +6 -9
  129. package/scripts/shortlist.mjs +4 -1
  130. package/scripts/shortlist.test.mjs +30 -16
  131. package/scripts/snapshot-repo.test.mjs +177 -4
  132. package/scripts/stash-prohibition-prose.test.mjs +1 -1
  133. package/scripts/temp-dir.mjs +47 -0
  134. package/scripts/tier-check.mjs +95 -28
  135. package/scripts/tier-check.test.mjs +131 -29
  136. package/scripts/tier-outcomes-header.test.mjs +11 -54
  137. package/scripts/tier-outcomes.mjs +34 -12
  138. package/scripts/tier-outcomes.test.mjs +157 -4
  139. package/scripts/tier-roles.mjs +118 -29
  140. package/scripts/tier-roles.test.mjs +226 -61
  141. package/scripts/tracker-block-copy-prose.test.mjs +3 -3
  142. package/scripts/verify-sha.test.mjs +4 -5
  143. package/scripts/watcher-degraded-block.test.mjs +5 -8
  144. package/scripts/within-run-pair-prose.test.mjs +43 -75
  145. package/scripts/worktree-audit.test.mjs +2 -1
  146. package/skills/next-ticket/SKILL.md +2 -2
  147. package/skills/run-team/SKILL.md +433 -303
  148. package/skills/run-team/references/ci-and-staleness.md +7 -6
  149. package/skills/run-team/references/correction-tickets.md +3 -3
  150. package/skills/run-team/references/isolation.md +1 -1
  151. package/skills/sizing-a-ticket/SKILL.md +8 -8
  152. package/scripts/tier-guard-gate-prose.test.mjs +0 -216
@@ -0,0 +1,576 @@
1
+ // Regression gate for delete-merged-branch.sh — the merge bot's own branch
2
+ // deletion (#2196), replacing the repo setting "Automatically delete head
3
+ // branches" the fleet used to lean on.
4
+ //
5
+ // Zero deps: `node --test plugin/scripts/delete-merged-branch.test.mjs`.
6
+ //
7
+ // Every fixture is a REAL bare origin and a real clone; only `gh` is stubbed.
8
+ // The assertion that matters is always read off the bare origin itself
9
+ // (`ls-remote`), never off the script's exit status or payload: #2196's trap
10
+ // is a merge step that reports success while the branch survives underneath
11
+ // it, so a test that only checked "exit 0" or "the delete was issued" would
12
+ // pass on exactly the broken implementation the ticket describes.
13
+ //
14
+ // The headline case puts the branch where every fleet-claimed ticket's branch
15
+ // lives — checked out in a linked worktree at `.worktrees/<issue>-<slug>` —
16
+ // which is where `gh pr merge --delete-branch`'s local cleanup dies with
17
+ // `fatal: 'main' is already used by worktree`. It then runs reap.sh over the
18
+ // result, so the whole post-merge chain is proved to leave no branch behind,
19
+ // remote or local.
20
+
21
+ import { test } from "node:test";
22
+ import assert from "node:assert/strict";
23
+ import { execFileSync, spawnSync } from "node:child_process";
24
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
25
+ import { tmpdir } from "node:os";
26
+ import { join } from "node:path";
27
+ import { fileURLToPath } from "node:url";
28
+
29
+ const SCRIPT = fileURLToPath(new URL("./delete-merged-branch.sh", import.meta.url));
30
+ const REAP = fileURLToPath(new URL("./reap.sh", import.meta.url));
31
+ const REAL_GIT = execFileSync("sh", ["-c", "command -v git"], { encoding: "utf8" }).trim();
32
+
33
+ // The gh stub's `pr list` pipes through the real jq (the script itself needs
34
+ // none: `gh --jq` is embedded). Without it every lookup would fail and the
35
+ // suite would read exit 2 everywhere — fail loudly instead of vacuously.
36
+ try {
37
+ execFileSync("jq", ["--version"], { stdio: "ignore" });
38
+ } catch {
39
+ throw new Error("jq is required to stub `gh pr list --jq`; install it before running this suite");
40
+ }
41
+
42
+ // Pinned identity, no developer config, no inherited repo pointers.
43
+ const ENV = {
44
+ ...process.env,
45
+ BASE_REF: undefined,
46
+ GIT_DIR: undefined,
47
+ GIT_WORK_TREE: undefined,
48
+ GIT_TEMPLATE_DIR: undefined,
49
+ GIT_INDEX_FILE: undefined,
50
+ GIT_AUTHOR_NAME: "t",
51
+ GIT_AUTHOR_EMAIL: "t@example.com",
52
+ GIT_COMMITTER_NAME: "t",
53
+ GIT_COMMITTER_EMAIL: "t@example.com",
54
+ GIT_CONFIG_GLOBAL: "/dev/null",
55
+ GIT_CONFIG_SYSTEM: "/dev/null",
56
+ };
57
+
58
+ const git = (cwd, ...args) => execFileSync("git", args, { cwd, env: ENV, encoding: "utf8" }).trim();
59
+
60
+ const commit = (w, msg) => {
61
+ git(w, "commit", "-q", "--allow-empty", "-m", msg);
62
+ return git(w, "rev-parse", "HEAD");
63
+ };
64
+
65
+ /** Bare origin + clone with one commit on main, `.worktrees/` ignored as §2.5 requires. */
66
+ function repo(t) {
67
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "delete-merged-branch-")));
68
+ t.after(() => rmSync(root, { recursive: true, force: true }));
69
+ const origin = join(root, "origin.git");
70
+ const w = join(root, "w");
71
+ execFileSync("git", ["-c", "init.defaultBranch=main", "init", "-q", "--bare", origin], { env: ENV });
72
+ execFileSync("git", ["clone", "-q", origin, w], { env: ENV, stdio: "pipe" });
73
+ writeFileSync(join(w, ".gitignore"), ".worktrees/\n.fleet/\n");
74
+ git(w, "add", ".gitignore");
75
+ commit(w, "root");
76
+ git(w, "branch", "-M", "main");
77
+ git(w, "push", "-q", "-u", "origin", "main");
78
+ return { root, origin, w };
79
+ }
80
+
81
+ /** Whether refs/heads/<name> exists on the bare origin — the ground truth. */
82
+ const onOrigin = (origin, name) =>
83
+ spawnSync("git", ["ls-remote", "--exit-code", "--heads", origin, `refs/heads/${name}`], { env: ENV }).status === 0;
84
+ const originTip = (origin, name) => git(origin, "rev-parse", `refs/heads/${name}`);
85
+
86
+ /**
87
+ * A fleet-claimed ticket, merged: branch `name` checked out in the linked
88
+ * worktree `.worktrees/<wtName>`, pushed, merged `--no-ff` into main on origin
89
+ * the way `gh pr merge --merge` does, and the remote branch LEFT IN PLACE — the
90
+ * state a repo with auto-delete off is in after the merge. Returns the head
91
+ * GitHub would report as `headRefOid`, and the worktree path.
92
+ */
93
+ function mergedInWorktree(w, name, wtName) {
94
+ const wt = join(w, ".worktrees", wtName);
95
+ git(w, "worktree", "add", "-q", wt, "-b", name, "main");
96
+ const oid = commit(wt, `work on ${name}`);
97
+ git(wt, "push", "-q", "-u", "origin", name);
98
+ git(w, "merge", "-q", "--no-ff", "-m", `Merge ${name}`, name);
99
+ git(w, "push", "-q", "origin", "main");
100
+ return { oid, wt };
101
+ }
102
+
103
+ /**
104
+ * A `gh` stub answering the script's `pr view` call and its two `pr list`
105
+ * lookups, from env vars. Returns a call log reader and an env builder.
106
+ *
107
+ * `pr list` is a faithful fake rather than canned output: it filters
108
+ * PR_LIST_JSON — every PR in the repo, `[{number,state,headRefName,
109
+ * baseRefName,isCrossRepository}]` — by `--head`/`--base`/`--state` the way
110
+ * GitHub does (`--head` matches a fork PR whose branch shares the name), then
111
+ * pipes the result through the real `jq` with the script's own `--jq`
112
+ * expression, so the selection the script asks for is under test rather than
113
+ * hard-coded into the fixture. PR_LIST_FAIL=head|base makes that lookup exit
114
+ * 1; PR_LIST_RAW_HEAD/PR_LIST_RAW_BASE replace its output verbatim at exit 0.
115
+ */
116
+ function ghStub(t, root) {
117
+ const bin = join(root, "bin");
118
+ mkdirSync(bin, { recursive: true });
119
+ const log = join(root, "gh.log");
120
+ writeFileSync(log, "");
121
+ writeFileSync(
122
+ join(bin, "gh"),
123
+ `#!/bin/sh
124
+ printf '%s\\n' "$*" >> "${log}"
125
+ case "$*" in
126
+ "pr view "*" --json state,isCrossRepository,headRefName,headRefOid,baseRefName --jq "*)
127
+ [ "\${GH_FAIL:-0}" = 0 ] || { echo "gh: simulated failure" >&2; exit 1; }
128
+ printf '%s\\037%s\\037%s\\037%s\\037%s\\n' "\${PR_STATE:-MERGED}" "\${PR_CROSS:-false}" "\$PR_HEAD" "\$PR_OID" "\${PR_BASE:-main}"
129
+ exit 0
130
+ ;;
131
+ "pr list "*) ;;
132
+ *) echo "gh: unstubbed call: $*" >&2; exit 1 ;;
133
+ esac
134
+ shift 2
135
+ head= base= state= expr=. which= limit=30
136
+ while [ $# -gt 0 ]; do
137
+ case "$1" in
138
+ --head) head=$2; which=head; shift 2 ;;
139
+ --base) base=$2; which=base; shift 2 ;;
140
+ --state) state=$2; shift 2 ;;
141
+ --limit) limit=$2; shift 2 ;;
142
+ --jq) expr=$2; shift 2 ;;
143
+ *) shift ;;
144
+ esac
145
+ done
146
+ [ "\${PR_LIST_FAIL:-}" = "$which" ] && { echo "gh: simulated pr list --$which failure" >&2; exit 1; }
147
+ if [ "$which" = head ] && [ -n "\${PR_LIST_RAW_HEAD+set}" ]; then printf '%s\\n' "$PR_LIST_RAW_HEAD"; exit 0; fi
148
+ if [ "$which" = base ] && [ -n "\${PR_LIST_RAW_BASE+set}" ]; then printf '%s\\n' "$PR_LIST_RAW_BASE"; exit 0; fi
149
+ printf '%s' "\${PR_LIST_JSON:-[]}" |
150
+ jq --arg head "$head" --arg base "$base" --arg state "$state" --argjson limit "$limit" \\
151
+ '[.[] | select(($head == "" or .headRefName == $head) and ($base == "" or .baseRefName == $base) and ($state == "" or $state == "all" or (.state | ascii_downcase) == $state))] | .[:$limit]' |
152
+ jq -r "$expr"
153
+ `,
154
+ { mode: 0o755 },
155
+ );
156
+ return {
157
+ bin,
158
+ calls: () => readFileSync(log, "utf8").trim().split("\n").filter(Boolean),
159
+ env: (extra = {}) => ({ ...ENV, PATH: `${bin}:${ENV.PATH}`, ...extra }),
160
+ };
161
+ }
162
+
163
+ /** One PR as GitHub's `gh pr list --json` would describe it. */
164
+ const pr = (number, headRefName, baseRefName, state = "OPEN", isCrossRepository = false) => ({
165
+ number,
166
+ state,
167
+ headRefName,
168
+ baseRefName,
169
+ isCrossRepository,
170
+ });
171
+
172
+ /** `json` is the script's one-line payload; exit 3 prints `branch-kept-#<n>` lines instead, read off `stdout`. */
173
+ function run(cwd, args, env) {
174
+ const r = spawnSync("sh", [SCRIPT, ...args], { cwd, env, encoding: "utf8" });
175
+ const out = r.stdout.trim();
176
+ return { code: r.status, stdout: r.stdout, json: out.startsWith("{") ? JSON.parse(out) : null, stderr: r.stderr };
177
+ }
178
+
179
+ test("a merged branch checked out in a .worktrees/<issue>-<slug> worktree is deleted from origin, and reap.sh then reaps it locally", (t) => {
180
+ const { root, origin, w } = repo(t);
181
+ const branch = "fix/2196-delete-branch";
182
+ const { oid, wt } = mergedInWorktree(w, branch, "2196-delete-branch");
183
+ assert.ok(onOrigin(origin, branch), "fixture: the branch must still be on origin after the merge");
184
+ const gh = ghStub(t, root);
185
+
186
+ const r = run(w, ["7"], gh.env({ PR_HEAD: branch, PR_OID: oid }));
187
+
188
+ assert.equal(r.code, 0, r.stderr);
189
+ assert.deepEqual(r.json, { pr: 7, branch, deleted: true });
190
+ assert.equal(onOrigin(origin, branch), false, "the branch must actually be gone from origin, not merely reported deleted");
191
+ // Remote-only: the worktree and its local branch are untouched, so a held
192
+ // worktree can neither make this step fail nor lose anything to it.
193
+ assert.ok(existsSync(wt), "the worktree must survive this step — it is reap.sh's to remove");
194
+ assert.equal(git(wt, "rev-parse", "HEAD"), oid);
195
+ assert.doesNotMatch(r.stderr, /already used by worktree/);
196
+
197
+ // The rest of the chain: the controller reaps on the merge bot's report.
198
+ const reap = spawnSync("sh", [REAP, "--apply"], { cwd: w, env: ENV, encoding: "utf8" });
199
+ assert.equal(reap.status, 0, reap.stderr);
200
+ assert.deepEqual(JSON.parse(reap.stdout).reaped, [branch]);
201
+ assert.equal(
202
+ spawnSync("git", ["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`], { cwd: w, env: ENV }).status,
203
+ 1,
204
+ "the local branch must be gone once reap.sh has run",
205
+ );
206
+ assert.equal(existsSync(wt), false, "the worktree must be gone once reap.sh has run");
207
+ });
208
+
209
+ test("a merged branch that was never checked out locally is deleted the same way — a hand-opened PR or the controller's own chore PR", (t) => {
210
+ const { root, origin, w } = repo(t);
211
+ // Pushed from a second clone, so this checkout has no worktree and no local
212
+ // branch for it at all. The quote is legal in a refname and must survive
213
+ // into the JSON payload escaped.
214
+ const other = join(root, "other");
215
+ execFileSync("git", ["clone", "-q", origin, other], { env: ENV });
216
+ const branch = 'chore/run-artifacts-"x"';
217
+ git(other, "switch", "-q", "-c", branch);
218
+ const oid = commit(other, "artifacts");
219
+ git(other, "push", "-q", "origin", branch);
220
+ git(other, "switch", "-q", "main");
221
+ git(other, "merge", "-q", "--no-ff", "-m", "merge", branch);
222
+ git(other, "push", "-q", "origin", "main");
223
+ const gh = ghStub(t, root);
224
+
225
+ const r = run(w, ["8"], gh.env({ PR_HEAD: branch, PR_OID: oid }));
226
+
227
+ assert.equal(r.code, 0, r.stderr);
228
+ assert.deepEqual(r.json, { pr: 8, branch, deleted: true });
229
+ assert.equal(onOrigin(origin, branch), false);
230
+ });
231
+
232
+ // What this change must ACCEPT: a repo that still has auto-delete on (GitHub
233
+ // removed the branch at the merge instant) must not turn every merge into a
234
+ // failure report.
235
+ test("a branch already gone from origin is success, and no delete is pushed", (t) => {
236
+ const { root, origin, w } = repo(t);
237
+ const branch = "feat/9-gone";
238
+ const { oid } = mergedInWorktree(w, branch, "9-gone");
239
+ git(w, "push", "-q", "origin", "--delete", branch);
240
+ const gh = ghStub(t, root);
241
+
242
+ const r = run(w, ["9"], gh.env({ PR_HEAD: branch, PR_OID: oid }));
243
+
244
+ assert.equal(r.code, 0, r.stderr);
245
+ assert.deepEqual(r.json, { pr: 9, branch, deleted: false, alreadyGone: true });
246
+ assert.doesNotMatch(r.stderr, /git push/);
247
+ assert.equal(onOrigin(origin, branch), false);
248
+ });
249
+
250
+ test("a branch whose tip moved after the merge is NOT deleted — the lease refuses, exit 1", (t) => {
251
+ const { root, origin, w } = repo(t);
252
+ const branch = "fix/10-moved";
253
+ const { oid, wt } = mergedInWorktree(w, branch, "10-moved");
254
+ const later = commit(wt, "pushed after the merge");
255
+ git(wt, "push", "-q", "origin", branch);
256
+ const gh = ghStub(t, root);
257
+
258
+ const r = run(w, ["10"], gh.env({ PR_HEAD: branch, PR_OID: oid }));
259
+
260
+ assert.equal(r.code, 1, r.stderr);
261
+ assert.equal(r.json.deleted, false);
262
+ assert.equal(r.json.tip, later);
263
+ assert.match(r.json.reason, /a push landed after the merge/);
264
+ assert.equal(originTip(origin, branch), later, "commits main never received must survive");
265
+ });
266
+
267
+ // The trap #2196 names: the delete is issued, reports success, and the
268
+ // branch is still there. A `git` that swallows `push` at exit 0 is exactly
269
+ // that, and only the read-back can catch it.
270
+ test("a delete that exits 0 but leaves the branch on origin is a failure, never a success", (t) => {
271
+ const { root, origin, w } = repo(t);
272
+ const branch = "fix/11-silent";
273
+ const { oid } = mergedInWorktree(w, branch, "11-silent");
274
+ const gh = ghStub(t, root);
275
+ writeFileSync(
276
+ join(gh.bin, "git"),
277
+ `#!/bin/sh\nfor a in "$@"; do [ "$a" = push ] && exit 0; done\nexec "${REAL_GIT}" "$@"\n`,
278
+ { mode: 0o755 },
279
+ );
280
+
281
+ const r = run(w, ["11"], gh.env({ PR_HEAD: branch, PR_OID: oid }));
282
+
283
+ assert.equal(r.code, 1, r.stderr);
284
+ assert.equal(r.json.deleted, false);
285
+ assert.match(r.json.reason, /exited 0 and the branch is still on origin/);
286
+ assert.ok(onOrigin(origin, branch));
287
+ });
288
+
289
+ test("a delete the remote refuses is exit 1 with the branch still reported", (t) => {
290
+ const { root, origin, w } = repo(t);
291
+ const branch = "fix/12-refused";
292
+ const { oid } = mergedInWorktree(w, branch, "12-refused");
293
+ writeFileSync(join(origin, "hooks", "pre-receive"), "#!/bin/sh\necho 'deletes are protected' >&2\nexit 1\n", { mode: 0o755 });
294
+ const gh = ghStub(t, root);
295
+
296
+ const r = run(w, ["12"], gh.env({ PR_HEAD: branch, PR_OID: oid }));
297
+
298
+ assert.equal(r.code, 1, r.stderr);
299
+ assert.equal(r.json.tip, oid);
300
+ assert.match(r.json.reason, /git push --delete exited [1-9]/);
301
+ assert.ok(onOrigin(origin, branch));
302
+ });
303
+
304
+ // A push the script's own net budget kills is not a server's refusal: the
305
+ // reason must say it was killed, the way remote_tip says it for ls-remote.
306
+ test("a delete killed by the net budget says so, exit 1 with the branch still reported", (t) => {
307
+ const { root, origin, w } = repo(t);
308
+ const branch = "fix/19-stalled";
309
+ const { oid } = mergedInWorktree(w, branch, "19-stalled");
310
+ writeFileSync(join(origin, "hooks", "pre-receive"), "#!/bin/sh\nsleep 20\nexit 1\n", { mode: 0o755 });
311
+ const gh = ghStub(t, root);
312
+
313
+ const r = run(w, ["19"], gh.env({ PR_HEAD: branch, PR_OID: oid, FLEET_NET_TIMEOUT: "1" }));
314
+
315
+ assert.equal(r.code, 1, r.stderr);
316
+ assert.equal(r.json.tip, oid);
317
+ assert.match(r.json.reason, /git push --delete did not finish within 1s and was killed/);
318
+ assert.ok(onOrigin(origin, branch));
319
+ });
320
+
321
+ // The race the script's last branch exists for: the push fails, yet something
322
+ // else (a repo still auto-deleting) removed the branch between the two reads.
323
+ // The outcome this step exists for holds, so it is not a failure — but nor is
324
+ // it this run's delete.
325
+ test("a failed push whose branch is gone on the read-back is already gone, not deleted", (t) => {
326
+ const { root, origin, w } = repo(t);
327
+ const branch = "fix/20-raced";
328
+ const { oid } = mergedInWorktree(w, branch, "20-raced");
329
+ const gh = ghStub(t, root);
330
+ writeFileSync(
331
+ join(gh.bin, "git"),
332
+ `#!/bin/sh\nfor a in "$@"; do [ "$a" = push ] && { "${REAL_GIT}" "$@"; exit 1; }; done\nexec "${REAL_GIT}" "$@"\n`,
333
+ { mode: 0o755 },
334
+ );
335
+
336
+ const r = run(w, ["20"], gh.env({ PR_HEAD: branch, PR_OID: oid }));
337
+
338
+ assert.equal(r.code, 0, r.stderr);
339
+ assert.deepEqual(r.json, { pr: 20, branch, deleted: false, alreadyGone: true });
340
+ assert.equal(onOrigin(origin, branch), false);
341
+ });
342
+
343
+ test("a PR that is not merged is refused before any git call, branch untouched", (t) => {
344
+ const { root, origin, w } = repo(t);
345
+ const branch = "fix/13-open";
346
+ const { oid } = mergedInWorktree(w, branch, "13-open");
347
+ const gh = ghStub(t, root);
348
+
349
+ for (const state of ["OPEN", "CLOSED"]) {
350
+ const r = run(w, ["13"], gh.env({ PR_STATE: state, PR_HEAD: branch, PR_OID: oid }));
351
+ assert.equal(r.code, 2, state);
352
+ assert.match(r.stderr, new RegExp(`not merged \\(state=${state}\\)`));
353
+ assert.doesNotMatch(r.stderr, /ls-remote|git push/);
354
+ assert.equal(r.json, null);
355
+ }
356
+ assert.ok(onOrigin(origin, branch));
357
+ });
358
+
359
+ test("a fork PR is skipped — a same-named branch on our origin is not its head", (t) => {
360
+ const { root, origin, w } = repo(t);
361
+ const branch = "fix/14-fork";
362
+ const { oid } = mergedInWorktree(w, branch, "14-fork");
363
+ const gh = ghStub(t, root);
364
+
365
+ const r = run(w, ["14"], gh.env({ PR_CROSS: "true", PR_HEAD: branch, PR_OID: oid }));
366
+
367
+ assert.equal(r.code, 0, r.stderr);
368
+ assert.deepEqual(r.json, { pr: 14, branch, deleted: false, skipped: "cross-repository" });
369
+ assert.ok(onOrigin(origin, branch));
370
+ });
371
+
372
+ test("a head that names the base branch is refused, base untouched", (t) => {
373
+ const { root, origin, w } = repo(t);
374
+ const gh = ghStub(t, root);
375
+ const main = originTip(origin, "main");
376
+
377
+ const r = run(w, ["15"], gh.env({ PR_HEAD: "main", PR_OID: main }));
378
+
379
+ assert.equal(r.code, 2);
380
+ assert.match(r.stderr, /is its base branch 'main'/);
381
+ assert.equal(originTip(origin, "main"), main);
382
+ });
383
+
384
+ test("usage errors refuse before calling gh", (t) => {
385
+ const { root, w } = repo(t);
386
+ const gh = ghStub(t, root);
387
+ for (const args of [[], ["abc"], ["007"], ["01"], ["1", "2"]]) {
388
+ const r = run(w, args, gh.env());
389
+ assert.equal(r.code, 2, JSON.stringify(args));
390
+ }
391
+ assert.deepEqual(gh.calls(), []);
392
+ });
393
+
394
+ test("a failed gh read is exit 2, not a verdict", (t) => {
395
+ const { root, w } = repo(t);
396
+ const gh = ghStub(t, root);
397
+ const r = run(w, ["16"], gh.env({ GH_FAIL: "1" }));
398
+ assert.equal(r.code, 2);
399
+ assert.match(r.stderr, /gh pr view 16 failed/);
400
+ assert.equal(r.json, null);
401
+ });
402
+
403
+ // A tab is IFS whitespace, so a tab-joined read collapses an empty field and
404
+ // shifts the rest left — the base branch then reads as the head commit.
405
+ test("an empty head branch from gh is refused as missing, not misread as a later field", (t) => {
406
+ const { root, w } = repo(t);
407
+ const gh = ghStub(t, root);
408
+ const r = run(w, ["21"], gh.env({ PR_HEAD: "", PR_OID: "a".repeat(40) }));
409
+ assert.equal(r.code, 2);
410
+ assert.match(r.stderr, /returned no head branch or head commit/);
411
+ assert.equal(r.json, null);
412
+ });
413
+
414
+ test("an unreachable origin is exit 2, never read as an already-gone branch", (t) => {
415
+ const { root, origin, w } = repo(t);
416
+ const branch = "fix/17-unreachable";
417
+ const { oid } = mergedInWorktree(w, branch, "17-unreachable");
418
+ git(w, "remote", "set-url", "origin", join(root, "nowhere.git"));
419
+ const gh = ghStub(t, root);
420
+
421
+ const r = run(w, ["17"], gh.env({ PR_HEAD: branch, PR_OID: oid }));
422
+
423
+ assert.equal(r.code, 2);
424
+ assert.match(r.stderr, /git ls-remote failed/);
425
+ assert.equal(r.json, null);
426
+ assert.ok(onOrigin(origin, branch));
427
+ });
428
+
429
+ // An ambient GIT_DIR naming another repository would point `ls-remote origin`
430
+ // at THAT repository's origin, where the branch does not exist — read as
431
+ // already gone, exit 0, with the real branch still on the real origin.
432
+ test("an ambient GIT_DIR naming another repository does not redirect the delete", (t) => {
433
+ const { root, origin, w } = repo(t);
434
+ const branch = "fix/18-ambient";
435
+ const { oid } = mergedInWorktree(w, branch, "18-ambient");
436
+ const decoy = join(root, "decoy");
437
+ execFileSync("git", ["-c", "init.defaultBranch=main", "init", "-q", decoy], { env: ENV });
438
+ execFileSync("git", ["-c", "init.defaultBranch=main", "init", "-q", "--bare", join(root, "decoy-origin.git")], { env: ENV });
439
+ git(decoy, "remote", "add", "origin", join(root, "decoy-origin.git"));
440
+ const gh = ghStub(t, root);
441
+
442
+ const r = run(w, ["18"], gh.env({ PR_HEAD: branch, PR_OID: oid, GIT_DIR: join(decoy, ".git") }));
443
+
444
+ assert.equal(r.code, 0, r.stderr);
445
+ assert.deepEqual(r.json, { pr: 18, branch, deleted: true });
446
+ assert.equal(onOrigin(origin, branch), false);
447
+ });
448
+
449
+ // #2295: deleting a branch closes every open PR headed by it, and may close
450
+ // rather than retarget every open PR based on it. Either one keeps the branch:
451
+ // no push, one `branch-kept-#<pr>` line per such PR, exit 3. The proof that no
452
+ // delete went out is read off the bare origin — the tip is still the merged head.
453
+ function keptFixture(t, branch, wtName) {
454
+ const { root, origin, w } = repo(t);
455
+ const { oid } = mergedInWorktree(w, branch, wtName);
456
+ return { origin, w, oid, gh: ghStub(t, root) };
457
+ }
458
+
459
+ test("an open PR headed by the branch keeps it — no push, branch-kept-#<that PR>, exit 3", (t) => {
460
+ const branch = "fix/22-head";
461
+ const { origin, w, oid, gh } = keptFixture(t, branch, "22-head");
462
+ const list = [pr(22, branch, "main", "MERGED"), pr(31, branch, "release")];
463
+
464
+ const r = run(w, ["22"], gh.env({ PR_HEAD: branch, PR_OID: oid, PR_LIST_JSON: JSON.stringify(list) }));
465
+
466
+ assert.equal(r.code, 3, r.stderr);
467
+ assert.equal(r.stdout, "branch-kept-#31\n");
468
+ assert.match(r.stderr, /open PR #31 uses fix\/22-head as its head/);
469
+ assert.doesNotMatch(r.stderr, /git push/);
470
+ assert.equal(originTip(origin, branch), oid);
471
+ });
472
+
473
+ test("an open PR based on the branch keeps it — no push, branch-kept-#<that PR>, exit 3", (t) => {
474
+ const branch = "fix/23-base";
475
+ const { origin, w, oid, gh } = keptFixture(t, branch, "23-base");
476
+ const list = [pr(23, branch, "main", "MERGED"), pr(40, "feat/40-stacked", branch)];
477
+
478
+ const r = run(w, ["23"], gh.env({ PR_HEAD: branch, PR_OID: oid, PR_LIST_JSON: JSON.stringify(list) }));
479
+
480
+ assert.equal(r.code, 3, r.stderr);
481
+ assert.equal(r.stdout, "branch-kept-#40\n");
482
+ assert.match(r.stderr, /open PR #40 uses fix\/23-base as its base/);
483
+ assert.doesNotMatch(r.stderr, /git push/);
484
+ assert.equal(originTip(origin, branch), oid);
485
+ });
486
+
487
+ test("open PRs of both kinds print one branch-kept-# line per PR, exit 3", (t) => {
488
+ const branch = "fix/24-both";
489
+ const { origin, w, oid, gh } = keptFixture(t, branch, "24-both");
490
+ const list = [
491
+ pr(24, branch, "main", "MERGED"),
492
+ pr(51, branch, "release"),
493
+ pr(9, "feat/9-stacked", branch),
494
+ pr(60, "feat/60-stacked", branch),
495
+ pr(70, "feat/70-old", branch, "CLOSED"),
496
+ ];
497
+
498
+ const r = run(w, ["24"], gh.env({ PR_HEAD: branch, PR_OID: oid, PR_LIST_JSON: JSON.stringify(list) }));
499
+
500
+ assert.equal(r.code, 3, r.stderr);
501
+ assert.deepEqual(r.stdout.trim().split("\n").sort(), ["branch-kept-#51", "branch-kept-#60", "branch-kept-#9"]);
502
+ assert.doesNotMatch(r.stderr, /git push/);
503
+ assert.equal(originTip(origin, branch), oid);
504
+ });
505
+
506
+ test("every open PR on the branch gets its branch-kept-# line, however many there are — gh lists 30 unless asked for more", (t) => {
507
+ const branch = "fix/25-many";
508
+ const { origin, w, oid, gh } = keptFixture(t, branch, "25-many");
509
+ const list = [pr(25, branch, "main", "MERGED")];
510
+ for (let n = 100; n < 140; n++) list.push(pr(n, `feat/${n}-stacked`, branch));
511
+
512
+ const r = run(w, ["25"], gh.env({ PR_HEAD: branch, PR_OID: oid, PR_LIST_JSON: JSON.stringify(list) }));
513
+
514
+ assert.equal(r.code, 3, r.stderr);
515
+ assert.equal(r.stdout.trim().split("\n").length, 40);
516
+ assert.equal(originTip(origin, branch), oid);
517
+ });
518
+
519
+ test("a failed or unparsable open-PR lookup is exit 2, names the lookup, and pushes nothing", (t) => {
520
+ const branch = "fix/25-unknown";
521
+ const { origin, w, oid, gh } = keptFixture(t, branch, "25-unknown");
522
+ const cases = [
523
+ [{ PR_LIST_FAIL: "head" }, /lookup `gh pr list --head fix\/25-unknown` failed/],
524
+ [{ PR_LIST_FAIL: "base" }, /lookup `gh pr list --base fix\/25-unknown` failed/],
525
+ [{ PR_LIST_RAW_HEAD: "[]" }, /lookup `gh pr list --head fix\/25-unknown` answered with something that is not a list of PR numbers/],
526
+ [{ PR_LIST_RAW_BASE: "40\nnull" }, /lookup `gh pr list --base fix\/25-unknown` answered with something that is not a list of PR numbers/],
527
+ ];
528
+ for (const [extra, named] of cases) {
529
+ const r = run(w, ["25"], gh.env({ PR_HEAD: branch, PR_OID: oid, ...extra }));
530
+ const label = JSON.stringify(extra);
531
+ assert.equal(r.code, 2, `${label}: ${r.stderr}`);
532
+ assert.match(r.stderr, named, label);
533
+ assert.doesNotMatch(r.stderr, /git push/, label);
534
+ assert.equal(r.stdout, "", label);
535
+ }
536
+ assert.equal(originTip(origin, branch), oid);
537
+ });
538
+
539
+ // What the guard must ACCEPT: none of these PRs is affected by the delete —
540
+ // the merged PR itself, closed PRs, a merged PR based on the branch, a fork PR
541
+ // whose own branch merely shares the name (`--head` matches it; it lives in the
542
+ // fork), and an open PR on an unrelated branch. A guard that kept on any of them
543
+ // would stop every delete.
544
+ test("PRs the delete cannot affect do not keep the branch — it is deleted, exit 0", (t) => {
545
+ const branch = "fix/26-clear";
546
+ const { origin, w, oid, gh } = keptFixture(t, branch, "26-clear");
547
+ const list = [
548
+ pr(26, branch, "main", "MERGED"),
549
+ pr(27, branch, "main", "CLOSED"),
550
+ pr(28, "feat/28-old", branch, "MERGED"),
551
+ pr(29, branch, "main", "OPEN", true),
552
+ pr(30, "feat/30-other", "main"),
553
+ ];
554
+
555
+ const r = run(w, ["26"], gh.env({ PR_HEAD: branch, PR_OID: oid, PR_LIST_JSON: JSON.stringify(list) }));
556
+
557
+ assert.equal(r.code, 0, r.stderr);
558
+ assert.deepEqual(r.json, { pr: 26, branch, deleted: true });
559
+ assert.equal(onOrigin(origin, branch), false);
560
+ });
561
+
562
+ // The lookups guard a delete; a branch already gone has none left to guard,
563
+ // so a lookup that would fail cannot turn the outcome this step exists for
564
+ // into "can't tell", and nothing is kept to report.
565
+ test("a branch already gone is success even when an open-PR lookup would fail", (t) => {
566
+ const { root, origin, w } = repo(t);
567
+ const branch = "feat/32-gone";
568
+ const { oid } = mergedInWorktree(w, branch, "32-gone");
569
+ git(w, "push", "-q", "origin", "--delete", branch);
570
+ const gh = ghStub(t, root);
571
+
572
+ const r = run(w, ["32"], gh.env({ PR_HEAD: branch, PR_OID: oid, PR_LIST_FAIL: "head" }));
573
+
574
+ assert.equal(r.code, 0, r.stderr);
575
+ assert.deepEqual(r.json, { pr: 32, branch, deleted: false, alreadyGone: true });
576
+ });
@@ -38,13 +38,24 @@
38
38
  # Recipe, so nothing here ever runs the command.
39
39
  set -eu
40
40
 
41
- # Byte semantics for the one byte-sensitive construct below: the `case`
42
- # patterns that pick the command's leading word apart (`[A-Za-z_]` ranges and
43
- # `*` over an arbitrary byte string from the cache). Under an ambient UTF-8
44
- # locale a range is collation-ordered and `*` refuses to match across an
45
- # invalid byte (#582's hazard). Nothing here sorts or folds case, so pinning
46
- # the locale changes nothing else — locale-pin-prose.test.mjs enforces the
47
- # placement (#612).
41
+ # Byte semantics for every construct below that reads a string by bytes:
42
+ #
43
+ # the `case` patterns that pick the command's leading word apart past
44
+ # `NAME=value` prefixes — `[A-Za-z_]` ranges, ASCII by intent, and `*` over
45
+ # an arbitrary byte string from the cache. Under an ambient UTF-8 locale a
46
+ # range is collation-ordered and `*` refuses to match across an invalid byte.
47
+ #
48
+ # the digit-only guard on node's byte-count file (`*[!0-9]*`), ASCII digits
49
+ # by intent like the ranges above.
50
+ #
51
+ # the `${#framed}` length compare, which must count BYTES to equal the byte
52
+ # count node writes. Under a UTF-8 locale `${#…}` counts characters, so a
53
+ # valid cache whose command holds a multi-byte character would be refused
54
+ # as chatter on node's stdout.
55
+ #
56
+ # The hex range in the inline `node -e` validator is JavaScript and out of the
57
+ # shell locale's reach. Nothing here sorts or folds case. The pin sits ahead of
58
+ # every line that does work, so it covers all of the above.
48
59
  export LC_ALL=C
49
60
 
50
61
  # Below the locale pin, not above it with `set -eu`: `unset` touches no
@@ -1,9 +1,11 @@
1
1
  import { test } from "node:test";
2
2
  import assert from "node:assert/strict";
3
3
  import { execFileSync, spawnSync } from "node:child_process";
4
- import { mkdtempSync, mkdirSync, writeFileSync, symlinkSync, chmodSync, readFileSync } from "node:fs";
4
+ import { mkdirSync, writeFileSync, symlinkSync, chmodSync, readFileSync } from "node:fs";
5
5
  import { tmpdir } from "node:os";
6
+ import { tempDir } from "./temp-dir.mjs";
6
7
  import { join } from "node:path";
8
+ import { writeExecStub } from "./exec-stub.mjs";
7
9
 
8
10
  // derive-testcmd.sh is the ONE reader of a repository's Recipe cache (ADR
9
11
  // 0015) — reused by claim-ticket.sh and review-core.mjs's snapshot agent. It
@@ -24,7 +26,7 @@ const [, FRAME_OPEN, FRAME_CLOSE] = FRAME_MATCH;
24
26
  const FIXTURE_ENV = { ...process.env, GIT_DIR: undefined, GIT_WORK_TREE: undefined };
25
27
 
26
28
  function repo(files = {}) {
27
- const dir = mkdtempSync(join(tmpdir(), "derive-testcmd-"));
29
+ const dir = tempDir("derive-testcmd-");
28
30
  const git = (...a) => execFileSync("git", a, { cwd: dir, stdio: "pipe", env: FIXTURE_ENV, encoding: "utf8" });
29
31
  git("init", "-q");
30
32
  git("config", "user.email", "t@t");
@@ -89,7 +91,7 @@ test("a linked worktree reads the main checkout's cache, not a private one", ()
89
91
  // once, beside the common git dir, like the ledger.
90
92
  const { dir, head } = repo();
91
93
  cache(dir, recipe(head, { test: "true" }));
92
- const wt = join(mkdtempSync(join(tmpdir(), "derive-wt-")), "wt");
94
+ const wt = join(tempDir("derive-wt-"), "wt");
93
95
  execFileSync("git", ["worktree", "add", "-q", "--detach", wt], { cwd: dir, stdio: "pipe", env: FIXTURE_ENV });
94
96
  const r = derive(wt);
95
97
  assert.equal(r.status, 0, r.err);
@@ -110,7 +112,7 @@ test("wrong argument count and an unknown field refuse with a usage message", ()
110
112
  });
111
113
 
112
114
  test("a non-repository directory refuses cleanly", () => {
113
- const dir = mkdtempSync(join(tmpdir(), "derive-testcmd-not-a-repo-"));
115
+ const dir = tempDir("derive-testcmd-not-a-repo-");
114
116
  const r = derive(dir);
115
117
  assert.equal(r.status, 1);
116
118
  assert.match(r.err, /is not a git repository/);
@@ -303,7 +305,7 @@ test("the success path writes nothing to stderr, even when node is chatty (#1175
303
305
  // interpreter is really unreachable rather than shadowed.
304
306
  const SHIMMED = ["sh", "git", "mktemp", "cat", "rm"];
305
307
  function shimPath({ node }) {
306
- const bin = mkdtempSync(join(tmpdir(), "derive-path-"));
308
+ const bin = tempDir("derive-path-");
307
309
  for (const name of SHIMMED) {
308
310
  const real = execFileSync("sh", ["-c", `command -v ${name}`], { encoding: "utf8" }).trim();
309
311
  symlinkSync(real, join(bin, name));
@@ -336,9 +338,8 @@ test("an unusable interpreter refuses in this script's own voice, never the cach
336
338
  // did not resolve, handed on when it did. Every stub runs the real interpreter
337
339
  // by ABSOLUTE path: re-running `node` through PATH would find the stub again.
338
340
  function nodeStub(body) {
339
- const bin = mkdtempSync(join(tmpdir(), "derive-stub-"));
340
- writeFileSync(join(bin, "node"), `#!/bin/sh\n${body.replaceAll("NODE", `'${process.execPath}'`)}\n`);
341
- chmodSync(join(bin, "node"), 0o755);
341
+ const bin = tempDir("derive-stub-");
342
+ writeExecStub(join(bin, "node"), `#!/bin/sh\n${body.replaceAll("NODE", `'${process.execPath}'`)}\n`);
342
343
  return { ...process.env, PATH: `${bin}:${process.env.PATH}` };
343
344
  }
344
345