Skip to content

switch-broken#268

Draft
Cedric / ViaDézo1er (viadezo1er) wants to merge 1 commit into
mainfrom
cedric/switch-broken
Draft

switch-broken#268
Cedric / ViaDézo1er (viadezo1er) wants to merge 1 commit into
mainfrom
cedric/switch-broken

Conversation

@viadezo1er

@viadezo1er Cedric / ViaDézo1er (viadezo1er) commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

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

  1. 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.

  2. 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.

  3. 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).

  4. 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)

  1. Percent-decode trace URL path segments. Url::path_segments returns encoded segments, so BT%20Staging is now decoded to BT Staging before
    org/project resolution.
  2. Surface URL-driven profile/org overrides. When a trace URL causes bt view to use a different profile/org than the active config, it now
    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.

@viadezo1er Cedric / ViaDézo1er (viadezo1er) changed the title draft switch-broken Jul 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Latest downloadable build artifacts for this PR commit fe34d7ea3e62:

Available artifact names
  • artifacts-build-global
  • artifacts-build-local-x86_64-apple-darwin
  • artifacts-build-local-x86_64-pc-windows-msvc
  • artifacts-build-local-aarch64-pc-windows-msvc
  • artifacts-build-local-x86_64-unknown-linux-musl
  • artifacts-build-local-x86_64-unknown-linux-gnu
  • artifacts-build-local-aarch64-apple-darwin
  • artifacts-build-local-aarch64-unknown-linux-gnu
  • artifacts-plan-dist-manifest
  • cargo-dist-cache

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant