diff options
| author | Adam Malczewski <[email protected]> | 2026-08-17 15:04:03 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-08-17 15:04:03 +0900 |
| commit | ac5a6acddc78d7df3d44bda87fe287bc9391531d (patch) | |
| tree | 0810ee36ff4abce1c359688b1a9d8dd44f54be43 /src/app/store.test.ts | |
| parent | 774519e052fd869952cc5e05aca159e4bf978fa1 (diff) | |
| download | dispatch-web-ac5a6acddc78d7df3d44bda87fe287bc9391531d.tar.gz dispatch-web-ac5a6acddc78d7df3d44bda87fe287bc9391531d.zip | |
fix(thinking): handle SPA fallback responses
Diffstat (limited to 'src/app/store.test.ts')
| -rw-r--r-- | src/app/store.test.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/app/store.test.ts b/src/app/store.test.ts index 47c3977..518a7b2 100644 --- a/src/app/store.test.ts +++ b/src/app/store.test.ts @@ -898,6 +898,7 @@ describe("createAppStore", () => { if (url.endsWith("/thinking")) { return new Response(JSON.stringify({ conversationId: "x", thinking: false }), { status: 200, + headers: { "content-type": "application/json" }, }); } return base(input, init); @@ -946,6 +947,38 @@ describe("createAppStore", () => { store.dispose(); }); + it("treats a SPA-fallback response (200 + text/html) as 'never set' (null ⇒ ON)", async () => { + // In production (DISPATCH_WEB_DIR set), unknown API routes get the SPA + // fallback: index.html with HTTP 200 + text/html. This must NOT crash + // res.json() — it should leave `thinking` null (ON, the default). + const base = fakeFetchImpl(); + const fetchImpl: typeof fetch = async (input, init) => { + const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url; + if (url.endsWith("/thinking")) { + return new Response("<!DOCTYPE html><html><body>SPA fallback</body></html>", { + status: 200, + headers: { "content-type": "text/html; charset=utf-8" }, + }); + } + return base(input, init); + }; + const ws = fakeSocket(); + const store = createAppStore({ + socketFactory: () => ws, + fetchImpl, + localStorage: createFakeStorage(), + }); + ws.resolveOpen(); + + // give the (HTML) fetch a tick to settle + await vi.waitFor(() => { + expect(store.reasoningEffort).not.toBe(undefined); + }); + expect(store.thinking).toBeNull(); + + store.dispose(); + }); + it("setThinking PUTs the flag and updates local state from the echo", async () => { const calls: { url: string; method: string; body: string | undefined }[] = []; const base = fakeFetchImpl(); @@ -956,11 +989,13 @@ describe("createAppStore", () => { const sent = JSON.parse(init.body as string) as { thinking: boolean }; return new Response(JSON.stringify({ conversationId: "x", thinking: sent.thinking }), { status: 200, + headers: { "content-type": "application/json" }, }); } if (url.endsWith("/thinking")) { return new Response(JSON.stringify({ conversationId: "x", thinking: null }), { status: 200, + headers: { "content-type": "application/json" }, }); } return base(input, init); |
