🐛 Fix orgs/projects showing only one org due to project-scoped token#206
🐛 Fix orgs/projects showing only one org due to project-scoped token#206
Conversation
…er auth The `orgs` and `projects` commands used `loadConfig()` which picks up project-scoped tokens from `vizzly project link` mappings. These tokens are scoped to a single org, so the API only returned data for that org. Both commands now prefer the user auth token (from `vizzly login`) since listing orgs and projects are user-level operations. Falls back to config.apiKey when no user auth token exists. Also fixes CLAUDE.md incorrectly referencing vitest as the test runner — the CLI uses Node's built-in test runner (`node --test`).
This comment has been minimized.
This comment has been minimized.
Code ReviewThis PR fixes a real bug where StrengthsCorrect Problem Diagnosis:
Minimal, Focused Changes:
Good Documentation:
Issues & Recommendations1. Missing Token Expiration HandlingThe commands use export async function getAccessToken() {
const auth = await getAuthTokens();
return auth?.accessToken || null;
}This returns expired tokens without validation. Compare with Impact: Users might get cryptic API errors when their token is expired rather than helpful "Please run vizzly login" messages. Recommendation: Either:
2. Missing Test CoverageNeither
The test plan in the PR description shows manual testing, but automated tests would catch regressions. Recommendation: Add integration tests covering:
3. Token Priority Logic Could Be More ExplicitThe current code: let token = (await getAccessToken()) || config.apiKey;This works but requires understanding that
The fallback chain is spread across multiple files ( Recommendation (Optional): Consider a comment explaining the full fallback chain, e.g.: // Prefer user auth token for listing orgs/projects (project tokens are org-scoped)
// Falls back to config.apiKey which may contain: VIZZLY_TOKEN, --token flag, or project token
let token = (await getAccessToken()) || config.apiKey;4. Potential Edge Case: Both User Token and Project Token PresentWhen a user is logged in AND in a linked project directory:
This works correctly, but it changes behavior from before. Previously, the project token would be used. Now the user token is always preferred. Question: Could this cause issues if:
This seems unlikely to cause real problems (user tokens should have broader permissions), but worth considering. Code QualityPositive:
No Security Concerns:
Performance:
SummaryThis is a solid bug fix with clear motivation and correct implementation. The main areas for improvement are:
The code is ready to merge with the understanding that token expiration handling should be addressed in a follow-up (or as part of this PR). Recommendation: Approve with suggestion to add token expiration check and tests in follow-up PR. |
This comment has been minimized.
This comment has been minimized.
- getAccessToken() now validates token expiration before returning, preventing cryptic API errors from expired tokens - Refactor orgs/projects commands to accept deps for testability, matching the existing pattern used by builds command - Add 17 tests covering token priority, fallback behavior, JSON/human output, empty states, pagination, and org filtering
93e96fa to
f772e01
Compare
Vizzly - Visual Test ResultsCLI Reporter - 9 changes need review
Changes needing review (9)filter-failed-only · Firefox · 1920×1080 · 1.3% diff fullscreen-viewer · Firefox · 1920×1080 · 1.4% diff bulk-accept-dialog · Firefox · 1920×1080 · 0.2% diff viewer-slide-mode · Firefox · 1920×1080 · 0.5% diff viewer-overlay-mode · Firefox · 1920×1080 · 5.6% diff viewer-zoomed-100 · Firefox · 1920×1080 · 0.3% diff ...and 3 more in Vizzly. CLI TUI - 1 change needs review
|







Summary
vizzly orgsandvizzly projectsonly showed data from one org when run inside a linked project directory. The commands usedloadConfig()which picks up the project-scoped token (fromvizzly project link) before falling back to the user auth token. Project tokens are scoped to a single org, so the API only returned that org's data.vizzly login) since listing orgs/projects are user-level operations. Falls back toconfig.apiKeywhen no user auth token exists (e.g.,VIZZLY_TOKENor--token).node --test), not vitest. The vitest references were causing confusion across sessions.Test plan
vizzly loginand verify all orgs are shownvizzly orgsinside a linked project directory — should now show all orgs, not just onevizzly projectsinside a linked project directory — should now show projects across all orgsvizzly orgswithout being logged in but withVIZZLY_TOKENset — should still work via fallbacknpm testto verify all 1910 tests pass