test: migrate remaining mkdtempSync sites to createTempDir (PR #814 follow-up) - #819
Merged
kelsonpw merged 11 commits intoMay 22, 2026
Merged
Conversation
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
5 tasks
kelsonpw
force-pushed
the
refactor/extract-temp-dir-helper
branch
from
May 18, 2026 03:51
18a9eb5 to
7b8c420
Compare
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Finishes the migration started in #814. PR #814 extracted the shared
createTempDirhelper atsrc/utils/__tests__/helpers/temp-dir.tsand migrated 27 of the ~75 test files that inlinedmkdtempSync+rmSyncpatterns. 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:
batch 1— 9 single-callsrc/lib/__tests__/filesbatch 2— 7 multi-callsrc/lib/__tests__/files (wizard-tools keepsmakeTmpDir/cleanupwrappers that delegate to the helper, since 30+ callsites use them)batch 3— 5 remainingsrc/lib/__tests__/files (4-siteampli-config,download-skill; in-it()-block patterns)batch 4— 7src/lib/{agent,middleware,observability,orchestration,wizard-tools}/__tests__/filesbatch 5— 8src/ui/tui/screens/__tests__/filesbatch 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.tsFiles (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
pnpm testbaseline)Verification
pnpm tsc --noEmitcleanpnpm lintcleanpnpm test— 4474/4474 passsrc/utils/wizard-abort.tsuntouched (per scope)mkdtempSynccalls insrc/**/__tests__/*.test.{ts,tsx}(except the helper's own test)/tmp/temp-dir-contwill be removed after mergePatterns preserved
try { rmSync(...) } catch {}) becomestry { cleanup() } catch {}— same semantics.download-skill.test.tshost-allowlist cases,file-change-ledger.test.ts"outside install dir" case) become inlinecreateTempDir(...) + try/finally cleanup().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.OutroScreen.overdraw.test.tsx,ReportViewer.overdraw.test.tsx) — converted tocreateTempDirwithout adding cleanup (preserves prior behaviour; if leak fixing is wanted that's a separate PR).rmSynccalls 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/rmSynctemp directory patterns to the sharedcreateTempDirhelper, 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 tocreateTempDir(including a smallcleanupByDirmap inwizard-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.