fix(test): isolate server unit tests from thread-pool env bleed - #6800
Conversation
The precommit individual-file path ran server tests through the root vitest config (pool: threads), letting process.env mutations in vi.hoisted() leak between concurrent workers. Full-suite runs used the server config (forks, sequential) and were unaffected, creating an intermittent-only failure signature that varied by test ordering. Three fixes: 1. Pass --config server/vitest.config.ts on the individual-file precommit path so server tests always fork. 2. Declare pool: 'forks' explicitly in server/vitest.config.ts instead of relying on the implicit default. 3. Route tests/announcement/** and tests/billing/** to the forks pool in the root vitest config via poolMatchGlobs — these directories set WORKOS/Stripe secrets in vi.hoisted() and cannot share process.env with parallel thread workers. Also add tests/setup/env-defaults.ts to pre-set common WORKOS env defaults before any root test file runs. Refs adcontextprotocol#6740
|
I pushed a maintainer follow-up that narrows this to the effective fix:
Verified with:
|
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — two-file test-infra fix with no blocking findings.
What I checked:
scripts/precommit-server-unit.cjsnow passes--config server/vitest.config.tson the individual-file path, so partial-commit server unit runs use the server config instead of falling through to the root threads pool. Correct and consistent with the full path (package.json:122 test:server-unitalready used the server config).server/vitest.config.tsmakespool: 'forks'explicit — sound.- No protocol surface touched (
static/schemas/source/**,docs/reference/**,dist/**, task defs), so no changeset is required. Schema↔docs coherence, oneOf discriminator, artifact immutability, and 3.1.x eligibility gates are all N/A.
Medium findings: none.
Note (low, non-blocking): The PR description overclaims — items 3-4 (a root vitest.config.ts poolMatchGlobs edit, a new tests/setup/env-defaults.ts, and 1052 root tests) are referenced but not present in the diff (only 2 files changed). The actual change on disk is sound; the mismatch is a description accuracy issue, not a code defect.
No critical/high/medium findings. gated_paths is false, high_risk is false, no author-team gate. Falls through to row 9 → approve. (review_decision: REVIEW_REQUIRED only blocks approval when gated_paths is true, which it is not here.)
Summary
Fix the flaky server-unit precommit path by ensuring individual changed test files run with the same isolated server Vitest configuration as the full suite.
Root cause: the precommit script's individual-file path (
planServerUnitRun→kind: 'files') invoked Vitest without--config, so it did not load the server setup and isolation settings. Full-suite runs were unaffected becausenpm run test:server-unitalready passes the server config.Changes
scripts/precommit-server-unit.cjs— pass--config server/vitest.config.tson the individual-file path.server/vitest.config.ts— explicitly declarepool: 'forks'instead of relying on the default.Verification
npx vitest run tests/precommit-server-unit.test.ts— 14 passednpm exec -- vitest run --config server/vitest.config.ts server/tests/unit/auth-api-key-format.test.ts— 5 passedRefs #6740