From f369971db99f0034bbf7b1bf404bc34bdc986536 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Fri, 3 Apr 2026 17:37:17 +0900 Subject: [PATCH] fix(tests): type tmux fetch mocks Model the tmux fetch test doubles with the fetch shape Bun expects so the tests drop without changing assertions. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- src/shared/tmux/tmux-utils.test.ts | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/shared/tmux/tmux-utils.test.ts b/src/shared/tmux/tmux-utils.test.ts index c5c4ea243..421cc070b 100644 --- a/src/shared/tmux/tmux-utils.test.ts +++ b/src/shared/tmux/tmux-utils.test.ts @@ -10,6 +10,14 @@ import { } from "./tmux-utils" import { isInsideTmuxEnvironment } from "./tmux-utils/environment" +function createFetchMock(responseFactory: () => Promise): typeof fetch & ReturnType { + const fetchMock = mock(async (_input: RequestInfo | URL, _init?: RequestInit) => responseFactory()) + const preconnect = globalThis.fetch.preconnect?.bind(globalThis.fetch) + return Object.assign(fetchMock, { + preconnect, + }) as typeof fetch & ReturnType +} + describe("isInsideTmux", () => { test("returns true when TMUX env is set", () => { // given @@ -66,7 +74,7 @@ describe("isServerRunning", () => { test("returns true when server responds OK", async () => { // given - globalThis.fetch = mock(async () => ({ ok: true })) as any + globalThis.fetch = createFetchMock(async () => new Response(null, { status: 200 })) // when const result = await isServerRunning("http://localhost:4096") @@ -77,9 +85,9 @@ describe("isServerRunning", () => { test("returns false when server not reachable", async () => { // given - globalThis.fetch = mock(async () => { + globalThis.fetch = createFetchMock(async () => { throw new Error("ECONNREFUSED") - }) as any + }) // when const result = await isServerRunning("http://localhost:4096") @@ -90,7 +98,7 @@ describe("isServerRunning", () => { test("returns false when fetch returns not ok", async () => { // given - globalThis.fetch = mock(async () => ({ ok: false })) as any + globalThis.fetch = createFetchMock(async () => new Response(null, { status: 500 })) // when const result = await isServerRunning("http://localhost:4096") @@ -101,7 +109,7 @@ describe("isServerRunning", () => { test("caches successful result", async () => { // given - const fetchMock = mock(async () => ({ ok: true })) as any + const fetchMock = createFetchMock(async () => new Response(null, { status: 200 })) globalThis.fetch = fetchMock // when @@ -114,9 +122,9 @@ describe("isServerRunning", () => { test("does not cache failed result", async () => { // given - const fetchMock = mock(async () => { + const fetchMock = createFetchMock(async () => { throw new Error("ECONNREFUSED") - }) as any + }) globalThis.fetch = fetchMock // when @@ -129,7 +137,7 @@ describe("isServerRunning", () => { test("uses different cache for different URLs", async () => { // given - const fetchMock = mock(async () => ({ ok: true })) as any + const fetchMock = createFetchMock(async () => new Response(null, { status: 200 })) globalThis.fetch = fetchMock // when @@ -150,7 +158,7 @@ describe("resetServerCheck", () => { test("allows re-checking after reset", async () => { // given const originalFetch = globalThis.fetch - const fetchMock = mock(async () => ({ ok: true })) as any + const fetchMock = createFetchMock(async () => new Response(null, { status: 200 })) globalThis.fetch = fetchMock // when @@ -182,7 +190,7 @@ describe("markServerRunningInProcess", () => { test("skips HTTP fetch when marked as running in-process", async () => { // given - const fetchMock = mock(async () => ({ ok: true })) as any + const fetchMock = createFetchMock(async () => new Response(null, { status: 200 })) globalThis.fetch = fetchMock markServerRunningInProcess()