@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
@@ -134,7 +134,7 @@ For each labeled PR clearing the hold rule, lowest first:
134
134
 
135
135
  This also repairs a branch carrying a merge commit — GitHub's rebase drops those too.
136
136
 
137
- **A worktree for this branch, if one exists, goes stale here** — the API rebased the remote, not your checkout. Expected, not a divergence. To prove it holds nothing unique, run `git cherry origin/<branch> HEAD` from the worktree **before the merge, never after**, and **not** `git cherry origin/main HEAD`: `main` never contained this PR's commits before the merge either, so it reads `+` for all of them regardless of staleness and proves nothing (measured, feigi/claude-config#149). The window is the point: GitHub deletes the remote branch when the PR lands — the same reason step 4 never passes `--delete-branch` — so `origin/<branch>` outlives the merge only until the next pruning fetch, and step 4's `prove-merge.sh` runs one seconds later (`grep -n 'git fetch --quiet origin' scripts/prove-merge.sh`, plain, which prunes under the `fetch.prune=true` this machine's global config sets — `git config --show-origin --get fetch.prune`). Past that fetch the probe fails on a missing ref, an error easy to misread as the divergence it was meant to rule out.
137
+ **A worktree for this branch, if one exists, goes stale here** — the API rebased the remote, not your checkout. Expected, not a divergence. To prove it holds nothing unique, run `git cherry origin/<branch> HEAD` from the worktree **before the merge, never after**, and **not** `git cherry origin/main HEAD`: `main` never contained this PR's commits before the merge either, so it reads `+` for all of them regardless of staleness and proves nothing (measured, feigi/claude-config#149). The window is the point: step 4 deletes the remote branch once the PR lands (`delete-merged-branch.sh`; a repo that auto-deletes head branches removes it at the merge itself), so `origin/<branch>` outlives the merge only until the next pruning fetch, and step 4's `prove-merge.sh` runs one seconds later (`grep -n 'git fetch --quiet origin' scripts/prove-merge.sh`, plain, which prunes under the `fetch.prune=true` this machine's global config sets — `git config --show-origin --get fetch.prune`). Past that fetch the probe fails on a missing ref, an error easy to misread as the divergence it was meant to rule out.
138
138
 
139
139
  **Neither result halts this path, and a `+` here is not the diverged-worktree STOP.** The clean answer is the absence of a `+`, not the absence of output: `git cherry` prints a line per commit in `origin/<branch>..HEAD`, `-` where the upstream already holds an equivalent patch and `+` where it does not, so it never goes silent merely because the rebase superseded everything. A worktree that has not fetched since the API rebase — the state this step leaves it in, since no local git command runs here — reads nothing; one that has fetched reads `-` for every rebased commit. Both are clean (measured 2026-08-29 in a scratch repo: a bare remote, a branch rebased onto an advanced `main` and force-pushed, and a clone left at the pre-rebase head — `git cherry origin/feat HEAD` printed nothing before that clone fetched and a `-` per rebased commit after, while an unpushed commit added on top raised a `+` in both). A `+` names a commit the worktree holds and that branch does not — say so alongside the merge, since it is the only signal that something local is unpushed, but it does not stop the merge, because nothing local reaches the remote from here: this step rebases through the API and pushes nothing, and step 4 merges the remote head, so an unpushed local commit is structurally unable to enter the merge. That STOP lives in the fallback (server-side rebase unavailable) and does not halt for the reason just ruled out here: neither path can carry a local commit to the remote, because neither pushes. What differs is what gets verified — the fallback rebases the worktree and verifies *that* head, so a commit only the worktree holds makes the verified tree something other than the reviewed head; here the worktree is only read, never rebased, so a `+` is a report, not a halt.
140
140
 
@@ -180,7 +180,7 @@ For each labeled PR clearing the hold rule, lowest first:
180
180
 
181
181
  **A repo that gates on currency cannot merge from this path — and this one does.** The fallback leaves the remote head behind `origin/main` on purpose, which is the exact condition `rebase-check` fails on: `.github/workflows/ci.yml` checks out `pull_request.head.sha` and exits 1 when the merge-base is not the base tip. It is an expected job, so `ci-state.mjs` reports non-green, step 3's gate never opens, and `mergeStateStatus` cannot read `CLEAN` either. The four checks above are still the honest verification of the *content*, but they do not clear that gate. So here the fallback **ends without merging**: report `rebase-fallback-#<pr>` as blocked and hand it back — choosing between resolving the conflict and turning `allow_update_branch` on is a human's call. Step 4's merge is reachable from this path only where no expected job gates on currency.
182
182
 
183
- **When that hand-back is a conflict, record it on the ledger before you report — your report is gone when you exit, and nothing else durable says the PR is stuck (#2064).** It is a conflict when the fallback's local rebase stopped on conflicting paths, whether you then resolved them for verification or aborted: nothing on this path pushes, so the remote head still carries the conflict either way. Not when the server-side rebase failed only because `allow_update_branch` is off and the local rebase applied clean — there is nothing for a fix-applier to resolve. The stopped rebase already named the conflicting paths — read them before you resolve or abort (`git -C <worktree> diff --name-only --diff-filter=U`) — so a later auditor can tell what collided from the row text alone, without re-reading this report (#2064 story 15). Append the hold to the ticket row that names the PR — the row whose first `PR#` mention is `PR#<pr>`, or the row keyed `#<pr>` when none does — as one rewrite of that row's own text, never a bare line — **unless it already carries one unresolved.** Read the row fresh (below) before writing: if its last `conflict-hold:#<pr>` has no `fix-pr-<n>` settled after it, the row already says what you are about to say — a duplicate write teaches the tick nothing new and can reset a live fix-applier's `fixSince` out from under it. Report `rebase-fallback-#<pr>` and stop there; only write when the row's last hold (if any) has a settled fix-pr after it, or carries no hold at all.
183
+ **When that hand-back is a conflict, record it on the ledger before you report — your report is gone when you exit, and nothing else durable says the PR is stuck (#2064).** It is a conflict when the fallback's local rebase stopped on conflicting paths, whether you then resolved them for verification or aborted: nothing on this path pushes, so the remote head still carries the conflict either way. Not when the server-side rebase failed only because `allow_update_branch` is off and the local rebase applied clean — there is nothing for a fix-applier to resolve. The stopped rebase already named the conflicting paths — read them before you resolve or abort (`git -C <worktree> diff --name-only --diff-filter=U`) — so a later auditor can tell what collided from the row text alone, without re-reading this report (#2064 story 15). Append the hold to the ticket row that names the PR — the row whose first `PR#` mention is `PR#<pr>`, or the row keyed `#<pr>` when none does — as one rewrite of that row's own text, never a bare line — **unless it already carries one unresolved.** Read the row fresh (below) before writing: if its last `conflict-hold:#<pr>` has no `fix-pr-<n>` settled after it, the row already says what you are about to say — a duplicate write teaches the tick nothing new, and once a fix-applier already working the first hold settles in place before your copy, the tick reads your copy as a fresh hold that settle never cleared. Report `rebase-fallback-#<pr>` and stop there; only write when the row's last hold (if any) has a settled fix-pr after it, or carries no hold at all.
184
184
 
185
185
  ```bash
186
186
  ~/.fleet/bin/fleet-run ledger.mjs read # the row: `#<key> <text>`
@@ -224,7 +224,7 @@ For each labeled PR clearing the hold rule, lowest first:
224
224
 
225
225
  **Why twice: a conclusion can invert under a fixed run id.** A rerun rewrites the *existing* run rather than creating a new one, so a run id you read as `success` can later read `failure` with nothing pushed to the branch. Observed twice in one fleet run, on two PRs: a refresh workflow re-ran the currency check after `main` advanced and flipped the same id on the same SHA. And a CI wait puts minutes between the first reading and the merge — minutes in which the label can be pulled and the instrument set can change. Never carry a reading across a wait; the second run is the reading the merge rests on.
226
226
 
227
- 4. `gh pr merge <pr> --merge` (no-ff). It can exit silently — confirm with `gh pr view <pr> --json state,mergedAt,mergeCommit` before claiming it merged. **Never `--delete-branch`**; GitHub removes the remote branch anyway.
227
+ 4. `gh pr merge <pr> --merge` (no-ff). It can exit silently — confirm with `gh pr view <pr> --json state,mergedAt,mergeCommit` before claiming it merged. **Never `--delete-branch` on this call** — the head branch is deleted below, by `delete-merged-branch.sh`, never by `gh`.
228
228
 
229
229
  **`--merge` (no-ff) is load-bearing, not stylistic — and do not let a content claim reach you worded as a graph-shape one.** It always writes a **two-parent** merge commit, even where the branch is trivially fast-forwardable, and step 5's proof *requires* that: `prove-merge.sh` dies at `has no second parent — not a merge commit` and exits **2** on a single-parent merge. Exit 2 is "could not evaluate the claim at all", not "the claim is false" — so a real fast-forward leaves you with no proof to report and a halt, not a failed proof. Measured on #908: a controller brief predicted "the merge will be a fast-forward", and the merge tree *was* byte-identical to the reviewed head (`988f29d1`, `git diff <pin> <merge>` empty) — but the commit still had two parents, which is the only reason the proof was available. "The merge adds nothing" is a statement about content; **never write it as "fast-forward", which is a statement about shape, and which would have broken step 5.**
230
230
 
@@ -250,6 +250,16 @@ For each labeled PR clearing the hold rule, lowest first:
250
250
 
251
251
  Exit 0 done or nothing to close, **1 a removal failed — report it as `label-drop-failed-#<issue>`, never swallow it**: a merged ticket that keeps the label is invisible the moment it is reopened. Exit 2 means the PR was not actually MERGED yet — call this only after the merge is confirmed at the top of this step.
252
252
 
253
+ **Delete the head branch from `origin`** — this bot owns that step, and no repo setting does it for you (#2196). Without it a merged branch is never `[gone]`, so `reap.sh` never reaps it or its worktree:
254
+
255
+ ```bash
256
+ ~/.fleet/bin/fleet-run delete-merged-branch.sh <pr>
257
+ ```
258
+
259
+ Exit 0 the branch is gone from `origin` — `deleted`, `alreadyGone` (a repo that still auto-deletes), or `skipped` for a fork PR, whose branch is not ours. **1 the branch is still on `origin` — report it as `branch-delete-failed-#<pr>`, never swallow it**: either a push landed on it after the merge (the delete is leased to the merged head, so it refuses rather than destroy commits `main` never received) or the push failed. The script reads the deletion back from `origin` rather than trusting the push's exit status. Exit 2 could not tell what to delete — the PR is not MERGED, a `gh` or `ls-remote` read failed, or the lookup for other open PRs on the branch failed (nothing is deleted then); call this only after the merge is confirmed at the top of this step. **Exit 3 the branch is kept on purpose — another open PR uses it as its head or its base** (#2295): deleting it would close the PRs headed by it, and may close rather than retarget the PRs based on it. Nothing was pushed. Its stdout is one `branch-kept-#<pr>` line per such PR, naming that open PR, not the merged one — report each line as printed. A deliberate keep, not a failure: never retry it, and never report it as `branch-delete-failed`. The branch stays on `origin`, so it is not `[gone]` and `reap.sh` leaves it and its worktree in place.
260
+
261
+ It deletes the **remote** ref only, and that is why it exists instead of `gh pr merge --delete-branch`: that flag's local cleanup dies with `fatal: 'main' is already used by worktree at <path>` whenever the branch is checked out in a worktree — which every fleet-claimed branch is, at `.worktrees/<issue>-<slug>` — or strands the feature worktree on `main`, after the remote merge already succeeded. The local branch and its worktree are left `[gone]` for `reap.sh`, which removes the worktree before deleting the branch and keeps either when it holds anything unmerged.
262
+
253
263
  Then re-fetch and **re-evaluate the queue from scratch** — labels and numbers move while CI runs, and a merge newly unblocks or blocks others.
254
264
 
255
265
  **Staleness fires *within* a pass, and it compounds.** The first merge makes every other PR behind — including the second of this same pass, verified green minutes ago. The gate's `behind` re-reads currency before **each** merge, and refuses a behind head as `behind:<n>` — step 3.1's ordinary skip-and-report arm, same as any other exit 1: label untouched, report `behind:<n>-#<pr>`, move on to the next candidate. That PR is rebased again only if it is still labelled when a **later** merge in this pass drives the next queue re-evaluation from scratch (step 4's last line) and selects it fresh from step 1 — nothing retries it on the strength of the skip alone, and a pass that merges nothing else after skipping it reports the skip, not a retry. Any behind-count handed to you at dispatch is already expired.
@@ -258,7 +268,7 @@ Measured over one three-merge pass: the next queue member went 0 → 2 → 7 →
258
268
 
259
269
  **A PR whose heavy jobs have only ever `skipped` is getting its first real verification from your rebase.** Reviewers may legitimately have labelled on the checks that did run plus local evidence, saying so explicitly. When your post-rebase run finally executes those suites, treat a red there as a **genuine first result**, not a regression you caused — read the failing job before concluding, and do not hand it back as "the rebase broke it".
260
270
 
261
- Report merged / skipped-unlabeled / held-behind-#X / worktree-diverged-#X / head-moved-after-label-#X / label-drop-failed-#X / rebase-fallback-#X / instrument-set-changed-#X / `<reason>-#X` for any other gate refusal / blocked after the pass — a dispatched bot once, at exit, after its grace (**Grace, then one report**, below).
271
+ Report merged / skipped-unlabeled / held-behind-#X / worktree-diverged-#X / head-moved-after-label-#X / label-drop-failed-#X / branch-delete-failed-#X / branch-kept-#X (X the open PR that keeps the merged branch — a keep, not a failure) / rebase-fallback-#X / instrument-set-changed-#X / `<reason>-#X` for any other gate refusal / blocked after the pass — a dispatched bot once, at exit, after its grace (**Grace, then one report**, below).
262
272
 
263
273
  ## No-undo audit (before every rebase)
264
274
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "0.0.0",
3
+ "version": "3.16.3",
4
4
  "description": "Agent fleet: run-team controller, merge bot, PR reviewer, and the ticket pipeline they share",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -18,6 +18,8 @@
18
18
  "NOTICE"
19
19
  ],
20
20
  "omp": {
21
- "extensions": ["scripts/member-write-guard.mjs"]
21
+ "extensions": [
22
+ "scripts/member-write-guard.mjs"
23
+ ]
22
24
  }
23
25
  }
@@ -1,9 +1,10 @@
1
1
  import { test } from "node:test";
2
2
  import assert from "node:assert/strict";
3
3
  import { spawnSync } from "node:child_process";
4
- import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, chmodSync, symlinkSync, copyFileSync, realpathSync } from "node:fs";
5
- import { tmpdir } from "node:os";
4
+ import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, chmodSync, symlinkSync, realpathSync } from "node:fs";
5
+ import { tempDir } from "./temp-dir.mjs";
6
6
  import { join, dirname, relative } from "node:path";
7
+ import { writeExecStub } from "./exec-stub.mjs";
7
8
 
8
9
  // This repository's own test runner, `./agent-test` at the repo root: the
9
10
  // `node --test` argument shim that left claim-ticket.sh's emitter for a
@@ -11,6 +12,9 @@ import { join, dirname, relative } from "node:path";
11
12
  // what they assert; only the fixture changed — the runner is copied into a
12
13
  // fixture tree rather than emitted by a claim.
13
14
  const RUNNER = join(import.meta.dirname, "..", "..", "agent-test");
15
+ // Installed through `writeExecStub`, never copied: a copy is a new executable
16
+ // inode per fixture, and macOS scans each one on its first exec.
17
+ const RUNNER_BODY = readFileSync(RUNNER, "utf8");
14
18
 
15
19
  // `node --test` marks the processes it spawns, and an inherited mark makes
16
20
  // the runner's own `node --test` report to a parent that is not listening —
@@ -37,8 +41,8 @@ function runnerEnv() {
37
41
  // it (and the copy of the suite sitting in it) is part of what the
38
42
  // vendored-path guards have to ignore, and only a fixture built under a
39
43
  // `node_modules` parent can pin that.
40
- function apply(files, parent = tmpdir()) {
41
- const dir = mkdtempSync(join(parent, "claim-"));
44
+ function apply(files, parent = null) {
45
+ const dir = parent === null ? tempDir("claim-") : mkdtempSync(join(parent, "claim-"));
42
46
  const wt = join(dir, ".worktrees", "42-slug");
43
47
  for (const root of [dir, wt]) {
44
48
  mkdirSync(root, { recursive: true });
@@ -47,8 +51,7 @@ function apply(files, parent = tmpdir()) {
47
51
  writeFileSync(join(root, name), body);
48
52
  }
49
53
  }
50
- copyFileSync(RUNNER, join(wt, "agent-test"));
51
- chmodSync(join(wt, "agent-test"), 0o755);
54
+ writeExecStub(join(wt, "agent-test"), RUNNER_BODY);
52
55
  const env = runnerEnv();
53
56
  return {
54
57
  wt,
@@ -148,13 +151,13 @@ test("runner: a directory whose path holds a space still runs its tests", () =>
148
151
  // deleting both pins keeps this test green.
149
152
  test("runner: an invalid UTF-8 byte in a discovered path does not drop it", () => {
150
153
  const a = apply(SUITE);
151
- const bin = mkdtempSync(join(tmpdir(), "claim-locale-"));
154
+ const bin = tempDir("claim-locale-");
152
155
  // The byte cannot be spelled in JS — node re-encodes every string as UTF-8 on
153
156
  // the way to argv, turning `\xFF` into the two valid bytes `\303\277`. POSIX
154
157
  // `printf` interprets the octal escape, so the fixture stays pure ASCII and
155
158
  // the shell makes the byte.
156
- writeFileSync(join(bin, "find"), "#!/bin/sh\nprintf 't/b\\377ad.test.mjs\\nt/ok.test.mjs\\n'\n", { mode: 0o755 });
157
- writeFileSync(join(bin, "node"), '#!/bin/sh\nprintf %s "$#"\n', { mode: 0o755 });
159
+ writeExecStub(join(bin, "find"), "#!/bin/sh\nprintf 't/b\\377ad.test.mjs\\nt/ok.test.mjs\\n'\n");
160
+ writeExecStub(join(bin, "node"), '#!/bin/sh\nprintf %s "$#"\n');
158
161
  const r = spawnSync(join(a.wt, "agent-test"), ["t"], {
159
162
  cwd: a.wt,
160
163
  encoding: "utf8",
@@ -268,7 +271,7 @@ test("runner: a symlink to a directory containing a vendored tree still runs its
268
271
  // resolving outside) also passes the refusal leg alone.
269
272
  test("runner: a symlink to a vendored tree outside the worktree refuses", () => {
270
273
  const a = apply(SUITE);
271
- const outside = mkdtempSync(join(tmpdir(), "outside-"));
274
+ const outside = tempDir("outside-");
272
275
  const vendor = join(outside, "node_modules", "pkg");
273
276
  mkdirSync(vendor, { recursive: true });
274
277
  writeFileSync(join(vendor, "v.test.mjs"), PASSES);
@@ -301,7 +304,7 @@ test("runner: a symlink to a vendored tree outside the worktree refuses", () =>
301
304
  // and resolved forms are asserted side by side here because agreement between
302
305
  // them, not any single row, is the property.
303
306
  test("runner: a node_modules in the worktree's own ancestry refuses nothing", () => {
304
- const under = join(mkdtempSync(join(tmpdir(), "anc-")), "node_modules");
307
+ const under = join(tempDir("anc-"), "node_modules");
305
308
  mkdirSync(under, { recursive: true });
306
309
  const a = apply(SUITE, under);
307
310
  for (const [args, count] of [
@@ -380,7 +383,7 @@ test("runner: a node_modules in the worktree's own ancestry refuses nothing", ()
380
383
  // must still run, which is #230's property and what separates this test from
381
384
  // one that merely refuses everything spelled from outside.
382
385
  test("runner: a relative argument through the shared ancestor is refused from outside the worktree", () => {
383
- const under = join(mkdtempSync(join(tmpdir(), "anc-")), "node_modules");
386
+ const under = join(tempDir("anc-"), "node_modules");
384
387
  mkdirSync(under, { recursive: true });
385
388
  const a = apply(SUITE, under);
386
389
  // Four levels up from the worktree: `42-slug` -> `.worktrees` -> `claim-XXXX`
@@ -421,7 +424,7 @@ test("runner: a relative argument through the shared ancestor is refused from ou
421
424
  // vendored legs it must keep refusing are the two tests above, which this one
422
425
  // deliberately does not repeat.
423
426
  test("runner: a resolution outside the worktree is judged from the divergence, not the runner's own root", () => {
424
- const ancestor = join(mkdtempSync(join(tmpdir(), "anc-")), "node_modules");
427
+ const ancestor = join(tempDir("anc-"), "node_modules");
425
428
  mkdirSync(ancestor, { recursive: true });
426
429
  const a = apply(SUITE, ancestor);
427
430
  // A sibling of the repo, so the argument diverges ABOVE the worktree while
@@ -487,10 +490,9 @@ test("runner: the divergence walk ends on an argument that resolves TO the share
487
490
  // is always `.worktrees/<issue>-<slug>`, which cannot be that name. So the
488
491
  // runner is copied straight into a `node_modules` directory instead — same
489
492
  // bytes, and no worktree the assertions below never inspect.
490
- const home = join(mkdtempSync(join(tmpdir(), "nm-")), "node_modules");
493
+ const home = join(tempDir("nm-"), "node_modules");
491
494
  mkdirSync(home, { recursive: true });
492
- copyFileSync(RUNNER, join(home, "agent-test"));
493
- chmodSync(join(home, "agent-test"), 0o755);
495
+ writeExecStub(join(home, "agent-test"), RUNNER_BODY);
494
496
  writeFileSync(join(home, "a.test.mjs"), PASSES);
495
497
  // Vendored content one level in, where the exemption is at its widest: the
496
498
  // runner's own directory name IS the excluded word, and the guard still has
@@ -521,7 +523,7 @@ test("runner: the divergence walk ends on an argument that resolves TO the share
521
523
  // The walk reaches the equality three iterations down rather than on the
522
524
  // first, and the runner is unmoved, so this row cannot be dismissed as an
523
525
  // artifact of relocating one.
524
- const under = join(mkdtempSync(join(tmpdir(), "anc-")), "node_modules");
526
+ const under = join(tempDir("anc-"), "node_modules");
525
527
  mkdirSync(under, { recursive: true });
526
528
  const a = apply(SUITE, under);
527
529
  // 12: the six test files of the committed fixture, once in the repo's own
@@ -595,8 +597,8 @@ test("runner: a directory with no test files refuses instead of exiting 0", () =
595
597
  // reported as ITS failure, not folded into the empty-directory message.
596
598
  test("runner: a grep failure mid-scan is reported distinctly from an empty result", () => {
597
599
  const a = apply(SUITE);
598
- const bin = mkdtempSync(join(tmpdir(), "claim-grepfail-"));
599
- writeFileSync(join(bin, "grep"), "#!/bin/sh\nexit 2\n", { mode: 0o755 });
600
+ const bin = tempDir("claim-grepfail-");
601
+ writeExecStub(join(bin, "grep"), "#!/bin/sh\nexit 2\n");
600
602
  const r = spawnSync(join(a.wt, "agent-test"), ["t"], {
601
603
  cwd: a.wt,
602
604
  encoding: "utf8",
@@ -613,8 +615,8 @@ test("runner: a grep failure mid-scan is reported distinctly from an empty resul
613
615
  // from grep's — the failure must still name sed, not grep or "no test files".
614
616
  test("runner: a sed failure mid-scan is reported distinctly from an empty result", () => {
615
617
  const a = apply(SUITE);
616
- const bin = mkdtempSync(join(tmpdir(), "claim-sedfail-"));
617
- writeFileSync(join(bin, "sed"), "#!/bin/sh\nexit 2\n", { mode: 0o755 });
618
+ const bin = tempDir("claim-sedfail-");
619
+ writeExecStub(join(bin, "sed"), "#!/bin/sh\nexit 2\n");
618
620
  const r = spawnSync(join(a.wt, "agent-test"), ["t"], {
619
621
  cwd: a.wt,
620
622
  encoding: "utf8",
@@ -637,8 +639,8 @@ test("runner: a sed failure mid-scan is reported distinctly from an empty result
637
639
  // asserting `no test files under t` instead of a reported sed failure.)
638
640
  test("runner: a BSD-style sed rc-1 failure is reported, not tolerated as a no-match analog", () => {
639
641
  const a = apply(SUITE);
640
- const bin = mkdtempSync(join(tmpdir(), "claim-sedrc1-"));
641
- writeFileSync(join(bin, "sed"), "#!/bin/sh\nexit 1\n", { mode: 0o755 });
642
+ const bin = tempDir("claim-sedrc1-");
643
+ writeExecStub(join(bin, "sed"), "#!/bin/sh\nexit 1\n");
642
644
  const r = spawnSync(join(a.wt, "agent-test"), ["t"], {
643
645
  cwd: a.wt,
644
646
  encoding: "utf8",
@@ -657,8 +659,8 @@ test("runner: a BSD-style sed rc-1 failure is reported, not tolerated as a no-ma
657
659
  // "no test files" message, not the new "grep exited" one.
658
660
  test("runner: grep's plain no-match rc still reads as no test files, not a grep failure", () => {
659
661
  const a = apply(SUITE);
660
- const bin = mkdtempSync(join(tmpdir(), "claim-grepnomatch-"));
661
- writeFileSync(join(bin, "grep"), "#!/bin/sh\nexit 1\n", { mode: 0o755 });
662
+ const bin = tempDir("claim-grepnomatch-");
663
+ writeExecStub(join(bin, "grep"), "#!/bin/sh\nexit 1\n");
662
664
  const r = spawnSync(join(a.wt, "agent-test"), ["t"], {
663
665
  cwd: a.wt,
664
666
  encoding: "utf8",
@@ -917,8 +919,10 @@ test("runner: a vendored directory with no search bit is refused as vendored, no
917
919
  // Root can read anything, so it cannot see this.
918
920
  test("runner: an unreadable directory under a node_modules ancestor names the read fault in every spelling", (t) => {
919
921
  if (process.getuid?.() === 0) return t.skip("root searches every directory");
920
- const real = mkdtempSync(join(tmpdir(), "anc-"));
921
- const spelled = `${real}-link`;
922
+ const base = tempDir("anc-");
923
+ const real = join(base, "real");
924
+ const spelled = join(base, "link");
925
+ mkdirSync(real);
922
926
  symlinkSync(real, spelled);
923
927
  mkdirSync(join(real, "node_modules"), { recursive: true });
924
928
  const a = apply(SUITE, join(spelled, "node_modules"));
@@ -1090,7 +1094,7 @@ test("runner: a vendored file argument refuses under an inherited CDPATH", () =>
1090
1094
  const vendor = join(a.wt, "node_modules", "plain");
1091
1095
  mkdirSync(vendor, { recursive: true });
1092
1096
  writeFileSync(join(vendor, "v.test.mjs"), PASSES);
1093
- const decoy = mkdtempSync(join(tmpdir(), "cdpath-decoy-"));
1097
+ const decoy = tempDir("cdpath-decoy-");
1094
1098
  mkdirSync(join(decoy, "node_modules", "plain"), { recursive: true });
1095
1099
  const r = spawnSync(join(a.wt, "agent-test"), ["t/a.test.mjs", "node_modules/plain/v.test.mjs"], {
1096
1100
  cwd: a.wt,
@@ -1277,7 +1281,7 @@ test("runner: a symlink to a vendored file refuses however it is spelled", () =>
1277
1281
  // directory would already have caught, kept so the fix is not narrowed to
1278
1282
  // final-component links alone.
1279
1283
  symlinkSync(join("node_modules", "pkg"), join(a.wt, "dirlink"));
1280
- const outside = mkdtempSync(join(tmpdir(), "outside-"));
1284
+ const outside = tempDir("outside-");
1281
1285
  mkdirSync(join(outside, "node_modules", "pkg"), { recursive: true });
1282
1286
  writeFileSync(join(outside, "node_modules", "pkg", "o.test.mjs"), PASSES);
1283
1287
  symlinkSync(join(outside, "node_modules", "pkg", "o.test.mjs"), join(a.wt, "extlink.test.mjs"));
@@ -1334,7 +1338,7 @@ test("runner: a symlink to a vendored file refuses however it is spelled", () =>
1334
1338
  test("runner: a symlink to a non-vendored file still runs", () => {
1335
1339
  const a = apply(SUITE);
1336
1340
  symlinkSync(join("t", "b.test.mjs"), join(a.wt, "oklink.test.mjs"));
1337
- const outside = mkdtempSync(join(tmpdir(), "outside-ok-"));
1341
+ const outside = tempDir("outside-ok-");
1338
1342
  mkdirSync(join(outside, "lib", "node_modules"), { recursive: true });
1339
1343
  writeFileSync(join(outside, "lib", "o.test.mjs"), PASSES);
1340
1344
  symlinkSync(join(outside, "lib", "o.test.mjs"), join(a.wt, "sidelink.test.mjs"));
@@ -1387,8 +1391,8 @@ test("runner: an unresolvable argument refuses rather than running unchecked", (
1387
1391
  mkdirSync(vendor, { recursive: true });
1388
1392
  writeFileSync(join(vendor, "v.test.mjs"), PASSES);
1389
1393
  symlinkSync(join("node_modules", "pkg", "v.test.mjs"), join(a.wt, "vendlink.test.mjs"));
1390
- const bin = mkdtempSync(join(tmpdir(), "no-realpath-"));
1391
- writeFileSync(join(bin, "realpath"), "#!/bin/sh\nexit 127\n", { mode: 0o755 });
1394
+ const bin = tempDir("no-realpath-");
1395
+ writeExecStub(join(bin, "realpath"), "#!/bin/sh\nexit 127\n");
1392
1396
  // The vendored spelling goes FIRST: every file argument is judged, so the
1393
1397
  // refusal names whichever one the loop reaches first, and naming this one is
1394
1398
  // what shows the guard is still armed rather than merely dying early.
@@ -36,7 +36,7 @@
36
36
  // What this file does NOT pin: per-site behaviour, or that EVERY git-naming
37
37
  // line in a COVERED file individually reaches `gitEnv(`. That lives in each
38
38
  // file's own test file, behaviourally — ledger.test.mjs, pr-overlap.test.mjs,
39
- // repo-root.test.mjs, ci-state.test.mjs, staleness.test.mjs — where a mutation
39
+ // repo-root.test.mjs, staleness.test.mjs — where a mutation
40
40
  // that deletes any ONE of a multi-site file's scrub calls (repo-root.mjs
41
41
  // carries three separate ones) reds exactly the fixture built for that site
42
42
  // and leaves its siblings green; that per-site isolation is what a source
@@ -141,10 +141,9 @@ const countGitEnvCalls = (src) =>
141
141
  // `gitEnv()` — this ticket's fix. Each value is the exact number of
142
142
  // `gitEnv(` call EXPRESSIONS the file's own code carries today, derived once
143
143
  // by reading it rather than guessed, and written out rather than computed
144
- // from the git-call count above: the two numbers disagree on purpose in the
145
- // two files with a wrapper indirection (ci-state.mjs's `tryRun`,
146
- // staleness.mjs's `git`), where several named call sites share ONE spawn
147
- // primitive and therefore one scrub.
144
+ // from the git-call count above: the two numbers disagree on purpose in
145
+ // staleness.mjs, whose `git` wrapper is ONE spawn primitive several named
146
+ // call sites share, and therefore one scrub.
148
147
  const COVERED_MJS = {
149
148
  // Three separate `spawnSync`/`execFileSync` calls, no shared wrapper —
150
149
  // `isTrackedBy()`, `repoRoot()`, `trackedFiles()` (behind all three of
@@ -155,16 +154,9 @@ const COVERED_MJS = {
155
154
  // on BOTH — no half here is inert the uniform way
156
155
  // `ambient-git-vars-prose.test.mjs`'s `inflight.sh`/`derive-testcmd.sh` are.
157
156
  "repo-root.mjs": 3,
158
- // ONE spawn primitive (`tryRun`), reused for both this file's named git
159
- // call sites (`workflowsPath()`'s rev-parse, the behind-count block's
160
- // `remote get-url origin`) and for every `gh` call in the file — scrubbing
161
- // once at the primitive protects both, and is harmless for `gh`, which
162
- // reads neither name.
163
- "ci-state.mjs": 1,
164
157
  // ONE spawn primitive (`git(args)`), reused for all four of this file's
165
158
  // named git call sites (`rev-parse --show-toplevel`, then three `-C root`
166
- // calls) — same shape as ci-state.mjs's `tryRun`, one scrub for the whole
167
- // set.
159
+ // calls) — one scrub for the whole set.
168
160
  "staleness.mjs": 1,
169
161
  // ONE spawn primitive, `trackedBasenameCounts()`'s own `git ls-files -z`.
170
162
  "pr-overlap.mjs": 1,
@@ -228,6 +220,24 @@ const COVERED_MJS = {
228
220
  // member-write-guard.test.mjs, "an ambient GIT_DIR naming another repository
229
221
  // does not change the answer".
230
222
  "member-write-guard.mjs": 1,
223
+ // ONE spawn primitive, `git(what, args, cwd, env)`, behind both of the
224
+ // file's git calls — `resolveMainCheckout()`'s `rev-parse --git-common-dir`
225
+ // and `snapshot()`'s `status --porcelain -uall` (#2210). An ambient GIT_DIR
226
+ // would answer both for another repository, so the tick would compare —
227
+ // and `--record` would baseline — the wrong tree. Measured in
228
+ // main-checkout.test.mjs, "an ambient GIT_DIR naming another repository
229
+ // does not change the answer (#1599)".
230
+ "main-checkout.mjs": 1,
231
+ // ONE spawn primitive, `git(repo, args, what)`, behind all four of the
232
+ // file's git calls — the merge-base against `origin/main`, the diff the
233
+ // touched lines come from, `rev-parse --show-toplevel` (#2342), and
234
+ // `rev-parse --git-common-dir`, which locates the ledger. An ambient GIT_DIR
235
+ // would answer all four for another repository and judge the record against
236
+ // that repository's diff and write its verdict to that repository's ledger.
237
+ // Measured in dispositions-check.test.mjs, "an ambient GIT_DIR naming
238
+ // another repository does not change the answer" (the diff and merge-base)
239
+ // and "… does not change which ledger is found" (the common dir).
240
+ "dispositions-check.mjs": 1,
231
241
  };
232
242
 
233
243
  // The two-name-only exemption list #1599's second design question answers
@@ -28,6 +28,7 @@ import assert from "node:assert/strict";
28
28
  import { spawnSync } from "node:child_process";
29
29
  import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
30
30
  import { tmpdir } from "node:os";
31
+ import { writeExecStub } from "./exec-stub.mjs";
31
32
  import { join } from "node:path";
32
33
  import { fileURLToPath } from "node:url";
33
34
 
@@ -135,7 +136,7 @@ function run(t, { spec: specObj, list = listed([42, "main", "Repository"]), list
135
136
  const bin = join(dir, "bin");
136
137
  mkdirSync(fix);
137
138
  mkdirSync(bin);
138
- writeFileSync(join(bin, "gh"), GH_STUB, { mode: 0o755 });
139
+ writeExecStub(join(bin, "gh"), GH_STUB);
139
140
 
140
141
  const specFile = join(dir, "spec.json");
141
142
  if (specObj !== undefined) {
@@ -175,8 +176,8 @@ function pathWith(t, names) {
175
176
  for (const n of names) {
176
177
  // `gh` is the stub even here: this PATH exists to make one tool missing,
177
178
  // never to let a real API call out.
178
- if (n === "gh") writeFileSync(join(dir, n), GH_STUB, { mode: 0o755 });
179
- else writeFileSync(join(dir, n), `#!/bin/sh\nexec ${which(n)} "$@"\n`, { mode: 0o755 });
179
+ if (n === "gh") writeExecStub(join(dir, n), GH_STUB);
180
+ else writeExecStub(join(dir, n), `#!/bin/sh\nexec ${which(n)} "$@"\n`);
180
181
  }
181
182
  return dir;
182
183
  }
@@ -287,6 +287,7 @@ test("every script the roster grep returns refuses a stray flag in its own wordi
287
287
  const GUARD_FIRST_FIXTURE = {
288
288
  "scripts/ci-state.mjs": ["--pr", "1"],
289
289
  "scripts/diff-stats.mjs": ["--pr", "1"],
290
+ "scripts/dispositions-check.mjs": ["--member", "fix-pr-1", "--scratch", "1"],
290
291
  "scripts/merge-gate.mjs": ["--pr", "1", "--pre", "0".repeat(40)],
291
292
  "scripts/pr-overlap.mjs": ["--a", "1", "--b", "1"],
292
293
  "scripts/staleness.mjs": ["--path", "1", "--gone", "1"],
@@ -1,11 +1,12 @@
1
1
  import { test } from "node:test";
2
2
  import assert from "node:assert";
3
- import { readFileSync, writeFileSync, mkdtempSync, existsSync, rmSync } from "node:fs";
3
+ import { readFileSync, writeFileSync, existsSync, rmSync } from "node:fs";
4
4
  import { spawnSync } from "node:child_process";
5
5
  import { fileURLToPath } from "node:url";
6
- import { tmpdir } from "node:os";
6
+ import { tempDir } from "./temp-dir.mjs";
7
7
  import { join } from "node:path";
8
8
  import { stripComments } from "./strip-comments.mjs";
9
+ import { writeExecStub } from "./exec-stub.mjs";
9
10
 
10
11
  const ARG_MODULE = fileURLToPath(new URL("./arg.mjs", import.meta.url));
11
12
 
@@ -81,7 +82,7 @@ test("every fleet script wires die() to arg.mjs's makeDie under its own NAME —
81
82
  // on fd 2), and a regex over the template literal would pin the spelling while
82
83
  // still proving nothing about what reaches the fd.
83
84
  test("die()'s refusal starts its own line even when a partial line is already on fd 2", () => {
84
- const dir = mkdtempSync(join(tmpdir(), "arg-die-"));
85
+ const dir = tempDir("arg-die-");
85
86
  writeFileSync(join(dir, "arg.mjs"), readFileSync(ARG_MODULE));
86
87
  writeFileSync(join(dir, "run.mjs"), [
87
88
  'import { writeSync } from "node:fs";',
@@ -123,7 +124,7 @@ test("die() keeps exit 2 when its own writeSync throws — the guard executed, n
123
124
  // Measured on darwin: guarded, exit 2; with the try/catch reverted, exit 1.
124
125
  // That is the #299 inversion itself, reproduced without the race, so this is
125
126
  // the assertion that discriminates on a machine where EAGAIN never fires.
126
- const dir = mkdtempSync(join(tmpdir(), "arg-die-throw-"));
127
+ const dir = tempDir("arg-die-throw-");
127
128
  writeFileSync(join(dir, "arg.mjs"), readFileSync(ARG_MODULE));
128
129
  writeFileSync(join(dir, "run.mjs"), [
129
130
  'import { closeSync } from "node:fs";',
@@ -155,7 +156,7 @@ test("die() keeps exit 2 when its own writeSync throws — the guard executed, n
155
156
  // different (already-handled) failure this loop's cap is not needed for.
156
157
  test("die() exits 2 within a bound even when stderr is a saturated pipe whose reader never drains — #889's retry cap", (t) => {
157
158
  if (spawnSync("python3", ["-c", ""]).status !== 0) return t.skip("needs python3");
158
- const dir = mkdtempSync(join(tmpdir(), "arg-die-stall-"));
159
+ const dir = tempDir("arg-die-stall-");
159
160
  writeFileSync(join(dir, "arg.mjs"), readFileSync(ARG_MODULE));
160
161
  writeFileSync(join(dir, "run.mjs"), [
161
162
  'import { makeDie } from "./arg.mjs";',
@@ -286,7 +287,7 @@ function spawnUntilShortWrite(runScript, recordPath) {
286
287
  // never the limiting factor here (measured: every run delivered the message
287
288
  // whole).
288
289
  test("die() resumes from a genuine short write and delivers the full message, not just the first pipe buffer", (t) => {
289
- const dir = mkdtempSync(join(tmpdir(), "arg-die-short-"));
290
+ const dir = tempDir("arg-die-short-");
290
291
  // The fixture embeds the message, so this is the largest dir this file
291
292
  // creates; reaped here the way staleness.test.mjs reaps its own repos.
292
293
  t.after(() => rmSync(dir, { recursive: true, force: true }));
@@ -404,7 +405,7 @@ test("writeAll()'s loop consumes writeSync's return value, resets its EAGAIN ret
404
405
  // the fd really did short-write rather than take everything at once, retried
405
406
  // the same way when a spawn loses the race.
406
407
  test("writeAll() returns true and delivers every byte across a genuine short write — the case it must never refuse", (t) => {
407
- const dir = mkdtempSync(join(tmpdir(), "arg-writeall-short-"));
408
+ const dir = tempDir("arg-writeall-short-");
408
409
  t.after(() => rmSync(dir, { recursive: true, force: true }));
409
410
  writeFileSync(join(dir, "arg.mjs"), readFileSync(ARG_MODULE));
410
411
  const payload = "w".repeat(SHORT_WRITE_BYTES);
@@ -453,7 +454,7 @@ test("writeAll() returns true and delivers every byte across a genuine short wri
453
454
  // a write that is genuinely lost has to come back false, or a caller that
454
455
  // promised "a failed write is a could-not-check" silently reports success.
455
456
  test("writeAll() returns false when the write is genuinely lost, not merely delayed", (t) => {
456
- const dir = mkdtempSync(join(tmpdir(), "arg-writeall-lost-"));
457
+ const dir = tempDir("arg-writeall-lost-");
457
458
  t.after(() => rmSync(dir, { recursive: true, force: true }));
458
459
  writeFileSync(join(dir, "arg.mjs"), readFileSync(ARG_MODULE));
459
460
  writeFileSync(join(dir, "run.mjs"), [
@@ -536,7 +537,7 @@ test("writeAll() delivers the full payload across more confirmed EAGAIN stalls t
536
537
  Number.isFinite(MAX_EAGAIN_RETRIES),
537
538
  "arg.mjs no longer declares `const MAX_EAGAIN_RETRIES = <digits>;` — this test cannot say what its transfer has to cross",
538
539
  );
539
- const dir = mkdtempSync(join(tmpdir(), "arg-writeall-slowdrain-"));
540
+ const dir = tempDir("arg-writeall-slowdrain-");
540
541
  t.after(() => rmSync(dir, { recursive: true, force: true }));
541
542
  writeFileSync(join(dir, "arg.mjs"), readFileSync(ARG_MODULE));
542
543
  // Half again the cap: far enough past it that an accumulating counter
@@ -694,9 +695,9 @@ const GH_FLOOD = [
694
695
  // under test takes its execFileSync catch. The payload is a file the stub
695
696
  // `cat`s rather than shell-generated, to keep the byte count exact.
696
697
  function runWithFloodingGh(script, argv, bytes) {
697
- const dir = mkdtempSync(join(tmpdir(), "arg-die-flood-"));
698
+ const dir = tempDir("arg-die-flood-");
698
699
  writeFileSync(join(dir, "flood"), "z".repeat(bytes));
699
- writeFileSync(join(dir, "gh"), `#!/bin/sh\ncat "${join(dir, "flood")}" >&2\nexit 1\n`, { mode: 0o755 });
700
+ writeExecStub(join(dir, "gh"), `#!/bin/sh\ncat "${join(dir, "flood")}" >&2\nexit 1\n`);
700
701
  return spawnSync(
701
702
  process.execPath,
702
703
  [fileURLToPath(new URL(`./${script}.mjs`, import.meta.url)), ...argv],
@@ -780,12 +781,12 @@ function stubGhBin() {
780
781
  // silently writes no receipt. Baked in here rather than left to the ambient
781
782
  // `TMPDIR` so every machine runs the hazardous shape, not just one whose
782
783
  // TMPDIR happens to contain a space.
783
- const dir = mkdtempSync(join(tmpdir(), "arg sweep-"));
784
+ const dir = tempDir("arg sweep-");
784
785
  const receipt = join(dir, "gh-was-called");
785
786
  // `>> "$GH_LOG"`, not the interpolated path: ci-state.test.mjs's GH_STUB
786
787
  // form, which keeps the path out of the generated script text entirely so
787
788
  // there is no interpolation left to quote wrongly.
788
- writeFileSync(join(dir, "gh"), `#!/bin/sh\necho "$@" >> "$GH_LOG"\nexit 1\n`, { mode: 0o755 });
789
+ writeExecStub(join(dir, "gh"), `#!/bin/sh\necho "$@" >> "$GH_LOG"\nexit 1\n`);
789
790
  // The env is built HERE, beside the path it carries. `GH_LOG` is now what
790
791
  // makes the receipt work at all, so handing callers a ready env is what
791
792
  // keeps the two from drifting apart — a caller assembling its own would be
@@ -921,16 +922,15 @@ for (const { script, argv, flag } of NON_NUMERIC) {
921
922
  // happen. `$2` is the subcommand (`gh pr view <n> --json …`, `gh pr diff <n>
922
923
  // --name-only`), the same positional pr-overlap.test.mjs's own stub keys on.
923
924
  function stubGhAnswering() {
924
- const dir = mkdtempSync(join(tmpdir(), "arg num-"));
925
+ const dir = tempDir("arg num-");
925
926
  const receipt = join(dir, "gh-was-called");
926
- writeFileSync(
927
+ writeExecStub(
927
928
  join(dir, "gh"),
928
929
  '#!/bin/sh\necho "$@" >> "$GH_LOG"\ncase "$2" in\n' +
929
930
  " view) echo '{\"files\":[{\"path\":\"a.ts\",\"additions\":1,\"deletions\":0}],\"changedFiles\":1}' ;;\n" +
930
931
  " diff) echo src/shared.ts ;;\n" +
931
932
  " *) exit 1 ;;\n" +
932
933
  "esac\n",
933
- { mode: 0o755 },
934
934
  );
935
935
  return { dir, receipt, env: { ...process.env, PATH: `${dir}:${process.env.PATH}`, GH_LOG: receipt } };
936
936
  }
@@ -1051,7 +1051,7 @@ for (const { script, argv, stray } of STRAY_POSITIONALS) {
1051
1051
  // caller's own `table` object, so the same harness drives defineFlags()'s
1052
1052
  // wrong-kind refusals and its construction-time snapshot further down.
1053
1053
  function runFlags(argv, flags, positionals, body) {
1054
- const dir = mkdtempSync(join(tmpdir(), "arg-stray-unit-"));
1054
+ const dir = tempDir("arg-stray-unit-");
1055
1055
  writeFileSync(join(dir, "arg.mjs"), readFileSync(ARG_MODULE));
1056
1056
  writeFileSync(join(dir, "run.mjs"), [
1057
1057
  'import { makeDie, defineFlags } from "./arg.mjs";',
@@ -1296,7 +1296,7 @@ test("stray() leaves a `--`-prefixed token alone, even an unknown one", () => {
1296
1296
  // behaviourally, by diff-stats.test.mjs's `--pr --json` case: measured, hoisting
1297
1297
  // diff-stats.mjs's sweep above its `if (!pr)` guard turns that red.
1298
1298
  function runSweep(argv) {
1299
- const dir = mkdtempSync(join(tmpdir(), "arg-sweep-unit-"));
1299
+ const dir = tempDir("arg-sweep-unit-");
1300
1300
  writeFileSync(join(dir, "arg.mjs"), readFileSync(ARG_MODULE));
1301
1301
  writeFileSync(join(dir, "run.mjs"), [
1302
1302
  'import { makeDie, defineFlags } from "./arg.mjs";',