mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
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>
33 lines
1.1 KiB
TypeScript
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" })
|
|
})
|