Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/opencode/test/mcp/lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
Loading