Repository navigation
fix(test): run spawned CLIs from a per-run snapshot of dist/ - #439
Conversation
|
@claude /review |
|
Claude finished @theCodeDrift's task in 1m 36s —— View job Review mode: incremental — read 0 prior review thread(s) before reviewing.
Checklist
AssessmentThis is a well-targeted fix with good self-documenting rationale in the comments. I read the full diff plus the three new/changed support files and Correctness of the snapshot mechanism (
No correctness, security, or test-adequacy issues found. This is test-only infrastructure as described, and the |
`vitest run` does not build, so every spawned CLI read whatever dist/ held at that moment, and a build that started mid-run (`pnpm lint` builds first) emptied dist/ before rewriting it. Measured: 22 of 343 spawns failed with builds running alongside, each exit 1 with empty stdout and `Cannot find module …/dist/index.js`; 0 of 414 without. A global setup now copies dist/ into packages/cli/tmp/dist-test/<pid>-* once per run, retrying if a build changes it mid-copy, and every test reads from there. It stays inside the package because the bundle finds tsx, ast-grep and Vale relative to its own file. Snapshots whose owning process has exited are swept on the next run. spawn-cli.ts now reports a missing built module as the CLI never having run, rather than as a contract failure. Fixes #262
c6ed7ab to
6c4f7ba
Compare
Declined: the ~2.5s delay only happens on a checkout with no build at all, and that case still ends in a clear "run — AI Coding Agent |
Two spawning tests failed once on a full-suite run and passed on an immediate rerun (#262). The cause:
vitest rundoes not build, so every spawned CLI reads whateverdist/holds at that moment, and a build that starts mid-run (pnpm lintbuilds first) emptiesdist/before rewriting it.Measured by spawning
auth login --anonymous --jsonin a loop:Every failure was exit code 1, empty stdout, and
Cannot find module …/dist/index.js(or a chunk) on stderr, which is exactly what both reported assertions choke on. Because the exit code is a real number, thespawn-cli.tshelper added for #262 reported it as a CLI contract failure, and its comment pointed at fork pressure instead.What changed
test/support/distribution-snapshot.ts: vitest global setup. It copiesdist/once per run intopackages/cli/tmp/dist-test/<pid>-*and retries if a build changesdist/mid-copy. Teardown removes the copy, and snapshots whose owning process has exited are swept on the next run, never a live one. Ifdist/index.jsis missing it fails with "runpnpm buildfirst".test/support/built-cli.ts:builtCli()/builtDirectory(). Every test that spawned or imported../dist(33 files) now reads the snapshot.test/support/spawn-cli.ts: a missing built module is reported as "the CLI never ran". Node's ESM loader names the realpath and the CJS loader the given path, so both are matched. There are two new real-spawn tests.The snapshot lives inside the package, not
os.tmpdir(), because the bundle finds tsx, ast-grep and Vale relative to its own file throughcreateRequire(import.meta.url). From a tmpdir copy bothtsxand@ast-grep/cliwere unresolvable.tmpis already gitignored.Verification
dist/was rebuilt in a loop underneath it: 1790/1790 passed.dist/error were both checked by hand.pnpm typecheck, eslint and prettier are clean.Test-only change, so no changeset.
Fixes #262