Follow-up to #1593.
That PR fixes the temp-dir leak in vitest-run test lanes by redirecting TMPDIR for the whole invocation via globalSetup/globalTeardown (scripts/vitest-tmpdir-global-setup.ts) and asserting it stays clean (scripts/check-tmpdir-leaks.ts).
That mechanism only covers vitest. The node --test lanes — test:smoke, test:integration:node, and other script-driven suites — still create scratch directories against the real, unredirected os.tmpdir(), with no cleanup. Some of the originally observed leak prefixes (help-bench, ime-lifecycle-state) came from exactly these lanes, so this isn't hypothetical.
Suggested approach
Same trick, applied at the npm-script level instead of via a test-runner hook, since node --test has no global setup/teardown concept:
- A tiny wrapper script (or inline
TMPDIR=$(mktemp -d) ...; rm -rf "$TMPDIR" in the relevant package.json scripts) that sets TMPDIR before invoking node --test, and does one recursive rm after it exits — mirroring scripts/vitest-tmpdir-global-setup.ts's /tmp-rooted approach (not nested inside macOS's deep per-user TMPDIR, to avoid the AF_UNIX sun_path-length issue that PR hit).
- Extend (or duplicate)
scripts/check-tmpdir-leaks.ts to also assert no leftover directory from these lanes.
Scoped out of #1593 to keep that PR focused; this is the ~10% of the leak surface it didn't close.
Follow-up to #1593.
That PR fixes the temp-dir leak in vitest-run test lanes by redirecting
TMPDIRfor the whole invocation viaglobalSetup/globalTeardown(scripts/vitest-tmpdir-global-setup.ts) and asserting it stays clean (scripts/check-tmpdir-leaks.ts).That mechanism only covers vitest. The
node --testlanes —test:smoke,test:integration:node, and other script-driven suites — still create scratch directories against the real, unredirectedos.tmpdir(), with no cleanup. Some of the originally observed leak prefixes (help-bench,ime-lifecycle-state) came from exactly these lanes, so this isn't hypothetical.Suggested approach
Same trick, applied at the npm-script level instead of via a test-runner hook, since
node --testhas no global setup/teardown concept:TMPDIR=$(mktemp -d) ...; rm -rf "$TMPDIR"in the relevantpackage.jsonscripts) that setsTMPDIRbefore invokingnode --test, and does one recursive rm after it exits — mirroringscripts/vitest-tmpdir-global-setup.ts's/tmp-rooted approach (not nested inside macOS's deep per-userTMPDIR, to avoid the AF_UNIXsun_path-length issue that PR hit).scripts/check-tmpdir-leaks.tsto also assert no leftover directory from these lanes.Scoped out of #1593 to keep that PR focused; this is the ~10% of the leak surface it didn't close.