mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 00:48:27 +00:00
test: move command status and health suites out of e2e
This commit is contained in:
93
src/commands/models.set.test.ts
Normal file
93
src/commands/models.set.test.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const readConfigFileSnapshot = vi.fn();
|
||||
const writeConfigFile = vi.fn().mockResolvedValue(undefined);
|
||||
const loadConfig = vi.fn().mockReturnValue({});
|
||||
|
||||
vi.mock("../config/config.js", () => ({
|
||||
CONFIG_PATH: "/tmp/openclaw.json",
|
||||
readConfigFileSnapshot,
|
||||
writeConfigFile,
|
||||
loadConfig,
|
||||
}));
|
||||
|
||||
function mockConfigSnapshot(config: Record<string, unknown> = {}) {
|
||||
readConfigFileSnapshot.mockResolvedValue({
|
||||
path: "/tmp/openclaw.json",
|
||||
exists: true,
|
||||
raw: "{}",
|
||||
parsed: {},
|
||||
valid: true,
|
||||
config,
|
||||
issues: [],
|
||||
legacyIssues: [],
|
||||
});
|
||||
}
|
||||
|
||||
function makeRuntime() {
|
||||
return { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
|
||||
}
|
||||
|
||||
function getWrittenConfig() {
|
||||
return writeConfigFile.mock.calls[0]?.[0] as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function expectWrittenPrimaryModel(model: string) {
|
||||
expect(writeConfigFile).toHaveBeenCalledTimes(1);
|
||||
const written = getWrittenConfig();
|
||||
expect(written.agents).toEqual({
|
||||
defaults: {
|
||||
model: { primary: model },
|
||||
models: { [model]: {} },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
let modelsSetCommand: typeof import("./models/set.js").modelsSetCommand;
|
||||
let modelsFallbacksAddCommand: typeof import("./models/fallbacks.js").modelsFallbacksAddCommand;
|
||||
|
||||
describe("models set + fallbacks", () => {
|
||||
beforeAll(async () => {
|
||||
({ modelsSetCommand } = await import("./models/set.js"));
|
||||
({ modelsFallbacksAddCommand } = await import("./models/fallbacks.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
readConfigFileSnapshot.mockClear();
|
||||
writeConfigFile.mockClear();
|
||||
});
|
||||
|
||||
it("normalizes z.ai provider in models set", async () => {
|
||||
mockConfigSnapshot({});
|
||||
const runtime = makeRuntime();
|
||||
|
||||
await modelsSetCommand("z.ai/glm-4.7", runtime);
|
||||
|
||||
expectWrittenPrimaryModel("zai/glm-4.7");
|
||||
});
|
||||
|
||||
it("normalizes z-ai provider in models fallbacks add", async () => {
|
||||
mockConfigSnapshot({ agents: { defaults: { model: { fallbacks: [] } } } });
|
||||
const runtime = makeRuntime();
|
||||
|
||||
await modelsFallbacksAddCommand("z-ai/glm-4.7", runtime);
|
||||
|
||||
expect(writeConfigFile).toHaveBeenCalledTimes(1);
|
||||
const written = getWrittenConfig();
|
||||
expect(written.agents).toEqual({
|
||||
defaults: {
|
||||
model: { fallbacks: ["zai/glm-4.7"] },
|
||||
models: { "zai/glm-4.7": {} },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("normalizes provider casing in models set", async () => {
|
||||
mockConfigSnapshot({});
|
||||
const runtime = makeRuntime();
|
||||
|
||||
await modelsSetCommand("Z.AI/glm-4.7", runtime);
|
||||
|
||||
expectWrittenPrimaryModel("zai/glm-4.7");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user