Files
openclaw-zero-token/plugins/bundled-provider-auth-env-vars.test.ts
sjhu 571e14a236 feat: upgrade to upstream v2026.3.28
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
2026-03-30 17:58:12 +08:00

111 lines
3.4 KiB
TypeScript

import fs from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
import {
collectBundledProviderAuthEnvVars,
writeBundledProviderAuthEnvVarModule,
} from "../../scripts/generate-bundled-provider-auth-env-vars.mjs";
import { BUNDLED_PROVIDER_AUTH_ENV_VAR_CANDIDATES } from "./bundled-provider-auth-env-vars.js";
import {
createGeneratedPluginTempRoot,
installGeneratedPluginTempRootCleanup,
pluginTestRepoRoot as repoRoot,
writeJson,
} from "./generated-plugin-test-helpers.js";
installGeneratedPluginTempRootCleanup();
function expectGeneratedAuthEnvVarModuleState(params: {
tempRoot: string;
expectedChanged: boolean;
expectedWrote: boolean;
}) {
const result = writeBundledProviderAuthEnvVarModule({
repoRoot: params.tempRoot,
outputPath: "src/plugins/bundled-provider-auth-env-vars.generated.ts",
check: true,
});
expect(result.changed).toBe(params.expectedChanged);
expect(result.wrote).toBe(params.expectedWrote);
}
function expectGeneratedAuthEnvVarCheckMode(tempRoot: string) {
expectGeneratedAuthEnvVarModuleState({
tempRoot,
expectedChanged: false,
expectedWrote: false,
});
}
function expectBundledProviderEnvVars(expected: Record<string, readonly string[]>) {
expect(
Object.fromEntries(
Object.keys(expected).map((providerId) => [
providerId,
BUNDLED_PROVIDER_AUTH_ENV_VAR_CANDIDATES[
providerId as keyof typeof BUNDLED_PROVIDER_AUTH_ENV_VAR_CANDIDATES
],
]),
),
).toEqual(expected);
}
function expectMissingBundledProviderEnvVars(providerIds: readonly string[]) {
providerIds.forEach((providerId) => {
expect(providerId in BUNDLED_PROVIDER_AUTH_ENV_VAR_CANDIDATES).toBe(false);
});
}
describe("bundled provider auth env vars", () => {
it("matches the generated manifest snapshot", () => {
expect(BUNDLED_PROVIDER_AUTH_ENV_VAR_CANDIDATES).toEqual(
collectBundledProviderAuthEnvVars({ repoRoot }),
);
});
it("reads bundled provider auth env vars from plugin manifests", () => {
expectBundledProviderEnvVars({
brave: ["BRAVE_API_KEY"],
firecrawl: ["FIRECRAWL_API_KEY"],
"github-copilot": ["COPILOT_GITHUB_TOKEN", "GH_TOKEN", "GITHUB_TOKEN"],
perplexity: ["PERPLEXITY_API_KEY", "OPENROUTER_API_KEY"],
tavily: ["TAVILY_API_KEY"],
"minimax-portal": ["MINIMAX_OAUTH_TOKEN", "MINIMAX_API_KEY"],
openai: ["OPENAI_API_KEY"],
fal: ["FAL_KEY"],
});
expectMissingBundledProviderEnvVars(["openai-codex"]);
});
it("supports check mode for stale generated artifacts", () => {
const tempRoot = createGeneratedPluginTempRoot("openclaw-provider-auth-env-vars-");
writeJson(path.join(tempRoot, "extensions", "alpha", "openclaw.plugin.json"), {
id: "alpha",
providerAuthEnvVars: {
alpha: ["ALPHA_TOKEN"],
},
});
const initial = writeBundledProviderAuthEnvVarModule({
repoRoot: tempRoot,
outputPath: "src/plugins/bundled-provider-auth-env-vars.generated.ts",
});
expect(initial.wrote).toBe(true);
expectGeneratedAuthEnvVarCheckMode(tempRoot);
fs.writeFileSync(
path.join(tempRoot, "src/plugins/bundled-provider-auth-env-vars.generated.ts"),
"// stale\n",
"utf8",
);
expectGeneratedAuthEnvVarModuleState({
tempRoot,
expectedChanged: true,
expectedWrote: false,
});
});
});