Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/test-file-size-budget.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"test/installer-integration/install-preflight.test.ts": 2995,
"test/agents/openclaw/runtime/nemoclaw-start.test.ts": 4337,
"test/onboarding/onboard-messaging.test.ts": 1960,
"test/onboarding/onboard-selection.test.ts": 4126
"test/onboarding/onboard-selection.test.ts": 4124
}
}
39 changes: 39 additions & 0 deletions src/lib/onboard/validation-recovery-prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,43 @@ describe("validation recovery credential prompt", () => {
expect(prompt).toHaveBeenCalledTimes(2);
expect(process.env.OPENAI_API_KEY).toBe("sk-existing");
});

it("tells the user that retry opens the credential prompt when authorization fails (#12079)", async () => {
vi.stubEnv("OPENAI_API_KEY", "sk-bad");
const log = vi.spyOn(console, "log").mockImplementation(() => undefined);
const { helpers, prompt } = createRecoveryPrompt(["retry", "selection"]);

await expect(
helpers.promptValidationRecovery("OpenAI", CREDENTIAL_RECOVERY, "OPENAI_API_KEY"),
).resolves.toBe("credential");

const messages = log.mock.calls.map(([message]) => message);
expect(messages).toContain(" OpenAI authorization failed.");
expect(messages).toContain(
" Choose retry to enter the API key securely, back to change the provider or model, or exit to stop onboarding.",
);
// The options prompt must not request a key and forbid entering one at once (#12079).
expect(messages).not.toContainEqual(expect.stringMatching(/paste/iu));
expect(prompt).toHaveBeenCalledWith(" Options: retry, back, exit [retry]: ", {
secret: true,
});
expectCredentialPromptWasSecret(prompt);
});

it("masks the options prompt so a pasted API key is not echoed (#12079)", async () => {
vi.stubEnv("OPENAI_API_KEY", "sk-bad");
const log = vi.spyOn(console, "log").mockImplementation(() => undefined);
const { helpers, prompt } = createRecoveryPrompt(["sk-pasted-at-the-options-prompt", "back"]);

await expect(
helpers.promptValidationRecovery("OpenAI", CREDENTIAL_RECOVERY, "OPENAI_API_KEY"),
).resolves.toBe("selection");

expect(prompt).toHaveBeenCalledWith(" Options: retry, back, exit [retry]: ", {
secret: true,
});
const messages = log.mock.calls.map(([message]) => message);
expect(messages).not.toContainEqual(expect.stringContaining("sk-pasted-at-the-options-prompt"));
expect(process.env.OPENAI_API_KEY).toBe("sk-bad");
});
});
13 changes: 5 additions & 8 deletions src/lib/onboard/validation-recovery-prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,14 @@ export function createValidationRecoveryPromptHelpers(
}

if (recovery.kind === "credential" && credentialEnv) {
console.log(` ${label} authorization failed.`);
console.log(
` ${label} authorization failed. Re-enter the API key or choose a different provider/model.`,
" Choose retry to enter the API key securely, back to change the provider or model, or exit to stop onboarding.",
);
console.log(" ⚠️ Do NOT paste your API key here — use the options below:");
const choice = (
await deps.prompt(
" Options: retry (re-enter key), back (change provider), exit [retry]: ",
{
secret: true,
},
)
await deps.prompt(" Options: retry, back, exit [retry]: ", {
secret: true,
})
)
.trim()
.toLowerCase();
Expand Down
3 changes: 1 addition & 2 deletions test/onboarding/onboard-selection-anthropic-retry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { describe, it } from "vitest";

import { testTimeout } from "../helpers/timeouts";

const CREDENTIAL_RETRY_PROMPT_RE =
/Options: retry \(re-enter key\), back \(change provider\), exit \[retry\]: /;
const CREDENTIAL_RETRY_PROMPT_RE = /Options: retry, back, exit \[retry\]: /;

const PROVIDER_SELECTION_TEST_TIMEOUT_MS = testTimeout(60_000);

Expand Down
6 changes: 2 additions & 4 deletions test/onboarding/onboard-selection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ import {
runOllamaPullScenario,
} from "../support/onboard-selection-test-helpers.js";

const CREDENTIAL_RETRY_PROMPT =
" Options: retry (re-enter key), back (change provider), exit [retry]: ";
const CREDENTIAL_RETRY_PROMPT_RE =
/Options: retry \(re-enter key\), back \(change provider\), exit \[retry\]: /;
const CREDENTIAL_RETRY_PROMPT = " Options: retry, back, exit [retry]: ";
const CREDENTIAL_RETRY_PROMPT_RE = /Options: retry, back, exit \[retry\]: /;
const OLLAMA_CHAT_COMPLETIONS_TOOL_CALL_RESPONSE =
'{"choices":[{"message":{"role":"assistant","content":"","tool_calls":[{"type":"function","function":{"name":"emit_ok","arguments":"{\\"ok\\":true}"}}]}}]}';
const PROVIDER_SELECTION_TEST_TIMEOUT_MS = testTimeout(60_000);
Expand Down
Loading