@feigi/fleet-ctl 0.0.0

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 (245) hide show
  1. package/.claude-plugin/plugin.json +9 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +18 -0
  4. package/agents/fleet-finisher.agent.md +7 -0
  5. package/agents/fleet-implementer-alt.agent.md +210 -0
  6. package/agents/fleet-implementer.agent.md +210 -0
  7. package/agents/fleet-merge-bot.agent.md +7 -0
  8. package/agents/fleet-review-comments.agent.md +40 -0
  9. package/agents/fleet-review-correctness.agent.md +43 -0
  10. package/agents/fleet-review-runner.agent.md +73 -0
  11. package/agents/fleet-review-silent-failure.agent.md +49 -0
  12. package/agents/fleet-review-simplify.agent.md +46 -0
  13. package/agents/fleet-review-snapshot.agent.md +24 -0
  14. package/agents/fleet-review-tests.agent.md +46 -0
  15. package/agents/fleet-review-types.agent.md +41 -0
  16. package/agents/fleet-review-verifier.agent.md +29 -0
  17. package/commands/review-and-fix.md +98 -0
  18. package/commands/run-merge-bot.md +357 -0
  19. package/commands/run-team-help.md +17 -0
  20. package/package.json +23 -0
  21. package/scripts/agent-test-dir-prose.test.mjs +59 -0
  22. package/scripts/agent-test.test.mjs +1636 -0
  23. package/scripts/ambient-git-vars-mjs-prose.test.mjs +354 -0
  24. package/scripts/ambient-git-vars-prose.test.mjs +192 -0
  25. package/scripts/ancestry-check-position-prose.test.mjs +175 -0
  26. package/scripts/apply-ruleset.test.mjs +420 -0
  27. package/scripts/arg-header-probes-prose.test.mjs +393 -0
  28. package/scripts/arg.mjs +600 -0
  29. package/scripts/arg.test.mjs +1354 -0
  30. package/scripts/board-cli.test.mjs +694 -0
  31. package/scripts/board-identity.test.mjs +429 -0
  32. package/scripts/board-liveness-banner.test.mjs +119 -0
  33. package/scripts/board-prev-shape.test.mjs +229 -0
  34. package/scripts/board-tryparse-null.test.mjs +119 -0
  35. package/scripts/board.html +471 -0
  36. package/scripts/board.mjs +2037 -0
  37. package/scripts/board.test.mjs +3086 -0
  38. package/scripts/brief-after-cut-prose.test.mjs +53 -0
  39. package/scripts/candidates-exit3-prose.test.mjs +302 -0
  40. package/scripts/candidates.mjs +674 -0
  41. package/scripts/candidates.test.mjs +2101 -0
  42. package/scripts/caveat-unification-prose.test.mjs +98 -0
  43. package/scripts/ci-comment-rot-prose.test.mjs +2025 -0
  44. package/scripts/ci-completes-premise-prose.test.mjs +257 -0
  45. package/scripts/ci-state-prose.test.mjs +113 -0
  46. package/scripts/ci-state.mjs +761 -0
  47. package/scripts/ci-state.test.mjs +1640 -0
  48. package/scripts/ci-vacuous-green.test.mjs +368 -0
  49. package/scripts/citation-sweep-prose.test.mjs +1572 -0
  50. package/scripts/claim-lifecycle.test.mjs +185 -0
  51. package/scripts/claim-ticket.sh +417 -0
  52. package/scripts/claim-ticket.test.mjs +1121 -0
  53. package/scripts/closing-keyword-prose.test.mjs +193 -0
  54. package/scripts/cockpit-launch-idempotent-prose.test.mjs +165 -0
  55. package/scripts/cockpit-tick-nonblocking.test.mjs +210 -0
  56. package/scripts/compute-board.mjs +579 -0
  57. package/scripts/compute-board.test.mjs +1060 -0
  58. package/scripts/compute-spend.mjs +329 -0
  59. package/scripts/compute-spend.test.mjs +451 -0
  60. package/scripts/cross-repo-citation-prose.test.mjs +156 -0
  61. package/scripts/cwd-isolation-pins.mjs +83 -0
  62. package/scripts/dedupe-guard-prose.test.mjs +243 -0
  63. package/scripts/derive-testcmd.sh +239 -0
  64. package/scripts/derive-testcmd.test.mjs +380 -0
  65. package/scripts/diff-stats.mjs +231 -0
  66. package/scripts/diff-stats.test.mjs +408 -0
  67. package/scripts/dispatch-block-golden-prose.test.mjs +1024 -0
  68. package/scripts/dispatch-block-pins-prose.test.mjs +615 -0
  69. package/scripts/drop-merged-label.sh +173 -0
  70. package/scripts/drop-merged-label.test.mjs +480 -0
  71. package/scripts/expected-jobs-prose.test.mjs +80 -0
  72. package/scripts/filing-bar-seat-prose.test.mjs +242 -0
  73. package/scripts/filing-claim-bar-prose.test.mjs +166 -0
  74. package/scripts/finisher-dispatch-premise-prose.test.mjs +312 -0
  75. package/scripts/finisher-halt-prose.test.mjs +106 -0
  76. package/scripts/finisher-name-prose.test.mjs +134 -0
  77. package/scripts/finisher-own-tree-prose.test.mjs +285 -0
  78. package/scripts/finisher-pin-race-prose.test.mjs +339 -0
  79. package/scripts/fix-applier-correction-rules-prose.test.mjs +201 -0
  80. package/scripts/fix-applier-result-file-prose.test.mjs +100 -0
  81. package/scripts/fleet-bootstrap +155 -0
  82. package/scripts/fleet-heartbeat.mjs +272 -0
  83. package/scripts/fleet-heartbeat.test.mjs +450 -0
  84. package/scripts/fleet-provenance +207 -0
  85. package/scripts/fleet-provenance.test.mjs +64 -0
  86. package/scripts/fleet-run +148 -0
  87. package/scripts/fleet-run.test.mjs +90 -0
  88. package/scripts/fleet-state.mjs +400 -0
  89. package/scripts/fleet-state.test.mjs +373 -0
  90. package/scripts/fleet-tick-prose.test.mjs +299 -0
  91. package/scripts/fleet-tick.mjs +832 -0
  92. package/scripts/fleet-tick.test.mjs +1332 -0
  93. package/scripts/force-with-lease-reason-prose.test.mjs +184 -0
  94. package/scripts/frontmatter-allowlist.json +64 -0
  95. package/scripts/frontmatter-check.mjs +256 -0
  96. package/scripts/frontmatter-check.test.mjs +436 -0
  97. package/scripts/git-env.mjs +124 -0
  98. package/scripts/git-env.test.mjs +149 -0
  99. package/scripts/git-status-untracked-mode-sweep.test.mjs +216 -0
  100. package/scripts/gone-walk.test.mjs +213 -0
  101. package/scripts/gp-sep-invariant-prose.test.mjs +188 -0
  102. package/scripts/head-moved-after-label-prose.test.mjs +233 -0
  103. package/scripts/immutable-body-claim-prose.test.mjs +413 -0
  104. package/scripts/implementer-model-tier.test.mjs +643 -0
  105. package/scripts/inflight-citation-prose.test.mjs +144 -0
  106. package/scripts/inflight-exit2-prose.test.mjs +81 -0
  107. package/scripts/inflight-probe-guard-prose.test.mjs +109 -0
  108. package/scripts/inflight-scan-scope-prose.test.mjs +57 -0
  109. package/scripts/inflight.sh +1106 -0
  110. package/scripts/inflight.test.mjs +2984 -0
  111. package/scripts/injection-control-prose.test.mjs +404 -0
  112. package/scripts/install-root-audit.test.mjs +464 -0
  113. package/scripts/instrument-check-prose.test.mjs +235 -0
  114. package/scripts/instruments.sh +394 -0
  115. package/scripts/instruments.test.mjs +787 -0
  116. package/scripts/issue-tracker-prose.test.mjs +71 -0
  117. package/scripts/json.sh +248 -0
  118. package/scripts/json.test.mjs +364 -0
  119. package/scripts/ledger-dispatch.test.mjs +516 -0
  120. package/scripts/ledger-grammar.mjs +85 -0
  121. package/scripts/ledger-grammar.test.mjs +142 -0
  122. package/scripts/ledger-read-require-file.test.mjs +197 -0
  123. package/scripts/ledger.mjs +1753 -0
  124. package/scripts/ledger.test.mjs +3554 -0
  125. package/scripts/line-distance-prose.test.mjs +245 -0
  126. package/scripts/liveness-rationale-prose.test.mjs +83 -0
  127. package/scripts/locale-pin-prose.test.mjs +189 -0
  128. package/scripts/member-outcome-prose.test.mjs +167 -0
  129. package/scripts/member-outcomes-header.test.mjs +148 -0
  130. package/scripts/member-outcomes-prose.test.mjs +63 -0
  131. package/scripts/member-outcomes.mjs +231 -0
  132. package/scripts/member-outcomes.test.mjs +507 -0
  133. package/scripts/member-prompt-prose.test.mjs +161 -0
  134. package/scripts/member-record.mjs +605 -0
  135. package/scripts/member-record.test.mjs +516 -0
  136. package/scripts/member-write-guard.mjs +279 -0
  137. package/scripts/member-write-guard.test.mjs +211 -0
  138. package/scripts/merge-commit-probe-prose.test.mjs +122 -0
  139. package/scripts/merge-gate.mjs +262 -0
  140. package/scripts/merge-gate.test.mjs +613 -0
  141. package/scripts/muted-git-guard-sweep.test.mjs +493 -0
  142. package/scripts/net-ssh-precedence-prose.test.mjs +91 -0
  143. package/scripts/net-watchdog-prose.test.mjs +79 -0
  144. package/scripts/net.sh +409 -0
  145. package/scripts/net.test.mjs +211 -0
  146. package/scripts/no-ci-gate-prose.test.mjs +108 -0
  147. package/scripts/no-undo-audit.sh +1134 -0
  148. package/scripts/no-undo-audit.test.mjs +3965 -0
  149. package/scripts/no-wave.test.mjs +138 -0
  150. package/scripts/node-floor-sweep.test.mjs +611 -0
  151. package/scripts/pointer-target-prose.test.mjs +186 -0
  152. package/scripts/pr-overlap.mjs +417 -0
  153. package/scripts/pr-overlap.test.mjs +695 -0
  154. package/scripts/printf-die-sweep.test.mjs +384 -0
  155. package/scripts/prompt-renderer.mjs +39 -0
  156. package/scripts/prompt-renderer.test.mjs +68 -0
  157. package/scripts/prose-pin.mjs +808 -0
  158. package/scripts/prose-pin.test.mjs +1034 -0
  159. package/scripts/prove-merge.sh +228 -0
  160. package/scripts/prove-merge.test.mjs +995 -0
  161. package/scripts/pull-table-relabel-prose.test.mjs +60 -0
  162. package/scripts/quiet-payload-prose.test.mjs +222 -0
  163. package/scripts/reap.sh +1768 -0
  164. package/scripts/reap.test.mjs +4395 -0
  165. package/scripts/reaping-prose.test.mjs +159 -0
  166. package/scripts/refuter-scratch-prose.test.mjs +135 -0
  167. package/scripts/release-label-required-prose.test.mjs +71 -0
  168. package/scripts/release-label-split-prose.test.mjs +169 -0
  169. package/scripts/release-ticket.sh +1716 -0
  170. package/scripts/release-ticket.test.mjs +5106 -0
  171. package/scripts/renovate-release-contract.test.mjs +379 -0
  172. package/scripts/repo-root.mjs +544 -0
  173. package/scripts/repo-root.test.mjs +873 -0
  174. package/scripts/reporter-output-rule-prose.test.mjs +208 -0
  175. package/scripts/review-agent-report-only.test.mjs +49 -0
  176. package/scripts/review-core-cwd-isolation.test.mjs +374 -0
  177. package/scripts/review-core-reads.test.mjs +478 -0
  178. package/scripts/review-core-refuter-scratch.test.mjs +148 -0
  179. package/scripts/review-core-snapshot-path.test.mjs +777 -0
  180. package/scripts/review-core-specialist-scratch.test.mjs +189 -0
  181. package/scripts/review-core-testcmd.test.mjs +288 -0
  182. package/scripts/review-core-unrun.test.mjs +530 -0
  183. package/scripts/review-core-unverified-discriminant.test.mjs +208 -0
  184. package/scripts/review-core.mjs +1028 -0
  185. package/scripts/review-eval-resolver-path.test.mjs +55 -0
  186. package/scripts/review-eval.mjs +197 -0
  187. package/scripts/review-host-fixture.mjs +73 -0
  188. package/scripts/review-in-run-retry.test.mjs +187 -0
  189. package/scripts/review-no-vendor-dispatch.test.mjs +45 -0
  190. package/scripts/review-path-default.test.mjs +796 -0
  191. package/scripts/review-runner-spawns.test.mjs +93 -0
  192. package/scripts/review-runner.test.mjs +155 -0
  193. package/scripts/review-tier-audit.test.mjs +140 -0
  194. package/scripts/run-artifact-pr-prose.test.mjs +341 -0
  195. package/scripts/run-merge-bot-prose.test.mjs +1391 -0
  196. package/scripts/scratch-partition-invariant-prose.test.mjs +74 -0
  197. package/scripts/scripts-path-citation-sweep.test.mjs +73 -0
  198. package/scripts/section-between-guard-prose.test.mjs +378 -0
  199. package/scripts/select-dimensions.test.mjs +674 -0
  200. package/scripts/shared-refusal.test.mjs +388 -0
  201. package/scripts/shell-traps-prose.test.mjs +507 -0
  202. package/scripts/shortlist.mjs +355 -0
  203. package/scripts/shortlist.test.mjs +366 -0
  204. package/scripts/slow-transport.mjs +72 -0
  205. package/scripts/snapshot-repo.test.mjs +772 -0
  206. package/scripts/snapshot-runner-audience-prose.test.mjs +129 -0
  207. package/scripts/spend-view.test.mjs +312 -0
  208. package/scripts/staleness-qualifier-prose.test.mjs +251 -0
  209. package/scripts/staleness-verdict-prose.test.mjs +142 -0
  210. package/scripts/staleness.mjs +414 -0
  211. package/scripts/staleness.test.mjs +893 -0
  212. package/scripts/stalled-member-liveness-prose.test.mjs +219 -0
  213. package/scripts/stash-prohibition-prose.test.mjs +313 -0
  214. package/scripts/strip-comments.mjs +44 -0
  215. package/scripts/tier-check.mjs +468 -0
  216. package/scripts/tier-check.test.mjs +726 -0
  217. package/scripts/tier-guard-gate-prose.test.mjs +216 -0
  218. package/scripts/tier-outcomes-header.test.mjs +586 -0
  219. package/scripts/tier-outcomes.mjs +441 -0
  220. package/scripts/tier-outcomes.test.mjs +342 -0
  221. package/scripts/tier-roles.mjs +250 -0
  222. package/scripts/tier-roles.test.mjs +316 -0
  223. package/scripts/tracker-block-copy-prose.test.mjs +288 -0
  224. package/scripts/triage-labels-gloss-prose.test.mjs +97 -0
  225. package/scripts/unattended-git-sweep.test.mjs +142 -0
  226. package/scripts/verify-sha-exit2-prose.test.mjs +269 -0
  227. package/scripts/verify-sha.sh +117 -0
  228. package/scripts/verify-sha.test.mjs +693 -0
  229. package/scripts/watcher-degraded-block.test.mjs +372 -0
  230. package/scripts/watcher-key-prose.test.mjs +106 -0
  231. package/scripts/within-run-pair-prose.test.mjs +208 -0
  232. package/scripts/worktree-audit.sh +482 -0
  233. package/scripts/worktree-audit.test.mjs +1407 -0
  234. package/scripts/worktree-head-prose.test.mjs +276 -0
  235. package/scripts/worktree-listing-sweep.test.mjs +217 -0
  236. package/scripts/worktree-model-prose.test.mjs +216 -0
  237. package/scripts/worktree.sh +470 -0
  238. package/skills/next-ticket/SKILL.md +138 -0
  239. package/skills/run-team/SKILL.md +3603 -0
  240. package/skills/run-team/references/ci-and-staleness.md +75 -0
  241. package/skills/run-team/references/correction-tickets.md +37 -0
  242. package/skills/run-team/references/isolation.md +23 -0
  243. package/skills/run-team/references/member-lifecycle.md +73 -0
  244. package/skills/run-team/references/reaping.md +73 -0
  245. package/skills/sizing-a-ticket/SKILL.md +39 -0
@@ -0,0 +1,1636 @@
1
+ import { test } from "node:test";
2
+ import assert from "node:assert/strict";
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";
6
+ import { join, dirname, relative } from "node:path";
7
+
8
+ // This repository's own test runner, `./agent-test` at the repo root: the
9
+ // `node --test` argument shim that left claim-ticket.sh's emitter for a
10
+ // repo-local runner (ADR 0015). These cases moved here with it, unchanged in
11
+ // what they assert; only the fixture changed — the runner is copied into a
12
+ // fixture tree rather than emitted by a claim.
13
+ const RUNNER = join(import.meta.dirname, "..", "..", "agent-test");
14
+
15
+ // `node --test` marks the processes it spawns, and an inherited mark makes
16
+ // the runner's own `node --test` report to a parent that is not listening —
17
+ // status 0 and not a byte of stdout. An artifact of testing a test runner
18
+ // from inside one; strip it so these assertions see what a member sees.
19
+ // FORCE_COLOR is stripped for the same reason: it reaches the runner's own
20
+ // `node --test`, which then SGR-wraps its summary even into a pipe
21
+ // (`\x1b[34mℹ pass 3\x1b[39m`), breaking every `run`/`runFrom` assertion
22
+ // that reads that summary literally. A developer with FORCE_COLOR set is
23
+ // exactly what these assertions have to survive, not exercise.
24
+ function runnerEnv() {
25
+ const env = { ...process.env };
26
+ delete env.NODE_TEST_CONTEXT;
27
+ delete env.NODE_TEST_WORKER_ID;
28
+ delete env.FORCE_COLOR;
29
+ return env;
30
+ }
31
+
32
+ // Lays `files` out the way a claim does — once in the repository's own
33
+ // checkout `<parent>/claim-XXXX` and once in its worktree
34
+ // `.worktrees/42-slug` under it — and puts the runner in the worktree. The
35
+ // layout is load-bearing: the runner judges an argument by where its
36
+ // resolution DIVERGES from the runner's own location, so the ancestry above
37
+ // it (and the copy of the suite sitting in it) is part of what the
38
+ // vendored-path guards have to ignore, and only a fixture built under a
39
+ // `node_modules` parent can pin that.
40
+ function apply(files, parent = tmpdir()) {
41
+ const dir = mkdtempSync(join(parent, "claim-"));
42
+ const wt = join(dir, ".worktrees", "42-slug");
43
+ for (const root of [dir, wt]) {
44
+ mkdirSync(root, { recursive: true });
45
+ for (const [name, body] of Object.entries(files)) {
46
+ mkdirSync(dirname(join(root, name)), { recursive: true });
47
+ writeFileSync(join(root, name), body);
48
+ }
49
+ }
50
+ copyFileSync(RUNNER, join(wt, "agent-test"));
51
+ chmodSync(join(wt, "agent-test"), 0o755);
52
+ const env = runnerEnv();
53
+ return {
54
+ wt,
55
+ env,
56
+ run: (...args) => spawnSync(join(wt, "agent-test"), args, { cwd: wt, encoding: "utf8", env }),
57
+ // The same runner invoked from a subdirectory. Node resolves argv against
58
+ // the cwd, so where a member stands is part of what an argument means.
59
+ runFrom: (sub, ...args) =>
60
+ spawnSync(join(wt, "agent-test"), args, { cwd: join(wt, sub), encoding: "utf8", env }),
61
+ };
62
+ }
63
+
64
+ const PASSES = 'import { test } from "node:test";\ntest("ok", () => {});\n';
65
+ // `root.test.mjs` exists so no assertion below can be satisfied by the argv
66
+ // being dropped: bare `node --test` discovers the whole fixture, and every
67
+ // count asserted here differs from that. Without it the two-file cases and
68
+ // discovery both landed on `pass 2`, and a test that cannot tell "argv was
69
+ // honoured" from "argv was discarded" pins nothing.
70
+ const SUITE = {
71
+ "t/a.test.mjs": PASSES,
72
+ "t/b.test.mjs": PASSES,
73
+ "t/nested/c.test.mjs": PASSES,
74
+ "root.test.mjs": PASSES,
75
+ "with space/s.test.mjs": PASSES,
76
+ "br[a]cket/g.test.mjs": PASSES,
77
+ "empty/README.md": "",
78
+ };
79
+
80
+ // `node --test <dir>` resolves the directory as a module specifier and dies
81
+ // with MODULE_NOT_FOUND before a single test runs. A directory is the
82
+ // ergonomic way to say "run this suite", and the red it produced was read as
83
+ // a finding against the diff under review rather than against the invocation.
84
+ // `pass 3` also pins the recursion: `t/` holds two files and `t/nested/` a
85
+ // third, so a `find` capped at one level reads as a red here.
86
+ test("runner: a directory argument runs the test files under it", () => {
87
+ const r = apply(SUITE).run("t");
88
+ assert.equal(r.status, 0, r.stdout + r.stderr);
89
+ // Bounded rather than line-anchored: a bare `pass 3` is a substring of
90
+ // `pass 3<n>` and stops discriminating once a fixture reaches 30, but a
91
+ // `^…$/m` anchor buys that at the cost of the line's raw edges — under a
92
+ // colored reporter the summary comes back SGR-wrapped (`\x1b[34mℹ pass 3…`),
93
+ // so it neither starts with the prefix nor ends with the digit. The reporter
94
+ // prefix plus a `(?!\d)` lookahead rejects `pass 30`-`pass 39` either way.
95
+ // Both prefixes because `node --test`'s default reporter is
96
+ // version-dependent — spec (`ℹ pass 3`) on newer node, tap (`# pass 3`) on
97
+ // older.
98
+ assert.match(r.stdout, /(?:ℹ|#) pass 3(?!\d)/);
99
+ });
100
+
101
+ // `set -f` and IFS only settle how the *shell* splits the expansion. Node
102
+ // globs its own argv afterwards, where a literal `[` is a bracket expression
103
+ // that cannot match itself — so an unescaped path matches nothing, node runs
104
+ // nothing, and it exits 0. That is the vacuous pass this shim exists to
105
+ // refuse, reached past the guard because `find` did match the file.
106
+ test("runner: a directory whose path holds a glob character still runs its tests", () => {
107
+ const r = apply(SUITE).run("br[a]cket");
108
+ assert.equal(r.status, 0, r.stdout + r.stderr);
109
+ // Bounded, same reason as above: a bare `pass 1` is the worst offender — it
110
+ // matches every count whose leading digit is 1: `pass 1` itself, 10-19, 100+.
111
+ assert.match(r.stdout, /(?:ℹ|#) pass 1(?!\d)/);
112
+ });
113
+
114
+ // The other half of the same claim: IFS pinned to a newline is what keeps a
115
+ // path with a space in it one word. On the default IFS it splits into two
116
+ // words node cannot resolve, and node drops unresolvable arguments silently.
117
+ test("runner: a directory whose path holds a space still runs its tests", () => {
118
+ const r = apply(SUITE).run("with space");
119
+ assert.equal(r.status, 0, r.stdout + r.stderr);
120
+ // Bounded, same reason as the glob-character case above.
121
+ assert.match(r.stdout, /(?:ℹ|#) pass 1(?!\d)/);
122
+ });
123
+
124
+ // #600: a filename is bytes, and the two tools that read find's output are told
125
+ // which only by the ambient locale. Under en_US.UTF-8 with a name holding \377,
126
+ // measured on macOS: `grep` drops that line silently — a green over a smaller
127
+ // suite, #582's own false-green — and BSD `sed`, fed that byte directly, abandons
128
+ // the whole stream ("RE error: illegal byte sequence", exit 1), which empties
129
+ // $files and refuses a suite that is right there. `LC_ALL=C` on each command is
130
+ // the fix.
131
+ //
132
+ // Two stubs, because neither half of the fixture can be built for real. APFS
133
+ // refuses the name outright (`Illegal byte sequence`), so no filesystem this
134
+ // suite can create holds it — `find` is stubbed to emit what a filesystem that
135
+ // does would. And node cannot be asked what it ran, so it is stubbed to report
136
+ // how many arguments survived discovery: `--test` plus both paths is 3, and the
137
+ // unpinned runner reaches this assertion with one of them (`2` — `--test` plus
138
+ // the one path grep's own silent drop lets through; `sed`'s abort never enters
139
+ // into it, since grep already dropped the bad line before sed would see it).
140
+ //
141
+ // LC_ALL is set on the child rather than inherited: the ambient locale is the
142
+ // hostile input here, so pre-seeding it is what makes the test discriminate at
143
+ // all instead of depending on the operator's environment.
144
+ //
145
+ // THE CEILING, inherited from locale-pin-prose.test.mjs: this kills its mutant
146
+ // on macOS only. GNU grep and sed are byte-oriented and pass every line through
147
+ // whatever the locale says, so on ubuntu-latest — the one platform ci.yml runs —
148
+ // deleting both pins keeps this test green.
149
+ test("runner: an invalid UTF-8 byte in a discovered path does not drop it", () => {
150
+ const a = apply(SUITE);
151
+ const bin = mkdtempSync(join(tmpdir(), "claim-locale-"));
152
+ // The byte cannot be spelled in JS — node re-encodes every string as UTF-8 on
153
+ // the way to argv, turning `\xFF` into the two valid bytes `\303\277`. POSIX
154
+ // `printf` interprets the octal escape, so the fixture stays pure ASCII and
155
+ // 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 });
158
+ const r = spawnSync(join(a.wt, "agent-test"), ["t"], {
159
+ cwd: a.wt,
160
+ encoding: "utf8",
161
+ env: { ...a.env, PATH: `${bin}:${a.env.PATH}`, LC_ALL: "en_US.UTF-8" },
162
+ });
163
+ assert.equal(r.status, 0, r.stdout + r.stderr);
164
+ assert.equal(r.stdout, "3", "discovery lost a path holding an invalid UTF-8 byte");
165
+ });
166
+
167
+ // The source-assertion half of #600, on both pins — same shape as
168
+ // locale-pin-prose.test.mjs, whose list covers plugin/scripts only; this
169
+ // runner is a repo-root file, so the decision is made here instead.
170
+ //
171
+ // This is the ONLY regression coverage the file-argument branch's own pin gets
172
+ // (`arg=$(printf '%s\n' "$arg" | LC_ALL=C sed …)`, below). A behavioural twin of
173
+ // the test above is not constructable for it, on either platform this suite
174
+ // runs on: `[ -e "$arg" ]` gates that line, and it needs a REAL file — APFS
175
+ // refuses to create one whose name holds an invalid UTF-8 byte at all (measured:
176
+ // `touch` on such a name exits "Illegal byte sequence", not just Node's own
177
+ // fs), and `[` is a shell builtin, not a PATH-resolved command, so it can't be
178
+ // stubbed the way `find` and `node` are above. Where the filesystem WOULD allow
179
+ // the name (ext4, ubuntu-latest — the platform CI actually runs), GNU sed's own
180
+ // byte-orientation makes the pin invisible anyway, same ceiling as the
181
+ // directory branch. Nothing behavioural can fail if this pin goes missing, on
182
+ // any platform available here — only a source check can.
183
+ test("agent-test still pins the locale on both find-output commands", () => {
184
+ const src = readFileSync(RUNNER, "utf8");
185
+ assert.equal((src.match(/LC_ALL=C grep\b/g) ?? []).length, 1,
186
+ "the directory branch's grep pin (find's output, above) went missing or moved");
187
+ assert.equal((src.match(/LC_ALL=C sed\b/g) ?? []).length, 2,
188
+ "one of the two sed pins (directory branch above, file-argument branch below) went missing");
189
+ });
190
+
191
+ // Why the trailing slash, and why not `-L`: agent-test, above `found=`.
192
+ // The symlink is written into the worktree rather than through `apply()` because
193
+ // the runner only ever stats a path in its cwd — whether a commit or a local
194
+ // `ln -s` put it there is invisible to it — and keeping it out of the shared
195
+ // fixture leaves every other count assertion in this file measuring what it
196
+ // measured before.
197
+ test("runner: a symlink to a directory runs the test files under it", () => {
198
+ const a = apply(SUITE);
199
+ symlinkSync("t", join(a.wt, "tlink"));
200
+ // `t/vendor` is the shape neither exclusion can see: a symlink into
201
+ // `node_modules` under another name — `-prune` matches the directory's own
202
+ // name and this one is called `vendor`, and the `case` guard reads the
203
+ // argument, which neither spells nor resolves into one. Measured: it
204
+ // is exactly as blind as the `-not -path` filter it replaced, both legs.
205
+ // The slash form does not descend it and reads 3; `find -L`
206
+ // sweeps the vendored test in and reads 4. Without this every test passes
207
+ // under `-L`, leaving the reasoning in agent-test as the only thing
208
+ // between a future tidy-up and a suite resting on third-party code.
209
+ mkdirSync(join(a.wt, "node_modules"), { recursive: true });
210
+ writeFileSync(join(a.wt, "node_modules", "v.test.mjs"), PASSES);
211
+ symlinkSync("../node_modules", join(a.wt, "t", "vendor"));
212
+ const r = a.run("tlink");
213
+ assert.equal(r.status, 0, r.stdout + r.stderr);
214
+ // Anchored for the same reason as the vendored-test count below: bare
215
+ // `pass 3` is a substring of `pass 3<n>` and stops discriminating once a
216
+ // fixture grows. 3 is `t/`'s own two files plus the one under `t/nested/`,
217
+ // so a `find` capped at one level reads as a red here too.
218
+ assert.match(r.stdout, /^(?:ℹ|#) pass 3$/m);
219
+ });
220
+
221
+ // #186: the argument itself is a symlink whose TARGET lies inside a vendored
222
+ // tree. Spelling can't see it — `vendlink` carries no `node_modules` in its
223
+ // own name — and `-prune` only fires on a dirent the walk descends THROUGH
224
+ // named `node_modules`; here the walk starts at the symlink's target,
225
+ // already past the vendored component, so neither existing guard sees it.
226
+ // Measured on the unfixed shim: `agent-test vendlink` exits 0 and reports
227
+ // the vendored test as a pass — the same green-over-third-party-code #109's
228
+ // prune exists to refuse, reached by a route neither mechanism covers.
229
+ test("runner: a symlink whose target is inside a vendored tree refuses", () => {
230
+ const a = apply(SUITE);
231
+ const vendor = join(a.wt, "node_modules", "pkg");
232
+ mkdirSync(vendor, { recursive: true });
233
+ writeFileSync(join(vendor, "v.test.mjs"), PASSES);
234
+ symlinkSync(join("node_modules", "pkg"), join(a.wt, "vendlink"));
235
+ const r = a.run("vendlink");
236
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
237
+ assert.match(r.stderr, /is under node_modules — excluded from the run/);
238
+ });
239
+
240
+ // The false-positive class of the same fix: a symlink to a directory that
241
+ // merely CONTAINS a vendored tree, rather than one whose own resolution ends
242
+ // inside it, must still run that directory's own tests and still exclude the
243
+ // real `node_modules` beneath it. Already true pre-fix (find's own prune
244
+ // handles it once the walk is inside), and must stay true — a resolved-path
245
+ // guard that widens into refusing every symlinked directory with
246
+ // `node_modules` somewhere underneath would regress this ordinary case.
247
+ test("runner: a symlink to a directory containing a vendored tree still runs its own tests", () => {
248
+ const a = apply(SUITE);
249
+ mkdirSync(join(a.wt, "proj"), { recursive: true });
250
+ writeFileSync(join(a.wt, "proj", "ok.test.mjs"), PASSES);
251
+ const vendor = join(a.wt, "proj", "node_modules", "pkg");
252
+ mkdirSync(vendor, { recursive: true });
253
+ writeFileSync(
254
+ join(vendor, "v.test.mjs"),
255
+ 'import { test } from "node:test";\ntest("VENDOR", () => { throw new Error("not ours"); });\n',
256
+ );
257
+ symlinkSync("proj", join(a.wt, "projlink"));
258
+ const r = a.run("projlink");
259
+ assert.equal(r.status, 0, r.stdout + r.stderr);
260
+ assert.match(r.stdout, /^(?:ℹ|#) pass 1$/m);
261
+ });
262
+
263
+ // The vendored tree the symlink lands in need not be inside the worktree.
264
+ // Judging the resolution RELATIVE TO THE WORKTREE ROOT passes every other test
265
+ // in this file and still runs this one green — the resolution lands outside, so
266
+ // there is nothing left to compare — which is #186's own class one input over.
267
+ // Both directions are here because the cheap over-correction (refuse anything
268
+ // resolving outside) also passes the refusal leg alone.
269
+ test("runner: a symlink to a vendored tree outside the worktree refuses", () => {
270
+ const a = apply(SUITE);
271
+ const outside = mkdtempSync(join(tmpdir(), "outside-"));
272
+ const vendor = join(outside, "node_modules", "pkg");
273
+ mkdirSync(vendor, { recursive: true });
274
+ writeFileSync(join(vendor, "v.test.mjs"), PASSES);
275
+ symlinkSync(vendor, join(a.wt, "extlink"));
276
+ const r = a.run("extlink");
277
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
278
+ assert.match(r.stderr, /is under node_modules — excluded from the run/);
279
+ const plain = join(outside, "lib");
280
+ mkdirSync(plain, { recursive: true });
281
+ writeFileSync(join(plain, "o.test.mjs"), PASSES);
282
+ symlinkSync(plain, join(a.wt, "oklink"));
283
+ const ok = a.run("oklink");
284
+ assert.equal(ok.status, 0, ok.stdout + ok.stderr);
285
+ assert.match(ok.stdout, /^(?:ℹ|#) pass 1$/m);
286
+ });
287
+
288
+ // The opposite error, and the one that actually shipped: `pwd -P` is absolute,
289
+ // so matching `*/node_modules/*` against it refuses on a `node_modules` in the
290
+ // WORKTREE'S OWN ANCESTRY — which is shared with the runner and says nothing
291
+ // about the argument. Measured on the unfixed shim: a worktree under such a
292
+ // parent refused every directory argument, the bare invocation's implicit `.`
293
+ // included, so the whole suite became unrunnable. No other fixture in this file
294
+ // is built under a `node_modules` parent, so nothing else can see it.
295
+ //
296
+ // The absolute spellings are the half that outlived the first fix (#230). An
297
+ // argument spelled absolutely carries the shared ancestor's `node_modules`
298
+ // inside its own text, so a guard term that reads the caller's spelling
299
+ // unanchored matches on it however the anchored term ruled — and the same
300
+ // directory reached two verdicts depending only on how it was named. Spelled
301
+ // and resolved forms are asserted side by side here because agreement between
302
+ // them, not any single row, is the property.
303
+ test("runner: a node_modules in the worktree's own ancestry refuses nothing", () => {
304
+ const under = join(mkdtempSync(join(tmpdir(), "anc-")), "node_modules");
305
+ mkdirSync(under, { recursive: true });
306
+ const a = apply(SUITE, under);
307
+ for (const [args, count] of [
308
+ [[], 6],
309
+ [["."], 6],
310
+ [[a.wt], 6],
311
+ [["t"], 3],
312
+ [[join(a.wt, "t")], 3],
313
+ // File arguments too: the file branch grew its own resolved-path check
314
+ // (#424), so the ancestor that must stay unread is now read by both arms.
315
+ [["t/a.test.mjs"], 1],
316
+ [[join(a.wt, "t", "a.test.mjs")], 1],
317
+ ]) {
318
+ const r = a.run(...args);
319
+ assert.equal(r.status, 0, `${JSON.stringify(args)}: ${r.stdout}${r.stderr}`);
320
+ assert.match(r.stdout, new RegExp(`^(?:ℹ|#) pass ${count}$`, "m"));
321
+ }
322
+ // ...and the guard still bites inside such a worktree.
323
+ const vendor = join(a.wt, "node_modules", "pkg");
324
+ mkdirSync(vendor, { recursive: true });
325
+ writeFileSync(join(vendor, "v.test.mjs"), PASSES);
326
+ symlinkSync(join("node_modules", "pkg"), join(a.wt, "vendlink"));
327
+ const r = a.run("vendlink");
328
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
329
+ assert.match(r.stderr, /is under node_modules — excluded from the run/);
330
+ // A DIRECTORY argument and a FILE argument in one argv, diverging from the
331
+ // runner at different depths. Both arms share one `diverge` walk writing one
332
+ // global `$shared` (POSIX sh has no `local`), so the file arm's verdict must
333
+ // not inherit the directory's: `t` diverges at the worktree, `outlink`
334
+ // resolves two levels above it, and reusing the deeper answer strips nothing
335
+ // — leaving the ANCESTRY's own `node_modules` inside the string the file arm
336
+ // scans, so the worktree refuses a file that is not vendored at all.
337
+ // Every other row here passes one argument, where `$shared` is empty before
338
+ // the call and dropping the call outright still reds. This row is the only
339
+ // one that catches reusing a STALE value: `[ -n "$shared" ] || diverge …`,
340
+ // the plausible optimization, left the whole file green before it existed
341
+ // (measured) and reds here now.
342
+ symlinkSync(join("..", "..", "root.test.mjs"), join(a.wt, "outlink.test.mjs"));
343
+ const mixed = a.run("t", "outlink.test.mjs");
344
+ assert.equal(mixed.status, 0, mixed.stdout + mixed.stderr);
345
+ assert.match(mixed.stdout, /(?:ℹ|#) pass 4(?!\d)/);
346
+ // The MIRROR order: a FILE argument first, then a DIRECTORY argument that
347
+ // diverges ABOVE the worktree, still under this ancestor's own
348
+ // `node_modules` — the shape the "resolution outside the worktree" test
349
+ // below proves correct when the directory arm's own `diverge` call runs.
350
+ // `t/a.test.mjs` diverges no further than the worktree, so the file arm
351
+ // leaves `$shared` sitting at `$root` itself; if the DIRECTORY arm's own
352
+ // `diverge` call were skipped in favour of that stale, narrower value,
353
+ // stripping it from the directory's resolution would strip nothing —
354
+ // leaving the ancestor's own `node_modules` in the string the directory arm
355
+ // scans, refusing an ordinary directory outside the worktree that is not
356
+ // vendored at all. Every row above passes a single argument in this order;
357
+ // this is the only one that catches the DIRECTORY arm reusing a stale
358
+ // value left behind by a FILE argument run first.
359
+ const outside2 = join(mkdtempSync(join(under, "out2-")), "lib");
360
+ mkdirSync(outside2, { recursive: true });
361
+ writeFileSync(join(outside2, "o2.test.mjs"), PASSES);
362
+ symlinkSync(outside2, join(a.wt, "outlink2"));
363
+ const mixed2 = a.run("t/a.test.mjs", "outlink2");
364
+ assert.equal(mixed2.status, 0, mixed2.stdout + mixed2.stderr);
365
+ assert.match(mixed2.stdout, /(?:ℹ|#) pass 2(?!\d)/);
366
+ });
367
+
368
+ // The spelling term's own reason to exist, and the only input in this repo that
369
+ // isolates it: a cwd OUTSIDE the worktree, from which a relative argument
370
+ // descends through the shared ancestor's `node_modules` and so names it in its
371
+ // own text, while resolving to an ordinary directory the divergence walk has
372
+ // already cleared. Measured: delete `${arg##/*}` from the guard and every other
373
+ // test in the repo stays green, so without this row the term reads as dead code
374
+ // to the next simplifier — and it is not, since node excludes an argv entry
375
+ // whose normalized relative form opens with `node_modules/` and says nothing
376
+ // about it (#100). The message is asserted, not just the status: without the
377
+ // term the argument reaches node, which reports its own `Could not find`, and
378
+ // the two exits are indistinguishable by status alone. The absolute leg is the
379
+ // control — the same directory named absolutely is exempt from that term and
380
+ // must still run, which is #230's property and what separates this test from
381
+ // one that merely refuses everything spelled from outside.
382
+ 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");
384
+ mkdirSync(under, { recursive: true });
385
+ const a = apply(SUITE, under);
386
+ // Four levels up from the worktree: `42-slug` -> `.worktrees` -> `claim-XXXX`
387
+ // -> `node_modules` -> the ancestor holding it, so a path relative to that cwd
388
+ // opens with the `node_modules` segment the guard has to read.
389
+ const up = join("..", "..", "..", "..");
390
+ const outside = a.runFrom(up, relative(join(a.wt, up), join(a.wt, "t")));
391
+ assert.notEqual(outside.status, 0, outside.stdout + outside.stderr);
392
+ assert.match(outside.stderr, /is under node_modules — excluded from the run/);
393
+ const ok = a.runFrom(up, join(a.wt, "t"));
394
+ assert.equal(ok.status, 0, ok.stdout + ok.stderr);
395
+ assert.match(ok.stdout, /^(?:ℹ|#) pass 3$/m);
396
+ });
397
+
398
+ // The divergence WALK itself (#797). Every row above names an argument that
399
+ // resolves under the worktree, where `$shared` and `$root` strip the same text
400
+ // and the walk does no work — measured, substituting `$root` for `$shared` in
401
+ // `${resolved#"$shared"}` is green on all 1873 tests. What separates the two is
402
+ // a resolution landing OUTSIDE the runner's own directory while still under the
403
+ // `node_modules` ancestor they share: `$root` is no prefix of it, so nothing is
404
+ // stripped, the ancestor's own `node_modules` stays in the text being matched,
405
+ // and an ordinary directory out there is refused as vendored. That is the
406
+ // "opposite error" the guard's comment names, reached from its false-refusal
407
+ // side rather than its false-green one.
408
+ // One row per guard arm, no absolute spelling of either, and that is measured
409
+ // rather than an omission. Directory: `$resolved` comes from `pwd -P`, which
410
+ // erases the spelling, so an absolute argument reaches the case with
411
+ // `$root`/`$resolved`/`$shared` byte-identical to the relative row's and can
412
+ // differ only in the spelling term `${arg##/*}` — which the test directly above
413
+ // already pins as its control leg, and which the unreadable-directory test below
414
+ // pins again through a symlinked ancestor. Measured over nine mutations of this
415
+ // guard: none reds an absolute row here while leaving the relative row and those
416
+ // two green. File: an absolute `$arg` carrying a `node_modules` segment is
417
+ // exempted from the file arm's resolved check by design (#401), so that row
418
+ // would pin nothing here either.
419
+ // The file arm runs the same walk via `diverge`, writing the shared `$shared`
420
+ // (#424), so the file row here holds that anchor with the same fixture; the
421
+ // vendored legs it must keep refusing are the two tests above, which this one
422
+ // deliberately does not repeat.
423
+ 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");
425
+ mkdirSync(ancestor, { recursive: true });
426
+ const a = apply(SUITE, ancestor);
427
+ // A sibling of the repo, so the argument diverges ABOVE the worktree while
428
+ // still sitting under the shared `node_modules` — the one shape that makes
429
+ // `$root` and `$shared` name different directories.
430
+ const outside = join(mkdtempSync(join(ancestor, "outside-")), "lib");
431
+ mkdirSync(outside, { recursive: true });
432
+ writeFileSync(join(outside, "o.test.mjs"), PASSES);
433
+ symlinkSync(outside, join(a.wt, "outlink"));
434
+ symlinkSync(join(outside, "o.test.mjs"), join(a.wt, "outlink.test.mjs"));
435
+ for (const arg of ["outlink", "outlink.test.mjs"]) {
436
+ const r = a.run(arg);
437
+ assert.equal(r.status, 0, `${arg}: ${r.stdout}${r.stderr}`);
438
+ assert.match(r.stdout, /^(?:ℹ|#) pass 1$/m, arg);
439
+ }
440
+ });
441
+
442
+ // The walk's EXACT-MATCH arm, `| "$shared"` (#1327). The test above pins the
443
+ // anchor the walk produces; nothing pinned the arm that ENDS the walk when the
444
+ // argument resolves TO an ancestor rather than under it. Deleting it reads as a
445
+ // no-op — the next iteration's `"$shared"/*` matches the same path — and is not
446
+ // one: it matches against a `$shared` one segment shorter, so
447
+ // `${resolved#"$shared"}` gains a leading `/<basename of $resolved>`, and where
448
+ // that basename is literally `node_modules` the guard refuses the shared
449
+ // ancestor itself. That is the false refusal the walk's own comment already
450
+ // names in prose — "a worktree living under one refused every directory
451
+ // argument, including the bare invocation's implicit `.`" — asserted there and
452
+ // unnoticed here: measured, deleting the arm left the rest of this file green.
453
+ //
454
+ // Two fixtures, because the arm is reached on two different iterations and the
455
+ // mutations that reach them are disjoint. V1 breaks on the FIRST iteration
456
+ // ($resolved IS $root); V2 on a later one ($resolved is a proper ancestor of
457
+ // $root). Measured over five template variants, every cell run against an
458
+ // emitted runner:
459
+ // V1 bare V1 vendored V2 ../../..
460
+ // `| "$shared"` deleted RED pass RED
461
+ // `case "$1"/ in "$shared"/*` pass pass pass
462
+ // `shared=${root%/*}` RED pass pass
463
+ // `shared=${shared%/*/*}` pass pass RED
464
+ // guard skipped when $root is vendored pass RED pass
465
+ // Row two is the behaviour-preserving rewrite of the same `case` — the equality
466
+ // spelled as a slash-bound subject instead of its own alternative — and it has
467
+ // to stay green, or these rows pin the spelling rather than the behaviour.
468
+ // The vendored row is asserted on the MESSAGE, not the status: under the
469
+ // over-exempt variant it still exits 1, with node's own `Could not find`, so
470
+ // status alone cannot tell a guard that refused from one that was skipped and
471
+ // handed node a path it drops (#100's silent shape — the same reason the
472
+ // relative-spelling test above asserts its message too).
473
+ //
474
+ // The file arm needs no row of its own, and that is measured rather than
475
+ // assumed. #1016 left ONE walk holding ONE such arm: it occurs exactly once in
476
+ // this template, and deleting that occurrence changes exactly one line of the
477
+ // emitted runner, so these rows pin it for both callers — and the mixed-argv
478
+ // rows above already pin that the file arm re-runs the walk rather than reading
479
+ // a stale `$shared`. The file caller cannot reach the arm in any case: it runs
480
+ // only from the `else` of `[ -d "$arg" ]`, over `realpath`'s answer for a path
481
+ // that is NOT a directory, while every value `$shared` can hold is `$root` or
482
+ // one of its ancestors — all directories, so the equality can never hold.
483
+ test("runner: the divergence walk ends on an argument that resolves TO the shared ancestor", () => {
484
+ // V1 — the runner's own directory is named `node_modules`, so a bare
485
+ // invocation's implicit `.` resolves to `$root` itself and the walk's first
486
+ // iteration is the equality. No claim can put a runner there: the worktree
487
+ // is always `.worktrees/<issue>-<slug>`, which cannot be that name. So the
488
+ // runner is copied straight into a `node_modules` directory instead — same
489
+ // bytes, and no worktree the assertions below never inspect.
490
+ const home = join(mkdtempSync(join(tmpdir(), "nm-")), "node_modules");
491
+ mkdirSync(home, { recursive: true });
492
+ copyFileSync(RUNNER, join(home, "agent-test"));
493
+ chmodSync(join(home, "agent-test"), 0o755);
494
+ writeFileSync(join(home, "a.test.mjs"), PASSES);
495
+ // Vendored content one level in, where the exemption is at its widest: the
496
+ // runner's own directory name IS the excluded word, and the guard still has
497
+ // to bite on a path that genuinely descends through another.
498
+ const vendor = join(home, "node_modules", "pkg");
499
+ mkdirSync(vendor, { recursive: true });
500
+ writeFileSync(join(vendor, "v.test.mjs"), PASSES);
501
+ const v1 = (...args) =>
502
+ spawnSync(join(home, "agent-test"), args, { cwd: home, encoding: "utf8", env: runnerEnv() });
503
+ // `pass 1`, not merely exit 0: the fixture holds two test files and one of
504
+ // them is vendored, so a count is what says the vendored one stayed out.
505
+ // It does NOT say the argument was honoured rather than dropped — measured,
506
+ // discarding the runner's own file-list handoff (`set -- "$@"` in place of
507
+ // `set -- "$@" $files`) leaves this row byte-identical
508
+ // at `pass 1`, because node's own default discovery from this cwd
509
+ // independently excludes the same vendored file too. V2's `pass 12` below
510
+ // is what pins the argument being honoured; this row does not.
511
+ const bare = v1();
512
+ assert.equal(bare.status, 0, bare.stdout + bare.stderr);
513
+ assert.match(bare.stdout, /^(?:ℹ|#) pass 1$/m);
514
+ const vendored = v1(join("node_modules", "pkg"));
515
+ assert.notEqual(vendored.status, 0, vendored.stdout + vendored.stderr);
516
+ assert.match(vendored.stderr, /is under node_modules — excluded from the run/);
517
+
518
+ // V2 — the runner where the claim actually put it, under a `node_modules`
519
+ // ancestor, with an argument naming that ancestor exactly:
520
+ // `42-slug` -> `.worktrees` -> `claim-XXXX` -> the `node_modules` itself.
521
+ // The walk reaches the equality three iterations down rather than on the
522
+ // first, and the runner is unmoved, so this row cannot be dismissed as an
523
+ // artifact of relocating one.
524
+ const under = join(mkdtempSync(join(tmpdir(), "anc-")), "node_modules");
525
+ mkdirSync(under, { recursive: true });
526
+ const a = apply(SUITE, under);
527
+ // 12: the six test files of the committed fixture, once in the repo's own
528
+ // checkout and once in the worktree built from it, both under the named
529
+ // ancestor. Bare discovery from the worktree reports 6, so the count also
530
+ // says the argument reached node instead of being dropped.
531
+ const r = a.run(join("..", "..", ".."));
532
+ assert.equal(r.status, 0, r.stdout + r.stderr);
533
+ assert.match(r.stdout, /^(?:ℹ|#) pass 12$/m);
534
+ });
535
+
536
+ // The guard resolves `$arg` against the process cwd, but `$root` against the
537
+ // runner's own location, so the two are no longer the same anchor and a
538
+ // subdirectory invocation exercises a different path than a root one. Measured:
539
+ // anchoring the argument at `$root` instead (`cd -- "$root/$arg"`, a one-token
540
+ // slip on the argument alone — the runner's `root=` assignment and its
541
+ // `resolved=` one now sit 171 lines apart, not side by side) is green on
542
+ // every OTHER test in this file while reporting
543
+ // the vendored test as a pass from one directory down.
544
+ // Second leg stops the fix degenerating into "refuse everything named from a
545
+ // subdirectory"; the stderr assert is load-bearing, since status alone cannot
546
+ // tell a refusal from a vendored test that threw.
547
+ test("runner: the resolved-path guard resolves against the cwd, from a subdirectory too", () => {
548
+ const a = apply(SUITE);
549
+ const vendor = join(a.wt, "node_modules", "pkg");
550
+ mkdirSync(vendor, { recursive: true });
551
+ writeFileSync(join(vendor, "v.test.mjs"), PASSES);
552
+ symlinkSync(join("..", "node_modules", "pkg"), join(a.wt, "t", "vendlink"));
553
+ const refused = a.runFrom("t", "vendlink");
554
+ assert.notEqual(refused.status, 0, refused.stdout + refused.stderr);
555
+ assert.match(refused.stderr, /is under node_modules — excluded from the run/);
556
+ const ran = a.runFrom("t", "nested");
557
+ assert.equal(ran.status, 0, ran.stdout + ran.stderr);
558
+ assert.match(ran.stdout, /^(?:ℹ|#) pass 1$/m);
559
+ });
560
+
561
+ // The false-positive leg of the resolved-path guard. The nested-node_modules
562
+ // test below pins `-prune`'s immunity to a `node_modules_old` lookalike, not
563
+ // this guard's: its argument is `t`, so neither half of the composed
564
+ // `"/$arg/ /…/"` string ever carries the lookalike and the `case` never sees
565
+ // one. Here only the RESOLUTION does — `vlink` is clean in spelling — which is
566
+ // the leg #186 added. Measured: relaxing the slash-bounding to `*node_modules*`
567
+ // leaves every other test in this file green and reddens only this one.
568
+ test("runner: a symlink resolving into a node_modules lookalike still runs", () => {
569
+ const a = apply(SUITE);
570
+ const lookalike = join(a.wt, "node_modules_old", "pkg");
571
+ mkdirSync(lookalike, { recursive: true });
572
+ writeFileSync(join(lookalike, "k.test.mjs"), PASSES);
573
+ symlinkSync(join("node_modules_old", "pkg"), join(a.wt, "vlink"));
574
+ const r = a.run("vlink");
575
+ assert.equal(r.status, 0, r.stdout + r.stderr);
576
+ assert.match(r.stdout, /^(?:ℹ|#) pass 1$/m);
577
+ });
578
+
579
+ // The sharp edge. `node --test` with zero files exits 0, so an expansion that
580
+ // matched nothing and shrugged would smuggle back the vacuous pass the emit
581
+ // guard refuses — this time past it, at run time.
582
+ test("runner: a directory with no test files refuses instead of exiting 0", () => {
583
+ const r = apply(SUITE).run("empty");
584
+ assert.notEqual(r.status, 0);
585
+ assert.match(r.stderr, /no test files under empty/);
586
+ });
587
+
588
+ // #1628: grep's and sed's own exit codes used to go unread in the
589
+ // directory-scan pipe — only whether `$files` ended up non-empty was
590
+ // checked — so a scan failure inside either tool (rc 2+, distinct from
591
+ // grep's normal rc-1 "no match") read through the emptiness test above as
592
+ // an indistinguishable "no test files", even though real test files sit
593
+ // right there. Stubbing `grep` itself to die outright (rc 2) is the
594
+ // cleanest reproduction of a scan tool breaking mid-run, and must be
595
+ // reported as ITS failure, not folded into the empty-directory message.
596
+ test("runner: a grep failure mid-scan is reported distinctly from an empty result", () => {
597
+ 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 r = spawnSync(join(a.wt, "agent-test"), ["t"], {
601
+ cwd: a.wt,
602
+ encoding: "utf8",
603
+ env: { ...a.env, PATH: `${bin}:${a.env.PATH}` },
604
+ });
605
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
606
+ assert.match(r.stderr, /could not scan for test files under t \(grep exited 2\)/);
607
+ assert.doesNotMatch(r.stderr, /no test files under/);
608
+ });
609
+
610
+ // The other half: sed sits downstream of grep in the same pipe, and its own
611
+ // rc was just as unread. Stubbing `sed` alone (grep runs for real, matches
612
+ // `t`'s two files, then hands them to the dying stub) isolates sed's status
613
+ // from grep's — the failure must still name sed, not grep or "no test files".
614
+ test("runner: a sed failure mid-scan is reported distinctly from an empty result", () => {
615
+ 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 r = spawnSync(join(a.wt, "agent-test"), ["t"], {
619
+ cwd: a.wt,
620
+ encoding: "utf8",
621
+ env: { ...a.env, PATH: `${bin}:${a.env.PATH}` },
622
+ });
623
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
624
+ assert.match(r.stderr, /could not scan for test files under t \(sed exited 2\)/);
625
+ assert.doesNotMatch(r.stderr, /no test files under/);
626
+ });
627
+
628
+ // BSD sed (this machine's actual /usr/bin/sed) exits rc 1 for EVERY error it
629
+ // reports — illegal byte sequence, malformed regex, missing file — there is
630
+ // no BSD sed error path that ever reaches rc 2+. A guard that tolerated
631
+ // `sed_rc -le 1` (mirroring grep's real "no match is rc 1" case) could NEVER
632
+ // catch a genuine BSD sed failure: the stub below reproduces that exact
633
+ // shape — always exit 1, the way real BSD sed does on a bad invocation —
634
+ // and must still be reported as a sed failure, not silently folded into "no
635
+ // test files" the way an unread rc would. (Reverting the guard to
636
+ // `-le 1` reproduces the pre-fix bug: this test goes green on silence,
637
+ // asserting `no test files under t` instead of a reported sed failure.)
638
+ test("runner: a BSD-style sed rc-1 failure is reported, not tolerated as a no-match analog", () => {
639
+ 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 r = spawnSync(join(a.wt, "agent-test"), ["t"], {
643
+ cwd: a.wt,
644
+ encoding: "utf8",
645
+ env: { ...a.env, PATH: `${bin}:${a.env.PATH}` },
646
+ });
647
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
648
+ assert.match(r.stderr, /could not scan for test files under t \(sed exited 1\)/);
649
+ assert.doesNotMatch(r.stderr, /no test files under/);
650
+ });
651
+
652
+ // grep's rc 1 ("no match") must NOT be swept into the same failure this pins
653
+ // above — that is the genuinely-empty case the pre-existing "no test files"
654
+ // test (above) already covers end to end. This is the narrower unit-level
655
+ // half: a stub that always exits 1, never touching `find` or the real test
656
+ // files, pins that a bare "no match" alone still reaches the ORIGINAL
657
+ // "no test files" message, not the new "grep exited" one.
658
+ test("runner: grep's plain no-match rc still reads as no test files, not a grep failure", () => {
659
+ 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 r = spawnSync(join(a.wt, "agent-test"), ["t"], {
663
+ cwd: a.wt,
664
+ encoding: "utf8",
665
+ env: { ...a.env, PATH: `${bin}:${a.env.PATH}` },
666
+ });
667
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
668
+ assert.match(r.stderr, /no test files under t/);
669
+ assert.doesNotMatch(r.stderr, /grep exited/);
670
+ });
671
+
672
+ test("runner: a file argument still works", () => {
673
+ const r = apply(SUITE).run("t/a.test.mjs");
674
+ assert.equal(r.status, 0, r.stdout + r.stderr);
675
+ // Bounded, same reason as the other bare `pass 1` cases above.
676
+ assert.match(r.stdout, /(?:ℹ|#) pass 1(?!\d)/);
677
+ });
678
+
679
+ // The shell expands a glob before the runner is entered, so the glob form
680
+ // reaches it as the plain multi-file argv this asserts on. Only the *matching*
681
+ // glob, though: one that matches nothing is handed over unexpanded, is not a
682
+ // directory, and so misses the shim entirely — node globs it, matches nothing
683
+ // and exits 0. That path is #100, not this test.
684
+ test("runner: the expanded glob form still works", () => {
685
+ const r = apply(SUITE).run("t/a.test.mjs", "t/b.test.mjs");
686
+ assert.equal(r.status, 0, r.stdout + r.stderr);
687
+ // Bounded, same reason as above: a bare `pass 2` is a substring of
688
+ // `pass 2<n>` and stops discriminating once a fixture reaches 20.
689
+ assert.match(r.stdout, /(?:ℹ|#) pass 2(?!\d)/);
690
+ });
691
+
692
+ // A subtree find cannot descend is the quiet version of the same hazard: find
693
+ // still prints what it reached, grep still matches it, and the count guard
694
+ // still passes — so the suite goes green having silently skipped whatever the
695
+ // unreadable directory held. Root can read anything, so it cannot see this.
696
+ test("runner: a directory it cannot fully read refuses instead of running a partial suite", (t) => {
697
+ if (process.getuid?.() === 0) return t.skip("root reads every directory");
698
+ const a = apply({ ...SUITE, "t/locked/z.test.mjs": PASSES });
699
+ chmodSync(join(a.wt, "t", "locked"), 0o000);
700
+ try {
701
+ const r = a.run("t");
702
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
703
+ assert.match(r.stderr, /cannot read every path under t/);
704
+ } finally {
705
+ chmodSync(join(a.wt, "t", "locked"), 0o755);
706
+ }
707
+ });
708
+
709
+ // #960 case 1: `find "-dir/" ...` — the old spelling — is read by both BSD
710
+ // find (macOS) and GNU find (Linux CI) as the start of an option cluster,
711
+ // trailing slash and all, and dies before reading a single path: measured
712
+ // directly, "illegal option -- i" (BSD) / "unknown predicate `-dir/'"
713
+ // (GNU), neither rescued by a POSIX `--`. The runner used to report that as
714
+ // `cannot read every path under -dir`, blaming the subtree's readability
715
+ // for what was find's own argument parser losing to the caller's spelling.
716
+ // `-dir` is written into the worktree directly rather than through
717
+ // `apply()`: a leading-dash directory NAME is a shell/CLI-argument concern,
718
+ // not something a git commit needs to reproduce.
719
+ // Node's own `--test` CLI turns out to share the same parser confusion one
720
+ // layer down — measured, a relative file spec that starts with `-` after
721
+ // node's own normalisation is read as a bad option too, `./`-prefixed or
722
+ // not — so this fixture cannot be made to actually run without rewriting
723
+ // every file this arm hands to node into an absolute path, a much larger
724
+ // change than this bug. The runner refuses instead, naming ITS cause
725
+ // rather than reporting a suite that never got to node as unreadable.
726
+ test("runner: a dash-named directory refuses naming the parsing hazard, not unreadability", () => {
727
+ const a = apply(SUITE);
728
+ mkdirSync(join(a.wt, "-dir"), { recursive: true });
729
+ writeFileSync(join(a.wt, "-dir", "z.test.mjs"), PASSES);
730
+ const r = a.run("-dir");
731
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
732
+ assert.match(r.stderr, /holds tests, but node reads a relative dash-led path as an option/);
733
+ assert.doesNotMatch(r.stderr, /cannot read every path under/);
734
+ });
735
+
736
+ // The other half of the same fixture: a dash-named directory that is
737
+ // GENUINELY unreadable must still report that real fault, not the parsing
738
+ // refusal's message. `./` only routes the argument around find's OWN
739
+ // parser (pinned above); once find actually descends, a permission denied
740
+ // down there is what `cannot read every path under` is for, and this pins
741
+ // that the parsing fix did not also swallow real unreadability.
742
+ // The wrapper text alone (`cannot read every path under -locked`) does not
743
+ // discriminate: it is byte-identical whether find died on the dash before
744
+ // reading anything, or genuinely hit this fixture's chmod 0 `sub`. find's
745
+ // OWN stderr is never redirected by the runner, so it reaches this test
746
+ // alongside the wrapper — measured, the two causes leave distinct text
747
+ // there: `find: .../sub: Permission denied` for the real fault this test
748
+ // means to pin, versus `find: illegal option -- i` (BSD) / `find: unknown
749
+ // predicate '...'` (GNU) for the argument-parsing failure this PR's `./`
750
+ // routing prevents. Asserting on find's message too, and ruling out the
751
+ // parsing signature, is what makes this test fail if the `./` routing
752
+ // this PR adds is reverted — checked directly: reverting it leaves this
753
+ // test green under the wrapper-only assertion alone.
754
+ test("runner: an unreadable dash-named directory still reports the real read fault", (t) => {
755
+ if (process.getuid?.() === 0) return t.skip("root reads every directory");
756
+ const a = apply(SUITE);
757
+ const locked = join(a.wt, "-locked");
758
+ mkdirSync(join(locked, "sub"), { recursive: true });
759
+ writeFileSync(join(locked, "sub", "z.test.mjs"), PASSES);
760
+ chmodSync(join(locked, "sub"), 0o000);
761
+ try {
762
+ const r = a.run("-locked");
763
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
764
+ assert.match(r.stderr, /cannot read every path under -locked/);
765
+ assert.doesNotMatch(r.stderr, /holds tests, but node reads/);
766
+ assert.match(r.stderr, /Permission denied/, `find must have actually descended into -locked rather than dying on its dash: ${r.stderr}`);
767
+ assert.doesNotMatch(r.stderr, /illegal option|unknown predicate/i,
768
+ `find's own argument-parsing failure text must not be present, or this is the parsing hazard, not the read fault: ${r.stderr}`);
769
+ } finally {
770
+ chmodSync(join(locked, "sub"), 0o755);
771
+ }
772
+ });
773
+
774
+ // Node's own discovery excludes `node_modules`; `find` does not, so a vendored
775
+ // test ran and the suite's result hung on third-party code passing. The live
776
+ // shape is a *real* nested `node_modules` — an install that did not hoist, or
777
+ // a bundled dependency. Not pnpm's: its per-package `node_modules` is a
778
+ // symlink farm, and `find` without `-L` never descends it.
779
+ // The vendor test fails on purpose: the count alone cannot tell "vendor was
780
+ // pruned" from "vendor ran and failed", and the exit status alone cannot tell
781
+ // "pruned" from "the expansion dropped some of ours" — losing all of them
782
+ // refuses with `no test files`, losing a few still exits 0. Both, or neither.
783
+ // `node_modules_old/` pins the other direction. Over-pruning is the worse
784
+ // bug — it deletes real tests and still exits 0 — and this is its only
785
+ // coverage in the fleet suite: an over-broad `*node_modules*` passes every
786
+ // other test in this file.
787
+ // It is written into the worktree rather than through `apply()` because that is
788
+ // where `node_modules` actually comes from — the install step, not a commit —
789
+ // and committing it would rest this test on whatever `core.excludesFile` the
790
+ // machine happens to have.
791
+ test("runner: a vendored test under a nested node_modules does not run", () => {
792
+ const a = apply(SUITE);
793
+ const vendor = join(a.wt, "t", "node_modules", "vendor");
794
+ mkdirSync(vendor, { recursive: true });
795
+ writeFileSync(
796
+ join(vendor, "v.test.mjs"),
797
+ 'import { test } from "node:test";\ntest("VENDOR", () => { throw new Error("not ours"); });\n',
798
+ );
799
+ const lookalike = join(a.wt, "t", "node_modules_old");
800
+ mkdirSync(lookalike, { recursive: true });
801
+ writeFileSync(join(lookalike, "k.test.mjs"), PASSES);
802
+ const r = a.run("t");
803
+ assert.equal(r.status, 0, r.stdout + r.stderr);
804
+ // Anchored: a bare `pass 4` is a substring and matches `pass 41`, so the pin
805
+ // would dissolve the moment the fixture grows past 40. Both prefixes because
806
+ // `node --test`'s default reporter is version- and TTY-dependent — spec
807
+ // (`ℹ pass 4`) on a terminal and on newer node, tap (`# pass 4`) when older
808
+ // node writes to a pipe, which is every CI run.
809
+ assert.match(r.stdout, /^(?:ℹ|#) pass 4$/m);
810
+ });
811
+
812
+ // The point of `-prune` over a path filter: content under `node_modules` is
813
+ // excluded from the run either way, so its readability cannot change the
814
+ // verdict. An unreadable directory *in* it used to still fail `find` and trip
815
+ // the guard above — a loud but pointless stall. Pruning skips descending
816
+ // `node_modules` entirely, so this directory's permissions are never even
817
+ // read. `pass 3` — the same count as the bare "t" case — pins that: the
818
+ // locked directory is empty and is never descended, so nothing about it can
819
+ // move the count or the status. Mutation-checked: reverting the walk to the
820
+ // `-not -path` filter, or typoing the prune's name, fails this test.
821
+ test("runner: an unreadable directory under node_modules no longer refuses the suite", (t) => {
822
+ if (process.getuid?.() === 0) return t.skip("root reads every directory");
823
+ const a = apply(SUITE);
824
+ const locked = join(a.wt, "t", "node_modules", "locked");
825
+ mkdirSync(locked, { recursive: true });
826
+ chmodSync(locked, 0o000);
827
+ try {
828
+ const r = a.run("t");
829
+ assert.equal(r.status, 0, r.stdout + r.stderr);
830
+ assert.match(r.stdout, /^(?:ℹ|#) pass 3$/m);
831
+ } finally {
832
+ chmodSync(locked, 0o755);
833
+ }
834
+ });
835
+
836
+ // Same directories, six spellings of the argument. The top-level pair alone
837
+ // is not coverage of "a vendored argument": `-prune` fires only where the
838
+ // walk DESCENDS through a `node_modules` dirent, so an argument at or under
839
+ // one prunes nothing and prints every file beneath it. Measured against the
840
+ // prune alone, the four spellings below the top level all ran their vendored
841
+ // test and exited 0 — the vacuous vendored green this shim exists to refuse.
842
+ // Only the `case` guard covers them, which is why every spelling is here.
843
+ // The message is asserted too, not just the status: falling through to the
844
+ // emptiness guard would report a deliberate exclusion as an absence and send
845
+ // a reader after a discovery bug that does not exist.
846
+ test("runner: a vendored directory argument refuses however it is spelled", () => {
847
+ const a = apply(SUITE);
848
+ mkdirSync(join(a.wt, "node_modules", "pkg"), { recursive: true });
849
+ mkdirSync(join(a.wt, "t", "node_modules", "pkg"), { recursive: true });
850
+ writeFileSync(join(a.wt, "node_modules", "v.test.mjs"), PASSES);
851
+ writeFileSync(join(a.wt, "node_modules", "pkg", "v.test.mjs"), PASSES);
852
+ writeFileSync(join(a.wt, "t", "node_modules", "v.test.mjs"), PASSES);
853
+ writeFileSync(join(a.wt, "t", "node_modules", "pkg", "v.test.mjs"), PASSES);
854
+ for (const spelling of [
855
+ "node_modules",
856
+ "./node_modules",
857
+ "node_modules/pkg",
858
+ "t/node_modules",
859
+ "t/node_modules/pkg",
860
+ join(a.wt, "node_modules", "pkg"),
861
+ ]) {
862
+ const r = a.run(spelling);
863
+ assert.notEqual(r.status, 0, `${spelling}: ${r.stdout}${r.stderr}`);
864
+ assert.match(r.stderr, /is under node_modules — excluded from the run/, spelling);
865
+ assert.doesNotMatch(r.stderr, /no test files under/, spelling);
866
+ }
867
+ });
868
+
869
+ // The vendored half of the no-search-bit case: `cd` fails on a directory
870
+ // `[ -d ]` admits but that carries no search bit, so unless the resolution is
871
+ // recovered from somewhere the divergence walk has nothing to measure and this
872
+ // argument stops being refused as vendored at all. Measured against this file:
873
+ // remove the recovery entirely and this is the one test that reds. What the
874
+ // recovery is ANCHORED on is a separate property and this test is blind to it —
875
+ // give it back the argument's raw text and this row stays green — which is why
876
+ // the ancestor-spelling test below exists as well as this one.
877
+ // One spelling, not two. The relative one was measured redundant across every
878
+ // mutation of both halves of the guard: with a recovery in place the resolved
879
+ // term reaches it unaided, and with none the spelling term does, so no mutation
880
+ // moves it. The absolute spelling is the row that carries this test.
881
+ // The readability message is asserted absent — `find` refuses a starting point
882
+ // it cannot open as well, so a bare non-zero cannot tell the guard's refusal
883
+ // from find's, and which cause the reader is sent after is the point.
884
+ // Root can read anything, so it cannot see this.
885
+ test("runner: a vendored directory with no search bit is refused as vendored, not as unreadable", (t) => {
886
+ if (process.getuid?.() === 0) return t.skip("root searches every directory");
887
+ const a = apply(SUITE);
888
+ const vendor = join(a.wt, "node_modules", "pkg");
889
+ mkdirSync(vendor, { recursive: true });
890
+ writeFileSync(join(vendor, "v.test.mjs"), PASSES);
891
+ chmodSync(vendor, 0o000);
892
+ try {
893
+ const r = a.run(vendor);
894
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
895
+ assert.match(r.stderr, /is under node_modules — excluded from the run/);
896
+ assert.doesNotMatch(r.stderr, /cannot read every path under/);
897
+ } finally {
898
+ chmodSync(vendor, 0o755);
899
+ }
900
+ });
901
+
902
+ // #230's own criterion in the one case the spelling exemption does not reach: a
903
+ // directory `[ -d ]` admits but that carries no search bit resolves to nothing,
904
+ // so what the guard falls back to is what decides the verdict. Anchored on the
905
+ // parent, every spelling of the directory agrees; anchored on the argument's raw
906
+ // text it did not — `$root` comes from `pwd -P`, so an absolute spelling routed
907
+ // through a symlinked ancestor shares no literal prefix with it, `$shared` walks
908
+ // down to empty, and the ancestor's own `node_modules` is left sitting in the
909
+ // text being matched. One directory, two absolute names, opposite verdicts.
910
+ // The symlinked ancestor is built here rather than borrowed from `$TMPDIR`:
911
+ // macOS resolves `/var/folders/...` to `/private/var/...` and would supply one
912
+ // for free, Linux would not, and a fixture that reproduces on one platform only
913
+ // stops discriminating on the other without saying so.
914
+ // NON-vendored on purpose. A vendored directory has to keep being refused (the
915
+ // test above pins that), so only a directory the guard has no business refusing
916
+ // can tell an anchored fallback from an unanchored one.
917
+ // Root can read anything, so it cannot see this.
918
+ test("runner: an unreadable directory under a node_modules ancestor names the read fault in every spelling", (t) => {
919
+ if (process.getuid?.() === 0) return t.skip("root searches every directory");
920
+ const real = mkdtempSync(join(tmpdir(), "anc-"));
921
+ const spelled = `${real}-link`;
922
+ symlinkSync(real, spelled);
923
+ mkdirSync(join(real, "node_modules"), { recursive: true });
924
+ const a = apply(SUITE, join(spelled, "node_modules"));
925
+ const locked = join(a.wt, "t");
926
+ chmodSync(locked, 0o000);
927
+ try {
928
+ for (const spelling of ["t", locked, join(realpathSync(a.wt), "t")]) {
929
+ const r = a.run(spelling);
930
+ assert.notEqual(r.status, 0, `${spelling}: ${r.stdout}${r.stderr}`);
931
+ assert.match(r.stderr, /cannot read every path under/, spelling);
932
+ assert.doesNotMatch(r.stderr, /is under node_modules/, spelling);
933
+ }
934
+ } finally {
935
+ chmodSync(locked, 0o755);
936
+ }
937
+ });
938
+
939
+ // #100: node counts argv separately from the runner's own `find`, and a file
940
+ // or glob argument reaches node with no check of its own. Node drops an
941
+ // argument it cannot resolve and exits non-zero only when it refuses every
942
+ // argument in argv — mixed with anything valid, the discard is silent and
943
+ // the runner used to exit 0 having run less than it was asked. These pin the
944
+ // shapes node discards: a typo, a file under `node_modules` however it is
945
+ // spelled, a path holding a `[`, and (the one deliberately left alone) an
946
+ // unmatched glob — plus the two it does NOT discard, a flag and a vendored
947
+ // spelling node runs anyway, which the guard must not refuse in their place.
948
+
949
+ // The repro from the issue itself: alone a typo is loud (node's own
950
+ // `Could not find`, exit 1) — mixed with a real file, node ran the one file
951
+ // and exited 0, and the runner reported a pass for a suite that only half
952
+ // ran. Named, not just refused: `no test files under` or a bare non-zero
953
+ // would both send a reader after the wrong bug.
954
+ test("runner: a typo'd path mixed with a valid one refuses and names the typo", () => {
955
+ const r = apply(SUITE).run("t/a.test.mjs", "t/typo.test.mjs");
956
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
957
+ assert.match(r.stderr, /t\/typo\.test\.mjs does not exist/);
958
+ });
959
+
960
+ test("runner: a typo'd path alone still refuses", () => {
961
+ const r = apply(SUITE).run("t/typo.test.mjs");
962
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
963
+ assert.match(r.stderr, /t\/typo\.test\.mjs does not exist/);
964
+ });
965
+
966
+ // #960 case 2: `[ -e "$arg" ]` cannot tell "not there" from "could not
967
+ // look" — stat() answers the same false whether $arg is genuinely absent
968
+ // or a directory in its path lacks the search bit needed to resolve the
969
+ // rest. A file behind an unsearchable parent used to fall straight through
970
+ // to the typo arm above and get called missing, though it is right there.
971
+ // The directory arm already gets the IDENTICAL fixture right (see "a
972
+ // directory it cannot fully read refuses instead of running a partial
973
+ // suite" above): both arms are run here on one `locked` directory to pin
974
+ // the asymmetry the ticket names directly — same cause, and now the same
975
+ // kind of answer from both, not just the directory arm's.
976
+ // Root can search anything, so it cannot see this.
977
+ test("runner: a file behind an unsearchable parent refuses naming the permission fault, not a typo", (t) => {
978
+ if (process.getuid?.() === 0) return t.skip("root searches every directory");
979
+ const a = apply({ ...SUITE, "locked/a.test.mjs": PASSES });
980
+ const locked = join(a.wt, "locked");
981
+ chmodSync(locked, 0o600);
982
+ try {
983
+ const asFile = a.run("locked/a.test.mjs");
984
+ assert.notEqual(asFile.status, 0, asFile.stdout + asFile.stderr);
985
+ assert.match(asFile.stderr, /cannot read locked\/a\.test\.mjs — locked is not searchable/);
986
+ assert.doesNotMatch(asFile.stderr, /does not exist/);
987
+
988
+ const asDir = a.run("locked");
989
+ assert.notEqual(asDir.status, 0, asDir.stdout + asDir.stderr);
990
+ assert.match(asDir.stderr, /cannot read every path under locked/);
991
+ } finally {
992
+ chmodSync(locked, 0o755);
993
+ }
994
+ });
995
+
996
+ // The fix above checks $fparent alone, which is the immediate parent —
997
+ // an unsearchable GRANDparent leaves `[ -d $fparent ]` itself false
998
+ // (resolving `t/u` needs search on `t`, the bit actually missing), so a
999
+ // single-level check falls through to "does not exist" one level further
1000
+ // up than the fixture above pins. This walks the fixture one directory
1001
+ // deeper: `t` (not `u`) is chmod'd 0600, so `t/u` can never be
1002
+ // resolved at all, and the ancestor actually blocking it — `t`, not
1003
+ // `t/u` — is what the message must name.
1004
+ test("runner: a file behind an unsearchable grandparent refuses naming that ancestor, not a typo", (t) => {
1005
+ if (process.getuid?.() === 0) return t.skip("root searches every directory");
1006
+ const a = apply({ ...SUITE, "t/u/a.test.mjs": PASSES });
1007
+ const tdir = join(a.wt, "t");
1008
+ chmodSync(tdir, 0o600);
1009
+ try {
1010
+ const r = a.run("t/u/a.test.mjs");
1011
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
1012
+ assert.match(r.stderr, /cannot read t\/u\/a\.test\.mjs — t is not searchable/);
1013
+ assert.doesNotMatch(r.stderr, /does not exist/);
1014
+ } finally {
1015
+ chmodSync(tdir, 0o755);
1016
+ }
1017
+ });
1018
+
1019
+ // The bound on the fix above: a PARENT that is simply missing
1020
+ // (`nosuchdir/x.test.mjs`) is the ordinary typo this arm already reported
1021
+ // correctly, and the permission-fault check must not swallow it — `-x` on
1022
+ // a nonexistent parent is false too, so without the `-d` term this input
1023
+ // would misreport as a permission fault it does not have.
1024
+ test("runner: a typo'd path with a missing parent still says it does not exist", () => {
1025
+ const r = apply(SUITE).run("nosuchdir/x.test.mjs");
1026
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
1027
+ assert.match(r.stderr, /nosuchdir\/x\.test\.mjs does not exist/);
1028
+ assert.doesNotMatch(r.stderr, /cannot read/);
1029
+ });
1030
+
1031
+ // #125's surviving case, per the issue's "Agent Brief": a vendored *file*
1032
+ // argument bypasses the directory branch entirely (that guard only ever sees
1033
+ // what `[ -d ]` is true for), so node — not this shim — is what would drop
1034
+ // it, and only when something else in argv resolves. Written into the
1035
+ // worktree rather than through `apply()` for the same reason as the nested
1036
+ // node_modules test above: this is what an unhoisted install produces, not
1037
+ // something anyone commits.
1038
+ // Four spellings, because one is not the class. `./` is the second literal
1039
+ // form, and dropping either alternative from a prefix match would go
1040
+ // uncaught with only the first pinned. `t/../node_modules/…` is why the
1041
+ // guard resolves the argument's own directory rather than matching a prefix
1042
+ // at all: node normalizes before applying its rule, so that spelling is
1043
+ // excluded too (measured directly against node v26.5.0 — `tests 1` for a
1044
+ // two-file argv) and a literal prefix misses it. And the `*` spelling is why
1045
+ // the vendored check runs BEFORE the glob classification: a metacharacter
1046
+ // anywhere in a vendored path used to route it into the passthrough arm and
1047
+ // out of this refusal entirely.
1048
+ test("runner: a vendored file argument refuses however it is spelled", () => {
1049
+ const a = apply(SUITE);
1050
+ const vendor = join(a.wt, "node_modules", "pkg");
1051
+ mkdirSync(vendor, { recursive: true });
1052
+ writeFileSync(join(vendor, "v.test.mjs"), PASSES);
1053
+ for (const spelling of [
1054
+ "node_modules/pkg/v.test.mjs",
1055
+ "./node_modules/pkg/v.test.mjs",
1056
+ "t/../node_modules/pkg/v.test.mjs",
1057
+ "node_modules/pkg/*.test.mjs",
1058
+ ]) {
1059
+ const r = a.run("t/a.test.mjs", spelling);
1060
+ assert.notEqual(r.status, 0, `${spelling}: ${r.stdout}${r.stderr}`);
1061
+ assert.match(r.stderr, /is under node_modules — node discards it silently/, spelling);
1062
+ }
1063
+ });
1064
+
1065
+ // The same guard under an inherited CDPATH, which nothing else in this suite
1066
+ // varies. `cd` consults CDPATH before the cwd, so with a decoy on it that
1067
+ // holds a same-named `node_modules/plain`, a bare `cd "$argdir"` resolves
1068
+ // into the DECOY: the guard's `"$PWD"/node_modules/*` pattern misses, it
1069
+ // falls through without refusing, and the vendored file reaches node — which
1070
+ // drops it silently at exit 0, #100 back with the refusal removed. `apply()`
1071
+ // hands the runner `{...process.env}`, so a developer's CDPATH reaches it.
1072
+ // The decoy shape is deliberate over a bare `CDPATH=/tmp`: /bin/sh on macOS
1073
+ // (bash 3.2) fails the `cd` outright when no CDPATH entry matches, while
1074
+ // /bin/dash falls back to the cwd per POSIX and stays immune — so a
1075
+ // non-matching decoy would pin this on the dev platform only. A MATCHING
1076
+ // entry diverts both shells, which is what makes this row portable.
1077
+ // The sibling directory branch already carries `CDPATH=` for this reason
1078
+ // (see agent-test, above `root=`); this pins the file branch's copy.
1079
+ // Mutation-tested both ways: dropping `CDPATH= ` from the file branch's `cd`
1080
+ // reds this row alone, and adding `-P` to it — the mutation the #401 row
1081
+ // below pins — leaves this one green.
1082
+ // Re-measured after #1005 collapsed that branch's unreachable `argdir` arm,
1083
+ // because the collapse is exactly the edit that could drop the `CDPATH= `
1084
+ // silently: stripping it from the collapsed line still reds this row and only
1085
+ // it (17/18 of the vendored rows green), and forcing `argdir` back to the
1086
+ // removed arm's `.` value reds five rows including this one — so the pin
1087
+ // discriminates the guard's behaviour, not the shape it is written in.
1088
+ test("runner: a vendored file argument refuses under an inherited CDPATH", () => {
1089
+ const a = apply(SUITE);
1090
+ const vendor = join(a.wt, "node_modules", "plain");
1091
+ mkdirSync(vendor, { recursive: true });
1092
+ writeFileSync(join(vendor, "v.test.mjs"), PASSES);
1093
+ const decoy = mkdtempSync(join(tmpdir(), "cdpath-decoy-"));
1094
+ mkdirSync(join(decoy, "node_modules", "plain"), { recursive: true });
1095
+ const r = spawnSync(join(a.wt, "agent-test"), ["t/a.test.mjs", "node_modules/plain/v.test.mjs"], {
1096
+ cwd: a.wt,
1097
+ encoding: "utf8",
1098
+ env: { ...a.env, CDPATH: decoy },
1099
+ });
1100
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
1101
+ assert.match(r.stderr, /is under node_modules — node discards it silently/);
1102
+ });
1103
+
1104
+ // The file-branch counterpart of the no-search-bit case pinned above for the
1105
+ // directory branch: `arg` here is a FILE, so `[ -d $arg ]` never runs at
1106
+ // all — this guard reads $argdir, the file's own parent, and it is $argdir
1107
+ // that loses its search bit. Before the fix, `cd`'s failure on $argdir was
1108
+ // discarded outright (`2>/dev/null`, nothing read from the pipeline), the
1109
+ // vendored `case` fell through unrefused, `[ -e $arg ]` downstream read
1110
+ // false because the parent could not be traversed, and the typo arm far
1111
+ // below reported a permission fault as `does not exist` — measured directly
1112
+ // against the unfixed shim. Root can read anything, so it cannot see this.
1113
+ test("runner: a vendored file behind an unreadable directory names the permission fault, not a typo", (t) => {
1114
+ if (process.getuid?.() === 0) return t.skip("root reads every directory");
1115
+ const a = apply(SUITE);
1116
+ const vendor = join(a.wt, "node_modules", "pkg");
1117
+ mkdirSync(vendor, { recursive: true });
1118
+ writeFileSync(join(vendor, "v.test.mjs"), PASSES);
1119
+ chmodSync(vendor, 0o000);
1120
+ try {
1121
+ const r = a.run("t/a.test.mjs", "node_modules/pkg/v.test.mjs");
1122
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
1123
+ assert.match(r.stderr, /cannot read node_modules\/pkg — check its permissions/);
1124
+ assert.doesNotMatch(r.stderr, /does not exist/);
1125
+ assert.doesNotMatch(r.stderr, /is under node_modules — node discards it silently/);
1126
+ } finally {
1127
+ chmodSync(vendor, 0o755);
1128
+ }
1129
+ });
1130
+
1131
+ // #1006's own warning about its remedy sketch: `[ -d $argdir ]` reads false
1132
+ // not only when $argdir is missing, but also whenever $argdir's OWN PARENT
1133
+ // is unreadable — so the guard above must not fire the permission message on
1134
+ // a fixture it cannot actually back up. Here `node_modules` (the file's
1135
+ // GRANDparent) loses its search bit, not `pkg` (the immediate parent): the
1136
+ // guard can no longer even confirm `pkg` exists, so it has to stay silent
1137
+ // and let the argument fall through exactly as an unmeasured path already
1138
+ // did, rather than assert a fault it cannot name. Measured directly: `-d`
1139
+ // reads false here where it read true in the row above, on the same
1140
+ // $argdir. The downstream message this falls through to belongs to the
1141
+ // general typo arm (#960/PR #1387), not this guard, and is deliberately
1142
+ // left unpinned here — its exact wording is that ticket's to change; this
1143
+ // row only pins that THIS guard neither over-fires nor claims the wrong
1144
+ // verdict. Root can read anything, so it cannot see this.
1145
+ test("runner: a vendored file whose ancestor is unreadable does not claim a permission fault it cannot confirm", (t) => {
1146
+ if (process.getuid?.() === 0) return t.skip("root reads every directory");
1147
+ const a = apply(SUITE);
1148
+ const vendor = join(a.wt, "node_modules", "pkg");
1149
+ mkdirSync(vendor, { recursive: true });
1150
+ writeFileSync(join(vendor, "v.test.mjs"), PASSES);
1151
+ const modules = join(a.wt, "node_modules");
1152
+ chmodSync(modules, 0o000);
1153
+ try {
1154
+ const r = a.run("t/a.test.mjs", "node_modules/pkg/v.test.mjs");
1155
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
1156
+ assert.doesNotMatch(r.stderr, /cannot read node_modules\/pkg — check its permissions/);
1157
+ assert.doesNotMatch(r.stderr, /is under node_modules — node discards it silently/);
1158
+ } finally {
1159
+ chmodSync(modules, 0o755);
1160
+ }
1161
+ });
1162
+
1163
+ // #401: nothing above pins the RESOLUTION MODE this guard uses, only its
1164
+ // spelling coverage. `cd`/`pwd` without `-P` is logical — it never resolves a
1165
+ // symlinked path component — and that is deliberate: it is the same textual
1166
+ // resolution node applies to its own argv, so the guard and node agree on
1167
+ // which files count as vendored. The ordinary npm/pnpm workspace shape is
1168
+ // where the two resolution modes diverge: `node_modules/pkg` is itself a
1169
+ // symlink to a sibling real directory (`pkg` hoisted or linked from
1170
+ // `packages/`). `pwd -P` there resolves `pkg` OUT of `node_modules`, so the
1171
+ // pattern below stops matching, this guard falls through without refusing,
1172
+ // and the argument reaches node unrefused — where it is excluded anyway, on
1173
+ // its own unresolved spelling, silently, at exit 0. That is #100's silent
1174
+ // drop back, minus the loud refusal that is supposed to catch it first.
1175
+ // Measured against a scratch copy of this script with `cd`/`pwd` mutated to
1176
+ // `cd -P`/`pwd -P` on this guard alone: this is the row that reds, and it
1177
+ // stayed red for both `/bin/sh` (bash on macOS) and `/bin/dash` — the two
1178
+ // disagree on many things but not on this.
1179
+ test("runner: a vendored file behind a symlinked node_modules entry refuses", () => {
1180
+ const a = apply(SUITE);
1181
+ const real = join(a.wt, "packages", "pkg");
1182
+ mkdirSync(real, { recursive: true });
1183
+ writeFileSync(join(real, "v.test.mjs"), PASSES);
1184
+ mkdirSync(join(a.wt, "node_modules"), { recursive: true });
1185
+ symlinkSync(join("..", "packages", "pkg"), join(a.wt, "node_modules", "pkg"));
1186
+ const r = a.run("t/a.test.mjs", "node_modules/pkg/v.test.mjs");
1187
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
1188
+ assert.match(r.stderr, /is under node_modules — node discards it silently/);
1189
+ });
1190
+
1191
+ // The other half of the same rule, and the guard against over-widening it.
1192
+ // Node's exclusion fires only when the argument's normalized RELATIVE form
1193
+ // starts with `node_modules/`: a deeper segment and an absolute path are NOT
1194
+ // excluded — node runs both and counts them, so there is no silent drop to
1195
+ // refuse and refusing them would reject argv node handles fine. `pass 2` is
1196
+ // what says the vendored file ran rather than being dropped, so borrowing
1197
+ // the directory branch's own `*/node_modules/*` pattern here reddens this.
1198
+ test("runner: the vendored file spellings node runs are not refused", () => {
1199
+ const a = apply(SUITE);
1200
+ const vendor = join(a.wt, "node_modules", "pkg");
1201
+ mkdirSync(vendor, { recursive: true });
1202
+ writeFileSync(join(vendor, "v.test.mjs"), PASSES);
1203
+ const nested = join(a.wt, "t", "node_modules", "pkg");
1204
+ mkdirSync(nested, { recursive: true });
1205
+ writeFileSync(join(nested, "n.test.mjs"), PASSES);
1206
+ for (const spelling of [
1207
+ "t/node_modules/pkg/n.test.mjs",
1208
+ join(a.wt, "node_modules", "pkg", "v.test.mjs"),
1209
+ ]) {
1210
+ const r = a.run("t/a.test.mjs", spelling);
1211
+ assert.equal(r.status, 0, `${spelling}: ${r.stdout}${r.stderr}`);
1212
+ assert.match(r.stdout, /^(?:ℹ|#) pass 2$/m, spelling);
1213
+ }
1214
+ });
1215
+
1216
+ // Node's exclusion is anchored at the cwd its arguments are relative to —
1217
+ // that is what "relative form" means, and it is what separates mirroring the
1218
+ // rule from matching a prefix. The two fixture files below swap verdicts on
1219
+ // nothing but where the runner is invoked from: at the worktree root
1220
+ // `node_modules/pkg/v.test.mjs` is the dropped one and `t/node_modules/…`
1221
+ // runs, while from inside `t/` the polarity inverts — `node_modules/pkg/…`
1222
+ // now names the nested file and is dropped, `../node_modules/pkg/…` names
1223
+ // the root one and runs. Measured against node itself, both ways. A guard
1224
+ // anchored at the worktree root rather than the cwd gets both backwards and
1225
+ // no other test in this file would see it.
1226
+ test("runner: the vendored rule is anchored at the cwd, as node's is", () => {
1227
+ const a = apply(SUITE);
1228
+ for (const p of ["node_modules/pkg", "t/node_modules/pkg"]) {
1229
+ mkdirSync(join(a.wt, p), { recursive: true });
1230
+ writeFileSync(join(a.wt, p, "v.test.mjs"), PASSES);
1231
+ }
1232
+ const refused = a.runFrom("t", "a.test.mjs", "node_modules/pkg/v.test.mjs");
1233
+ assert.notEqual(refused.status, 0, refused.stdout + refused.stderr);
1234
+ assert.match(refused.stderr, /is under node_modules — node discards it silently/);
1235
+ const ran = a.runFrom("t", "a.test.mjs", "../node_modules/pkg/v.test.mjs");
1236
+ assert.equal(ran.status, 0, ran.stdout + ran.stderr);
1237
+ assert.match(ran.stdout, /^(?:ℹ|#) pass 2$/m);
1238
+ });
1239
+
1240
+ // #424: the file-branch sibling of #186. The guard above judges the argument's
1241
+ // own SPELLING, and the logical directory that spelling names — which is what
1242
+ // node's silent-discard rule reads. A symlink whose name carries no
1243
+ // `node_modules` but whose TARGET is vendored passes it untouched, and node
1244
+ // then RUNS the vendored file rather than discarding it. So the hazard here is
1245
+ // not #100's: there is no silent drop left to make loud. It is #186's —
1246
+ // third-party code deciding this suite's result — one `-d` away, and it takes
1247
+ // #186's remedy: judge where the argument RESOLVES.
1248
+ //
1249
+ // Physical resolution, and only where the spelling does not already name
1250
+ // `node_modules`. Those spellings are the guard above's own input, the two it
1251
+ // deliberately lets run included, and re-judging them from a second place would
1252
+ // overturn that ruling; the two checks cover disjoint arguments instead, which
1253
+ // is what lets this one be physical while #401's stays logical.
1254
+ //
1255
+ // Anchored at the divergence from the runner's own location, as the directory
1256
+ // branch is: a `node_modules` ABOVE that point is an ancestor of the runner too
1257
+ // and says nothing about the argument. The absolute spelling is here because
1258
+ // resolution, unlike the directory branch's lexical spelling term, is immune to
1259
+ // how the caller named the file — a macOS $TMPDIR reaches the worktree through
1260
+ // a symlinked ancestor, so the two spellings share no literal prefix and only
1261
+ // the resolved form puts them on the same footing. The outside-the-worktree
1262
+ // target is the leg that separates anchoring at the divergence from anchoring
1263
+ // at the worktree root: its resolution lands outside the worktree entirely, so
1264
+ // a root-anchored guard has nothing left to compare and runs it green — #186's
1265
+ // own class, one input over.
1266
+ test("runner: a symlink to a vendored file refuses however it is spelled", () => {
1267
+ const a = apply(SUITE);
1268
+ const vendor = join(a.wt, "node_modules", "pkg");
1269
+ mkdirSync(vendor, { recursive: true });
1270
+ writeFileSync(join(vendor, "v.test.mjs"), PASSES);
1271
+ symlinkSync(join("node_modules", "pkg", "v.test.mjs"), join(a.wt, "vendlink.test.mjs"));
1272
+ // A chain of file symlinks: node follows it to the vendored file, so a guard
1273
+ // that resolves only one hop reports a clean path node never used.
1274
+ symlinkSync("vendlink.test.mjs", join(a.wt, "chainlink.test.mjs"));
1275
+ // The vendored component reached through a symlinked DIRECTORY, with a real
1276
+ // file as the final component — the half `cd`/`pwd -P` on the argument's own
1277
+ // directory would already have caught, kept so the fix is not narrowed to
1278
+ // final-component links alone.
1279
+ symlinkSync(join("node_modules", "pkg"), join(a.wt, "dirlink"));
1280
+ const outside = mkdtempSync(join(tmpdir(), "outside-"));
1281
+ mkdirSync(join(outside, "node_modules", "pkg"), { recursive: true });
1282
+ writeFileSync(join(outside, "node_modules", "pkg", "o.test.mjs"), PASSES);
1283
+ symlinkSync(join(outside, "node_modules", "pkg", "o.test.mjs"), join(a.wt, "extlink.test.mjs"));
1284
+ // A directory whose name merely ENDS in the word, spelled both ways — the
1285
+ // merged `case` judges the two on different arms. The relative spelling is
1286
+ // held out of the logical arm by that arm's own segment bound. The absolute
1287
+ // one is held out by the FIRST arm, whose job is the single shape both
1288
+ // guards decline (absolute AND naming a real `node_modules` segment) and
1289
+ // which therefore has to carry the bound too: written as the one glob that
1290
+ // looks equivalent, `/*node_modules/*`, it swallows this spelling into the
1291
+ // skip and node runs the vendored file. Measured — that collapse reds this
1292
+ // row and nothing else in the file, so the relative row alone did not pin
1293
+ // it. Unbounded, `*node_modules/*` claimed the argument for the logical
1294
+ // guard instead, whose own inner test is anchored at `$PWD/node_modules/`
1295
+ // and never fired: the argument left both guards unjudged, same result.
1296
+ mkdirSync(join(a.wt, "vendor_node_modules"), { recursive: true });
1297
+ symlinkSync(join("..", "node_modules", "pkg", "v.test.mjs"), join(a.wt, "vendor_node_modules", "link.test.mjs"));
1298
+ for (const spelling of [
1299
+ "vendlink.test.mjs",
1300
+ "./vendlink.test.mjs",
1301
+ join(a.wt, "vendlink.test.mjs"),
1302
+ "chainlink.test.mjs",
1303
+ "dirlink/v.test.mjs",
1304
+ "extlink.test.mjs",
1305
+ "vendor_node_modules/link.test.mjs",
1306
+ join(a.wt, "vendor_node_modules", "link.test.mjs"),
1307
+ ]) {
1308
+ const r = a.run("t/a.test.mjs", spelling);
1309
+ assert.notEqual(r.status, 0, `${spelling}: ${r.stdout}${r.stderr}`);
1310
+ // The resolved target is named, not just the argument: the refusal states
1311
+ // what was applied to THIS path — a caller who spelled a name carrying no
1312
+ // `node_modules` otherwise has to re-run `realpath` to see which link went
1313
+ // where, and reads the bare clause as a rule the runner does not apply to
1314
+ // every spelling (a literal `t/node_modules/pkg/x.test.mjs` still runs,
1315
+ // #401's ruling, deliberately).
1316
+ assert.match(r.stderr, /resolves to \S+, inside node_modules — excluded from the run/, spelling);
1317
+ }
1318
+ });
1319
+
1320
+ // The control, and what stops the fix above becoming a blanket refusal of
1321
+ // symlinks: the refusal leg alone passes just as well under a guard that
1322
+ // refuses every symlinked argument, or every argument with `node_modules`
1323
+ // anywhere in its resolution.
1324
+ //
1325
+ // `sidelink` is the second half: a target that merely SITS BESIDE a vendored
1326
+ // tree rather than inside one. `packages/pkg/w.test.mjs` is the ordinary
1327
+ // npm/pnpm workspace shape, named by its REAL path — there is no symlinked
1328
+ // spelling of it to grep for, because that is the point: `node_modules/pkg`
1329
+ // is a symlink OUT to `packages/pkg`, so a caller naming `packages/pkg/…`
1330
+ // names a file that is not vendored at all, and physical resolution is
1331
+ // exactly what has to agree. The
1332
+ // same tree spelled `node_modules/pkg/…` is #401's row above, refused by the
1333
+ // logical guard this one is deliberately blind to.
1334
+ test("runner: a symlink to a non-vendored file still runs", () => {
1335
+ const a = apply(SUITE);
1336
+ symlinkSync(join("t", "b.test.mjs"), join(a.wt, "oklink.test.mjs"));
1337
+ const outside = mkdtempSync(join(tmpdir(), "outside-ok-"));
1338
+ mkdirSync(join(outside, "lib", "node_modules"), { recursive: true });
1339
+ writeFileSync(join(outside, "lib", "o.test.mjs"), PASSES);
1340
+ symlinkSync(join(outside, "lib", "o.test.mjs"), join(a.wt, "sidelink.test.mjs"));
1341
+ const real = join(a.wt, "packages", "pkg");
1342
+ mkdirSync(real, { recursive: true });
1343
+ writeFileSync(join(real, "w.test.mjs"), PASSES);
1344
+ mkdirSync(join(a.wt, "node_modules"), { recursive: true });
1345
+ symlinkSync(join("..", "packages", "pkg"), join(a.wt, "node_modules", "pkg"));
1346
+ for (const spelling of [
1347
+ "oklink.test.mjs",
1348
+ "sidelink.test.mjs",
1349
+ "packages/pkg/w.test.mjs",
1350
+ ]) {
1351
+ const r = a.run("t/a.test.mjs", spelling);
1352
+ assert.equal(r.status, 0, `${spelling}: ${r.stdout}${r.stderr}`);
1353
+ assert.match(r.stdout, /^(?:ℹ|#) pass 2$/m, spelling);
1354
+ }
1355
+ });
1356
+
1357
+ // The resolved check is asked only of an argument that EXISTS, and that gate is
1358
+ // the whole platform pin. BSD `realpath` fails on a nonexistent final component
1359
+ // and GNU's succeeds on it, so one input drew opposite verdicts: this spelling
1360
+ // reported `does not exist` on macOS and `resolves inside node_modules — not
1361
+ // missing` on ubuntu-latest, asserting a missing file was not missing and
1362
+ // pre-empting the arm that names it. The whole file ran 77/77 under both
1363
+ // semantics, so nothing discriminated them — measured. This row does: green on
1364
+ // BSD with the gate or without it, red on GNU without it.
1365
+ test("runner: a missing file under a symlinked vendored directory is reported missing", () => {
1366
+ const a = apply(SUITE);
1367
+ const vendor = join(a.wt, "node_modules", "pkg");
1368
+ mkdirSync(vendor, { recursive: true });
1369
+ writeFileSync(join(vendor, "v.test.mjs"), PASSES);
1370
+ symlinkSync(join("node_modules", "pkg"), join(a.wt, "dirlink"));
1371
+ const r = a.run("t/a.test.mjs", "dirlink/nope.test.mjs");
1372
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
1373
+ assert.match(r.stderr, /dirlink\/nope\.test\.mjs does not exist/);
1374
+ assert.doesNotMatch(r.stderr, /node_modules/);
1375
+ });
1376
+
1377
+ // `realpath` is the one utility this runner reaches for that POSIX does not
1378
+ // mandate, so the runner dies rather than guessing when it is missing. Absent,
1379
+ // this guard disarmed whole: the vendored file ran, the run exited 0 reporting
1380
+ // `pass 2`, and not one byte reached stderr — #424's own defect restored with no
1381
+ // notice. Absence is not a fallback case, it is a question this cannot answer,
1382
+ // so it refuses. A stub that exits 127 rather than an emptied PATH, so `sed`,
1383
+ // `dirname` and `node` still work and the resolver is the only thing missing.
1384
+ test("runner: an unresolvable argument refuses rather than running unchecked", () => {
1385
+ const a = apply(SUITE);
1386
+ const vendor = join(a.wt, "node_modules", "pkg");
1387
+ mkdirSync(vendor, { recursive: true });
1388
+ writeFileSync(join(vendor, "v.test.mjs"), PASSES);
1389
+ 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 });
1392
+ // The vendored spelling goes FIRST: every file argument is judged, so the
1393
+ // refusal names whichever one the loop reaches first, and naming this one is
1394
+ // what shows the guard is still armed rather than merely dying early.
1395
+ const r = spawnSync(join(a.wt, "agent-test"), ["vendlink.test.mjs", "t/a.test.mjs"], {
1396
+ cwd: a.wt,
1397
+ encoding: "utf8",
1398
+ env: { ...a.env, PATH: `${bin}:${a.env.PATH}` },
1399
+ });
1400
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
1401
+ assert.match(r.stderr, /cannot resolve vendlink\.test\.mjs — refusing rather than running it unchecked/);
1402
+ assert.doesNotMatch(r.stdout, /(?:ℹ|#) pass/);
1403
+ });
1404
+
1405
+ // The issue's own second case, verbatim: "and, before PR #75's escape,
1406
+ // bracketed paths". Node globs its own argv, where a literal `[` is a bracket
1407
+ // expression that cannot match itself — so the path matches nothing, node
1408
+ // drops it, and mixed with a resolvable file that drop is silent: the runner
1409
+ // reported `pass 1` for a two-file argv and exited 0. The escape is the same
1410
+ // `sed 's/\[/[[]/g'` the directory branch already applies to find's output,
1411
+ // and asking whether the path EXISTS before reading it as a glob is what
1412
+ // gets the argument to it. Both invocations are here because they fail
1413
+ // differently without the escape: mixed goes quiet, alone exits 1 because
1414
+ // node then has nothing left to run.
1415
+ test("runner: a bracketed file argument runs, alone and mixed with a valid one", () => {
1416
+ const a = apply(SUITE);
1417
+ const mixed = a.run("t/a.test.mjs", "br[a]cket/g.test.mjs");
1418
+ assert.equal(mixed.status, 0, mixed.stdout + mixed.stderr);
1419
+ assert.match(mixed.stdout, /^(?:ℹ|#) pass 2$/m);
1420
+ const alone = a.run("br[a]cket/g.test.mjs");
1421
+ assert.equal(alone.status, 0, alone.stdout + alone.stderr);
1422
+ assert.match(alone.stdout, /^(?:ℹ|#) pass 1$/m);
1423
+ });
1424
+
1425
+ // A flag is not a path, and only node can judge one. Reading an argument
1426
+ // that does not exist as a typo refused every documented `node --test` flag
1427
+ // as a missing file — argv that ran fine before this guard existed, and
1428
+ // nothing else in this suite passes a flag. Node takes flag values with `=`
1429
+ // (measured: the space-separated form exits 9 at node itself), so a flag is
1430
+ // always one argv entry and passing it through cannot swallow a path. A
1431
+ // typo'd flag stays loud without this runner's help: node rejects it and
1432
+ // exits 9, which is why the last assertion insists the refusal is NOT
1433
+ // `agent-test:`-prefixed.
1434
+ test("runner: a node --test flag reaches node instead of being read as a path", () => {
1435
+ const a = apply(SUITE);
1436
+ for (const flag of [
1437
+ "--test-name-pattern=ok",
1438
+ "--test-only",
1439
+ "--test-reporter=tap",
1440
+ "--test-concurrency=1",
1441
+ "--",
1442
+ ]) {
1443
+ const r = a.run(flag, "t/a.test.mjs");
1444
+ assert.equal(r.status, 0, `${flag}: ${r.stdout}${r.stderr}`);
1445
+ assert.doesNotMatch(r.stderr, /does not exist/, flag);
1446
+ }
1447
+ const typo = a.run("--test-nmae-pattern=ok", "t/a.test.mjs");
1448
+ assert.notEqual(typo.status, 0, typo.stdout + typo.stderr);
1449
+ assert.doesNotMatch(typo.stderr, /agent-test:/, typo.stdout + typo.stderr);
1450
+ });
1451
+
1452
+ // #352: a flag counts toward `$#`, so an argv of flags alone cleared the
1453
+ // bare-form default, contributed no path operand, and reached node holding
1454
+ // only flags. That is node's own default discovery — which does not recognise
1455
+ // the `.spec.` form — so this fixture reported zero tests run at exit 0, the
1456
+ // vacuous pass this runner exists to refuse. It refuses here too rather
1457
+ // than defaulting: prepending the default AHEAD of node's own flags reorders
1458
+ // argv, and no briefed workflow passes flags alone.
1459
+ //
1460
+ // `--` is in the list because POSIX's end-of-options marker reaches the same
1461
+ // pass-through arm as a flag, and is no more a path than one.
1462
+ //
1463
+ // `-v` is in the list because a corpus spelled entirely with double dashes
1464
+ // cannot tell the classification pattern `-*` from `--*`. That classification
1465
+ // now lives in the dispatch's own arm order (the flag-detection arm, `-*) ;;`):
1466
+ // narrow it to `--*` and every double-dash entry here is still refused
1467
+ // exactly as before, while a lone `-v` no longer matches that arm and falls
1468
+ // through to the default/typo arm instead, refused there as `-v does not
1469
+ // exist` (exit 1) rather than reaching node. The row still discriminates the
1470
+ // mutation — it pins the refusal's wording now, not a vacuous exit 0 — but
1471
+ // the exit-0-after-printing-its-version failure mode this paragraph used to
1472
+ // describe no longer applies to this code shape.
1473
+ // Measured in both directions against that one-token mutation.
1474
+ //
1475
+ // Both directions, because a suite that only feeds a new refusal invalid input
1476
+ // pins neither: the ACCEPT case below rides the same flag alongside a real
1477
+ // operand, on the same fixture, so a refusal that swallowed the flag
1478
+ // pass-through would be red here rather than invisible. The bare form — the
1479
+ // other thing this guard could wrongly refuse — is pinned by the `.spec.`
1480
+ // cases below.
1481
+ //
1482
+ // The fixture is the issue's own repro, and it is what discriminates: under
1483
+ // node's discovery a `.spec.` file is not a test, so the pre-fix runner exited
1484
+ // 0. A `.test.mjs` fixture would have run green both ways and pinned nothing.
1485
+ test("runner: an argv of flags alone refuses instead of reaching node's own discovery", () => {
1486
+ const a = apply({ "t/a.spec.mjs": PASSES });
1487
+ for (const argv of [["--test-concurrency=1"], ["-v"], ["--"], ["--test-only", "--test-reporter=tap"]]) {
1488
+ const r = a.run(...argv);
1489
+ assert.notEqual(r.status, 0, `${argv.join(" ")}: ${r.stdout}${r.stderr}`);
1490
+ assert.match(r.stderr, /agent-test: no test file or directory/, argv.join(" "));
1491
+ }
1492
+ const ok = a.run("--test-concurrency=1", "t/a.spec.mjs");
1493
+ assert.equal(ok.status, 0, ok.stdout + ok.stderr);
1494
+ assert.match(ok.stdout, /^(?:ℹ|#) pass 1$/m);
1495
+ });
1496
+
1497
+ // #961. The corpus above is spelled entirely with arguments that do not
1498
+ // exist, so it pins one row of the classification and leaves the rule that
1499
+ // produces it unpinned: a dash-led argument is an operand where it EXISTS,
1500
+ // and a flag otherwise. Both rows below are dash-led, and they answer
1501
+ // oppositely — which is what makes the rule, rather than the shape, the
1502
+ // thing being pinned. Measured on a runner built from this emitter.
1503
+ //
1504
+ // `-dash.test.mjs` exists, so it is an operand. The runner never gets it to
1505
+ // run — node reads a relative dash-led spec as an option and dies in ITS own
1506
+ // voice, the same ceiling the dash-named directory test above already
1507
+ // carries one level up (measured on node v26.8.1 and on the v26.5.0 the
1508
+ // `.nvmrc` pins; `./`-prefixing does not escape it, node strips that
1509
+ // prefix first). Which refusal a caller sees is the whole of what the
1510
+ // classification buys here, and it is exactly what discriminates: classify
1511
+ // this argument as a flag instead and the runner refuses in its own voice,
1512
+ // at exit 1, before node is reached. The positive `node:` match is
1513
+ // load-bearing beside the negative — a nonzero exit with nothing on stderr
1514
+ // satisfies the negative on its own.
1515
+ //
1516
+ // `-t/*.test.mjs` does not exist and holds a glob metacharacter, so it
1517
+ // reaches the arm order where dash-ness is read BEFORE glob-ness: a flag,
1518
+ // not a glob, contributing no operand. Read it the other way round — "a
1519
+ // glob is a glob whatever it starts with" — and this argv reaches node,
1520
+ // which drops the unmatched pattern silently and exits 0 having run
1521
+ // nothing: the vacuous pass the guard exists to refuse, one argv shape past
1522
+ // the corpus above. The dash-led file is written straight into the worktree
1523
+ // rather than through `apply()`, for the reason the dash-named directory
1524
+ // test above gives.
1525
+ test("runner: a dash-led argument counts as an operand only where it exists", () => {
1526
+ const a = apply(SUITE);
1527
+ writeFileSync(join(a.wt, "-dash.test.mjs"), PASSES);
1528
+
1529
+ const exists = a.run("-dash.test.mjs");
1530
+ assert.notEqual(exists.status, 0, exists.stdout + exists.stderr);
1531
+ assert.doesNotMatch(exists.stderr, /agent-test: no test file or directory/, exists.stdout + exists.stderr);
1532
+ assert.match(exists.stderr, /node: bad option/, exists.stdout + exists.stderr);
1533
+
1534
+ const missing = a.run("-t/*.test.mjs");
1535
+ assert.notEqual(missing.status, 0, missing.stdout + missing.stderr);
1536
+ assert.match(missing.stderr, /agent-test: no test file or directory/, missing.stdout + missing.stderr);
1537
+ });
1538
+
1539
+ // The deliberately preserved escape hatch: `set -f` above stops the *shell*
1540
+ // from touching this, so a literal `*` reaches the runner exactly as the
1541
+ // glob-detection guard requires — spawnSync never invokes a shell, so this
1542
+ // is the same argv a member's own shell produces for a quoted glob. Only
1543
+ // node can expand it, and here it matches real files, so it must still run
1544
+ // them rather than being refused as "does not exist".
1545
+ test("runner: a quoted glob argument still runs, unexpanded by the shell", () => {
1546
+ const r = apply(SUITE).run("t/*.test.mjs");
1547
+ assert.equal(r.status, 0, r.stdout + r.stderr);
1548
+ assert.match(r.stdout, /^(?:ℹ|#) pass 2$/m);
1549
+ });
1550
+
1551
+ // A valid mix of both argument shapes the passthrough branch and the
1552
+ // directory branch each handle — neither new guard may refuse an argument
1553
+ // that was never in question.
1554
+ test("runner: a mixed argv of files and directories still runs everything", () => {
1555
+ const r = apply(SUITE).run("t/a.test.mjs", "t/nested");
1556
+ assert.equal(r.status, 0, r.stdout + r.stderr);
1557
+ assert.match(r.stdout, /^(?:ℹ|#) pass 2$/m);
1558
+ });
1559
+
1560
+ // #97: a bare invocation must go through the same expansion as an explicit
1561
+ // ".", not fall through to node's own default discovery. `for arg do` with no
1562
+ // `in` clause iterates "$@", so on an empty argv the loop body never ran and
1563
+ // the runner fell straight to bare `node --test`. Mixing a `.spec.` file into
1564
+ // the plain SUITE is what makes `pass 7` discriminate: SUITE alone is *not* a
1565
+ // counter-example, since node's own default discovery happens to match every
1566
+ // `.test.mjs` name in it too — a fixture that pinned "6" against SUITE would
1567
+ // stay green under the pre-fix bare `node --test` and prove nothing.
1568
+ test("runner: a bare invocation runs the same suite as an explicit \".\"", () => {
1569
+ const a = apply({ ...SUITE, "t/d.spec.mjs": PASSES });
1570
+ const dot = a.run(".");
1571
+ assert.equal(dot.status, 0, dot.stdout + dot.stderr);
1572
+ assert.match(dot.stdout, /^(?:ℹ|#) pass 7$/m);
1573
+ const bare = a.run();
1574
+ assert.equal(bare.status, 0, bare.stdout + bare.stderr);
1575
+ assert.match(bare.stdout, /^(?:ℹ|#) pass 7$/m);
1576
+ });
1577
+
1578
+ // The sharpest edge of #97: node's own default discovery does not recognise
1579
+ // the `.spec.` form, so a repo whose only test file uses it went green over
1580
+ // zero tests run under the pre-fix bare invocation. This is the exact
1581
+ // fixture from the issue's own repro.
1582
+ test("runner: a bare invocation runs .spec. files, which node's own discovery does not", () => {
1583
+ const r = apply({ "t/a.spec.mjs": PASSES }).run();
1584
+ assert.equal(r.status, 0, r.stdout + r.stderr);
1585
+ assert.match(r.stdout, /^(?:ℹ|#) pass 1$/m);
1586
+ });
1587
+
1588
+ // A repo with zero test files anywhere never reaches this runner at all —
1589
+ // derive-testcmd.sh refuses at emit time before a runner is written, pinned
1590
+ // by "runner: no scripts.test and no test files refuses rather than passing
1591
+ // vacuously" below. Nothing about that guard changes here — and where the two
1592
+ // disagree, they disagree safely: the emit guard greps `git ls-tree`, which
1593
+ // excludes neither `node_modules` nor symlinks, while this walk prunes the
1594
+ // first and `-type f` drops the second. A repo whose only committed test files
1595
+ // are vendored or symlinked therefore does reach the runner, and gets the
1596
+ // emptiness guard's `no test files under .` at exit 1 — a loud refusal, never
1597
+ // a vacuous pass. Pinned here rather than asserted: the block above used to
1598
+ // claim this state was unreachable, and the only `no test files under` pins in
1599
+ // the file were an explicit directory argument and two `doesNotMatch`. Vendored
1600
+ // is the cheaper of the two shapes to build — the symlink one needs a mode
1601
+ // 120000 entry that `apply()` cannot express — and both end in the same guard.
1602
+ // Pre-fix this is the vacuous green #97 exists to refuse: node's own discovery
1603
+ // skips `node_modules`, finds nothing, and exits 0 over `tests 0`.
1604
+ test("runner: a bare invocation refuses a repo whose only test files are vendored", () => {
1605
+ const r = apply({ "node_modules/pkg/v.test.mjs": PASSES }).run();
1606
+ assert.notEqual(r.status, 0, r.stdout + r.stderr);
1607
+ assert.match(r.stderr, /no test files under \./);
1608
+ });
1609
+
1610
+ // The blocker named in the issue body (defaulting to "." would sweep vendored
1611
+ // tests) was discharged by #109's node_modules exclusion before this landed.
1612
+ // Confirm the defaulted path actually goes through that prune rather than
1613
+ // bypassing it some other way.
1614
+ // Both fixture choices carry the pin; neither is decoration. The `.spec.`
1615
+ // file is what makes the count discriminate #97 — SUITE alone reads `pass 6`
1616
+ // under the pre-fix bare `node --test` too, since node's own discovery
1617
+ // matches every `.test.mjs` name in it and already skips node_modules, so a
1618
+ // fixture pinning "6" here is exactly the hollow one the comment above
1619
+ // warns about. And the vendored file is NESTED rather than sitting at the
1620
+ // worktree root because node refuses an argv entry whose relative path
1621
+ // starts with `node_modules/`, dropping it silently while the rest of argv
1622
+ // resolves (#100). At the root that refusal stands in for the prune:
1623
+ // measured with the prune deleted, a root-level fixture still reads
1624
+ // `pass 7` and still exits 0, so the assertion cannot tell this shim's walk
1625
+ // from node's own behaviour. Nested, only the prune keeps the file out.
1626
+ // `pass 7` rather than `pass 8`, over a vendored test that fails on
1627
+ // purpose, is what says it ran.
1628
+ test("runner: a bare invocation excludes vendored tests under node_modules", () => {
1629
+ const a = apply({ ...SUITE, "t/d.spec.mjs": PASSES });
1630
+ const vendor = join(a.wt, "t", "node_modules");
1631
+ mkdirSync(vendor, { recursive: true });
1632
+ writeFileSync(join(vendor, "v.test.mjs"), 'import { test } from "node:test";\ntest("VENDOR", () => { throw new Error("not ours"); });\n');
1633
+ const r = a.run();
1634
+ assert.equal(r.status, 0, r.stdout + r.stderr);
1635
+ assert.match(r.stdout, /^(?:ℹ|#) pass 7$/m);
1636
+ });