mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:50:43 +00:00
test: isolate cli provider model-selection coverage
This commit is contained in:
31
src/agents/model-selection-cli.test.ts
Normal file
31
src/agents/model-selection-cli.test.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/types.js";
|
||||
import { __testing as setupRegistryRuntimeTesting } from "../plugins/setup-registry.runtime.js";
|
||||
import { isCliProvider } from "./model-selection-cli.js";
|
||||
|
||||
describe("isCliProvider", () => {
|
||||
beforeEach(() => {
|
||||
setupRegistryRuntimeTesting.resetRuntimeState();
|
||||
setupRegistryRuntimeTesting.setRuntimeModuleForTest({
|
||||
resolvePluginSetupCliBackend: ({ backend }) =>
|
||||
backend === "claude-cli"
|
||||
? {
|
||||
pluginId: "anthropic",
|
||||
backend: { id: "claude-cli", config: { command: "claude" } },
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
setupRegistryRuntimeTesting.resetRuntimeState();
|
||||
});
|
||||
|
||||
it("returns true for setup-registered cli backends", () => {
|
||||
expect(isCliProvider("claude-cli", {} as OpenClawConfig)).toBe(true);
|
||||
});
|
||||
|
||||
it("returns false for provider ids", () => {
|
||||
expect(isCliProvider("example-cli", {} as OpenClawConfig)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,12 +1,10 @@
|
||||
import { afterEach, beforeEach, describe, it, expect, vi } from "vitest";
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/types.js";
|
||||
import { resetLogger, setLoggerOverride } from "../logging/logger.js";
|
||||
import { createWarnLogCapture } from "../logging/test-helpers/warn-log-capture.js";
|
||||
import { __testing as setupRegistryRuntimeTesting } from "../plugins/setup-registry.runtime.js";
|
||||
import {
|
||||
buildAllowedModelSet,
|
||||
inferUniqueProviderFromConfiguredModels,
|
||||
isCliProvider,
|
||||
parseModelRef,
|
||||
buildModelAliasIndex,
|
||||
normalizeModelSelection,
|
||||
@@ -29,6 +27,10 @@ vi.mock("./provider-model-normalization.runtime.js", () => ({
|
||||
normalizeProviderModelIdWithRuntime: () => undefined,
|
||||
}));
|
||||
|
||||
vi.mock("./model-selection-cli.js", () => ({
|
||||
isCliProvider: () => false,
|
||||
}));
|
||||
|
||||
const EXPLICIT_ALLOWLIST_CONFIG = {
|
||||
agents: {
|
||||
defaults: {
|
||||
@@ -159,33 +161,6 @@ describe("model-selection", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("isCliProvider", () => {
|
||||
beforeEach(() => {
|
||||
setupRegistryRuntimeTesting.resetRuntimeState();
|
||||
setupRegistryRuntimeTesting.setRuntimeModuleForTest({
|
||||
resolvePluginSetupCliBackend: ({ backend }) =>
|
||||
backend === "claude-cli"
|
||||
? {
|
||||
pluginId: "anthropic",
|
||||
backend: { id: "claude-cli", config: { command: "claude" } },
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
setupRegistryRuntimeTesting.resetRuntimeState();
|
||||
});
|
||||
|
||||
it("returns true for setup-registered cli backends", () => {
|
||||
expect(isCliProvider("claude-cli", {} as OpenClawConfig)).toBe(true);
|
||||
});
|
||||
|
||||
it("returns false for provider ids", () => {
|
||||
expect(isCliProvider("example-cli", {} as OpenClawConfig)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("modelKey", () => {
|
||||
it("keeps canonical OpenRouter native ids without duplicating the provider", () => {
|
||||
expect(modelKey("openrouter", "openrouter/hunter-alpha")).toBe("openrouter/hunter-alpha");
|
||||
|
||||
Reference in New Issue
Block a user