



























@@ -37,6 +37,13 @@ function requireModelById(
3737return model;
3838}
393940+function requireRecord(value: unknown, label: string): Record<string, unknown> {
41+if (value === null || typeof value !== "object" || Array.isArray(value)) {
42+throw new Error(`expected ${label} to be a record`);
43+}
44+return value as Record<string, unknown>;
45+}
46+4047function makeGatewayModel(overrides: Record<string, unknown> = {}) {
4148return {
4249id: "anthropic/claude-sonnet-4",
@@ -148,23 +155,22 @@ describe("discoverKilocodeModels (fetch path)", () => {
148155await withFetchPathTest(mockFetch, async () => {
149156const models = await discoverKilocodeModels();
150157151-expect(fetchWithSsrFGuardMock).toHaveBeenCalledWith(
152-expect.objectContaining({
153-url: KILOCODE_MODELS_URL,
154-init: expect.objectContaining({
155-headers: { Accept: "application/json" },
156-}),
157-policy: { allowedHostnames: ["api.kilo.ai"] },
158-timeoutMs: 5000,
159-auditContext: "kilocode.model_discovery",
160-}),
161-);
162-expect(mockFetch).toHaveBeenCalledWith(
163-KILOCODE_MODELS_URL,
164-expect.objectContaining({
165-headers: { Accept: "application/json" },
166-}),
158+expect(fetchWithSsrFGuardMock).toHaveBeenCalledOnce();
159+const guardedFetch = requireRecord(
160+fetchWithSsrFGuardMock.mock.calls[0]?.[0],
161+"guarded fetch params",
167162);
163+expect(guardedFetch.url).toBe(KILOCODE_MODELS_URL);
164+const guardedInit = requireRecord(guardedFetch.init, "guarded fetch init");
165+expect(guardedInit.headers).toEqual({ Accept: "application/json" });
166+expect(guardedFetch.policy).toEqual({ allowedHostnames: ["api.kilo.ai"] });
167+expect(guardedFetch.timeoutMs).toBe(5000);
168+expect(guardedFetch.auditContext).toBe("kilocode.model_discovery");
169+170+expect(mockFetch).toHaveBeenCalledOnce();
171+expect(mockFetch.mock.calls[0]?.[0]).toBe(KILOCODE_MODELS_URL);
172+const fetchInit = requireRecord(mockFetch.mock.calls[0]?.[1], "mock fetch init");
173+expect(fetchInit.headers).toEqual({ Accept: "application/json" });
168174169175expect(models.length).toBe(2);
170176此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。