vitest-generated-child-test-file-race
Solution written to ~/solution.md.
Note: the heading repo at 9545664 was not present in this environment (only /workspace/problem.json exists), so I could not patch the live file. Instead I reconstructed the exact faulting shape from the description, applied the fix generically to the named file/config, and verified the mechanism with runnable tests:
Root cause — the parent writes hd-gap-051-generated-<pid>.test.ts into the globbed tests/crm/** directory, then deletes it in afterAll. Vitest collection is glob-then-import, not atomic with the file lifetime, so a concurrent worker/watch re-collection can enumerate the path after the write and import it after the delete → ENOENT/FileNotFoundError.
Fix
1. Generate the child into an excluded dir: apps/api/tests/crm-generated/.
2. Add '**/tests/crm-generated/**' to test.exclude in the Vitest config.
3. Add a globalSetup/teardown sweep to remove leftovers only after collection.
4. Keep .gitignore in the generated dir; execute the child by explicit path, not via the parent glob.
Verification performed
- Deterministic TOCTOU harness: buggy path → ENOENT, fixed path → no error.
- Real Vitest 2.1.8 vitest list: without exclude the generated child is collected; with the exclude it is not.
- Document includes exact apply/re-run commands (vitest run parent, 5× full-suite parallel loop, watch mode, git status cleanliness check).
# Evidence - Problem class: vitest-generated-child-test-file-race - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-09-29T13:40:07.318Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Parent test (apps/api/tests/crm/hd-gap-051-crm-boot.test.ts) writes hd-gap-051-generated-<pid>.test.ts then removes it in afterAll; a concurrent vitest worker can enumerate the file between write and rm and fail FileNotFoundError. Fix: write outside the vitest glob (tests/crm-generated/ ignored dir) or keep filename until a later afterAll sweep.", "environment": "", "language": "", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "vitest-generated-child-test-file-race", "provider": "openrouter", "solved_at": "2026-09-29T13:40:07.319Z", "version": ""}Solution written to ~/solution.md.
Note: the heading repo at 9545664 was not present in this environment (only /workspace/problem.json exists), so I could not patch the live file. Instead I reconstructed the exact faulting shape from the description, applied the fix generically to the named file/config, and verified the mechanism with runnable tests:
Root cause — the parent writes hd-gap-051-generated-<pid>.test.ts into the globbed tests/crm/** directory, then deletes it in afterAll. Vitest collection is glob-then-import, not atomic with the file lifetime, so a concurrent worker/watch re-collection can enumerate the path after the write and import it after the delete → ENOENT/FileNotFoundError.
Fix
1. Generate the child into an excluded dir: apps/api/tests/crm-generated/.
2. Add '**/tests/crm-generated/**' to test.exclude in the Vitest config.
3. Add a globalSetup/teardown sweep to remove leftovers only after collection.
4. Keep .gitignore in the generated dir; execute the child by explicit path, not via the parent glob.
Verification performed
- Deterministic TOCTOU harness: buggy path → ENOENT, fixed path → no error.
- Real Vitest 2.1.8 vitest list: without exclude the generated child is collected; with the exclude it is not.
- Document includes exact apply/re-run commands (vitest run parent, 5× full-suite parallel loop, watch mode, git status cleanliness check).
# Evidence - Problem class: vitest-generated-child-test-file-race - Model: openrouter/deepseek/deepseek-v4.1-flash - Solved: 2026-09-29T13:40:07.318Z - Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Parent test (apps/api/tests/crm/hd-gap-051-crm-boot.test.ts) writes hd-gap-051-generated-<pid>.test.ts then removes it in afterAll; a concurrent vitest worker can enumerate the file between write and rm and fail FileNotFoundError. Fix: write outside the vitest glob (tests/crm-generated/ ignored dir) or keep filename until a later afterAll sweep.", "environment": "", "language": "", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "vitest-generated-child-test-file-race", "provider": "openrouter", "solved_at": "2026-09-29T13:40:07.319Z", "version": ""}