mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-29 10:50:58 +00:00
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const normalizeProviderModelIdWithPluginMock = vi.fn();
|
|
|
|
vi.mock("../plugins/provider-runtime.js", () => ({
|
|
normalizeProviderModelIdWithPlugin: (params: unknown) =>
|
|
normalizeProviderModelIdWithPluginMock(params),
|
|
}));
|
|
|
|
describe("model-selection plugin runtime normalization", () => {
|
|
beforeEach(() => {
|
|
vi.resetModules();
|
|
normalizeProviderModelIdWithPluginMock.mockReset();
|
|
});
|
|
|
|
it("delegates provider-owned model id normalization to plugin runtime hooks", async () => {
|
|
normalizeProviderModelIdWithPluginMock.mockImplementation(({ provider, context }) => {
|
|
if (
|
|
provider === "custom-provider" &&
|
|
(context as { modelId?: string }).modelId === "custom-legacy-model"
|
|
) {
|
|
return "custom-modern-model";
|
|
}
|
|
return undefined;
|
|
});
|
|
|
|
const { parseModelRef } = await import("./model-selection.js");
|
|
|
|
expect(parseModelRef("custom-legacy-model", "custom-provider")).toEqual({
|
|
provider: "custom-provider",
|
|
model: "custom-modern-model",
|
|
});
|
|
expect(normalizeProviderModelIdWithPluginMock).toHaveBeenCalledWith({
|
|
provider: "custom-provider",
|
|
context: {
|
|
provider: "custom-provider",
|
|
modelId: "custom-legacy-model",
|
|
},
|
|
});
|
|
});
|
|
});
|