mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
test: merge duplicate undefined api-key persistence checks
This commit is contained in:
@@ -399,54 +399,47 @@ describe("applyAuthChoice", () => {
|
||||
expect(result.agentModelOverride).toBe("opencode/claude-opus-4-6");
|
||||
});
|
||||
|
||||
it("does not persist literal 'undefined' when Anthropic API key prompt returns undefined", async () => {
|
||||
await setupTempState();
|
||||
delete process.env.ANTHROPIC_API_KEY;
|
||||
it("does not persist literal 'undefined' when API key prompts return undefined", async () => {
|
||||
const scenarios = [
|
||||
{
|
||||
authChoice: "apiKey" as const,
|
||||
envKey: "ANTHROPIC_API_KEY",
|
||||
profileId: "anthropic:default",
|
||||
provider: "anthropic",
|
||||
},
|
||||
{
|
||||
authChoice: "openrouter-api-key" as const,
|
||||
envKey: "OPENROUTER_API_KEY",
|
||||
profileId: "openrouter:default",
|
||||
provider: "openrouter",
|
||||
},
|
||||
];
|
||||
|
||||
const text = vi.fn(async () => undefined as unknown as string);
|
||||
const prompter = createPrompter({ text });
|
||||
const runtime = createExitThrowingRuntime();
|
||||
for (const scenario of scenarios) {
|
||||
await setupTempState();
|
||||
delete process.env[scenario.envKey];
|
||||
|
||||
const result = await applyAuthChoice({
|
||||
authChoice: "apiKey",
|
||||
config: {},
|
||||
prompter,
|
||||
runtime,
|
||||
setDefaultModel: false,
|
||||
});
|
||||
const text = vi.fn(async () => undefined as unknown as string);
|
||||
const prompter = createPrompter({ text });
|
||||
const runtime = createExitThrowingRuntime();
|
||||
|
||||
expect(result.config.auth?.profiles?.["anthropic:default"]).toMatchObject({
|
||||
provider: "anthropic",
|
||||
mode: "api_key",
|
||||
});
|
||||
const result = await applyAuthChoice({
|
||||
authChoice: scenario.authChoice,
|
||||
config: {},
|
||||
prompter,
|
||||
runtime,
|
||||
setDefaultModel: false,
|
||||
});
|
||||
|
||||
expect((await readAuthProfile("anthropic:default"))?.key).toBe("");
|
||||
expect((await readAuthProfile("anthropic:default"))?.key).not.toBe("undefined");
|
||||
});
|
||||
expect(result.config.auth?.profiles?.[scenario.profileId]).toMatchObject({
|
||||
provider: scenario.provider,
|
||||
mode: "api_key",
|
||||
});
|
||||
|
||||
it("does not persist literal 'undefined' when OpenRouter API key prompt returns undefined", async () => {
|
||||
await setupTempState();
|
||||
delete process.env.OPENROUTER_API_KEY;
|
||||
|
||||
const text = vi.fn(async () => undefined as unknown as string);
|
||||
const prompter = createPrompter({ text });
|
||||
const runtime = createExitThrowingRuntime();
|
||||
|
||||
const result = await applyAuthChoice({
|
||||
authChoice: "openrouter-api-key",
|
||||
config: {},
|
||||
prompter,
|
||||
runtime,
|
||||
setDefaultModel: false,
|
||||
});
|
||||
|
||||
expect(result.config.auth?.profiles?.["openrouter:default"]).toMatchObject({
|
||||
provider: "openrouter",
|
||||
mode: "api_key",
|
||||
});
|
||||
|
||||
expect((await readAuthProfile("openrouter:default"))?.key).toBe("");
|
||||
expect((await readAuthProfile("openrouter:default"))?.key).not.toBe("undefined");
|
||||
const profile = await readAuthProfile(scenario.profileId);
|
||||
expect(profile?.key).toBe("");
|
||||
expect(profile?.key).not.toBe("undefined");
|
||||
}
|
||||
});
|
||||
|
||||
it("uses existing OPENROUTER_API_KEY when selecting openrouter-api-key", async () => {
|
||||
|
||||
Reference in New Issue
Block a user