Files
Matt Godbolt (bot acct) 05f59881f7 Make --tmp-dir authoritative over inherited environment (#8819)
Fixes #8816.

- `setupTempDir()` exports the configured dir as `TMPDIR`, `TMP` *and*
`TEMP`. POSIX `os.tmpdir()` consults `TMPDIR` first, so the old TMP-only
export meant an inherited `TMPDIR` silently defeated `--tmp-dir`
(verified empirically; prod was protected only by `sudo env_reset` in
start.sh). Setting all three also covers native Windows (`TEMP` > `TMP`
there) and WSL, and means spawned tools reading any of the variables
agree.
- Restores the `os.tmpdir() !== tmpDir → throw` sanity check from
613d7f688 (#6052), lost in the #7681 split refactor.
- The startup log now prints `os.tmpdir()` — the value that actually
matters — instead of `TEMP || TMP`, which printed `undefined` on a
default Linux run.
- The `lib/temp.ts` exit hook was `process.on('exit', async ...)`: exit
handlers can't await, so it never removed anything. Replaced with a
synchronous `cleanupSync()` (tested).
- Test hygiene fix that the work surfaced: the temp-dir tests restored
the environment by reassigning `process.env` wholesale; a replaced
`process.env` is a plain object whose writes never reach the real
environment, while `os.tmpdir()` reads the real environ via `safeGetenv`
— so the suite silently leaked env state across tests (and into any test
running later in the same worker). Now saves/restores the individual
variables.

The WSL `%TEMP%`-discovery-failure path (`wsl-vc.ts` parsing garbage on
fallback, #8816 item 4) is deliberately untouched — Windows-specific and
unverifiable here.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: mattgodbolt-molty <mattgodbolt-molty@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-06-14 20:11:35 +01:00
..