test(models): refresh list assertions after main sync

This commit is contained in:
Doruk Ardahan
2026-03-08 22:43:57 +03:00
committed by Peter Steinberger
parent b2b99f0325
commit 3da8882a02
2 changed files with 44 additions and 31 deletions

View File

@@ -354,8 +354,8 @@ describe("models list/status", () => {
await modelsListCommand({ all: true, json: true }, runtime); await modelsListCommand({ all: true, json: true }, runtime);
expect(ensureOpenClawModelsJson).toHaveBeenCalledTimes(1); expect(ensureOpenClawModelsJson).toHaveBeenCalled();
expect(ensureOpenClawModelsJson).toHaveBeenCalledWith(resolvedConfig); expect(ensureOpenClawModelsJson.mock.calls[0]?.[0]).toEqual(resolvedConfig);
}); });
it("toModelRow does not crash without cfg/authStore when availability is undefined", async () => { it("toModelRow does not crash without cfg/authStore when availability is undefined", async () => {

View File

@@ -67,6 +67,8 @@ const mocks = vi.hoisted(() => {
vi.mock("../../config/config.js", () => ({ vi.mock("../../config/config.js", () => ({
loadConfig: mocks.loadConfig, loadConfig: mocks.loadConfig,
getRuntimeConfigSnapshot: vi.fn().mockReturnValue(null),
getRuntimeConfigSourceSnapshot: vi.fn().mockReturnValue(null),
})); }));
vi.mock("../../agents/auth-profiles.js", async (importOriginal) => { vi.mock("../../agents/auth-profiles.js", async (importOriginal) => {
@@ -182,25 +184,29 @@ describe("modelsListCommand forward-compat", () => {
availableKeys: new Set(), availableKeys: new Set(),
registry: {}, registry: {},
}); });
mocks.listProfilesForProvider.mockImplementationOnce((_: unknown, provider: string) => mocks.listProfilesForProvider.mockImplementation((_: unknown, provider: string) =>
provider === "openai-codex" ? ([{ id: "profile-1" }] as Array<Record<string, unknown>>) : [], provider === "openai-codex" ? ([{ id: "profile-1" }] as Array<Record<string, unknown>>) : [],
); );
const runtime = { log: vi.fn(), error: vi.fn() }; const runtime = { log: vi.fn(), error: vi.fn() };
await modelsListCommand({ json: true }, runtime as never); try {
await modelsListCommand({ json: true }, runtime as never);
expect(mocks.printModelTable).toHaveBeenCalled(); expect(mocks.printModelTable).toHaveBeenCalled();
const rows = mocks.printModelTable.mock.calls.at(-1)?.[0] as Array<{ const rows = mocks.printModelTable.mock.calls.at(-1)?.[0] as Array<{
key: string; key: string;
available: boolean; available: boolean;
}>; }>;
expect(rows).toContainEqual( expect(rows).toContainEqual(
expect.objectContaining({ expect.objectContaining({
key: "openai-codex/gpt-5.4", key: "openai-codex/gpt-5.4",
available: true, available: true,
}), }),
); );
} finally {
mocks.listProfilesForProvider.mockReturnValue([]);
}
}); });
it("includes synthetic codex gpt-5.4 in --all output when catalog supports it", async () => { it("includes synthetic codex gpt-5.4 in --all output when catalog supports it", async () => {
@@ -238,7 +244,7 @@ describe("modelsListCommand forward-compat", () => {
contextWindow: 272000, contextWindow: 272000,
}, },
]); ]);
mocks.listProfilesForProvider.mockImplementationOnce((_: unknown, provider: string) => mocks.listProfilesForProvider.mockImplementation((_: unknown, provider: string) =>
provider === "openai-codex" ? ([{ id: "profile-1" }] as Array<Record<string, unknown>>) : [], provider === "openai-codex" ? ([{ id: "profile-1" }] as Array<Record<string, unknown>>) : [],
); );
mocks.resolveModelWithRegistry.mockImplementation( mocks.resolveModelWithRegistry.mockImplementation(
@@ -277,23 +283,30 @@ describe("modelsListCommand forward-compat", () => {
); );
const runtime = { log: vi.fn(), error: vi.fn() }; const runtime = { log: vi.fn(), error: vi.fn() };
await modelsListCommand({ all: true, provider: "openai-codex", json: true }, runtime as never); try {
await modelsListCommand(
{ all: true, provider: "openai-codex", json: true },
runtime as never,
);
expect(mocks.printModelTable).toHaveBeenCalled(); expect(mocks.printModelTable).toHaveBeenCalled();
const rows = mocks.printModelTable.mock.calls.at(-1)?.[0] as Array<{ const rows = mocks.printModelTable.mock.calls.at(-1)?.[0] as Array<{
key: string; key: string;
available: boolean; available: boolean;
}>; }>;
expect(rows).toEqual([ expect(rows).toEqual([
expect.objectContaining({ expect.objectContaining({
key: "openai-codex/gpt-5.3-codex", key: "openai-codex/gpt-5.3-codex",
}), }),
expect.objectContaining({ expect.objectContaining({
key: "openai-codex/gpt-5.4", key: "openai-codex/gpt-5.4",
available: true, available: true,
}), }),
]); ]);
} finally {
mocks.listProfilesForProvider.mockReturnValue([]);
}
}); });
it("keeps discovered rows in --all output when catalog lookup is empty", async () => { it("keeps discovered rows in --all output when catalog lookup is empty", async () => {