Skip to content

Commit 64f9f3c

Browse files
committed
fix(models): stabilize vertex marker regression tests
1 parent cd3eb43 commit 64f9f3c

5 files changed

Lines changed: 123 additions & 79 deletions

src/agents/model-auth-markers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const AWS_SDK_ENV_MARKERS = new Set([
3636
const CORE_NON_SECRET_API_KEY_MARKERS = [
3737
CUSTOM_LOCAL_AUTH_MARKER,
3838
CODEX_APP_SERVER_AUTH_MARKER,
39+
GCP_VERTEX_CREDENTIALS_MARKER,
3940
OLLAMA_LOCAL_AUTH_MARKER,
4041
NON_ENV_SECRETREF_MARKER,
4142
] as const;

src/agents/models-config.applies-config-env-vars.test.ts

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import fs from "node:fs/promises";
33
import os from "node:os";
44
import path from "node:path";
5+
import { fileURLToPath } from "node:url";
56
import { beforeAll, describe, expect, it } from "vitest";
67
import type { OpenClawConfig } from "../config/config.js";
78
import { createConfigRuntimeEnv } from "../config/env-vars.js";
@@ -17,6 +18,7 @@ import type { ProviderConfig } from "./models-config.providers.secrets.js";
1718
import { encodePluginModelCatalogRelativePath } from "./plugin-model-catalog.js";
1819

1920
const TEST_ENV_VAR = "OPENCLAW_MODELS_CONFIG_TEST_ENV";
21+
const BUNDLED_PLUGINS_DIR = fileURLToPath(new URL("../../extensions/", import.meta.url));
2022

2123
function createImplicitOpenRouterProvider(): ProviderConfig {
2224
return {
@@ -533,33 +535,42 @@ describe("models-config", () => {
533535
const credentialsPath = path.join(agentDir, "application_default_credentials.json");
534536
await fs.writeFile(credentialsPath, JSON.stringify({ type: "authorized_user" }), "utf8");
535537
try {
536-
const plan = await planOpenClawModelsJsonWithDeps(
538+
const plan = await withEnvAsync(
537539
{
538-
cfg: {
539-
agents: {
540-
defaults: {
541-
models: {
542-
"google-vertex/gemini-2.5-pro": {},
540+
OPENCLAW_BUNDLED_PLUGINS_DIR: BUNDLED_PLUGINS_DIR,
541+
OPENCLAW_DISABLE_BUNDLED_PLUGINS: undefined,
542+
},
543+
async () =>
544+
await planOpenClawModelsJsonWithDeps(
545+
{
546+
cfg: {
547+
agents: {
548+
defaults: {
549+
models: {
550+
"google-vertex/gemini-2.5-pro": {},
551+
},
552+
model: { primary: "google-vertex/gemini-2.5-pro" },
553+
},
543554
},
544-
model: { primary: "google-vertex/gemini-2.5-pro" },
555+
models: { providers: {} },
545556
},
557+
agentDir,
558+
env: {
559+
OPENCLAW_BUNDLED_PLUGINS_DIR: BUNDLED_PLUGINS_DIR,
560+
OPENCLAW_DISABLE_BUNDLED_PLUGINS: undefined,
561+
GOOGLE_APPLICATION_CREDENTIALS: credentialsPath,
562+
GOOGLE_CLOUD_PROJECT: "vertex-project",
563+
GOOGLE_CLOUD_LOCATION: "global",
564+
} as NodeJS.ProcessEnv,
565+
existingRaw: "",
566+
existingParsed: null,
546567
},
547-
models: { providers: {} },
548-
},
549-
agentDir,
550-
env: {
551-
GOOGLE_APPLICATION_CREDENTIALS: credentialsPath,
552-
GOOGLE_CLOUD_PROJECT: "vertex-project",
553-
GOOGLE_CLOUD_LOCATION: "global",
554-
} as NodeJS.ProcessEnv,
555-
existingRaw: "",
556-
existingParsed: null,
557-
},
558-
{
559-
resolveImplicitProviders: async () => ({
560-
"google-vertex": createImplicitGoogleVertexProvider(),
561-
}),
562-
},
568+
{
569+
resolveImplicitProviders: async () => ({
570+
"google-vertex": createImplicitGoogleVertexProvider(),
571+
}),
572+
},
573+
),
563574
);
564575

565576
expect(plan.action).toBe("write");

src/agents/models-config.providers.implicit.discovery-scope.test.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
import { mkdtemp, writeFile } from "node:fs/promises";
33
import os from "node:os";
44
import path from "node:path";
5+
import { fileURLToPath } from "node:url";
56
import { beforeEach, describe, expect, it, vi } from "vitest";
67
import type { PluginMetadataSnapshotOwnerMaps } from "../plugins/plugin-metadata-snapshot.js";
78
import type { ProviderPlugin } from "../plugins/types.js";
9+
import { withEnvAsync } from "../test-utils/env.js";
810

911
const mocks = vi.hoisted(() => ({
1012
resolveRuntimePluginDiscoveryProviders: vi.fn(),
1113
runProviderCatalog: vi.fn(),
1214
runProviderStaticCatalog: vi.fn(),
1315
}));
16+
const BUNDLED_PLUGINS_DIR = fileURLToPath(new URL("../../extensions/", import.meta.url));
1417

1518
vi.mock("../plugins/provider-discovery.js", () => ({
1619
resolveRuntimePluginDiscoveryProviders: mocks.resolveRuntimePluginDiscoveryProviders,
@@ -225,17 +228,26 @@ describe("resolveImplicitProviders startup discovery scope", () => {
225228
},
226229
});
227230

228-
const providers = await resolveImplicitProviders({
229-
agentDir: "/tmp/openclaw-agent",
230-
config: {},
231-
env: {
232-
GOOGLE_APPLICATION_CREDENTIALS: credentialsPath,
233-
GOOGLE_CLOUD_PROJECT: "vertex-project",
234-
GOOGLE_CLOUD_LOCATION: "global",
235-
} as NodeJS.ProcessEnv,
236-
explicitProviders: {},
237-
providerDiscoveryEntriesOnly: true,
238-
});
231+
const providers = await withEnvAsync(
232+
{
233+
OPENCLAW_BUNDLED_PLUGINS_DIR: BUNDLED_PLUGINS_DIR,
234+
OPENCLAW_DISABLE_BUNDLED_PLUGINS: undefined,
235+
},
236+
async () =>
237+
await resolveImplicitProviders({
238+
agentDir: "/tmp/openclaw-agent",
239+
config: {},
240+
env: {
241+
OPENCLAW_BUNDLED_PLUGINS_DIR: BUNDLED_PLUGINS_DIR,
242+
OPENCLAW_DISABLE_BUNDLED_PLUGINS: undefined,
243+
GOOGLE_APPLICATION_CREDENTIALS: credentialsPath,
244+
GOOGLE_CLOUD_PROJECT: "vertex-project",
245+
GOOGLE_CLOUD_LOCATION: "global",
246+
} as NodeJS.ProcessEnv,
247+
explicitProviders: {},
248+
providerDiscoveryEntriesOnly: true,
249+
}),
250+
);
239251

240252
expect(providers?.["google-vertex"]?.apiKey).toBe("gcp-vertex-credentials");
241253
});

src/agents/provider-attribution.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ const providerEndpointPlugins = vi.hoisted(() => [
7373
hosts: ["integrate.api.nvidia.com"],
7474
baseUrls: ["https://integrate.api.nvidia.com/v1"],
7575
},
76+
{
77+
endpointClass: "xiaomi-native",
78+
hosts: [
79+
"api.xiaomimimo.com",
80+
"token-plan-ams.xiaomimimo.com",
81+
"token-plan-cn.xiaomimimo.com",
82+
"token-plan-sgp.xiaomimimo.com",
83+
],
84+
},
7685
],
7786
providerRequest: {
7887
providers: {
@@ -90,6 +99,8 @@ const providerEndpointPlugins = vi.hoisted(() => [
9099
openrouter: { family: "openrouter" },
91100
qwen: { family: "modelstudio" },
92101
together: { family: "together" },
102+
xiaomi: { family: "xiaomi" },
103+
"xiaomi-token-plan": { family: "xiaomi" },
93104
xai: { family: "xai" },
94105
zai: { family: "zai" },
95106
},
@@ -104,6 +115,15 @@ vi.mock("../plugins/plugin-registry.js", () => ({
104115
}),
105116
}));
106117

118+
vi.mock("../plugins/manifest-metadata-scan.js", () => ({
119+
listOpenClawPluginManifestMetadata: () =>
120+
providerEndpointPlugins.map((manifest, index) => ({
121+
pluginDir: `provider-endpoint-fixture-${index}`,
122+
manifest,
123+
origin: "bundled",
124+
})),
125+
}));
126+
107127
import {
108128
listProviderAttributionPolicies,
109129
resolveProviderAttributionHeaders,

0 commit comments

Comments
 (0)