You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(login): reuse stored token, skip browser when valid (#15)
* feat(login): reuse stored token, skip browser when valid
`praxis login` now reuses the active profile's stored credentials
instead of opening the browser on every invocation. Re-running login
(the documented way to refresh skills + MCP manifest) is now a
no-browser operation when the profile already holds a valid token.
Precedence in loginCmd.RunE:
- --token X → unchanged (verify, save, post-auth setup)
- --force → skip reuse, always open the browser
- else → reuse: if the active profile has a token AND the
resolved URL == the stored profile URL, verify via
/ai-api/auth/me. Valid → persist + post-auth setup,
no browser. Invalid/expired → graceful one-line
fallback to the browser flow.
Also:
- resolveLoginURL now errors for a NEW *named* profile without --url
(no URL to reuse, and guessing askpraxis.ai would be wrong). The
`default` profile keeps the built-in fallback for zero-config first
run.
- Extract the persist + post-auth tail of saveAndVerifyToken into a
shared persistAndSetup() helper used by both the verify-then-save
path and the reuse path (reuse needs an error return for graceful
fallback, not os.Exit).
- browserLoginFn / postAuthSetup package seams so RunE path selection
and persistence are unit-testable without a browser, network, or
real skill installs.
Switching profiles still resets org skills (wipe praxis-* + reinstall
the new profile's catalog); reuse only skips the browser/key-creation
step, the post-auth setup runs unchanged.
TDD: 13 tests added covering URL resolution, the reuse decision, and
RunE precedence. Full `go test -race ./...` green.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* test(login): table-driven reuse tests + assert error contents
Address CodeRabbit review on PR #15, aligning with the repo's testing
conventions (CLAUDE.md):
- Consolidate the four resolveLoginURL tests and the four
tryReuseStoredToken tests into table-driven tests.
- Assert error *contents* (substring "--url") rather than just
err == nil for the new-named-profile-without-URL cases, in both
resolveLoginURL and the RunE-level test.
RunE precedence tests stay as separate functions — each exercises a
distinct branch with its own seam stubbing and browser-called/error
assertions, so a shared table would obscure more than it consolidates.
No production code change; full go test -race ./... green.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
0 commit comments