Verify the API key when pasted during install (next-microsoft#27)#243
Merged
Conversation
The installer accepted whatever the user pasted and always printed "Sign in successful", even for a wrong or whitespace-padded key. - Trim the pasted key (a tester copied it with newlines/extra spaces). - Verify the key via POST /status (200 = valid, 401 = invalid), which checks only the API key and nothing else about the install. - Re-prompt in a loop until a valid key is entered (or empty to skip); show a clear "Invalid API key" message, and a distinct message when the API cannot be reached. - Only print "Sign in successful" when a verified key is configured. Applied to both install.sh and install.ps1.
Previously an already-configured CODEPLAIN_API_KEY that the user chose to keep was trusted without checking, so a stale/expired key still printed "Sign in successful". - Verify the existing key against /status when the user keeps it (and in non-interactive mode). - If invalid: interactive falls through to enter a new key; non-interactive warns and does not claim success. - If the API is unreachable, keep the existing key rather than locking the user out over a transient network issue. - Track verification with API_KEY_VERIFIED and gate the "Sign in successful" banner on it (instead of mere key presence). Applied to both install.sh and install.ps1.
After installing, run `codeplain --status` as a final end-to-end check that the tool launches, is on PATH, and can reach the API. Output is suppressed; the result is mapped to a simple pass/fail. On failure the installer stops with a generic "something went wrong" message instead of declaring success. To make this signal reliable, `codeplain --status` now exits non-zero on failure (missing key or a failed status fetch); previously it always exited 0. Human-visible output is unchanged. The check runs only when an API key is configured, so users who skip key setup are not falsely told something went wrong. Applied to both install.sh and install.ps1.
zanjonke
approved these changes
Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Fixes Codeplain-ai/next-microsoft#27.
The install scripts accepted whatever the user pasted as an API key and always printed "✓ Sign in successful" — even for a wrong key or one copied with surrounding whitespace/newlines (as happened during testing). Nothing ever confirmed the key worked, and the installer never actually ran the
codeplaintool to confirm the install succeeded. This PR trims and verifies the key before proceeding, and runs a final end-to-end check that the installed tool works.Changes
API key verification during install (
install/bash/install.sh,install/powershell/install.ps1)POST /statuswith{"api_key": "..."}— chosen over/connection_checkbecause it takes only the key and returns a clean 200 (valid) / 401 (invalid), checking only the API key and nothing else about the install.API_KEY_VERIFIED), not merely when a key is present.API base URL is overridable via
CODEPLAIN_API_URL(defaults tohttps://api.codeplain.ai), matching the existingCODEPLAIN_SCRIPTS_BASE_URLpattern.Final installation verification (
install/bash/install.sh,install/powershell/install.ps1)codeplain --statusas an end-to-end check that the tool launches, is on PATH, and can reach the API.~/.local/binontoPATHfirst so the freshly installed tool is findable; PowerShell already handlesPATHearlier.Client change (
plain2code.py)codeplain --statusnow exits non-zero on failure (missing key, or a failed status fetch); previously it always exited0. This is what lets the installer map the result to a reliable pass/fail. Human-visible output is unchanged.codeplain --statuswill now see a non-zero exit on error. This is correct CLI behavior, but it is a change.Testing
bash -n install/bash/install.shpasses./statusverification helpers tested against a mock server: valid→200 accepted, wrong→401 rejected, whitespace-padded key trimmed & accepted, offline→000 rejected.codeplain --statusexit codes verified against the real API: valid key →0, invalid key (401) →1, missing key →1,--version(offline) →0.pwshwas not available locally to run a syntax check.