From 58859224330bbccf3e74e9a9e142919d3f52f756 Mon Sep 17 00:00:00 2001 From: Parman Mohammadalizadeh Date: Fri, 18 Sep 2026 21:28:37 +0200 Subject: [PATCH] fix(onboard): clarify that retry opens the credential prompt The options prompt told the user to re-enter the API key and then warned against entering it there. That warning applied to the options prompt, not to the masked credential prompt that retry opens, so the two lines read as a contradiction. State what retry, back, and exit each do, and name the secure prompt that retry opens. The options prompt stays masked so a pasted key is not echoed. Credential validation, storage, and non-interactive behavior do not change. Lower the onboard-selection test budget to the new line count, as the size ratchet requires for a changed test file. Signed-off-by: Parman Mohammadalizadeh --- ci/test-file-size-budget.json | 2 +- .../validation-recovery-prompt.test.ts | 39 +++++++++++++++++++ src/lib/onboard/validation-recovery-prompt.ts | 13 +++---- .../onboard-selection-anthropic-retry.test.ts | 3 +- test/onboarding/onboard-selection.test.ts | 6 +-- 5 files changed, 48 insertions(+), 15 deletions(-) diff --git a/ci/test-file-size-budget.json b/ci/test-file-size-budget.json index f62fad34cde..d4e62431b9e 100644 --- a/ci/test-file-size-budget.json +++ b/ci/test-file-size-budget.json @@ -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 } } diff --git a/src/lib/onboard/validation-recovery-prompt.test.ts b/src/lib/onboard/validation-recovery-prompt.test.ts index 85848033707..d42287c2a14 100644 --- a/src/lib/onboard/validation-recovery-prompt.test.ts +++ b/src/lib/onboard/validation-recovery-prompt.test.ts @@ -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"); + }); }); diff --git a/src/lib/onboard/validation-recovery-prompt.ts b/src/lib/onboard/validation-recovery-prompt.ts index 42353789c9c..681870d04d2 100644 --- a/src/lib/onboard/validation-recovery-prompt.ts +++ b/src/lib/onboard/validation-recovery-prompt.ts @@ -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(); diff --git a/test/onboarding/onboard-selection-anthropic-retry.test.ts b/test/onboarding/onboard-selection-anthropic-retry.test.ts index 3b60e44f1d4..80df09c9eae 100644 --- a/test/onboarding/onboard-selection-anthropic-retry.test.ts +++ b/test/onboarding/onboard-selection-anthropic-retry.test.ts @@ -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); diff --git a/test/onboarding/onboard-selection.test.ts b/test/onboarding/onboard-selection.test.ts index 1db5deb4e18..d46f5d69679 100644 --- a/test/onboarding/onboard-selection.test.ts +++ b/test/onboarding/onboard-selection.test.ts @@ -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);