mirror of
https://github.com/colbymchenry/codegraph.git
synced 2026-10-18 13:53:01 +08:00
2344ce0722
Every full test run left about 40 directories in the temp dir, even when it passed. On the Windows dev machine about 16,000 had piled up by mid-October. A full run with TEMP pointed at an empty folder showed where each one came from: - function-ref (20) and ts-field-classification (3): each case's `finally` cleared `tmpDir` right after `cg.destroy()`, so the `afterEach` that removes the dir found nothing to remove. - npm-sdk (3) and liveness-watchdog (3) never removed the dirs they made. - extraction's #1502 suite (3) made a dir in `beforeEach` and had no `afterEach`; pr19-improvements' schema-version case (1) made one inline. - setup-home-sandbox (6 on Windows): Vitest runs no hooks for a file whose every test is skipped, so each platform-gated file left its home sandbox. Each sandbox now records itself in a per-run registry, and a global teardown removes whatever is still listed and names any dir still in use. With the fix, the same full run leaves nothing behind but Node's own reused compile cache. test-home-sandbox gains two tests: a file's home is listed in the run's registry, and the teardown removes every listed home, then the registry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
3.2 KiB
TypeScript
65 lines
3.2 KiB
TypeScript
import { defineConfig } from 'vitest/config';
|
|
import { WASM_RUNTIME_FLAGS } from './src/extraction/wasm-runtime-flags';
|
|
|
|
/**
|
|
* The SHARED base. `vitest.workspace.mts` extends it twice — once for the
|
|
* engine's node-environment suites and once for the viewer package's jsdom
|
|
* one — so the environment, the plugins and the module-resolution conditions
|
|
* a browser test needs cannot leak into the other 200-odd suites.
|
|
*/
|
|
export default defineConfig({
|
|
test: {
|
|
globals: true,
|
|
environment: 'node',
|
|
include: ['__tests__/**/*.test.ts'],
|
|
// Suites that spawn the built CLI need a current dist/ (#1879), and the end
|
|
// of the run removes any home sandbox its own test file could not.
|
|
globalSetup: ['./__tests__/global-setup-dist.ts', './__tests__/global-setup-home-sandbox.ts'],
|
|
// A throwaway home dir (and git global config) per test file, so nothing
|
|
// the suite runs can write to the developer's real one (#2275).
|
|
setupFiles: ['./__tests__/setup-home-sandbox.ts'],
|
|
/**
|
|
* Several MCP integration tests (mcp-daemon, mcp-initialize, mcp-ppid-watchdog,
|
|
* mcp-roots) spawn `dist/bin/codegraph.js serve --mcp` with `process.execPath`
|
|
* and rely on the child inheriting `process.env`. On a Node >= 25 dev machine
|
|
* the CLI's hard-block (src/bin/codegraph.ts) would otherwise exit the child
|
|
* before it ever responds, so every spawn-based test times out — see #478.
|
|
*
|
|
* Setting the override here keeps the CLI's runtime guard intact for end
|
|
* users (it's still enforced when `codegraph` is invoked directly) while
|
|
* letting the test suite run on whatever Node the contributor happens to
|
|
* have installed. CI on Node 22/23 is unaffected — the guard doesn't fire
|
|
* there, so the variable is a no-op.
|
|
*/
|
|
env: {
|
|
CODEGRAPH_ALLOW_UNSAFE_NODE: '1',
|
|
/**
|
|
* The suite spawns real CLI/MCP processes; without this they would write
|
|
* telemetry state into the contributor's real ~/.codegraph and count test
|
|
* tool calls as real usage. The telemetry unit tests are unaffected —
|
|
* they inject their own `env` via the Telemetry constructor.
|
|
*/
|
|
CODEGRAPH_TELEMETRY: '0',
|
|
},
|
|
/**
|
|
* The same V8 flags every real launch path passes (the bundled launcher,
|
|
* the CLI's self re-exec, refresh-launcher): keep tree-sitter grammar
|
|
* compilation on the Liftoff baseline tier. Without them a pool worker
|
|
* runs the grammars on the turboshaft optimizing tier, and once enough
|
|
* parses have warmed a grammar function up, its background tier-up job
|
|
* exhausts a compiler Zone and aborts the worker — `Fatal process out of
|
|
* memory: Zone`, surfaced by vitest only as "Worker exited unexpectedly"
|
|
* with the rest of the file's tests silently unrun (#1779; the product-side
|
|
* story is in wasm-runtime-flags.ts, #293/#298). On Node 24 with a
|
|
* 660-test extraction suite this reproduced on every run at the same test.
|
|
* V8 flags are process-global, so the parse worker threads a test spawns
|
|
* are covered too.
|
|
*/
|
|
poolOptions: { forks: { execArgv: [...WASM_RUNTIME_FLAGS] } },
|
|
coverage: {
|
|
provider: 'v8',
|
|
reporter: ['text', 'json', 'html'],
|
|
},
|
|
},
|
|
});
|