mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 10:10:42 +00:00
test: tighten kilocode model discovery assertions
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user