Skip to content

test: prefer shared temp dir helpers in auto-reply and install-fallback tests#96051

Closed
xialonglee wants to merge 1 commit into
openclaw:mainfrom
xialonglee:main
Closed

test: prefer shared temp dir helpers in auto-reply and install-fallback tests#96051
xialonglee wants to merge 1 commit into
openclaw:mainfrom
xialonglee:main

Conversation

@xialonglee

@xialonglee xialonglee commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gap finding: tempdir-8h9i0j1k / tempdir-9i0j1k2l

~100+ test files still use raw fs.mkdtemp/fs.mkdtempSync instead of the shared temp directory helpers. This causes:

  1. Disk leaks — temp dirs created but never cleaned up, accumulating under /tmp/openclaw-*
  2. Parallel test conflicts — concurrent tests may collide on /tmp paths
  3. Inconsistent patterns — the project has standardized on shared helpers (see Background)

Background

This is part of a long-running migration following this trajectory:

  1. Origin88b87d8 ("refactor: share temp dir test helper", 2026-03-13, @steipete): extracted the common mkdtemp + finally cleanup pattern from 4 test files into withTempDir() in src/infra/.
  2. Evolution13df67e ("test: reuse shared temp dir roots"): introduced createSuiteTempRootTracker() for suite-level shared roots with per-case numbered subdirectories, reducing redundant mkdtemp calls within a suite.
  3. Institutionalization06431fd / test: add temp directory helper guidance #87298 ("test: add temp directory helper guidance", 2026-06-15):
    • Documented the guidance in docs/reference/test.md: "Prefer the shared helpers in test/helpers/temp-dir.ts"
    • Added scripts/report-test-temp-creations.mjs — CI warns on any new bare mkdtemp calls in diffs
  4. Ongoing migration — Follow-up commits like 91b78eb, 49a168a, d498eec and others have progressively moved more test files to the shared helpers.

Why This Change Was Made

This PR migrates the first batch of high-risk test files that have zero cleanup — temp dirs are created but never removed:

  • install-fallback.test.ts: a single workspaceDir variable is assigned in beforeAll, but the pattern is fragile; if tests are added reusing the same variable, earlier dirs are lost and afterAll can only clean the last one.
  • session-hooks-context.test.ts: createStorePath() helper calls mkdtemp for each test case but never cleans up.
  • abort.test.ts: createAbortConfig() creates and returns a temp root dir that is never cleaned by callers.
  • inbound.test.ts: two test cases each create their own temp dir, never cleaned.

User Impact

  • No user-facing impact. Test-only changes.
  • Reduces /tmp directory pressure during repeated test runs.
  • Makes the CI cleaner — no new warnings from scripts/report-test-temp-creations.mjs for these files.

Evidence

Real behavioral proof — all 4 modified files pass:

$ pnpm test src/auto-reply/reply/session-hooks-context.test.ts \
           src/auto-reply/reply/abort.test.ts \
           src/auto-reply/inbound.test.ts \
           src/skills/lifecycle/install-fallback.test.ts

 Test Files  3 passed (3)
      Tests  95 passed (95)
   Duration  14.37s

Full auto-reply suite (144 test files, 2888 tests) also passes with the changes — the 1 unrelated failure is pre-existing and not in any touched file.

Files Changed

File Risk Fix
src/skills/lifecycle/install-fallback.test.ts P0 — variable overwrite risk createSuiteTempRootTracker()
src/auto-reply/reply/session-hooks-context.test.ts P0 — helper leaks temp dirs createSuiteTempRootTracker()
src/auto-reply/reply/abort.test.ts P0 — createAbortConfig leaks root dir createSuiteTempRootTracker()
src/auto-reply/inbound.test.ts P0 — 2 test cases without cleanup createSuiteTempRootTracker()

Each file now uses createSuiteTempRootTracker() with proper beforeAll/afterAll setup/cleanup, eliminating the leak.

…ck tests

Replace raw fs.mkdtemp/mkdtempSync calls with createSuiteTempRootTracker()
for automatic cleanup and consistent temp directory management.

- session-hooks-context.test.ts: mkdtemp in helper leaked temp dirs
- abort.test.ts: createAbortConfig mkdtemp returned root without cleanup
- inbound.test.ts: two test cases created temp dirs without cleanup
- install-fallback.test.ts: workspaceDir variable could be overwritten

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant