Fix switch and oauth org precedence#273
Conversation
When switching projects without an explicit org, prefer the configured profile over the configured org for auth context. This prevents a stale config org from overriding an OAuth profile's stored org and causing project lookup to query the wrong workspace.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2ff46b156b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "Codex (@codex) review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".
| profile: Some("BT Staging".to_string()), | ||
| org: Some("braintrustdata.com".to_string()), |
There was a problem hiding this comment.
Replace real org/profile fixtures with synthetic names
The root AGENTS.md Privacy and Test Data section says not to add real organization or profile names/IDs to tests and to use synthetic placeholders instead. This regression test adds an internal-looking profile name and the real braintrustdata.com org, so the committed fixtures should be changed to placeholders like test-profile / test-org while preserving the stale-org scenario.
Useful? React with 👍 / 👎.
|
Latest downloadable build artifacts for this PR commit
Available artifact names
|
I don't have any env variable related to bt switch is still broken, the saved org isn't changed. Also the project lookup gives me the list of projects from the previous org (ced-test-1) not Braintrust SDKs. |
Cedric / ViaDézo1er (viadezo1er)
left a comment
There was a problem hiding this comment.
See comment above
Summary
Fixes
bt switchand OAuth auth resolution whenconfig.jsoncontains a staleorgthat disagrees with the selected OAuth profile’s storedorg_name.Problem
A config like this could cause
btto use the correct profile credentials but query the wrong org:{ "profile": "BT Staging", "org": "braintrustdata.com", "project": "Loop" }For OAuth profiles, the token is user-scoped, so the stale config org could override the selected profile’s org and cause commands like
bt switchto list projects from the wrong workspace.Repro
Given an OAuth auth profile like:
{ "profiles": { "BT Staging": { "auth_kind": "oauth", "api_url": "https://staging-api.braintrust.dev", "app_url": "https://www.braintrust.dev", "org_name": "BT Staging", "oauth_client_id": "bt_cli_default" } } }and a global config like:
{ "profile": "BT Staging", "org": "braintrustdata.com", "project": "Loop" }run:
Before this fix:
bt statusshowedprofile: BT Stagingbutorg: braintrustdata.combt switchused theBT Stagingprofile credentials but listed projects frombraintrustdata.comA second repro path was:
bt switch # Select org: BT StagingBefore this fix, the project picker could still show projects from the previously configured
braintrustdata.comorg instead of the selectedBT Stagingorg.Changes
For OAuth profiles, auth resolution now prefers:
--org/ env orgorg_nameorgPreserves existing API key profile behavior, where config org can still override profile org.
Updates
bt switchproject-only auth context to prefer the configured profile over a stale configured org.Adds regression tests for:
bt switchpreferring configured profile over stale orgValidation
Ran: