mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 13:01:25 +00:00
test(config): dedupe model provider fixture setup
This commit is contained in:
@@ -4,6 +4,31 @@ import { applyModelDefaults } from "./defaults.js";
|
|||||||
import type { OpenClawConfig } from "./types.js";
|
import type { OpenClawConfig } from "./types.js";
|
||||||
|
|
||||||
describe("applyModelDefaults", () => {
|
describe("applyModelDefaults", () => {
|
||||||
|
function buildProxyProviderConfig(overrides?: { contextWindow?: number; maxTokens?: number }) {
|
||||||
|
return {
|
||||||
|
models: {
|
||||||
|
providers: {
|
||||||
|
myproxy: {
|
||||||
|
baseUrl: "https://proxy.example/v1",
|
||||||
|
apiKey: "sk-test",
|
||||||
|
api: "openai-completions",
|
||||||
|
models: [
|
||||||
|
{
|
||||||
|
id: "gpt-5.2",
|
||||||
|
name: "GPT-5.2",
|
||||||
|
reasoning: false,
|
||||||
|
input: ["text"],
|
||||||
|
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||||
|
contextWindow: overrides?.contextWindow ?? 200_000,
|
||||||
|
maxTokens: overrides?.maxTokens ?? 8192,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} satisfies OpenClawConfig;
|
||||||
|
}
|
||||||
|
|
||||||
it("adds default aliases when models are present", () => {
|
it("adds default aliases when models are present", () => {
|
||||||
const cfg = {
|
const cfg = {
|
||||||
agents: {
|
agents: {
|
||||||
@@ -58,28 +83,7 @@ describe("applyModelDefaults", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("fills missing model provider defaults", () => {
|
it("fills missing model provider defaults", () => {
|
||||||
const cfg = {
|
const cfg = buildProxyProviderConfig();
|
||||||
models: {
|
|
||||||
providers: {
|
|
||||||
myproxy: {
|
|
||||||
baseUrl: "https://proxy.example/v1",
|
|
||||||
apiKey: "sk-test",
|
|
||||||
api: "openai-completions",
|
|
||||||
models: [
|
|
||||||
{
|
|
||||||
id: "gpt-5.2",
|
|
||||||
name: "GPT-5.2",
|
|
||||||
reasoning: false,
|
|
||||||
input: ["text"],
|
|
||||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
||||||
contextWindow: 200_000,
|
|
||||||
maxTokens: 8192,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
} satisfies OpenClawConfig;
|
|
||||||
|
|
||||||
const next = applyModelDefaults(cfg);
|
const next = applyModelDefaults(cfg);
|
||||||
const model = next.models?.providers?.myproxy?.models?.[0];
|
const model = next.models?.providers?.myproxy?.models?.[0];
|
||||||
@@ -92,28 +96,7 @@ describe("applyModelDefaults", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("clamps maxTokens to contextWindow", () => {
|
it("clamps maxTokens to contextWindow", () => {
|
||||||
const cfg = {
|
const cfg = buildProxyProviderConfig({ contextWindow: 32768, maxTokens: 40960 });
|
||||||
models: {
|
|
||||||
providers: {
|
|
||||||
myproxy: {
|
|
||||||
baseUrl: "https://proxy.example/v1",
|
|
||||||
apiKey: "sk-test",
|
|
||||||
api: "openai-completions",
|
|
||||||
models: [
|
|
||||||
{
|
|
||||||
id: "gpt-5.2",
|
|
||||||
name: "GPT-5.2",
|
|
||||||
reasoning: false,
|
|
||||||
input: ["text"],
|
|
||||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
||||||
contextWindow: 32768,
|
|
||||||
maxTokens: 40960,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
} satisfies OpenClawConfig;
|
|
||||||
|
|
||||||
const next = applyModelDefaults(cfg);
|
const next = applyModelDefaults(cfg);
|
||||||
const model = next.models?.providers?.myproxy?.models?.[0];
|
const model = next.models?.providers?.myproxy?.models?.[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user