diff --git a/packages/opencode/test/mcp/lifecycle.test.ts b/packages/opencode/test/mcp/lifecycle.test.ts index c771fee9d..a085274c3 100644 --- a/packages/opencode/test/mcp/lifecycle.test.ts +++ b/packages/opencode/test/mcp/lifecycle.test.ts @@ -2,7 +2,7 @@ import path from "node:path" import { mkdtempSync } from "node:fs" import os, { tmpdir } from "node:os" import { pathToFileURL } from "node:url" -import { expect, mock, beforeEach, spyOn } from "bun:test" +import { expect, mock, beforeEach, afterEach, spyOn } from "bun:test" import { ListRootsRequestSchema, ToolListChangedNotificationSchema } from "@modelcontextprotocol/sdk/types.js" import { Cause, Effect, Exit } from "effect" import type { MCP as MCPNS } from "../../src/mcp/index" @@ -257,6 +257,16 @@ beforeEach(() => { transportCloseCount = 0 }) +// Restore all spies (including the `os.homedir` spy installed above) after +// every test. Without this the spy persists past this file and pollutes any +// downstream test in the same worker that calls `os.homedir()` — most +// visibly the tilde/`$HOME`-expansion assertions in +// `test/permission/next.test.ts`, which then see two different random +// `mkdtempSync` paths within the same expect(). See issue #1042. +afterEach(() => { + mock.restore() +}) + // Import after mocks const { MCP } = await import("../../src/mcp/index") const { McpOAuthCallback } = await import("../../src/mcp/oauth-callback")