test: stabilize provider normalization lanes

This commit is contained in:
Peter Steinberger 2026-04-05 13:55:23 +01:00
parent 388f82f22f
commit ed1734a7c7
No known key found for this signature in database
2 changed files with 74 additions and 13 deletions

View File

@ -43,6 +43,9 @@ export function normalizeProviderSpecificConfig(
providerKey: string,
provider: ProviderConfig,
): ProviderConfig {
if (shouldNormalizeGoogleProviderConfig(providerKey, provider)) {
return normalizeGoogleProviderConfig(providerKey, provider);
}
const runtimeProviderKey = resolveProviderPluginLookupKey(providerKey, provider);
const normalized =
normalizeProviderConfigWithPlugin({
@ -55,9 +58,6 @@ export function normalizeProviderSpecificConfig(
if (normalized && normalized !== provider) {
return normalized;
}
if (shouldNormalizeGoogleProviderConfig(providerKey, provider)) {
return normalizeGoogleProviderConfig(providerKey, provider);
}
return provider;
}

View File

@ -1,15 +1,74 @@
import { describe, expect, it } from "vitest";
import {
loadBundledProviderCatalogExportMap,
resolveBundledProviderCatalogEntries,
} from "./models-config.providers.static.js";
import fs from "node:fs";
import { mkdtempSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
type StaticModule = typeof import("./models-config.providers.static.js");
const fixtureRoot = mkdtempSync(path.join(tmpdir(), "openclaw-provider-catalogs-"));
const fixtureExtensionsDir = path.join(fixtureRoot, "dist-runtime", "extensions");
function writeFixtureCatalog(dirName: string, exportNames: string[]) {
const pluginDir = path.join(fixtureExtensionsDir, dirName);
fs.mkdirSync(pluginDir, { recursive: true });
fs.writeFileSync(
path.join(pluginDir, "provider-catalog.js"),
exportNames
.map((exportName) => `export function ${exportName}() { return "${dirName}"; }`)
.join("\n") + "\n",
"utf8",
);
}
writeFixtureCatalog("openrouter", ["buildOpenrouterProvider"]);
writeFixtureCatalog("volcengine", ["buildDoubaoProvider", "buildDoubaoCodingProvider"]);
let staticModule: StaticModule;
beforeAll(async () => {
vi.resetModules();
vi.doMock("../plugins/bundled-plugin-metadata.js", () => ({
listBundledPluginMetadata: (_params: { rootDir: string }) => [
{
dirName: "openrouter",
publicSurfaceArtifacts: ["provider-catalog.js"],
manifest: { id: "openrouter", providers: ["openrouter"] },
},
{
dirName: "volcengine",
publicSurfaceArtifacts: ["provider-catalog.js"],
manifest: { id: "volcengine", providers: ["volcengine", "byteplus"] },
},
{
dirName: "ignored",
publicSurfaceArtifacts: ["api.js"],
manifest: { id: "ignored", providers: [] },
},
],
resolveBundledPluginPublicSurfacePath: ({
rootDir,
dirName,
artifactBasename,
}: {
rootDir: string;
dirName: string;
artifactBasename: string;
}) => path.join(rootDir, "dist-runtime", "extensions", dirName, artifactBasename),
}));
staticModule = await import("./models-config.providers.static.js");
});
afterAll(() => {
vi.doUnmock("../plugins/bundled-plugin-metadata.js");
vi.resetModules();
fs.rmSync(fixtureRoot, { recursive: true, force: true });
});
describe("models-config bundled provider catalogs", () => {
it("detects provider catalogs from plugin folders via metadata artifacts", () => {
const entries = resolveBundledProviderCatalogEntries();
expect(entries.map((entry) => entry.dirName)).toEqual(
expect.arrayContaining(["openrouter", "volcengine"]),
);
const entries = staticModule.resolveBundledProviderCatalogEntries({ rootDir: fixtureRoot });
expect(entries.map((entry) => entry.dirName)).toEqual(["openrouter", "volcengine"]);
expect(entries.find((entry) => entry.dirName === "volcengine")).toMatchObject({
dirName: "volcengine",
pluginId: "volcengine",
@ -17,7 +76,9 @@ describe("models-config bundled provider catalogs", () => {
});
it("loads provider catalog exports from detected plugin folders", async () => {
const exports = await loadBundledProviderCatalogExportMap();
const exports = await staticModule.loadBundledProviderCatalogExportMap({
rootDir: fixtureRoot,
});
expect(exports.buildOpenrouterProvider).toBeTypeOf("function");
expect(exports.buildDoubaoProvider).toBeTypeOf("function");
expect(exports.buildDoubaoCodingProvider).toBeTypeOf("function");