Repository navigation
Commit fec5f66
committed
test(mcp): restore os.homedir spy after each test to prevent cross-file leak
The `beforeEach` in `test/mcp/lifecycle.test.ts` installs a `spyOn(os, "homedir")`
that returns a fresh `mkdtempSync(... "mcp-lifecycle-home-...")` on every call.
Without a matching restore, the spy persists past this file into subsequent
files in the same bun worker process. Downstream tests that call `os.homedir()`
then get a different random path on every invocation — most visibly the
tilde and `$HOME` expansion assertions in `test/permission/next.test.ts`,
which see two different `mkdtempSync` paths within the same `expect().toEqual()`
call and fail 6 times.
The failure was file-order dependent (passes in isolation, fails when the
full suite runs in the wrong order), which manifested as a required
`CI/TypeScript` check failing intermittently on PRs — including v0.9.3.
Fix: add `afterEach(() => mock.restore())` in `lifecycle.test.ts` so the spy
is torn down between tests and cannot leak past the file boundary. Blanket
`mock.restore()` matches the pattern already used elsewhere in the suite
and cleans up any other spies installed during a test.
Closes #10421 parent a441d17 commit fec5f66
1 file changed
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
260 | 270 | | |
261 | 271 | | |
262 | 272 | | |
| |||
0 commit comments