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 <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-04-03 17:37:17 +09:00
parent e3f3bcc063
commit f369971db9
+18 -10
View File
@@ -10,6 +10,14 @@ import {
} from "./tmux-utils"
import { isInsideTmuxEnvironment } from "./tmux-utils/environment"
function createFetchMock(responseFactory: () => Promise<Response>): typeof fetch & ReturnType<typeof mock> {
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<typeof mock>
}
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()