mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-28 10:02:15 +00:00
81 lines
2.5 KiB
TypeScript
81 lines
2.5 KiB
TypeScript
import fs from "node:fs";
|
|
import type { Context, Model } from "openclaw/plugin-sdk/llm";
|
|
import { registerSingleProviderPlugin } from "openclaw/plugin-sdk/plugin-test-runtime";
|
|
import { createCapturedThinkingConfigStream } from "openclaw/plugin-sdk/provider-test-contracts";
|
|
import { describe, expect, it } from "vitest";
|
|
import plugin from "./index.js";
|
|
import { createKimiWebSearchProvider } from "./src/kimi-web-search-provider.js";
|
|
|
|
type MoonshotManifest = {
|
|
setup?: {
|
|
providers?: Array<{
|
|
id?: string;
|
|
envVars?: string[];
|
|
}>;
|
|
};
|
|
};
|
|
|
|
function readManifest(): MoonshotManifest {
|
|
return JSON.parse(
|
|
fs.readFileSync(new URL("./openclaw.plugin.json", import.meta.url), "utf8"),
|
|
) as MoonshotManifest;
|
|
}
|
|
|
|
describe("moonshot provider plugin", () => {
|
|
it("mirrors Kimi web-search env credentials in manifest metadata", () => {
|
|
const manifestEnvVars =
|
|
readManifest().setup?.providers?.find((provider) => provider.id === "moonshot")?.envVars ??
|
|
[];
|
|
|
|
expect([...manifestEnvVars].toSorted()).toStrictEqual(
|
|
[...createKimiWebSearchProvider().envVars].toSorted(),
|
|
);
|
|
});
|
|
|
|
it("owns replay policy for OpenAI-compatible Moonshot transports without mangling native Kimi tool_call IDs", async () => {
|
|
const provider = await registerSingleProviderPlugin(plugin);
|
|
|
|
const policy = provider.buildReplayPolicy?.({
|
|
provider: "moonshot",
|
|
modelApi: "openai-completions",
|
|
modelId: "kimi-k2.6",
|
|
} as never);
|
|
|
|
expect(policy).toEqual({
|
|
applyAssistantFirstOrderingFix: true,
|
|
validateGeminiTurns: true,
|
|
validateAnthropicTurns: true,
|
|
});
|
|
expect(policy).not.toHaveProperty("dropReasoningFromHistory");
|
|
expect(policy).not.toHaveProperty("sanitizeToolCallIds");
|
|
expect(policy).not.toHaveProperty("toolCallIdMode");
|
|
});
|
|
|
|
it("wires moonshot-thinking stream hooks", async () => {
|
|
const provider = await registerSingleProviderPlugin(plugin);
|
|
const capturedStream = createCapturedThinkingConfigStream();
|
|
|
|
const wrapped = provider.wrapStreamFn?.({
|
|
provider: "moonshot",
|
|
modelId: "kimi-k2.6",
|
|
thinkingLevel: "off",
|
|
streamFn: capturedStream.streamFn,
|
|
} as never);
|
|
|
|
void wrapped?.(
|
|
{
|
|
api: "openai-completions",
|
|
provider: "moonshot",
|
|
id: "kimi-k2.6",
|
|
} as Model<"openai-completions">,
|
|
{ messages: [] } as Context,
|
|
{},
|
|
);
|
|
|
|
expect(capturedStream.getCapturedPayload()).toEqual({
|
|
config: { thinkingConfig: { thinkingBudget: -1 } },
|
|
thinking: { type: "disabled" },
|
|
});
|
|
});
|
|
});
|