Skip to content

fix(test): sandbox os.homedir() via spyOn instead of env vars - #4

Merged
jaesbit merged 1 commit into
mainfrom
fix/test-homedir-mock
Jul 2, 2026
Merged

fix(test): sandbox os.homedir() via spyOn instead of env vars#4
jaesbit merged 1 commit into
mainfrom
fix/test-homedir-mock

Conversation

@jaesbit

@jaesbit jaesbit commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Why

Bun 1.3.14's os.homedir() ignores a runtime process.env.HOME/USERPROFILE reassignment. orientation-store.test.ts and kb-protocol.test.ts both relied on that reassignment in beforeEach to sandbox home-dir-derived paths — it silently no-op'd, so bun test fell through to the real user home.

Confirmed impact: a test run clobbered the real ~/.omp/agent/commands/start.md with fixture content (description: "Quoted summary", body: "body"), which is how this surfaced (deck's /start auto-orientation prompt lost its real content).

Fix

Stub os.homedir() directly with spyOn in both test files instead of the env var. Works identically on Windows/Linux since production code (orientation-store.ts, env-store.ts, kb-service.ts) always resolves the home dir through that one call — no platform coverage lost.

Scope

Test-only change. No production code touched.

Verification

  • bun test orientation-store: 15 pass
  • bun test kb-protocol: 10 pass
  • Confirmed ~/.omp/agent/commands/start.md mtime unchanged after re-running the fixed suite

Bun 1.3.14's os.homedir() ignores a runtime process.env.HOME/USERPROFILE
reassignment, so the beforeEach override in orientation-store.test.ts and
kb-protocol.test.ts silently no-op'd. getStartCommandPath() (and the
kb-service homedir fallback) fell through to the real user home, and a
test run clobbered the real ~/.omp/agent/commands/start.md with fixture
content (description: "Quoted summary", body: "body").

Stub os.homedir() directly with spyOn instead — verified against the
actual Bun runtime, works regardless of platform since production code
always resolves the home dir through this single call.
@jaesbit
jaesbit merged commit 1740780 into main Jul 2, 2026
@jaesbit
jaesbit deleted the fix/test-homedir-mock branch July 2, 2026 20:54
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