mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 15:24:32 +00:00
Tests: cover allowlist refs missing from catalog
This commit is contained in:
@@ -2,12 +2,14 @@ import { describe, it, expect, vi } from "vitest";
|
|||||||
import type { OpenClawConfig } from "../config/config.js";
|
import type { OpenClawConfig } from "../config/config.js";
|
||||||
import { resetLogger, setLoggerOverride } from "../logging/logger.js";
|
import { resetLogger, setLoggerOverride } from "../logging/logger.js";
|
||||||
import {
|
import {
|
||||||
|
buildAllowedModelSet,
|
||||||
parseModelRef,
|
parseModelRef,
|
||||||
resolveModelRefFromString,
|
|
||||||
resolveConfiguredModelRef,
|
|
||||||
buildModelAliasIndex,
|
buildModelAliasIndex,
|
||||||
normalizeProviderId,
|
|
||||||
modelKey,
|
modelKey,
|
||||||
|
normalizeProviderId,
|
||||||
|
resolveAllowedModelRef,
|
||||||
|
resolveConfiguredModelRef,
|
||||||
|
resolveModelRefFromString,
|
||||||
} from "./model-selection.js";
|
} from "./model-selection.js";
|
||||||
|
|
||||||
describe("model-selection", () => {
|
describe("model-selection", () => {
|
||||||
@@ -159,6 +161,71 @@ describe("model-selection", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("buildAllowedModelSet", () => {
|
||||||
|
it("keeps explicitly allowlisted models even when missing from bundled catalog", () => {
|
||||||
|
const cfg: OpenClawConfig = {
|
||||||
|
agents: {
|
||||||
|
defaults: {
|
||||||
|
model: { primary: "openai/gpt-5.2" },
|
||||||
|
models: {
|
||||||
|
"anthropic/claude-sonnet-4-6": { alias: "sonnet" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as OpenClawConfig;
|
||||||
|
|
||||||
|
const catalog = [
|
||||||
|
{ provider: "anthropic", id: "claude-sonnet-4-5", name: "Claude Sonnet 4.5" },
|
||||||
|
{ provider: "openai", id: "gpt-5.2", name: "gpt-5.2" },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = buildAllowedModelSet({
|
||||||
|
cfg,
|
||||||
|
catalog,
|
||||||
|
defaultProvider: "anthropic",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.allowAny).toBe(false);
|
||||||
|
expect(result.allowedKeys.has("anthropic/claude-sonnet-4-6")).toBe(true);
|
||||||
|
expect(result.allowedCatalog).toEqual([
|
||||||
|
{ provider: "anthropic", id: "claude-sonnet-4-6", name: "claude-sonnet-4-6" },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("resolveAllowedModelRef", () => {
|
||||||
|
it("accepts explicit allowlist refs absent from bundled catalog", () => {
|
||||||
|
const cfg: OpenClawConfig = {
|
||||||
|
agents: {
|
||||||
|
defaults: {
|
||||||
|
model: { primary: "openai/gpt-5.2" },
|
||||||
|
models: {
|
||||||
|
"anthropic/claude-sonnet-4-6": { alias: "sonnet" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as OpenClawConfig;
|
||||||
|
|
||||||
|
const catalog = [
|
||||||
|
{ provider: "anthropic", id: "claude-sonnet-4-5", name: "Claude Sonnet 4.5" },
|
||||||
|
{ provider: "openai", id: "gpt-5.2", name: "gpt-5.2" },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = resolveAllowedModelRef({
|
||||||
|
cfg,
|
||||||
|
catalog,
|
||||||
|
raw: "anthropic/claude-sonnet-4-6",
|
||||||
|
defaultProvider: "openai",
|
||||||
|
defaultModel: "gpt-5.2",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
key: "anthropic/claude-sonnet-4-6",
|
||||||
|
ref: { provider: "anthropic", model: "claude-sonnet-4-6" },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("resolveModelRefFromString", () => {
|
describe("resolveModelRefFromString", () => {
|
||||||
it("should resolve from string with alias", () => {
|
it("should resolve from string with alias", () => {
|
||||||
const index = {
|
const index = {
|
||||||
|
|||||||
Reference in New Issue
Block a user