Files
openclaw/extensions/kilocode/index.test.ts
2026-04-06 19:53:27 +01:00

117 lines
3.3 KiB
TypeScript

import type { StreamFn } from "@mariozechner/pi-agent-core";
import type { Context, Model } from "@mariozechner/pi-ai";
import { describe, expect, it } from "vitest";
import { registerSingleProviderPlugin } from "../../test/helpers/plugins/plugin-registration.js";
import plugin from "./index.js";
describe("kilocode provider plugin", () => {
it("owns passthrough-gemini replay policy for Gemini-backed models", async () => {
const provider = await registerSingleProviderPlugin(plugin);
expect(
provider.buildReplayPolicy?.({
provider: "kilocode",
modelApi: "openai-completions",
modelId: "gemini-2.5-pro",
} as never),
).toMatchObject({
applyAssistantFirstOrderingFix: false,
validateGeminiTurns: false,
validateAnthropicTurns: false,
sanitizeThoughtSignatures: {
allowBase64Only: true,
includeCamelCase: true,
},
});
});
it("wires kilocode-thinking stream hooks", async () => {
const provider = await registerSingleProviderPlugin(plugin);
let capturedPayload: Record<string, unknown> | undefined;
const baseStreamFn: StreamFn = (model, _context, options) => {
const payload = { config: { thinkingConfig: { thinkingBudget: -1 } } } as Record<
string,
unknown
>;
options?.onPayload?.(payload as never, model as never);
capturedPayload = payload;
return {} as never;
};
const wrappedReasoning = provider.wrapStreamFn?.({
provider: "kilocode",
modelId: "openai/gpt-5.4",
thinkingLevel: "high",
streamFn: baseStreamFn,
} as never);
void wrappedReasoning?.(
{
api: "openai-completions",
provider: "kilocode",
id: "openai/gpt-5.4",
} as Model<"openai-completions">,
{ messages: [] } as Context,
{},
);
expect(capturedPayload).toMatchObject({
reasoning: { effort: "high" },
});
const wrappedAuto = provider.wrapStreamFn?.({
provider: "kilocode",
modelId: "kilo/auto",
thinkingLevel: "high",
streamFn: baseStreamFn,
} as never);
void wrappedAuto?.(
{
api: "openai-completions",
provider: "kilocode",
id: "kilo/auto",
} as Model<"openai-completions">,
{ messages: [] } as Context,
{},
);
expect(capturedPayload).not.toHaveProperty("reasoning");
});
it("publishes configured Kilo models through plugin-owned catalog augmentation", async () => {
const provider = await registerSingleProviderPlugin(plugin);
expect(
provider.augmentModelCatalog?.({
config: {
models: {
providers: {
kilocode: {
models: [
{
id: "google/gemini-3-pro-preview",
name: "Gemini 3 Pro Preview",
input: ["text", "image"],
reasoning: true,
contextWindow: 1048576,
},
],
},
},
},
},
} as never),
).toEqual([
{
provider: "kilocode",
id: "google/gemini-3-pro-preview",
name: "Gemini 3 Pro Preview",
input: ["text", "image"],
reasoning: true,
contextWindow: 1048576,
},
]);
});
});