fix(login): normalize quoted/prefixed API key on the interactive prompt#26
Draft
dark-sorceror wants to merge 4 commits into
Draft
fix(login): normalize quoted/prefixed API key on the interactive prompt#26dark-sorceror wants to merge 4 commits into
dark-sorceror wants to merge 4 commits into
Conversation
0e3f5b1 to
562f124
Compare
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.
Summary
Fixes #25
The interactive
loginprompt was the only API-key input path that didn't normalize what the user typed. Every other source — the--api-keyflag,--env-file, process env, config, and an auto-discovered.env— already runs the value throughnormalizeApiKey(), which strips a pastedTRACEROOT_API_KEY=assignment prefix (optionallyexport-prefixed) and any surrounding quotes. The prompt only called.trim(), so pasting the dashboard's copy valueTRACEROOT_API_KEY="tr_..."— or simply a quote-wrapped key — was sent verbatim and failed authentication.This makes the prompt behave identically to every other entry point: the same
normalizeApiKey()is now the single normalizer all paths share.How it works
Key invariant: every input form collapses to the bare key, on every entry point.
tr_abc123tr_abc123"tr_abc123"/'tr_abc123'tr_abc123TRACEROOT_API_KEY="tr_abc123"tr_abc123export TRACEROOT_API_KEY="tr_abc123"tr_abc123What's changed
Shared config helper (TypeScript)
src/config/apiKey.ts(new) —normalizeApiKey()moved here verbatim and exported, so the resolution chain and the prompt share one implementation (no duplicated regex/quote-stripping).src/config/resolve.ts— importsnormalizeApiKeyfrom the new module; resolution behavior unchanged (pure move).Login command (TypeScript)
src/commands/login.ts— the interactive prompt runs its input throughnormalizeApiKey()instead of a bare.trim(). The already-resolved-key branch (resolved keys are normalized upstream) and the empty-keyMISSING_KEYguard are untouched.Tests
tests/config.apiKey.test.ts(new) — unit coverage for every form, including the fullTRACEROOT_API_KEY="..."copy line.tests/commands/login.test.ts— adds two interactive cases: the prompt returnsTRACEROOT_API_KEY="tr_..."and"tr_...", asserting the bare key is what gets validated and persisted.Out of scope (already correct, intentionally untouched): the flag/env/config/
.envnormalization paths, the separate quote-stripping insrc/config/envFile.ts, and any re-prompt-on-bad-input UX.Before / After
Test plan
normalizeApiKey()unit tests cover bare, double/single-quoted,TRACEROOT_API_KEY=,export …=, and the full copy lineTRACEROOT_API_KEY="tr_..."and"tr_..."both resolve to the bare key forcreateClient+writeConfignpm test) passes;npm run lintandnpm run typecheckcleantraceroot loginin a real TTY, paste the dashboardTRACEROOT_API_KEY="..."value → logs in, config stores the bare keySummary by cubic
Fixes the interactive
loginprompt to normalize pasted API keys (quoted or withTRACEROOT_API_KEY=) so auth succeeds like other input paths. ExtractsnormalizeApiKey()to a shared module and expands tests, including unquoted prefix and empty-after-normalize.Bug Fixes
normalizeApiKey(); handles"tr_...",'tr_...',TRACEROOT_API_KEY=..., andexport TRACEROOT_API_KEY=....Refactors
normalizeApiKey()tosrc/config/apiKey.tsand imported fromresolve.ts(no behavior change).TRACEROOT_API_KEY=..., single-quoted input, and empty-after-normalize.Written for commit 562f124. Summary will update on new commits.