Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { isProxy, ref } from "vue";
import { createBrowserOpenClawMock } from "@/browser-openclaw";
import { readConfiguredModels } from "@/utils/configured-models";
import { readConfiguredCatalogs, useProviderModelCatalog } from "./use-provider-model-catalog";
Expand All @@ -24,6 +25,41 @@ beforeEach(() => {
});

describe("shared provider catalogs", () => {
it.each(["load", "loadConfigured"] as const)(
"passes cloneable requests from reactive provider configuration through %s",
async (method) => {
const shared = useProviderModelCatalog();
const inputs = ref(readConfiguredCatalogs(config));
expect(isProxy(inputs.value.qwen)).toBe(true);
vi.mocked(window.openclaw.model.discoverModels).mockImplementation((input) => {
structuredClone(input);
return Promise.resolve({ ok: true, models: ["old", "new", "latest"] });
});

if (method === "load") {
await shared.load(inputs.value.qwen);
} else {
await shared.loadConfigured(inputs.value);
}

expect(window.openclaw.model.discoverModels).toHaveBeenCalledOnce();
const [request] = vi.mocked(window.openclaw.model.discoverModels).mock.calls[0];
expect(isProxy(request)).toBe(false);
expect(request).not.toBe(inputs.value.qwen);
expect(request).toEqual({
baseUrl: config.models.providers.qwen.baseUrl,
apiKey: config.models.providers.qwen.apiKey,
});
expect(shared.errors(inputs.value)).toBe("");
expect(
shared
.merge(readConfiguredModels(config).models, inputs.value)
.filter((model) => model.providerKey === "qwen")
.map((model) => model.id),
).toEqual(["old", "new", "latest"]);
},
);

it("shares the full live list between form, default and conversation consumers without writes", async () => {
const form = useProviderModelCatalog();
const defaults = useProviderModelCatalog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function createCatalog(api: Window["openclaw"]["model"]) {
if (entry.pending) return entry.pending;
const current = entry;
current.pending = api
.discoverModels(input)
.discoverModels({ baseUrl: input.baseUrl, apiKey: input.apiKey })
.catch((): ProviderCatalogResult => ({ ok: false, error: "network" }))
.then((result) => {
current.result.value = result;
Expand Down
6 changes: 3 additions & 3 deletions desktop/renderer/src/views/SettingsView.models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,9 @@ describe("SettingsView model integration", () => {
apiKey: "fixture",
models: [{ id: "saved", name: "Saved" }],
};
window.openclaw.model.discoverModels = vi.fn().mockResolvedValue({
ok: true,
models: ["saved", "live-one", "live-two"],
vi.spyOn(window.openclaw.model, "discoverModels").mockImplementation((input) => {
structuredClone(input);
return Promise.resolve({ ok: true, models: ["saved", "live-one", "live-two"] });
});
const { wrapper } = await open();
const picker = wrapper.getComponent(DefaultPickerStub);
Expand Down
Loading