





















@@ -1,6 +1,6 @@
11import { describe, expect, it } from "vitest";
22import type { OpenClawConfig } from "../config/config.js";
3-import { applyProviderAuthConfigPatch } from "./provider-auth-choice-helpers.js";
3+import { applyDefaultModel, applyProviderAuthConfigPatch } from "./provider-auth-choice-helpers.js";
4455describe("applyProviderAuthConfigPatch", () => {
66const base = {
@@ -102,3 +102,74 @@ describe("applyProviderAuthConfigPatch", () => {
102102});
103103});
104104});
105+106+describe("applyDefaultModel", () => {
107+it("sets the primary when none exists", () => {
108+const config = {
109+agents: { defaults: {} },
110+} as OpenClawConfig;
111+const next = applyDefaultModel(config, "openrouter/auto");
112+expect(next.agents?.defaults?.model).toEqual({ primary: "openrouter/auto" });
113+});
114+115+it("overwrites an existing primary by default", () => {
116+const config = {
117+agents: {
118+defaults: {
119+model: { primary: "anthropic/claude-opus-4-6" },
120+},
121+},
122+} as OpenClawConfig;
123+const next = applyDefaultModel(config, "openrouter/auto");
124+expect(next.agents?.defaults?.model).toEqual({
125+primary: "openrouter/auto",
126+});
127+});
128+129+it("preserves an existing primary when requested", () => {
130+const config = {
131+agents: {
132+defaults: {
133+model: { primary: "anthropic/claude-opus-4-6" },
134+},
135+},
136+} as OpenClawConfig;
137+const next = applyDefaultModel(config, "openrouter/auto", {
138+preserveExistingPrimary: true,
139+});
140+expect(next.agents?.defaults?.model).toEqual({
141+primary: "anthropic/claude-opus-4-6",
142+});
143+});
144+145+it("preserves an existing primary and keeps fallbacks", () => {
146+const config = {
147+agents: {
148+defaults: {
149+model: {
150+primary: "anthropic/claude-opus-4-6",
151+fallbacks: ["openai/gpt-5.4"],
152+},
153+},
154+},
155+} as OpenClawConfig;
156+const next = applyDefaultModel(config, "openrouter/auto", {
157+preserveExistingPrimary: true,
158+});
159+expect(next.agents?.defaults?.model).toEqual({
160+primary: "anthropic/claude-opus-4-6",
161+fallbacks: ["openai/gpt-5.4"],
162+});
163+});
164+165+it("adds the model to the allowlist", () => {
166+const config = {
167+agents: { defaults: { models: { "anthropic/claude-sonnet-4-6": {} } } },
168+} as OpenClawConfig;
169+const next = applyDefaultModel(config, "openrouter/auto");
170+expect(next.agents?.defaults?.models).toEqual({
171+"anthropic/claude-sonnet-4-6": {},
172+"openrouter/auto": {},
173+});
174+});
175+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。