Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): forward Bitbucket credentials from the login shell #9022

ClosedMichaelCharles(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/9022/headopened View on GitHub

Fixes #5840.

Problem

On macOS and Linux the desktop app is started by the session manager, not a shell, so T3CODE_BITBUCKET_* exports in ~/.zshrc or ~/.profile never reach it. docs/user/source-control.md tells users to set those credentials exactly that way, and the server reads them straight from process env in apps/server/src/sourceControl/BitbucketApi.ts. The result is Bitbucket reporting as unauthenticated in the desktop app while the identical credentials work in a server started from a terminal.

The startup login-shell probe is not the problem. It runs, and the credentials are in scope for it. readLoginShellEnvironment issues one printenv per name in LOGIN_SHELL_ENV_NAMES, and that list covers PATH, locale, XDG, Homebrew and SSH_AUTH_SOCK only, so the values were never asked for. extractEnvironment filters by the same list, so nothing downstream could recover them either.

Reproduced on 0.0.37, macOS 26.6.2, Apple Silicon, with credentials exported from ~/.zshrc:

$ ps eww $(python3 -c "import json;print(json.load(open(/Users/michael/.t3/userdata/server-runtime.json))[pid])") \
    | tr " " "\n" | grep -c "^T3CODE_BITBUCKET_API_TOKEN="
0

Fix

Add the three credential names the server reads to the probe list, and hydrate them in installPosixEnvironment.

They are hydrated as a single precedence group rather than per name, following the locale group already in that function. An access token outranks an email plus API token, so filling in a shell-probed pair alongside an inherited access token would produce a set that authenticates with the inherited token while the probed values go silently unused. Taking the whole set from one source keeps that from happening, and anything already in the process env still wins.

This is the POSIX path only. Windows GUI processes inherit User-level variables set through SetEnvironmentVariable, so there is no gap there, and the wsl.exe boundary is handled separately by #7620, whose forwarded set this matches.

Tests

Two cases alongside the existing probe tests in DesktopShellEnvironment.test.ts: hydration of the credentials from the login shell, and the group rule holding when the process already carries an access token. The first fails on main. The second is a regression guard against a later switch to per-name hydration; it passes before the fix, since nothing is hydrated at all then.

apps/desktop tests (16/16) and typecheck are clean, as are lint and format on the touched files.


Written by Claude Opus 5 in Claude Code, reviewed by me before submitting.


Note

Medium Risk Touches authentication-related environment forwarding on desktop startup; behavior is constrained by all-or-nothing hydration and existing process env winning, with regression tests for mixed credential sets.

Overview Fixes Bitbucket showing unauthenticated in the GUI when credentials are only exported in the user’s shell profile (~/.zshrc, etc.), which session-launched desktop apps do not inherit.

The desktop login-shell probe now requests T3CODE_BITBUCKET_ACCESS_TOKEN, T3CODE_BITBUCKET_EMAIL, and T3CODE_BITBUCKET_API_TOKEN (same names the server reads from process.env). On POSIX, those values are copied into the process only when none of the three are already set, so an inherited access token is not combined with shell-probed email/API token pairs that would be ignored by precedence rules.

Tests cover full hydration from the shell and the “no mixing” case when an access token is already present.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 9ec7039d2865ffc5fb7bef67ff9fbd11765d96b2. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Forward T3CODE_BITBUCKET_* credentials from login shell in installPosixEnvironment

  • Adds BITBUCKET_CREDENTIAL_ENV_NAMES constant and includes it in LOGIN_SHELL_ENV_NAMES so the login shell probe reads T3CODE_BITBUCKET_ACCESS_TOKEN, T3CODE_BITBUCKET_EMAIL, and T3CODE_BITBUCKET_API_TOKEN
  • On POSIX, installPosixEnvironment copies these variables from the login shell snapshot into config.env only when none are already set in the process environment; if any one is already present, all shell values are skipped to avoid mixing an inherited token with shell-provided email/API token
  • Behavioral Change: a process that sets only T3CODE_BITBUCKET_ACCESS_TOKEN will no longer receive T3CODE_BITBUCKET_EMAIL or T3CODE_BITBUCKET_API_TOKEN from the login shell
Macroscope summarized 9ec7039.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This change changes desktop authentication behavior by importing Bitbucket credentials from login-shell profiles into the server process on POSIX platforms. Because it handles sensitive authentication credentials and changes their process visibility, human review is warranted despite the focused scope and regression tests.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Superseded by #14103 — Bitbucket credentials can now be saved from Settings → Source Control, so login-shell env forwarding for T3CODE_BITBUCKET_* is no longer needed for #5840.

    4. juliusmarminge closed this

Sign in to join this conversation.