switch-broken#268
Draft
Cedric / ViaDézo1er (viadezo1er) wants to merge 1 commit into
Draft
Conversation
Contributor
|
Latest downloadable build artifacts for this PR commit
Available artifact names
|
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.
Slop description:
This is draft PR #268 ("switch-broken"). It fixes a class of bugs where bt switch --org and bt auth login could land on the wrong
org/deployment because of stale config-file org values and cross-deployment JWT mismatches. Changes across 5 files:
Core fix — src/auth.rs
Profile org now wins over stale config org. In resolve_auth, the precedence for org_name changed from base.org_name → cfg_org →
profile.org_name to base.org_name → profile.org_name → cfg_org. The config-file org (cfg_org) can be a leftover from a different profile,
so letting it override the selected profile's org caused a JWT/org-name mismatch and made bt switch --org switch to the wrong org. An
explicit --org flag still wins.
Re-login authenticates against the profile's deployment. run_login_oauth now resolves the OAuth exchange URL as --api-url → existing
profile's api_url → default(prod). So re-logging into a staging profile (e.g. bt auth login --profile "BT Staging") gets a staging-issued
JWT instead of a prod one. A JWT is only valid for the deployment that issued it.
Cross-deployment guard. After the user picks an org, if that org's api_url lives on a different deployment than the one that just issued
the JWT, it bails with an actionable error (Re-run with --api-url ) instead of silently failing or re-opening the browser. New
same_deployment() helper compares hosts (case-insensitive, ignores trailing slashes).
Refactored the OAuth flow into oauth_authorize_and_exchange, existing_profile_api_url, and same_deployment. Added tests for all three
behaviors.
Mirrored fix — src/status.rs
A selected profile's org_name now wins over a stale config org in bt status too, while preserving an explicit --org.
src/switch.rs
When writing config during bt switch, if the API client's org_name is empty, fall back to the active profile's stored org_name so the written
config reflects the profile's org.
src/traces.rs (bt view)
org/project resolution.
prints an info note on stderr (suppressed under --json/--quiet) so the cross-deployment override is visible instead of silent.
apply_url_hints_to_base now returns (BaseArgs, UrlHints); added maybe_surface_url_profile_override and url_hints_override_active. Tests
added.
src/ui/ratatui_table.rs
Minor cleanup: loop { let Some(..) else break } → while let Some(..).
In short: the PR makes the selected profile the authority for its org, ensures OAuth re-login targets the right deployment, detects/halts
cross-deployment org selection, and makes bt view decode trace URLs and announce when it's crossing profiles.