Repository navigation
fix(auth): review follow-ups: scopes exit 4 on empty refresh token, --readonly poll refuses before polling, envelope docs - #55
Merged
Conversation
The JSON Error Envelope section said a failing command writes nothing to stdout. That is false for --fail-empty: exit 3 still prints the empty JSON payload on stdout, and TestExecute_JSONErrors_EmptyResults asserts it. The envelope itself never goes to stdout; say that instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…before polling `wk auth scopes` exited 1 when the stored record had an empty refresh token: InspectGrantedScopes returned its unexported missing-token error, which fell through to the generic OAuth wrapper. The command now checks the record itself and exits 4 (auth_required) with the re-authorize command, like a missing token. `auth poll --readonly --email <email>` polled the relay and asked Google for the account before the store-time merge check refused a stored token that records no scopes. It now runs the same pre-flight check as `auth add --readonly`, so the refusal (exit 2) comes before any poll or OAuth round trip. Without --email the address is known only after the poll, so that path still refuses at store time. Tests: - TestAuthScopes_EmptyRefreshTokenExitsAuth drives the real inspector over a record with a blank refresh token and expects exit 4. - TestAuthScopes_JSON_Source asserts `source` is token_endpoint on the refresh path and tokeninfo on the fallback path. - TestAuthPoll_Readonly_RefusesTokenWithoutRecordedScopesBeforePoll expects exit 2 with zero poll and userinfo calls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Follow-ups to the review of #50–#54.
1. docs/agent.md: JSON Error Envelope
The section said a failing command writes "nothing to stdout". That is false for
--fail-empty: exit 3 still prints the empty JSON payload on stdout, andTestExecute_JSONErrors_EmptyResultsasserts it. The corrected sentence says the envelope never goes to stdout, a command that fails before producing a result leaves stdout empty, and--fail-emptyprints its empty payload first.2.
wk auth scopes: empty refresh token exits 4A stored record with a blank refresh token reached
InspectGrantedScopes, which returned its unexported missing-token error (internal/googleauth/token_scopes.go:54-55).WrapOAuthErrorthen turned that into exit 1 (internal/cmd/auth_scopes.go). The command now checks the record itself and exits 4 (auth_required) withwk --client <c> auth add <email> --force-consent, like a missing or revoked token.New tests (
internal/cmd/auth_scopes_test.go):TestAuthScopes_EmptyRefreshTokenExitsAuthruns the real inspector over a record with a blank refresh token. It expects exit 4, the fix command in the message, andkind: auth_requiredin the stderr envelope. The real inspector rejects the token before any network call.TestAuthScopes_JSON_Sourcechecks that the JSONsourcefield istoken_endpointon the refresh path andtokeninfoon the fallback path.3.
auth poll --readonlyover a token with no recorded scopesUntil now only the secrets layer tested this. The command-level test found a real gap:
auth poll --readonly --email <e>polled the relay and called userinfo before the store-time merge check refused. The poll now runs the same pre-flightCheckReadOnlyMergeasauth add --readonly(shared helperrefuseReadOnlyMerge). It exits 2 before any poll or OAuth round trip. Without--emailthe address is only known after the poll, so that path still refuses at store time.docs/auth.mdsays so.New test:
TestAuthPoll_Readonly_RefusesTokenWithoutRecordedScopesBeforePoll(internal/cmd/auth_readonly_hygiene_test.go). It expects exit 2, the "records no scopes" message with the--clienthint, zero poll and zero userinfo calls, and the imported token left untouched.docs/auth.mdalso now namessourceand the exit-4 case for a record without a refresh token.Revert checks (each new test fails without its fix)
internal/cmd/auth_scopes.go→ origin/mainTestAuthScopes_EmptyRefreshTokenExitsAuthexit = 1, want 4 (err=missing token)internal/cmd/auth.go→ origin/mainTestAuthPoll_Readonly_RefusesTokenWithoutRecordedScopesBeforePollno poll or OAuth round trip may run before the refusal (poll=1 userinfo=1)"source"dropped from the JSON mapTestAuthScopes_JSON_Sourcesource = "", want "token_endpoint"/"tokeninfo")All HTTP stays in fakes. No Google call is made with real credentials.
Gate
make ciat c3c3968 (throwaway HOME,WK_*unset, own TMPDIR,GOFLAGS=-timeout=45mbecause the race stage passes 10 min on the loaded host): rc 0,deadcode baseline check: OK,coverage total: 70.6% (min 70.0%).🤖 Generated with Claude Code