diff --git a/extensions/kilocode/provider-models.test.ts b/extensions/kilocode/provider-models.test.ts index ebb13257638..f2f2c411db3 100644 --- a/extensions/kilocode/provider-models.test.ts +++ b/extensions/kilocode/provider-models.test.ts @@ -37,6 +37,13 @@ function requireModelById( return model; } +function requireRecord(value: unknown, label: string): Record { + if (value === null || typeof value !== "object" || Array.isArray(value)) { + throw new Error(`expected ${label} to be a record`); + } + return value as Record; +} + function makeGatewayModel(overrides: Record = {}) { return { id: "anthropic/claude-sonnet-4", @@ -148,23 +155,22 @@ describe("discoverKilocodeModels (fetch path)", () => { await withFetchPathTest(mockFetch, async () => { const models = await discoverKilocodeModels(); - expect(fetchWithSsrFGuardMock).toHaveBeenCalledWith( - expect.objectContaining({ - url: KILOCODE_MODELS_URL, - init: expect.objectContaining({ - headers: { Accept: "application/json" }, - }), - policy: { allowedHostnames: ["api.kilo.ai"] }, - timeoutMs: 5000, - auditContext: "kilocode.model_discovery", - }), - ); - expect(mockFetch).toHaveBeenCalledWith( - KILOCODE_MODELS_URL, - expect.objectContaining({ - headers: { Accept: "application/json" }, - }), + expect(fetchWithSsrFGuardMock).toHaveBeenCalledOnce(); + const guardedFetch = requireRecord( + fetchWithSsrFGuardMock.mock.calls[0]?.[0], + "guarded fetch params", ); + expect(guardedFetch.url).toBe(KILOCODE_MODELS_URL); + const guardedInit = requireRecord(guardedFetch.init, "guarded fetch init"); + expect(guardedInit.headers).toEqual({ Accept: "application/json" }); + expect(guardedFetch.policy).toEqual({ allowedHostnames: ["api.kilo.ai"] }); + expect(guardedFetch.timeoutMs).toBe(5000); + expect(guardedFetch.auditContext).toBe("kilocode.model_discovery"); + + expect(mockFetch).toHaveBeenCalledOnce(); + expect(mockFetch.mock.calls[0]?.[0]).toBe(KILOCODE_MODELS_URL); + const fetchInit = requireRecord(mockFetch.mock.calls[0]?.[1], "mock fetch init"); + expect(fetchInit.headers).toEqual({ Accept: "application/json" }); expect(models.length).toBe(2);