fix(test): sandbox os.homedir() via spyOn instead of env vars - #4
Merged
Conversation
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.
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.
Why
Bun 1.3.14's
os.homedir()ignores a runtimeprocess.env.HOME/USERPROFILEreassignment.orientation-store.test.tsandkb-protocol.test.tsboth relied on that reassignment inbeforeEachto sandbox home-dir-derived paths — it silently no-op'd, sobun testfell through to the real user home.Confirmed impact: a test run clobbered the real
~/.omp/agent/commands/start.mdwith fixture content (description: "Quoted summary",body: "body"), which is how this surfaced (deck's/startauto-orientation prompt lost its real content).Fix
Stub
os.homedir()directly withspyOnin 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 passbun test kb-protocol: 10 pass~/.omp/agent/commands/start.mdmtime unchanged after re-running the fixed suite