Skip to content

Commit db49a9a

Browse files
steipetePeter Steinberger
andauthored
fix(cerebras): keep documented model catalog static (#117584)
Co-authored-by: Peter Steinberger <[email protected]>
1 parent d334de8 commit db49a9a

3 files changed

Lines changed: 68 additions & 3 deletions

File tree

‎extensions/cerebras/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ export default defineSingleProviderPluginEntry({
2424
].join("\n"),
2525
noteTitle: "Cerebras",
2626
},
27-
catalog: { liveModelDiscovery: true },
27+
catalog: {},
2828
},
2929
});

‎extensions/cerebras/onboard.test.ts‎

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
import { registerSingleProviderPlugin } from "openclaw/plugin-sdk/plugin-test-runtime";
22
import { resolveAgentModelPrimaryValue } from "openclaw/plugin-sdk/provider-onboard";
3-
import { describe, expect, it, vi } from "vitest";
3+
import { afterEach, describe, expect, it, vi } from "vitest";
44
import plugin from "./index.js";
55
import { applyCerebrasConfig, CEREBRAS_DEFAULT_MODEL_REF } from "./onboard.js";
66
import manifest from "./openclaw.plugin.json" with { type: "json" };
77

8+
const ssrfRuntimeMocks = vi.hoisted(() => ({
9+
fetchWithSsrFGuard: vi.fn(),
10+
ssrfPolicyFromHttpBaseUrlAllowedHostname: vi.fn((baseUrl: string) => ({
11+
allowedHostnames: [new URL(baseUrl).hostname],
12+
})),
13+
}));
14+
15+
vi.mock("openclaw/plugin-sdk/ssrf-runtime", () => ssrfRuntimeMocks);
16+
17+
afterEach(() => {
18+
ssrfRuntimeMocks.fetchWithSsrFGuard.mockReset();
19+
ssrfRuntimeMocks.ssrfPolicyFromHttpBaseUrlAllowedHostname.mockClear();
20+
});
21+
822
describe("Cerebras onboarding", () => {
923
it("applies the manifest catalog, default, and alias", () => {
1024
const config = applyCerebrasConfig({});
@@ -51,4 +65,55 @@ describe("Cerebras onboarding", () => {
5165
[CEREBRAS_DEFAULT_MODEL_REF]: { alias: "Cerebras Gemma 4 31B" },
5266
});
5367
});
68+
69+
it("keeps the authenticated runtime catalog static without querying the model endpoint", async () => {
70+
ssrfRuntimeMocks.fetchWithSsrFGuard.mockResolvedValueOnce({
71+
response: Response.json({ data: [{ id: "gpt-oss-120b", object: "model" }] }),
72+
finalUrl: "https://api.cerebras.ai/v1/models",
73+
release: vi.fn(),
74+
});
75+
const provider = await registerSingleProviderPlugin(plugin);
76+
const result = await provider.catalog?.run({
77+
config: {},
78+
env: {},
79+
resolveProviderApiKey: () => ({ apiKey: "fixture-cerebras-key" }),
80+
} as never);
81+
82+
expect(ssrfRuntimeMocks.fetchWithSsrFGuard).not.toHaveBeenCalled();
83+
if (!result || !("provider" in result)) {
84+
throw new Error("expected authenticated Cerebras provider catalog");
85+
}
86+
expect(result.provider.apiKey).toBe("fixture-cerebras-key");
87+
expect(result.provider.models.map((model) => model.id)).toEqual(
88+
manifest.modelCatalog.providers.cerebras.models.map((model) => model.id),
89+
);
90+
expect(result.provider.models.find((model) => model.id === "gemma-4-31b")?.input).toEqual([
91+
"text",
92+
"image",
93+
]);
94+
const staticResult = await provider.staticCatalog?.run({ config: {}, env: {} } as never);
95+
if (!staticResult || !("provider" in staticResult)) {
96+
throw new Error("expected static Cerebras provider catalog");
97+
}
98+
expect(staticResult.provider.models.map((model) => model.id)).toEqual(
99+
manifest.modelCatalog.providers.cerebras.models.map((model) => model.id),
100+
);
101+
});
102+
103+
it("declares the bundled provider catalog as static", () => {
104+
expect(manifest.modelCatalog.discovery.cerebras).toBe("static");
105+
});
106+
107+
it("keeps the runtime catalog inactive without a Cerebras credential", async () => {
108+
const provider = await registerSingleProviderPlugin(plugin);
109+
110+
await expect(
111+
provider.catalog?.run({
112+
config: {},
113+
env: {},
114+
resolveProviderApiKey: () => ({}),
115+
} as never),
116+
).resolves.toBeNull();
117+
expect(ssrfRuntimeMocks.fetchWithSsrFGuard).not.toHaveBeenCalled();
118+
});
54119
});

‎extensions/cerebras/openclaw.plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
}
7272
},
7373
"discovery": {
74-
"cerebras": "refreshable"
74+
"cerebras": "static"
7575
}
7676
},
7777
"setup": {

0 commit comments

Comments
 (0)