diff --git a/src/agents/tools/web-tools.fetch.test.ts b/src/agents/tools/web-tools.fetch.test.ts index f786482db1b..f48d319b410 100644 --- a/src/agents/tools/web-tools.fetch.test.ts +++ b/src/agents/tools/web-tools.fetch.test.ts @@ -82,6 +82,12 @@ function installMockFetch( return mockFetch; } +function firstFetchRequestInit( + mockFetch: ReturnType, +): (RequestInit & { dispatcher?: unknown }) | undefined { + return mockFetch.mock.calls[0]?.[1] as (RequestInit & { dispatcher?: unknown }) | undefined; +} + function createFetchTool(fetchOverrides: Record = {}) { return createWebFetchTool({ config: { @@ -344,9 +350,7 @@ describe("web_fetch extraction fallbacks", () => { await tool?.execute?.("call", { url: "https://example.com/proxy" }); - const requestInit = mockFetch.mock.calls.at(0)?.[1] as - | (RequestInit & { dispatcher?: unknown }) - | undefined; + const requestInit = firstFetchRequestInit(mockFetch); const dispatcher = requestInit?.dispatcher; if (!dispatcher) { throw new Error("expected SSRF dispatcher"); @@ -372,9 +376,7 @@ describe("web_fetch extraction fallbacks", () => { await tool?.execute?.("call", { url: "https://example.com/proxy" }); - const requestInit = mockFetch.mock.calls.at(0)?.[1] as - | (RequestInit & { dispatcher?: unknown }) - | undefined; + const requestInit = firstFetchRequestInit(mockFetch); const dispatcher = requestInit?.dispatcher; if (!dispatcher) { throw new Error("expected trusted proxy dispatcher");