Skip to content

Commit a626330

Browse files
authored
fix(deepinfra): model list fails when HTTP proxy is required (#111428)
1 parent 6c9b31e commit a626330

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// DeepInfra proxy tests cover the live model discovery transport policy.
2+
import { afterEach, describe, expect, it, vi } from "vitest";
3+
4+
const fetchWithSsrFGuardMock = vi.hoisted(() => vi.fn());
5+
6+
vi.mock("openclaw/plugin-sdk/ssrf-runtime", async (importOriginal) => ({
7+
...(await importOriginal<typeof import("openclaw/plugin-sdk/ssrf-runtime")>()),
8+
fetchWithSsrFGuard: fetchWithSsrFGuardMock,
9+
}));
10+
11+
import { discoverDeepInfraModels } from "./provider-models.js";
12+
13+
const ORIGINAL_VITEST = process.env.VITEST;
14+
const ORIGINAL_NODE_ENV = process.env.NODE_ENV;
15+
16+
function restoreEnv(key: "VITEST" | "NODE_ENV", value: string | undefined) {
17+
if (value === undefined) {
18+
delete process.env[key];
19+
} else {
20+
process.env[key] = value;
21+
}
22+
}
23+
24+
afterEach(() => {
25+
restoreEnv("VITEST", ORIGINAL_VITEST);
26+
restoreEnv("NODE_ENV", ORIGINAL_NODE_ENV);
27+
fetchWithSsrFGuardMock.mockReset();
28+
vi.restoreAllMocks();
29+
});
30+
31+
describe("DeepInfra model discovery proxy policy", () => {
32+
it("allows the guarded official catalog request to use an eligible HTTP proxy", async () => {
33+
delete process.env.VITEST;
34+
process.env.NODE_ENV = "development";
35+
const release = vi.fn(async () => undefined);
36+
fetchWithSsrFGuardMock.mockResolvedValue({
37+
response: new Response("unavailable", { status: 503 }),
38+
release,
39+
});
40+
41+
await discoverDeepInfraModels({ hasApiKey: true });
42+
43+
expect(fetchWithSsrFGuardMock).toHaveBeenCalledWith(
44+
expect.objectContaining({
45+
mode: "trusted_env_proxy",
46+
url: "https://api.deepinfra.com/v1/openai/models?sort_by=openclaw&filter=with_meta",
47+
}),
48+
);
49+
expect(release).toHaveBeenCalledOnce();
50+
});
51+
});

‎extensions/deepinfra/provider-models.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Deepinfra provider module implements model/runtime integration.
2+
3+
import { withTrustedEnvProxyGuardedFetchMode } from "openclaw/plugin-sdk/fetch-runtime";
24
import { isProviderApiKeyConfigured } from "openclaw/plugin-sdk/provider-auth";
35
import {
46
getCachedLiveProviderModelRows,
@@ -8,6 +10,7 @@ import { buildManifestModelProviderConfig } from "openclaw/plugin-sdk/provider-c
810
import type { ModelDefinitionConfig } from "openclaw/plugin-sdk/provider-model-shared";
911
import { createSubsystemLogger } from "openclaw/plugin-sdk/runtime-env";
1012
import { hasConfiguredSecretInput } from "openclaw/plugin-sdk/secret-input";
13+
import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime";
1114
import { asPositiveSafeInteger } from "openclaw/plugin-sdk/string-coerce-runtime";
1215
import manifest from "./openclaw.plugin.json" with { type: "json" };
1316

@@ -413,6 +416,7 @@ export async function discoverDeepInfraSurfaces(options?: {
413416
buildRequestHeaders: () => ({ Accept: "application/json" }),
414417
auditContext: "deepinfra-model-discovery",
415418
shouldCacheRows: hasDeepInfraSurfaceModelRows,
419+
fetchGuard: (params) => fetchWithSsrFGuard(withTrustedEnvProxyGuardedFetchMode(params)),
416420
});
417421
if (data.length === 0) {
418422
log.warn("No models found from DeepInfra agent-projection endpoint, using static catalog");

0 commit comments

Comments
 (0)