diff --git a/src/features/mcp-oauth/callback-server.test.ts b/src/features/mcp-oauth/callback-server.test.ts
index 063f2bdea..528d5bdb8 100644
--- a/src/features/mcp-oauth/callback-server.test.ts
+++ b/src/features/mcp-oauth/callback-server.test.ts
@@ -1,93 +1,21 @@
-import { afterEach, beforeEach, describe, expect, it, spyOn } from "bun:test"
+///
+
+import { afterEach, describe, expect, it } from "bun:test"
import { startCallbackServer, type CallbackServer } from "./callback-server"
const HOSTNAME = "127.0.0.1"
-const nativeFetch = Bun.fetch.bind(Bun)
-
-function supportsRealSocketBinding(): boolean {
- try {
- const server = Bun.serve({
- port: 0,
- hostname: HOSTNAME,
- fetch: () => new Response("probe"),
- })
- server.stop(true)
- return true
- } catch {
- return false
- }
-}
-
-const canBindRealSockets = supportsRealSocketBinding()
-
-type MockServerState = {
- port: number
- stopped: boolean
- fetch: (request: Request) => Response | Promise
-}
describe("startCallbackServer", () => {
let server: CallbackServer | null = null
- let serveSpy: ReturnType | null = null
- let activeServer: MockServerState | null = null
async function request(url: string): Promise {
- if (canBindRealSockets) {
- return nativeFetch(url)
- }
-
- if (!activeServer || activeServer.stopped) {
- throw new Error("Connection refused")
- }
-
- return await activeServer.fetch(new Request(url))
+ return await Bun.fetch(url)
}
- beforeEach(() => {
- if (canBindRealSockets) {
- return
- }
-
- activeServer = null
- serveSpy = spyOn(Bun, "serve").mockImplementation((options: {
- port: number
- hostname?: string
- fetch: (request: Request) => Response | Promise
- }) => {
- const state: MockServerState = {
- port: options.port === 0 ? 19877 : options.port,
- stopped: false,
- fetch: options.fetch,
- }
-
- const handle = {
- port: state.port,
- stop: (_force?: boolean) => {
- state.stopped = true
- if (activeServer === state) {
- activeServer = null
- }
- },
- }
-
- activeServer = state
- return handle as ReturnType
- })
- })
-
afterEach(async () => {
server?.close()
server = null
-
- if (serveSpy) {
- serveSpy.mockRestore()
- serveSpy = null
- }
- activeServer = null
-
- if (canBindRealSockets) {
- await Bun.sleep(10)
- }
+ await Bun.sleep(10)
})
it("starts server and returns port", async () => {