Skip to content

Commit 358e11b

Browse files
committed
fix(cli): keep the git-ignored tmp/ scratch tree out of the vitest tier walk
packages/cli/vitest-tiers.ts walked the whole package at config load, including tmp/, where sibling tests render scaffolds (test files included) and delete them mid-run. A delete inside the walk threw ENOENT out of the config load, so the #18788 pin's no-override vitest list child exited 1 in the merge queue. tmp/ is now skipped; the control plants a test file there and asserts the listing does not name it. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01REwoooZ6nXESkVCEtsbeRC
1 parent 36b2670 commit 358e11b

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎packages/cli/test/hook-timeout-override-refusal.test.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@
7979
*/
8080

8181
import { execFileSync } from 'node:child_process';
82+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
8283
import { createRequire } from 'node:module';
83-
import { dirname, resolve } from 'node:path';
84+
import { dirname, join, resolve } from 'node:path';
8485
import { fileURLToPath } from 'node:url';
8586
import { describe, expect, it } from 'vitest';
8687
import { childEnv } from './helpers/serve-process.js';
@@ -214,12 +215,27 @@ describe('#18788 a CLI timeout override that cannot reach a project is refused,
214215
it('⭐ CONTROL — a run naming no override passes and says nothing', () => {
215216
// Without this leg the three above are satisfied by a config that refuses
216217
// everything, which would be a worse defect than the one being fixed.
217-
const run = runVitestList();
218+
//
219+
// #26047: the walk that builds this run's population must not read the
220+
// package's git-ignored `tmp/`. Sibling tests render whole scaffolds there,
221+
// test files included, and delete them mid-run; a delete that landed inside
222+
// the walk threw `ENOENT` out of the config load and this child exited 1. A
223+
// test file planted there is in no tier, so the listing must not name it.
224+
mkdirSync(join(PKG, 'tmp'), { recursive: true });
225+
const scratch = mkdtempSync(join(PKG, 'tmp', 'hook-timeout-control-'));
226+
writeFileSync(join(scratch, 'planted.test.ts'), 'export {};\n');
227+
let run: ChildRun;
228+
try {
229+
run = runVitestList();
230+
} finally {
231+
rmSync(scratch, { recursive: true, force: true });
232+
}
218233

219234
expect(run.status, describeRun(run)).toBe(0);
220235
expect(run.output).not.toContain(REFUSAL);
221236
// It really listed something, so the zero is a reading and not an empty run.
222237
expect(run.output).toMatch(/\.test\.ts/);
238+
expect(run.output).not.toContain('planted.test.ts');
223239
}, VITEST_LIST_BUDGET_MS);
224240

225241
it('⭐ CONTROL — `--testTimeout` is on vitest’s allowlist, reaches the projects, and is NOT refused', () => {

‎packages/cli/vitest-tiers.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,15 @@ export function tierOfFile(pkgRoot: string, relPath: string): TierSignals {
193193
// ---------------------------------------------------------------------------
194194

195195
const TEST_FILE_RE = /\.(?:test|spec)\.[cm]?[jt]sx?$/;
196-
const SKIP_DIRS = new Set(['node_modules', 'dist', '.git', '.turbo', 'coverage']);
196+
/**
197+
* `tmp` is this package's git-ignored scratch tree (#26047). Sibling tests
198+
* render whole scaffolds into it, real `*.test.ts` files included, and delete
199+
* them while other children load this config. Walking it put fixture files in
200+
* the population and, when a delete landed mid-walk, threw `ENOENT` out of the
201+
* config load, so a `vitest list` child exited 1. Nothing under it is ever a
202+
* test of this package.
203+
*/
204+
const SKIP_DIRS = new Set(['node_modules', 'dist', '.git', '.turbo', 'coverage', 'tmp']);
197205

198206
/**
199207
* `pkgRoot`-relative, POSIX-separated paths of every test file on disk that

0 commit comments

Comments
 (0)