opencode/packages/util/src/no-timeout-fetch.test.ts
Finn763 52a10f573f
fix(tui): keep long-pending requests past Bun's fetch deadline (#55149)
Give the TUI client timeout: false, share the no-timeout fetch helper across run, mini and the TUI via @opencode/util/no-timeout-fetch, and surface existing-session shell failures with a toast and composer restore.

Closes #54974

Co-authored-by: Finn763 <finn763@users.noreply.github.com>
2026-10-19 13:37:11 -04:00

33 lines
1.1 KiB
TypeScript

import { afterAll, expect, test } from "bun:test"
import { noTimeoutFetch } from "./no-timeout-fetch.js"
const pending = Promise.withResolvers<void>()
const server = Bun.serve({
port: 0,
fetch: async (request) => {
if (new URL(request.url).pathname === "/hang") {
pending.resolve()
return new Promise<Response>(() => {})
}
return Response.json({ method: request.method, header: request.headers.get("x-test"), body: await request.text() })
},
})
afterAll(() => server.stop(true))
test("preserves the request init", async () => {
const response = await noTimeoutFetch(new URL("/echo", server.url), {
method: "POST",
headers: { "x-test": "value" },
body: "payload",
})
expect(await response.json()).toEqual({ method: "POST", header: "value", body: "payload" })
})
test("still honours an abort signal", async () => {
const controller = new AbortController()
const request = noTimeoutFetch(new URL("/hang", server.url), { signal: controller.signal })
await pending.promise
controller.abort()
await expect(request).rejects.toMatchObject({ name: "AbortError" })
})