Bug type
Behavior bug (incorrect output/state without crash)
Summary
Test runs create /tmp/openclaw-* temporary directories that are never cleaned up, accumulating 192+ stale directories over time.
Steps to reproduce
- Clone the repository and run tests:
npx vitest run
- Check
/tmp after the run:
ls -d /tmp/openclaw-*/ | wc -l
- Run tests again — the count only increases
Expected behavior
Temporary directories created during tests should be cleaned up after each test suite completes.
Actual behavior
44 test files call fs.mkdtempSync / fs.mkdtemp without a corresponding fs.rm() in afterAll/afterEach. Examples:
src/infra/exec-approvals.test.ts — mkdtempSync in helper, no cleanup
src/infra/dotenv.test.ts — mkdtemp in withDotEnvFixture, no finally cleanup
src/agents/pi-auth-json.test.ts — mkdtemp per test, no cleanup
src/gateway/hooks-mapping.test.ts — 8 mkdtempSync calls, no cleanup
The existing test helpers (withTempHome, withStateDirEnv, createTempHomeEnv) properly handle cleanup, but these 44 files bypass them and call mkdtemp directly.
OpenClaw version
main (commit 150c048)
Operating system
Ubuntu 20.04 (Linux 5.4.0-216-generic)
Install method
pnpm dev (source checkout)
Logs, screenshots, and evidence
$ ls -d /tmp/openclaw-*/ | wc -l
192
$ ls -d /tmp/openclaw-*/
/tmp/openclaw-0xxu2H/
/tmp/openclaw-41vG5I/
/tmp/openclaw-6pTB1G/
/tmp/openclaw-agent/
/tmp/openclaw-before-write-Jgr5AG/
/tmp/openclaw-depth-policy-TlWPpD/
/tmp/openclaw-dotenv-test-*/
/tmp/openclaw-exec-approvals-*/
/tmp/openclaw-gw-*/
... (192 directories total)
Impact and severity
- Affected: All developers running tests locally; CI environments
- Severity: Low (does not block workflows, but wastes disk space)
- Frequency: Every test run adds more stale directories
- Consequence: Gradual disk space accumulation; stale test artifacts in
/tmp
Additional information
Proposed fix
Add trackedMkdtempSync / trackedMkdtemp utility functions to test/test-env.ts that wrap mkdtemp, track created directories, and clean them up via the existing installTestEnv().cleanup().
const trackedTempDirs: string[] = [];
export function trackedMkdtempSync(prefix: string): string {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
trackedTempDirs.push(dir);
return dir;
}
export function cleanupTrackedTempDirs(): void {
for (const dir of trackedTempDirs) {
try { fs.rmSync(dir, { recursive: true, force: true }); } catch {}
}
trackedTempDirs.length = 0;
}
Why not monkey-patch fs.mkdtempSync? ~13 files destructure the import (import { mkdtempSync } from "node:fs"), capturing a direct reference. An explicit utility function is more reliable.
Migration plan:
- First PR: Add utilities + migrate
src/infra/ tests (6 files)
- Follow-up PRs: Migrate remaining files by area
Bug type
Behavior bug (incorrect output/state without crash)
Summary
Test runs create
/tmp/openclaw-*temporary directories that are never cleaned up, accumulating 192+ stale directories over time.Steps to reproduce
npx vitest run/tmpafter the run:Expected behavior
Temporary directories created during tests should be cleaned up after each test suite completes.
Actual behavior
44 test files call
fs.mkdtempSync/fs.mkdtempwithout a correspondingfs.rm()inafterAll/afterEach. Examples:src/infra/exec-approvals.test.ts—mkdtempSyncin helper, no cleanupsrc/infra/dotenv.test.ts—mkdtempinwithDotEnvFixture, nofinallycleanupsrc/agents/pi-auth-json.test.ts—mkdtempper test, no cleanupsrc/gateway/hooks-mapping.test.ts— 8mkdtempSynccalls, no cleanupThe existing test helpers (
withTempHome,withStateDirEnv,createTempHomeEnv) properly handle cleanup, but these 44 files bypass them and callmkdtempdirectly.OpenClaw version
main (commit 150c048)
Operating system
Ubuntu 20.04 (Linux 5.4.0-216-generic)
Install method
pnpm dev (source checkout)
Logs, screenshots, and evidence
Impact and severity
/tmpAdditional information
Proposed fix
Add
trackedMkdtempSync/trackedMkdtemputility functions totest/test-env.tsthat wrapmkdtemp, track created directories, and clean them up via the existinginstallTestEnv().cleanup().Why not monkey-patch
fs.mkdtempSync? ~13 files destructure the import (import { mkdtempSync } from "node:fs"), capturing a direct reference. An explicit utility function is more reliable.Migration plan:
src/infra/tests (6 files)