fix(whoami): report the active project from config, not the key-bound team - #319
Merged
Conversation
… team /cli-auth/validate intentionally omits the X-Team-ID header (stale project_id must not 401 a valid key), so it always resolves the project from the API key's bound team. After 'hookdeck project use', whoami therefore kept reporting the previous project/org even though every other command targeted the new one. whoami now resolves the display values from the profile's active project_id via the project list when it differs from the key-bound team, falling back to the validate response (with a warning) when the lookup fails or the project no longer exists. Fixes #318 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tt8HTLV1iCoQyxH9vozKra
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes hookdeck whoami showing a stale project/organization after hookdeck project use by continuing to trust /cli-auth/validate for user identity while resolving the displayed project/org/mode from the active project_id in config when it differs from the key-bound project.
Changes:
- Add
resolveActiveProjectto prefer the config’s activeproject_idby looking it up viaListProjects()(which uses the header-stripping client) and parsing the[Org] Projectformat viaproject.ParseProjectName. - Update
whoamioutput to use the resolved project/org and to prefer the resolved project mode when deriving “Project type”. - Add unit tests covering “no active project”, “active == key-bound (no list call)”, “resolved from list”, parse fallback, list error fallback with warning, and missing/deleted project fallback with warning.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/cmd/whoami.go | Resolve displayed project/org/mode from the active project_id (when it differs) and print explicit warnings on fallback. |
| pkg/cmd/whoami_test.go | Add focused unit tests for resolveActiveProject behavior and fallback paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Fixes #318
Problem
After switching projects with
hookdeck project use,hookdeck whoamistill reported the previously active project and organization, even though every other command correctly targeted the newly selected project.Root cause:
whoamidisplays whateverGET /cli-auth/validatereturns, andValidateAPIKey()deliberately strips theX-Team-ID/X-Project-IDheaders (viaclientForCLIAuthValidate()) so a staleproject_idcan't 401 a valid key. As a result the server always resolves the project from the API key's bound team, ignoring the config's activeproject_id.Fix
whoamikeeps using the validate response for the user identity, but now resolves the project/org/mode display values from the profile's activeproject_idwhen it differs from the key-bound team:ListProjects()client call and parses org/name withproject.ParseProjectName(same pathproject use/project listuse).project_idor it matches the key-bound project.hookdeck project usehint for the stale-project case) instead of silently reporting the wrong project.The intentional header-stripping in
clientForCLIAuthValidate()is untouched.Testing
TestResolveActiveProjectunit tests cover: no active project, active == key-bound (asserts no extra list call), active resolved from the list, unparsable project name fallback, list-error fallback with warning, and deleted/missing project fallback with warning.go build ./...andgo test ./...pass locally (one pre-existing, unrelated failure inpkg/listen/healthcheckthat requires binding port 443, which this sandbox disallows).🤖 Generated with Claude Code
https://claude.ai/code/session_01Tt8HTLV1iCoQyxH9vozKra
Generated by Claude Code