test: scrub ambient PTY_ROOT so the suite is hermetic inside a pty session (#62)
When the vitest process itself runs inside a pty session, its ambient
PTY_ROOT / PTY_SESSION / PTY_SESSION_DIR leaked into every spawned `pty`.
getSessionDir() prefers PTY_ROOT over the per-test PTY_SESSION_DIR that the
helpers pass, so the spawned CLI read the developer's REAL live session dir
instead of the test tmpdir — non-deterministic failures, and a risk of
mutating live sessions.
- tests/setup/isolate-env.ts: new per-worker setupFile (registered in
vitest.config) that scrubs the three ambient vars before any test module
runs — the hard guard.
- Session.spawn: extract buildSpawnEnv() (pure, exported) and also scrub
ambient PTY_ROOT / PTY_SESSION_DIR there, so external users of the shipped
testing library get the same isolation. Guarded: an explicit root passed via
opts.env still wins.
- tests/env-isolation.test.ts: unit tests for buildSpawnEnv + a guard test
asserting the setupFile scrubbed the worker env.
- gc-flap-clear-badge-root-len: the restart test was passing only because an
ambient PTY_SESSION made `pty restart` skip its attach; set PTY_SESSION
explicitly so it no longer depends on the leak.
Verified: full suite green (1213 passed) WITH ambient PTY_ROOT set and no
env -u / shim workarounds; unchanged in clean CI (scrub is a no-op there).