diff --git a/src/infra/net/fetch-guard.ssrf.test.ts b/src/infra/net/fetch-guard.ssrf.test.ts index e571bc8af83..82343de93f3 100644 --- a/src/infra/net/fetch-guard.ssrf.test.ts +++ b/src/infra/net/fetch-guard.ssrf.test.ts @@ -97,6 +97,10 @@ function expectDispatcherAttached(value: unknown): void { expect(getDispatcherClassName(value)).toMatch(/^(Agent|Mock)$/u); } +function firstMockCall(mock: { mock: { calls: T[] } }): T | undefined { + return mock.mock.calls[0]; +} + function getSecondRequestHeaders(fetchImpl: ReturnType): Headers { const [, secondInit] = fetchImpl.mock.calls.at(1) as [string, RequestInit]; return new Headers(secondInit.headers); @@ -301,7 +305,7 @@ describe("fetchWithSsrFGuard hardening", () => { ).rejects.toThrow(/private|internal|blocked/i); expect(fetchImpl).not.toHaveBeenCalled(); expect(logWarnMock).toHaveBeenCalledTimes(1); - const [warning] = logWarnMock.mock.calls.at(0) as [string]; + const [warning] = firstMockCall(logWarnMock) as [string]; expect(warning).toContain( "security: blocked URL fetch (qa-audit) targetOrigin=http://127.0.0.1:8080", ); @@ -602,7 +606,7 @@ describe("fetchWithSsrFGuard hardening", () => { }, }); expect(fetchImpl).toHaveBeenCalledTimes(1); - const fetchCall = fetchImpl.mock.calls.at(0) as [string, { dispatcher?: unknown }] | undefined; + const fetchCall = firstMockCall(fetchImpl) as [string, { dispatcher?: unknown }] | undefined; expect(fetchCall?.[0]).toBe("https://public.example/resource"); if (!fetchCall?.[1].dispatcher) { throw new Error("Expected proxy dispatcher");