Skip to content

test: migrate remaining mkdtempSync sites to createTempDir (PR #814 follow-up) - #819

Merged
kelsonpw merged 11 commits into
refactor/extract-temp-dir-helperfrom
refactor/temp-dir-migration-cont
May 22, 2026
Merged

test: migrate remaining mkdtempSync sites to createTempDir (PR #814 follow-up)#819
kelsonpw merged 11 commits into
refactor/extract-temp-dir-helperfrom
refactor/temp-dir-migration-cont

Conversation

@kelsonpw

@kelsonpw kelsonpw commented May 17, 2026

Copy link
Copy Markdown
Member

Summary

Finishes the migration started in #814. PR #814 extracted the shared createTempDir helper at src/utils/__tests__/helpers/temp-dir.ts and migrated 27 of the ~75 test files that inlined mkdtempSync + rmSync patterns. This PR migrates the remaining 46 test files to use the same helper.

Stacked on refactor/extract-temp-dir-helper; merge after #814.

Migration count

46 files migrated across 6 commits. Each commit groups files by directory / pattern so the diff stays reviewable:

  1. batch 1 — 9 single-call src/lib/__tests__/ files
  2. batch 2 — 7 multi-call src/lib/__tests__/ files (wizard-tools keeps makeTmpDir/cleanup wrappers that delegate to the helper, since 30+ callsites use them)
  3. batch 3 — 5 remaining src/lib/__tests__/ files (4-site ampli-config, download-skill; in-it()-block patterns)
  4. batch 4 — 7 src/lib/{agent,middleware,observability,orchestration,wizard-tools}/__tests__/ files
  5. batch 5 — 8 src/ui/tui/screens/__tests__/ files
  6. batch 6 — 10 remaining files: src/__tests__/cli.test.ts, src/commands/__tests__/, src/steps/__tests__/, src/ui/tui/{primitives,components,utils}/__tests__/, src/ui/tui/__tests__/store.test.ts

Files (deduped against PR #814)

Zero overlap with #814's 27-file list. All migrated files in this PR are net-new to the migration. The full list is the diff of this branch against refactor/extract-temp-dir-helper.

Tests

  • Before: 4474 passing
  • After: 4474 passing (same count, same pnpm test baseline)

Verification

Patterns preserved

  • Best-effort cleanup (try { rmSync(...) } catch {}) becomes try { cleanup() } catch {} — same semantics.
  • In-it() ad-hoc dirs (e.g. download-skill.test.ts host-allowlist cases, file-change-ledger.test.ts "outside install dir" case) become inline createTempDir(...) + try/finally cleanup().
  • Local makeTmpDir / cleanup(dir) wrapper functions (e.g. dashboard-plan.test.ts, diagnostics-collector.test.ts, wizard-tools.test.ts) — refactored to delegate to the helper.
  • Tests with no pre-existing cleanup (e.g. OutroScreen.overdraw.test.tsx, ReportViewer.overdraw.test.tsx) — converted to createTempDir without adding cleanup (preserves prior behaviour; if leak fixing is wanted that's a separate PR).
  • Mid-test rmSync calls that simulate user-driven directory wipes (e.g. observability/logger.test.ts, ampli-config.test.ts .amplitude/ subdir) — left inline; only the temp-dir setup/teardown moved to the helper.

🤖 Generated with Claude Code


Note

Low Risk
Test-only refactor that standardizes temp directory creation/cleanup; low risk aside from potential test isolation/cleanup behavior differences if any call sites were relying on implicit rmSync semantics.

Overview
Completes the test-suite migration away from ad-hoc mkdtempSync/rmSync temp directory patterns to the shared createTempDir helper, updating setup/teardown across remaining CLI, command, lib, agent, middleware, orchestration, and TUI test files.

A few tests that previously used local makeTmpDir/cleanup(dir) helpers were updated to delegate to createTempDir (including a small cleanupByDir map in wizard-tools.test.ts) so existing call sites keep working while centralizing cleanup semantics.

Reviewed by Cursor Bugbot for commit 922b7ed. Bugbot is set up for automated code reviews on this repo. Configure here.

kelsonpw added 11 commits May 16, 2026 23:58
Adds src/utils/__tests__/helpers/temp-dir.ts. ~75 test files inline the
same mkdtempSync + rmSync boilerplate, and the helper consolidates that
into one returning { dir, cleanup } so migrations are a pure refactor
with identical setup/teardown semantics.
Migrates 6 src/utils/__tests__ files to use the shared createTempDir
helper instead of inlined mkdtempSync + rmSync blocks. Identical setup
and teardown semantics; only the temp-directory boilerplate moves.
Continues the temp-dir helper migration across src/utils/__tests__:
file-utils, last-used-selection, orchestrator-context, package-json-light,
package-manager, port-detection, project-marker, setup-utils,
update-notifier, storage-paths, storage-migration, and
storage-migration-exdev. No behaviour change.
Migrates 10 framework test files (django/fastapi/flask/javascript-web/
nextjs/python utils plus python preflight/detect-ignores, javascript-web
agent, vue agent) to import createTempDir from the shared helpers
module. No behaviour change.
…TempDir

Continues the temp-dir helper migration across src/lib/__tests__ for the
session-checkpoint, agent-state, and agent-state-hydrate suites. Identical
beforeEach/afterEach semantics.
Migrates 9 src/lib/__tests__/ files from inlined `mkdtempSync` +
`rmSync` patterns to the shared `createTempDir` helper. Preserves
existing `beforeEach`/`afterEach` semantics — only the temp directory
ownership moves to the helper.

Files migrated:
- agent-interface.test.ts
- agent-ops.test.ts
- claude-settings-scope.test.ts
- dashboard-plan.test.ts (drops local makeTmpDir/cleanup wrappers)
- detect-amplitude.test.ts
- diagnostics-collector.test.ts (drops local wrappers; keeps os for homedir())
- event-plan-parser.test.ts
- integration-skill-resolve.test.ts
- package-manager-detection.test.ts (drops local wrappers)
Migrates 7 src/lib/__tests__/ files that contain 2-4 mkdtempSync sites
each. The wizard-tools.test.ts file keeps its makeTmpDir/cleanup
wrappers (called from 30+ scattered describe blocks) and delegates them
to createTempDir to avoid touching every callsite.

Files migrated:
- wizard-tools.test.ts (wrappers delegate to helper)
- wizard-mcp-server.test.ts
- file-change-ledger.integration.test.ts
- agent-plans.test.ts
- pre-stage-skills.test.ts
- session-checkpoint-events.test.ts
- workspace-analysis.test.ts
…tch 3)

Migrates the rest of src/lib/__tests__/ files using mkdtempSync. These
hold 1-4 sites each, with patterns including beforeEach/afterEach blocks,
nested it()-level temp dirs (try/finally), and best-effort try/catch
cleanup.

Files migrated:
- download-skill.test.ts (4 sites, all in it() blocks)
- ampli-config.test.ts (4 sites, distinct describes)
- file-change-ledger.test.ts (2 sites, one in nested it())
- self-heal.test.ts (3 sites; preserves os.homedir() use)
- agent-runner.test.ts (3 sites, distinct describes)
Migrates mkdtempSync sites in src/lib/{agent,middleware,observability,
orchestration,wizard-tools}/__tests__/ to the shared createTempDir
helper.

Files migrated:
- agent/preflight-context.test.ts (3 sites: 2 beforeEach + 1 in-it loop)
- agent/project-size.test.ts (drops local makeTmpDir wrapper)
- middleware/config.test.ts (2 sites, dual cleanup vars)
- observability/logger.test.ts (keeps rmSync for mid-test simulation)
- wizard-tools/bundled-skills-index.test.ts (1 site in try/finally)
- orchestration/store.test.ts (drops manual setup/teardown helpers)
- orchestration/last-stopping-point.test.ts
Migrates 8 src/ui/tui/screens/__tests__/ files to the shared
createTempDir helper. Each test file's cleanup pattern (try/catch
best-effort or simple rmSync) is preserved.

Files migrated:
- OutroScreen.overdraw.test.tsx (2 it()-block sites; no cleanup pre-existing)
- IntroScreen.snap.test.tsx (1 try/finally + 1 beforeEach)
- OutroScreen.preserveFiles.test.tsx
- OutroScreen.cancelFileState.test.tsx
- OutroScreen.error.test.tsx (preserves tmpdir() use in module-scope literal)
- OutroScreen.eventList.test.tsx
- RunScreen.eventsTab.test.tsx
- DataIngestionCheckScreen.tracking-plan.test.tsx
Final batch — migrates the last 10 test files holding inlined
mkdtempSync calls (TUI primitives/components/utils, root commands,
steps, top-level cli test). After this batch, the only remaining
mkdtempSync call in src/**/__tests__/ is inside the helper's own test.

Files migrated:
- src/__tests__/cli.test.ts (5 sites; mix of beforeEach + in-test dirs)
- src/commands/__tests__/orchestration.test.ts
- src/commands/__tests__/apply-lock-held.test.ts
- src/steps/__tests__/create-dashboard.test.ts
- src/ui/tui/__tests__/store.test.ts (createStore() helper)
- src/ui/tui/components/__tests__/PathInput.test.ts (keeps homedir())
- src/ui/tui/primitives/__tests__/LogViewer.snap.test.tsx
- src/ui/tui/primitives/__tests__/LogViewer.collapse.test.tsx
- src/ui/tui/primitives/__tests__/ReportViewer.overdraw.test.tsx
- src/ui/tui/utils/__tests__/welcome-back-context.test.ts
@kelsonpw
kelsonpw requested a review from a team as a code owner May 17, 2026 08:15
@kelsonpw
kelsonpw force-pushed the refactor/extract-temp-dir-helper branch from 18a9eb5 to 7b8c420 Compare May 18, 2026 03:51
@kelsonpw
kelsonpw removed the request for review from a team May 18, 2026 18:04
@kelsonpw
kelsonpw merged commit ef1d220 into refactor/extract-temp-dir-helper May 22, 2026
12 checks passed
kelsonpw added a commit that referenced this pull request May 22, 2026
…ollow-up) (#819)

* test(helpers): introduce createTempDir shared test helper

Adds src/utils/__tests__/helpers/temp-dir.ts. ~75 test files inline the
same mkdtempSync + rmSync boilerplate, and the helper consolidates that
into one returning { dir, cleanup } so migrations are a pure refactor
with identical setup/teardown semantics.

* test(utils): migrate batch 1 to createTempDir helper

Migrates 6 src/utils/__tests__ files to use the shared createTempDir
helper instead of inlined mkdtempSync + rmSync blocks. Identical setup
and teardown semantics; only the temp-directory boilerplate moves.

* test(utils): migrate batch 2 to createTempDir helper

Continues the temp-dir helper migration across src/utils/__tests__:
file-utils, last-used-selection, orchestrator-context, package-json-light,
package-manager, port-detection, project-marker, setup-utils,
update-notifier, storage-paths, storage-migration, and
storage-migration-exdev. No behaviour change.

* test(frameworks): migrate framework tests to createTempDir helper

Migrates 10 framework test files (django/fastapi/flask/javascript-web/
nextjs/python utils plus python preflight/detect-ignores, javascript-web
agent, vue agent) to import createTempDir from the shared helpers
module. No behaviour change.

* test(lib): migrate session-checkpoint and agent-state tests to createTempDir

Continues the temp-dir helper migration across src/lib/__tests__ for the
session-checkpoint, agent-state, and agent-state-hydrate suites. Identical
beforeEach/afterEach semantics.

* test(lib): migrate single-call lib tests to createTempDir (batch 1)

Migrates 9 src/lib/__tests__/ files from inlined `mkdtempSync` +
`rmSync` patterns to the shared `createTempDir` helper. Preserves
existing `beforeEach`/`afterEach` semantics — only the temp directory
ownership moves to the helper.

Files migrated:
- agent-interface.test.ts
- agent-ops.test.ts
- claude-settings-scope.test.ts
- dashboard-plan.test.ts (drops local makeTmpDir/cleanup wrappers)
- detect-amplitude.test.ts
- diagnostics-collector.test.ts (drops local wrappers; keeps os for homedir())
- event-plan-parser.test.ts
- integration-skill-resolve.test.ts
- package-manager-detection.test.ts (drops local wrappers)

* test(lib): migrate multi-call lib tests to createTempDir (batch 2)

Migrates 7 src/lib/__tests__/ files that contain 2-4 mkdtempSync sites
each. The wizard-tools.test.ts file keeps its makeTmpDir/cleanup
wrappers (called from 30+ scattered describe blocks) and delegates them
to createTempDir to avoid touching every callsite.

Files migrated:
- wizard-tools.test.ts (wrappers delegate to helper)
- wizard-mcp-server.test.ts
- file-change-ledger.integration.test.ts
- agent-plans.test.ts
- pre-stage-skills.test.ts
- session-checkpoint-events.test.ts
- workspace-analysis.test.ts

* test(lib): migrate remaining lib/__tests__ files to createTempDir (batch 3)

Migrates the rest of src/lib/__tests__/ files using mkdtempSync. These
hold 1-4 sites each, with patterns including beforeEach/afterEach blocks,
nested it()-level temp dirs (try/finally), and best-effort try/catch
cleanup.

Files migrated:
- download-skill.test.ts (4 sites, all in it() blocks)
- ampli-config.test.ts (4 sites, distinct describes)
- file-change-ledger.test.ts (2 sites, one in nested it())
- self-heal.test.ts (3 sites; preserves os.homedir() use)
- agent-runner.test.ts (3 sites, distinct describes)

* test(lib): migrate lib subdirectory tests to createTempDir (batch 4)

Migrates mkdtempSync sites in src/lib/{agent,middleware,observability,
orchestration,wizard-tools}/__tests__/ to the shared createTempDir
helper.

Files migrated:
- agent/preflight-context.test.ts (3 sites: 2 beforeEach + 1 in-it loop)
- agent/project-size.test.ts (drops local makeTmpDir wrapper)
- middleware/config.test.ts (2 sites, dual cleanup vars)
- observability/logger.test.ts (keeps rmSync for mid-test simulation)
- wizard-tools/bundled-skills-index.test.ts (1 site in try/finally)
- orchestration/store.test.ts (drops manual setup/teardown helpers)
- orchestration/last-stopping-point.test.ts

* test(ui): migrate TUI screen tests to createTempDir (batch 5)

Migrates 8 src/ui/tui/screens/__tests__/ files to the shared
createTempDir helper. Each test file's cleanup pattern (try/catch
best-effort or simple rmSync) is preserved.

Files migrated:
- OutroScreen.overdraw.test.tsx (2 it()-block sites; no cleanup pre-existing)
- IntroScreen.snap.test.tsx (1 try/finally + 1 beforeEach)
- OutroScreen.preserveFiles.test.tsx
- OutroScreen.cancelFileState.test.tsx
- OutroScreen.error.test.tsx (preserves tmpdir() use in module-scope literal)
- OutroScreen.eventList.test.tsx
- RunScreen.eventsTab.test.tsx
- DataIngestionCheckScreen.tracking-plan.test.tsx

* test: migrate remaining mkdtempSync sites to createTempDir (batch 6)

Final batch — migrates the last 10 test files holding inlined
mkdtempSync calls (TUI primitives/components/utils, root commands,
steps, top-level cli test). After this batch, the only remaining
mkdtempSync call in src/**/__tests__/ is inside the helper's own test.

Files migrated:
- src/__tests__/cli.test.ts (5 sites; mix of beforeEach + in-test dirs)
- src/commands/__tests__/orchestration.test.ts
- src/commands/__tests__/apply-lock-held.test.ts
- src/steps/__tests__/create-dashboard.test.ts
- src/ui/tui/__tests__/store.test.ts (createStore() helper)
- src/ui/tui/components/__tests__/PathInput.test.ts (keeps homedir())
- src/ui/tui/primitives/__tests__/LogViewer.snap.test.tsx
- src/ui/tui/primitives/__tests__/LogViewer.collapse.test.tsx
- src/ui/tui/primitives/__tests__/ReportViewer.overdraw.test.tsx
- src/ui/tui/utils/__tests__/welcome-back-context.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant