test: tighten kilocode model discovery assertions

This commit is contained in:
Peter Steinberger
2026-05-09 20:34:07 +01:00
parent 38442a9342
commit f89baa047d

View File

@@ -37,6 +37,13 @@ function requireModelById(
return model;
}
function requireRecord(value: unknown, label: string): Record<string, unknown> {
if (value === null || typeof value !== "object" || Array.isArray(value)) {
throw new Error(`expected ${label} to be a record`);
}
return value as Record<string, unknown>;
}
function makeGatewayModel(overrides: Record<string, unknown> = {}) {
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);