|
1 | 1 | import { afterEach, describe, expect, test } from "bun:test"; |
2 | 2 | import { runWebSearch } from "../src/web-search/executor"; |
| 3 | +import { runWithWebSearch } from "../src/web-search/loop"; |
3 | 4 | import { describeImage } from "../src/vision/describe"; |
| 5 | +import { parseRequest } from "../src/responses/parser"; |
| 6 | +import type { ProviderAdapter } from "../src/adapters/base"; |
4 | 7 | import type { OcxProviderConfig } from "../src/types"; |
5 | 8 |
|
6 | 9 | const originalFetch = globalThis.fetch; |
@@ -30,6 +33,39 @@ function installAbortAwareFetch(): () => AbortSignal { |
30 | 33 | } |
31 | 34 |
|
32 | 35 | describe("sidecar abort propagation", () => { |
| 36 | + test("web-search loop routed-provider fetch observes the WebSocket turn abort signal", async () => { |
| 37 | + const getSignal = installAbortAwareFetch(); |
| 38 | + const turn = new AbortController(); |
| 39 | + const adapter: ProviderAdapter = { |
| 40 | + name: "mock", |
| 41 | + buildRequest: () => ({ url: "https://routed.test/v1/chat/completions", method: "POST", headers: {}, body: "{}" }), |
| 42 | + async *parseStream() { /* unused */ }, |
| 43 | + async parseResponse() { return []; }, |
| 44 | + }; |
| 45 | + const response = runWithWebSearch({ |
| 46 | + parsed: parseRequest({ |
| 47 | + model: "routed/model", |
| 48 | + input: "Search for current docs", |
| 49 | + stream: true, |
| 50 | + tools: [{ type: "web_search" }], |
| 51 | + }), |
| 52 | + adapter, |
| 53 | + forwardProvider, |
| 54 | + hostedTool: { type: "web_search" }, |
| 55 | + incomingHeaders: new Headers({ authorization: "Bearer token" }), |
| 56 | + settings: { model: "gpt-5.4-mini", reasoning: "low", timeoutMs: 30_000 }, |
| 57 | + maxSearches: 1, |
| 58 | + abortSignal: turn.signal, |
| 59 | + }); |
| 60 | + |
| 61 | + const signal = getSignal(); |
| 62 | + expect(signal).toBe(turn.signal); |
| 63 | + expect(signal.aborted).toBe(false); |
| 64 | + turn.abort("replacement turn"); |
| 65 | + expect(signal.aborted).toBe(true); |
| 66 | + expect((await response).status).toBe(502); |
| 67 | + }); |
| 68 | + |
33 | 69 | test("web-search sidecar fetch observes the WebSocket turn abort signal", async () => { |
34 | 70 | const getSignal = installAbortAwareFetch(); |
35 | 71 | const turn = new AbortController(); |
|
0 commit comments