Skip to content

Remove each test's temp files when it ends - #266

Merged
vicmaster merged 1 commit into
masterfrom
test-temp-cleanup
Nov 24, 2026
Merged

vicmaster merged 1 commit into
masterfrom
test-temp-cleanup

Conversation

@vicmaster

Copy link
Copy Markdown
Owner

Test runs left their files in the system temp dir and never removed them. These were the throwaway canvas stores that test/env.ts makes, the repos and stores other tests make with mkdtemp, and the Chrome profiles Puppeteer creates. On 2026-11-24 about 11,000 of these folders, 5 GB in all, filled the disk partway through a test run. A full run left about a hundred more each time.

What changed

  • Every test gets its own temp folder. scripts/run-tests.ts creates a folder for each test and points TMPDIR, TMP and TEMP at it. When the test ends, whether it passed, failed or timed out, the runner deletes the folder. If you press Ctrl-C, it deletes the folder of the test that was running. mkdtemp and Puppeteer's Chrome profiles both follow TMPDIR, so nothing a test makes outlives it.
  • The caches stay shared. tsx keeps its compile cache in the temp dir, and Node keeps one there too. Without help, each test would start both cold and run slower. Each test's folder links to the shared caches instead, and deleting the folder deletes only the link.
  • A runner started by a test does not nest its folders. The runner's own tests start a second runner. That inner runner puts its test folders beside the outer one rather than inside it. tsx opens a Unix socket under TMPDIR, and macOS limits socket paths to about 104 characters, so a folder two levels deep broke tsx with "listen EINVAL".
  • test/env.ts removes its own store when the process exits, cleanly or with an error. This covers a single test run on its own, outside the runner.
  • The README says what the runner does with temp folders.

Tests

  • New: test/unit/test-runner-temp.ts. It runs the real runner over three throwaway tests: one passes, one fails, and one hangs until it is killed. Each makes a folder and a file under os.tmpdir(). The test checks that:

    • each test had its own temp folder, not the system one;
    • all three folders are gone afterwards, the killed one included;
    • a nested runner puts its folders beside the outer one, not inside it;
    • the shared caches survive the cleanup;
    • test/env.ts run on its own removes its store after a clean exit and after process.exit(1).

    Against the old runner and env.ts, the test fails 6 checks and leaves 3 folders behind.

  • Full tier: 156/157 pass. I listed the system temp dir before and after the run. It gained no framesmith-* or fs-* folders, where it used to gain about a hundred.

  • The one failure was load. test-patterns-desktop timed out at 180 seconds while the machine's load average was 10 to 15. Run alone it passes, in 77 seconds on this branch and 72 on master.

Limits

  • Chrome's own scratch files. On macOS, Chrome writes about 40 small com.google.Chrome.* entries per full run to the user temp dir, which it finds without reading TMPDIR. This change does not clean those.
  • Tests run on their own. A test run directly, not through the runner, removes only the store test/env.ts made for it. Other temp folders it makes stay until the system cleans them.

Test runs left their stores, repo copies and Chrome profiles in the system
temp dir; 5 GB of them filled the disk. The runner now gives every test its
own TMPDIR, linked to the shared tsx and Node compile caches, and removes it
when the test passes, fails or times out. test/env.ts removes the store it
made when a test run on its own exits.
@vicmaster
vicmaster merged commit af01642 into master Nov 24, 2026
3 checks passed
@vicmaster
vicmaster deleted the test-temp-cleanup branch November 24, 2026 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant