Onboard: store OpenAI auth in profiles instead of .env

This commit is contained in:
joshavant
2026-02-21 14:55:56 -08:00
committed by Peter Steinberger
parent 09c7cb5d34
commit 68b9d89ee7
6 changed files with 131 additions and 26 deletions

View File

@@ -1,5 +1,9 @@
import { afterEach, describe, expect, it } from "vitest";
import { setCloudflareAiGatewayConfig, setMoonshotApiKey } from "./onboard-auth.js";
import {
setCloudflareAiGatewayConfig,
setMoonshotApiKey,
setOpenaiApiKey,
} from "./onboard-auth.js";
import {
createAuthTestLifecycle,
readAuthProfilesForAgent,
@@ -12,6 +16,7 @@ describe("onboard auth credentials secret refs", () => {
"OPENCLAW_AGENT_DIR",
"PI_CODING_AGENT_DIR",
"MOONSHOT_API_KEY",
"OPENAI_API_KEY",
"CLOUDFLARE_AI_GATEWAY_API_KEY",
]);
@@ -100,4 +105,20 @@ describe("onboard auth credentials secret refs", () => {
});
expect(parsed.profiles?.["cloudflare-ai-gateway:default"]?.key).toBeUndefined();
});
it("stores env-backed openai key as keyRef", async () => {
const env = await setupAuthTestEnv("openclaw-onboard-auth-credentials-openai-");
lifecycle.setStateDir(env.stateDir);
process.env.OPENAI_API_KEY = "sk-openai-env";
await setOpenaiApiKey("sk-openai-env");
const parsed = await readAuthProfilesForAgent<{
profiles?: Record<string, { key?: string; keyRef?: unknown }>;
}>(env.agentDir);
expect(parsed.profiles?.["openai:default"]).toMatchObject({
keyRef: { source: "env", id: "OPENAI_API_KEY" },
});
expect(parsed.profiles?.["openai:default"]?.key).toBeUndefined();
});
});