refactor(commands): share default model applier

This commit is contained in:
Peter Steinberger
2026-02-15 17:41:14 +00:00
parent 9084c4e345
commit 04f00f8ef2
4 changed files with 76 additions and 74 deletions

View File

@@ -0,0 +1,23 @@
import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import { applyAgentDefaultPrimaryModel } from "./model-default.js";
describe("applyAgentDefaultPrimaryModel", () => {
it("does not mutate when already set", () => {
const cfg = { agents: { defaults: { model: { primary: "a/b" } } } } as OpenClawConfig;
const result = applyAgentDefaultPrimaryModel({ cfg, model: "a/b" });
expect(result.changed).toBe(false);
expect(result.next).toBe(cfg);
});
it("normalizes legacy models", () => {
const cfg = { agents: { defaults: { model: { primary: "legacy" } } } } as OpenClawConfig;
const result = applyAgentDefaultPrimaryModel({
cfg,
model: "a/b",
legacyModels: new Set(["legacy"]),
});
expect(result.changed).toBe(false);
expect(result.next).toBe(cfg);
});
});