Files
hermes-agent/apps/desktop/vitest.run-tmp.ts
teknium1 989798cd5e fix(desktop): test runs stop leaking temp dirs into TMPDIR
Hermes points TMPDIR at ~/.hermes/cache/scratch, so every Desktop test
run's leftovers pile up there until the 24h idle pruner catches them:
one day on a dev host left 688 playwright-tracing-*, 152
playwright-artifacts-*, 75 hermes-e2e-mock-* sandboxes and ~600 small
vitest mkdtemp dirs.

- Playwright (main + core configs): e2e/run-tmp.ts gives the run one
  temp root that workers, Electron and the backend inherit via TMPDIR,
  and removes it when the runner exits. Covers the stack-trace dirs the
  Electron tracing patch orphans (2 per launch, even on green runs),
  sandboxes a failed/timed-out setup never cleans, and Playwright's own
  artifact dirs. A SIGKILLed run now leaves one pw-* dir for the pruner.
  The update suite keeps os.tmpdir(): its seeded install is reused
  across runs and bakes its path into AF_UNIX sockets.
- vitest (apps/desktop): globalSetup does the same for the run; one
  `--project electron` run left 54 dirs from tests that never remove
  what they mkdtemp.
2026-09-27 23:10:22 -07:00

20 lines
633 B
TypeScript

/**
* One temp root per vitest run, removed at teardown.
*
* Tests mkdtemp under os.tmpdir() and not all of them remove what they make:
* one run of the `electron` project left 54 dirs behind. Workers inherit
* TMPDIR from this process, so everything a test creates lands here instead.
*/
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
export default function setup(): () => void {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'vitest-'))
process.env.TMPDIR = root
process.env.TEMP = root
process.env.TMP = root
return () => fs.rmSync(root, { recursive: true, force: true })
}