Skip to content

fix(#842): tsx-spawning integration tests blow vitest's 5s default — phase-registry now uses the prebuilt dist - #843

Merged
admarble merged 3 commits into
mainfrom
feature/842-fix-test-tsx-spawning-integration-tests-blow-v
Jul 29, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/842-fix-test-tsx-spawning-integration-tests-blow-v

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

phase-registry.integration.test.ts spawned tsx bin/cli.ts, recompiling the whole TypeScript program on every spawn, against a 5000 ms budget that vitest.config.ts never set explicitly. The behavior under test was always correct — the constant was mis-sized.

  • Convert phase-registry to the prebuilt dist/bin/cli.js (AC-1), matching its five siblings and the stated purpose of vitest.global-setup.ts. --phases is Commander argument coercion, byte-identical in source and compiled form, so this removes the compile from the hot path rather than widening a tolerance. Measured 4.2 s → 0.25 s per test.
  • Guard missing dist with a throwing beforeAll, not describe.skipIf (AC-6) — a skip would let the validation gate silently vanish for anyone running vitest without a build.
  • Keep sync-source-invocation on tsx (AC-2). fix(templates): getTemplatesDir resolves one level too high under tsx — source-run sync/init prints "✔ Synced" while installing nothing #822's bug lived in runtime import.meta.url resolution, so the compile is the thing under test; moving it to dist would delete the coverage. It gets a 60 s child timeout paired with a 90 s testTimeout instead, sized from measurement.
  • Order every child timeout strictly below its vitest ceiling (AC-3). A spawnSync timeout: is a child-process kill, not a test timeout — the old 30 s and 120 s values sat above the 5 s default and could never fire.
  • Add a 30 s testTimeout floor to the integration project only (AC-5); unit keeps vitest's 5 s.

Reviewing tip: use git diff -w. Adding the { timeout } option to sync-source-invocation's describe forced prettier to re-indent the whole body — ~150 of the ~184 added lines there are pure whitespace. The substantive diff is 104 insertions.

Beyond the named files

AC-3 is phrased repo-wide, so I audited every execSync/spawnSync child timeout rather than only the two files the issue names. Two further live violations of the same class turned up:

File Child timeout Vitest ceiling (before) Status
scripts/qa/precheck.test.ts 30 s + 60 s 5 s — no .integration. infix, so it sits in the unit project Fixed: own 90 s ceiling
scripts/qa/tautology-detector-cli.test.ts 30 s 30 s after this PR's floor — equal, not greater Fixed: own 60 s ceiling

precheck.test.ts shells out to npx tsx twice under a 5 s budget — a live flake of exactly this class that simply hadn't been diagnosed yet. src/lib/workflow/state-update-cli.test.ts already pairs 30 s/60 s correctly and is left untouched — it's the precedent the rest now follow.

AC coverage

AC Status Evidence
AC-1 MET No tsx invocation remains (only header prose explaining the change); assertions unchanged
AC-2 MET tsxBin still used; testTimeout: 90_000 with a comment justifying both the tsx requirement and the number
AC-3 MET Repo-wide audit; every child timeout now strictly below its ceiling
AC-4 MET 3 consecutive vitest run src/lib/workflow src/commands — 87 files, 1713 tests, zero timeout failures
AC-5 MET Scoped to the integration block with a justifying comment; unit block untouched
AC-6 MET Verified by removing dist and confirming a loud failure, not a green skip

Test plan

  • npm run build and npm run lint clean
  • Three consecutive runs of npx vitest run src/lib/workflow src/commands — all green across a 37→72 s spread in run duration, which is the load variance that used to break this
  • Full suite: 219 files, 4575 passed, 0 failures
  • AC-6 mutation check: rm -rf dist + a config without globalSetup → suite fails naming the missing path and telling the reader to run npm run build
  • Issue's verbatim motivating example run under both tsx and dist — identical validator output, confirming the conversion preserves what the test asserts

Notes for the reviewer

  • These commits are unsigned. gpg-agent could not launch pinentry in the non-interactive session that produced them, and I did not want to silently disable your signing config. Re-sign before merge if you want the branch to match repo convention.
  • Pre-existing, unrelated: src/lib/workflow/qa-stagnation.test.ts fails locally for anyone with global commit.gpgsign = true — its temp repos don't disable signing, so git commit dies with gpg: signing failed: No pinentry. This is the known environmental condition, not a defect in this PR; reproduced identically on unmodified main. The AC-4 and full-suite runs above were done with that confound neutralized via GIT_CONFIG_* env vars only — your global git config was not touched.

Closes #842

admarble added 2 commits July 28, 2026 22:35
…fault

phase-registry.integration.test.ts spawned `tsx bin/cli.ts`, recompiling the
whole TypeScript program per spawn — 4.2s idle on a cold cache, 7.5-17.8s under
full-suite load — against vitest's unset-and-therefore-5000ms testTimeout. The
behavior under test was always correct; the constant was mis-sized.

- Convert phase-registry to the prebuilt `dist/bin/cli.js`, matching its five
  siblings and the stated purpose of vitest.global-setup.ts. `--phases` is
  Commander coercion, identical in source and compiled form, so this removes
  the compile from the hot path rather than widening a tolerance. 4.2s -> 0.25s.
- Guard the missing-dist case with a throwing beforeAll, not
  `describe.skipIf`, so the validation gate cannot silently vanish (AC-6).
- Keep sync-source-invocation on tsx — #822's bug lived in runtime
  `import.meta.url` resolution, so the compile *is* the thing under test and
  moving to dist would delete the coverage. Instead pair a 60s child timeout
  with a 90s testTimeout, sized off the 17.8s worst case.
- Order every child timeout strictly below its vitest timeout so the child
  kill wins and reports `SIGTERM` plus captured output, instead of vitest's
  opaque "Test timed out". Fixes the same unreachable-timeout confusion in
  precheck.test.ts (30s/60s children under the unit project's 5s default) and
  tautology-detector-cli.test.ts (30s child equal to the new 30s floor).
- Give the integration project a 30s testTimeout floor; the unit project keeps
  vitest's 5s default, where a slow test is a real signal.

Verified: 3 consecutive `vitest run src/lib/workflow src/commands` (87 files,
1713 tests) with zero timeout failures across a 37-72s spread in run duration,
plus a full-suite run (219 files, 4575 tests). AC-6 checked by removing dist
and confirming a loud failure rather than a green skip.

Closes #842
…k at the cause, add a convention guard

Second adversarial pass. Three gaps:

1. AC-6 was applied narrowly while AC-3 was applied repo-wide — inconsistent.
   cli.integration.test.ts carried a describe.skipIf(!distExists) block whose
   only test asserted expect(distExists).toBe(true): skipped in exactly the
   case it would have failed, so it could never fail under any condition.
   run-tui.integration.test.ts's two flag-wiring assertions vanished silently
   on an unbuilt tree via it.skipIf. Both now fail loudly via the throwing
   beforeAll guard, naming the missing path and the remedy.

2. The precheck CLI fix treated the symptom, not the cause. A 90s ceiling
   left the two `npx tsx` spawns in the unit project, where fileParallelism
   is ON and they race every other unit file for CPU — the exact contention
   fileParallelism: false exists to prevent. The CLI block moves to
   precheck-cli.integration.test.ts (integration project by name: serialized,
   30s floor, 90s ceiling kept strictly above the 60s child timeout). The 28
   in-process precheck tests stay in the parallel unit project.

3. Nothing stopped the silent-skip pattern coming back — three files had
   independently reached for it. scripts/qa/dist-skip-guard.test.ts now walks
   every test file and fails naming the offender on any dist-conditioned
   skipIf. Comments are stripped before matching (the fixed files quote the
   forbidden pattern in their own explanatory comments). Mutation-verified:
   planting a real describe.skipIf(!distExists) fails the guard with the
   planted file's path; removing it goes green.

Verified: both converted files fail loudly against a genuinely absent dist
(no globalSetup, dist removed); full suite 221 files / 4576 passed.

Deleted test note: the "dist/ directory exists" test is removed because it
was tautological (see 1) — its job is now done by a guard that actually runs
when dist is missing.
@admarble

Copy link
Copy Markdown
Contributor Author

Round 2 pushed in 14b0e692 — a second adversarial pass applied AC-6 as repo-wide as AC-3: killed the two surviving silent skipIf(!distExists) sites (one was a test that could never fail: describe.skipIf(!distExists) wrapping expect(distExists).toBe(true)), moved the precheck CLI tests into the integration project instead of papering over the CPU contention with a bigger timeout, and added scripts/qa/dist-skip-guard.test.ts so the pattern can't come back (mutation-verified). Full suite: 221 files, 4576 passed. Details in the round-2 QA review on the issue.

@admarble
admarble merged commit 31f8b3e into main Jul 29, 2026
5 checks passed
@admarble
admarble deleted the feature/842-fix-test-tsx-spawning-integration-tests-blow-v branch July 29, 2026 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(test): tsx-spawning integration tests blow vitest's 5s default — phase-registry should use the prebuilt dist like its five siblings

1 participant