Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
322 lines
10 KiB
TypeScript
322 lines
10 KiB
TypeScript
// Kilocode tests cover provider models plugin behavior.
|
|
import { afterAll, describe, expect, it, vi } from "vitest";
|
|
|
|
const { fetchWithSsrFGuardMock } = vi.hoisted(() => ({
|
|
fetchWithSsrFGuardMock: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("openclaw/plugin-sdk/ssrf-runtime", () => ({
|
|
fetchWithSsrFGuard: fetchWithSsrFGuardMock,
|
|
ssrfPolicyFromHttpBaseUrlAllowedHostname: (baseUrl: string) => ({
|
|
allowedHostnames: [new URL(baseUrl).hostname],
|
|
}),
|
|
}));
|
|
|
|
import { discoverKilocodeModels, KILOCODE_MODELS_URL } from "./provider-models.js";
|
|
|
|
type MockKilocodeFetch = ((url: string, init?: RequestInit) => Promise<Response>) & {
|
|
mock: { calls: unknown[][] };
|
|
};
|
|
|
|
const EXPECTED_STATIC_KILOCODE_MODELS = [
|
|
{
|
|
id: "kilo/auto",
|
|
name: "Kilo Auto",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
contextWindow: 1000000,
|
|
maxTokens: 128000,
|
|
},
|
|
];
|
|
|
|
function requireModelById(
|
|
models: Awaited<ReturnType<typeof discoverKilocodeModels>>,
|
|
id: string,
|
|
): Awaited<ReturnType<typeof discoverKilocodeModels>>[number] {
|
|
const model = models.find((candidate) => candidate.id === id);
|
|
if (!model) {
|
|
throw new Error(`expected Kilocode model ${id}`);
|
|
}
|
|
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 requireFirstMockCall(mock: { mock: { calls: unknown[][] } }, label: string): unknown[] {
|
|
const [call] = mock.mock.calls;
|
|
if (!call) {
|
|
throw new Error(`expected ${label}`);
|
|
}
|
|
return call;
|
|
}
|
|
|
|
function makeGatewayModel(overrides: Record<string, unknown> = {}) {
|
|
return {
|
|
id: "anthropic/claude-sonnet-4",
|
|
name: "Anthropic: Claude Sonnet 4",
|
|
created: 1700000000,
|
|
description: "A model",
|
|
context_length: 200000,
|
|
architecture: {
|
|
input_modalities: ["text", "image"],
|
|
output_modalities: ["text"],
|
|
tokenizer: "Claude",
|
|
},
|
|
top_provider: {
|
|
is_moderated: false,
|
|
max_completion_tokens: 8192,
|
|
},
|
|
pricing: {
|
|
prompt: "0.000003",
|
|
completion: "0.000015",
|
|
input_cache_read: "0.0000003",
|
|
input_cache_write: "0.00000375",
|
|
},
|
|
supported_parameters: ["max_tokens", "temperature", "tools", "reasoning"],
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function makeAutoModel(overrides: Record<string, unknown> = {}) {
|
|
return makeGatewayModel({
|
|
id: "kilo/auto",
|
|
name: "Kilo: Auto",
|
|
context_length: 1000000,
|
|
architecture: {
|
|
input_modalities: ["text", "image"],
|
|
output_modalities: ["text"],
|
|
tokenizer: "Other",
|
|
},
|
|
top_provider: {
|
|
is_moderated: false,
|
|
max_completion_tokens: 128000,
|
|
},
|
|
pricing: {
|
|
prompt: "0.000005",
|
|
completion: "0.000025",
|
|
},
|
|
supported_parameters: ["max_tokens", "temperature", "tools", "reasoning", "include_reasoning"],
|
|
...overrides,
|
|
});
|
|
}
|
|
|
|
function jsonResponse(payload: unknown, init: ResponseInit = {}): Response {
|
|
return new Response(JSON.stringify(payload), {
|
|
status: 200,
|
|
headers: { "Content-Type": "application/json" },
|
|
...init,
|
|
});
|
|
}
|
|
|
|
async function withFetchPathTest(mockFetch: MockKilocodeFetch, runAssertions: () => Promise<void>) {
|
|
const release = vi.fn(async () => {});
|
|
vi.stubEnv("NODE_ENV", "");
|
|
vi.stubEnv("VITEST", "");
|
|
|
|
fetchWithSsrFGuardMock.mockReset();
|
|
const callMockFetch = mockFetch as unknown as (
|
|
url: string,
|
|
init?: RequestInit,
|
|
) => Promise<unknown>;
|
|
fetchWithSsrFGuardMock.mockImplementation(
|
|
async (params: { url: string; init?: RequestInit }) => ({
|
|
response: await callMockFetch(params.url, params.init),
|
|
release,
|
|
}),
|
|
);
|
|
|
|
try {
|
|
await runAssertions();
|
|
} finally {
|
|
vi.unstubAllEnvs();
|
|
fetchWithSsrFGuardMock.mockReset();
|
|
}
|
|
}
|
|
|
|
afterAll(() => {
|
|
vi.doUnmock("openclaw/plugin-sdk/ssrf-runtime");
|
|
vi.resetModules();
|
|
});
|
|
|
|
describe("discoverKilocodeModels", () => {
|
|
it("returns static catalog in test environment", async () => {
|
|
const models = await discoverKilocodeModels();
|
|
expect(models).toStrictEqual(EXPECTED_STATIC_KILOCODE_MODELS);
|
|
});
|
|
|
|
it("static catalog has correct defaults for kilo/auto", async () => {
|
|
const models = await discoverKilocodeModels();
|
|
const auto = requireModelById(models, "kilo/auto");
|
|
expect(auto.name).toBe("Kilo Auto");
|
|
expect(auto.reasoning).toBe(true);
|
|
expect(auto.input).toEqual(["text", "image"]);
|
|
expect(auto.contextWindow).toBe(1000000);
|
|
expect(auto.maxTokens).toBe(128000);
|
|
expect(auto.cost).toEqual({ input: 0, output: 0, cacheRead: 0, cacheWrite: 0 });
|
|
});
|
|
});
|
|
|
|
describe("discoverKilocodeModels (fetch path)", () => {
|
|
it("parses gateway models with correct pricing conversion", async () => {
|
|
const mockFetch = vi.fn().mockResolvedValue(
|
|
jsonResponse({
|
|
data: [makeAutoModel(), makeGatewayModel()],
|
|
}),
|
|
);
|
|
await withFetchPathTest(mockFetch, async () => {
|
|
const models = await discoverKilocodeModels();
|
|
|
|
expect(fetchWithSsrFGuardMock).toHaveBeenCalledOnce();
|
|
const [guardedFetchParams] = requireFirstMockCall(
|
|
fetchWithSsrFGuardMock,
|
|
"guarded fetch call",
|
|
);
|
|
const guardedFetch = requireRecord(guardedFetchParams, "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();
|
|
const [fetchUrl, fetchOptions] = requireFirstMockCall(mockFetch, "mock fetch call");
|
|
expect(fetchUrl).toBe(KILOCODE_MODELS_URL);
|
|
const fetchInit = requireRecord(fetchOptions, "mock fetch init");
|
|
expect(fetchInit.headers).toEqual({ Accept: "application/json" });
|
|
|
|
expect(models.length).toBe(2);
|
|
|
|
const sonnet = requireModelById(models, "anthropic/claude-sonnet-4");
|
|
expect(sonnet.cost.input).toBeCloseTo(3);
|
|
expect(sonnet.cost.output).toBeCloseTo(15);
|
|
expect(sonnet.cost.cacheRead).toBeCloseTo(0.3);
|
|
expect(sonnet.cost.cacheWrite).toBeCloseTo(3.75);
|
|
expect(sonnet.input).toEqual(["text", "image"]);
|
|
expect(sonnet.reasoning).toBe(true);
|
|
expect(sonnet.contextWindow).toBe(200000);
|
|
expect(sonnet.maxTokens).toBe(8192);
|
|
});
|
|
});
|
|
|
|
it("falls back to static catalog on network error", async () => {
|
|
const mockFetch = vi.fn().mockRejectedValue(new Error("network error"));
|
|
await withFetchPathTest(mockFetch, async () => {
|
|
const models = await discoverKilocodeModels();
|
|
expect(models).toStrictEqual(EXPECTED_STATIC_KILOCODE_MODELS);
|
|
});
|
|
});
|
|
|
|
it("falls back to static catalog on HTTP error", async () => {
|
|
const mockFetch = vi.fn().mockResolvedValue(new Response("", { status: 500 }));
|
|
await withFetchPathTest(mockFetch, async () => {
|
|
const models = await discoverKilocodeModels();
|
|
expect(models).toStrictEqual(EXPECTED_STATIC_KILOCODE_MODELS);
|
|
});
|
|
});
|
|
|
|
it("falls back to static catalog for malformed successful model list payloads", async () => {
|
|
for (const payload of [[], { data: {} }, { data: [null] }]) {
|
|
const mockFetch = vi.fn().mockResolvedValue(jsonResponse(payload));
|
|
await withFetchPathTest(mockFetch, async () => {
|
|
const models = await discoverKilocodeModels();
|
|
expect(models).toStrictEqual(EXPECTED_STATIC_KILOCODE_MODELS);
|
|
});
|
|
}
|
|
});
|
|
|
|
it("falls back from malformed live token metadata", async () => {
|
|
const mockFetch = vi.fn().mockResolvedValue(
|
|
jsonResponse({
|
|
data: [
|
|
makeGatewayModel({
|
|
id: "some/bad-window",
|
|
context_length: -1,
|
|
top_provider: { max_completion_tokens: 8192.5 },
|
|
}),
|
|
makeGatewayModel({
|
|
id: "some/bad-output",
|
|
context_length: Number.POSITIVE_INFINITY,
|
|
top_provider: { max_completion_tokens: 0 },
|
|
}),
|
|
],
|
|
}),
|
|
);
|
|
|
|
await withFetchPathTest(mockFetch, async () => {
|
|
const models = await discoverKilocodeModels();
|
|
|
|
expect(requireModelById(models, "some/bad-window")).toMatchObject({
|
|
contextWindow: 1000000,
|
|
maxTokens: 128000,
|
|
});
|
|
expect(requireModelById(models, "some/bad-output")).toMatchObject({
|
|
contextWindow: 1000000,
|
|
maxTokens: 128000,
|
|
});
|
|
});
|
|
});
|
|
|
|
it("ensures kilo/auto is present even when API doesn't return it", async () => {
|
|
const mockFetch = vi.fn().mockResolvedValue(
|
|
jsonResponse({
|
|
data: [makeGatewayModel()],
|
|
}),
|
|
);
|
|
await withFetchPathTest(mockFetch, async () => {
|
|
const models = await discoverKilocodeModels();
|
|
expect(requireModelById(models, "kilo/auto").id).toBe("kilo/auto");
|
|
expect(requireModelById(models, "anthropic/claude-sonnet-4").id).toBe(
|
|
"anthropic/claude-sonnet-4",
|
|
);
|
|
});
|
|
});
|
|
|
|
it("detects text-only models without image modality", async () => {
|
|
const textOnlyModel = makeGatewayModel({
|
|
id: "some/text-model",
|
|
architecture: {
|
|
input_modalities: ["text"],
|
|
output_modalities: ["text"],
|
|
},
|
|
supported_parameters: ["max_tokens", "temperature"],
|
|
});
|
|
|
|
const mockFetch = vi.fn().mockResolvedValue(jsonResponse({ data: [textOnlyModel] }));
|
|
await withFetchPathTest(mockFetch, async () => {
|
|
const models = await discoverKilocodeModels();
|
|
const textModel = requireModelById(models, "some/text-model");
|
|
expect(textModel.input).toEqual(["text"]);
|
|
expect(textModel.reasoning).toBe(false);
|
|
});
|
|
});
|
|
|
|
it("keeps a later valid duplicate when an earlier entry is malformed", async () => {
|
|
const malformedAutoModel = makeAutoModel({
|
|
name: "Broken Kilo Auto",
|
|
pricing: undefined,
|
|
});
|
|
|
|
const mockFetch = vi.fn().mockResolvedValue(
|
|
jsonResponse({
|
|
data: [malformedAutoModel, makeAutoModel(), makeGatewayModel()],
|
|
}),
|
|
);
|
|
await withFetchPathTest(mockFetch, async () => {
|
|
const models = await discoverKilocodeModels();
|
|
const auto = requireModelById(models, "kilo/auto");
|
|
expect(auto.name).toBe("Kilo: Auto");
|
|
expect(auto.cost.input).toBeCloseTo(5);
|
|
expect(requireModelById(models, "anthropic/claude-sonnet-4").id).toBe(
|
|
"anthropic/claude-sonnet-4",
|
|
);
|
|
});
|
|
});
|
|
});
|