Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(cli): keep --base-dir in the sudo command browser setup prints #23646

Mergedonly21mil(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/23646/headmerged by maria-rcks View on GitHub

Problem

On Linux, t3 browser setup without root checks T3's browser and prints a sudo command to finish the job. With --base-dir <dir>, it checks the browser under <dir>, but the command it prints drops the flag:

This needs root. Run:

  sudo t3 browser setup

The root run then looks for the browser in the default ~/.t3 instead. T3CODE_HOME has the same gap, because sudo resets the environment by default. If no browser is there, setup finds no missing libraries and skips installing them, so the browser under <dir> still fails to start.

Change

  • resolveRootCliCommand takes an optional argument list and passes it to resolveHostCliCommand, which already quotes arguments for the host's shell. The sudo env "PATH=$PATH" and absolute-launcher forms are unchanged.
  • browser setup resolves its home once, uses it for the browser check, and passes --base-dir <home> to the printed command when the user chose a home with --base-dir or T3CODE_HOME. Without either, the command is the same as before.

DatabaseStorage already passes --base-dir <home> to resolveHostCliCommand for its t3 doctor command, so this follows that pattern.

Scope and approval

No issue. This is a very small, focused fix of an obvious bug: the command setup tells the user to run checks a different directory from the one it just checked. It changes no package choices, privilege checks or setup steps. No open PR changes resolveRootCliCommand or cli/browser.ts.

Verification

New test in invocation.test.ts: resolveRootCliCommand keeps its arguments, quoted, for a user-installed Node (sudo env "PATH=$PATH" t3 ...) and for an absolute launcher, using a home with a space.

vp test run apps/server/src/cli/invocation.test.ts

It fails on main, where the arguments are dropped, and passes on this branch:

The new test failing on main and passing on this branch

I also ran the real CLI on Linux, built with vp pack from main and from this branch. Fonts were hidden in a mount namespace (bwrap --tmpfs /etc/fonts --tmpfs /usr/share/fonts), so setup had something to fix and printed its root command. Nothing ran as root. On main, all three runs print sudo t3 browser setup. On this branch, the --base-dir and T3CODE_HOME runs keep the home, and the run with neither prints the same command as before.

browser setup output on main and on this branch, with --base-dir, with T3CODE_HOME, and with neither

Other checks on this branch: tsc --noEmit in apps/server, vp lint and vp fmt --check on the changed files all pass.

Not checked:

  • Running the printed command as root. It would install packages, so I did not run it. Given --base-dir, setup uses that directory and skips its fallback to the sudo user's home.
  • The setup command shown by the server when its browser fails to start (ServerBrowser.ts, HtmlRender.ts). Those messages also call resolveRootCliCommand without a home. This PR leaves them alone.

Prior PRs

No earlier PR makes this change. adrilasar's #17570 added the font check and install to this command, and mxdhavgautam's #19846 added its warning for a root account. Both are merged; this builds on them and reuses no code from other PRs.

Production fix, tests, PR description and images written with Claude Opus 5.5 in T3 Code Nightly.

🤖 Generated with Claude Opus 5.5 in T3 Code Nightly

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Approvability

      Verdict: Approved at b208108

      Macroscope's review found this PR approvable — This focused CLI fix preserves the existing default command while carrying an explicitly selected base directory through sudo setup. The argument propagation is small, isolated, and covered by quoting tests for both launcher forms.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      📥 Commits

      Reviewing files that changed from the base of the PR and between f054d1b8018721bd997d99cbb918a7b17bf098a4 and b20810863221ed3fbd14d48a29639ede49c0c8a1.

      📒 Files selected for processing: 3
      • apps/server/src/cli/browser.ts
      • apps/server/src/cli/invocation.test.ts
      • apps/server/src/cli/invocation.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

      📝 Walkthrough

      The browser setup handler passes the resolved base directory to the root setup command when a base directory is specified or T3CODE_HOME is set. The root CLI resolver now forwards optional arguments, and tests verify argument preservation and quoting.

      Changes: Browser setup command

      Layer / File(s)Summary
      Forward base-directory arguments
      apps/server/src/cli/invocation.ts, apps/server/src/cli/browser.ts, apps/server/src/cli/invocation.test.ts
      The root CLI resolver accepts and forwards optional arguments. The browser setup handler adds --base-dir when a base directory is specified or T3CODE_HOME is set. Tests check argument preservation and quoting for both launcher types.

      Priority: ➖ Normal

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix

      Possibly related issues

      • Issue 22626 describes the Linux AppArmor browser setup flow and privileged setup command. This change preserves an explicitly selected --base-dir for that command.

      Suggested reviewers: mxdhavgautam, juliusmarminge

      Merge Risk: ⚪ Minimal · up to b2081

      The selected base directory is preserved in the privileged browser setup command, with no identified merge-blocking risk.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main fix: preserving --base-dir in the sudo command printed by browser setup.
      Description checkPassedThe description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the bug, implementation, focused scope, test results, manual checks, limitations, and …
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Description check

      Explanation

      The description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the bug, implementation, focused scope, test results, manual checks, limitations, and agent usage.

      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Comment `@coderabbitai help` to get the list of available commands.
    4. maria-rckscommented

      Note

      Written by gpt-6.1-sol on behalf of Maria

      Verified in a real dev environment

      verified unchanged head b20810863221ed3fbd14d48a29639ede49c0c8a1 on this Linux Boat VM. no code changes were needed.

      • reproduced on github/main (32ecd71726) in a separate worktree after vp i: an explicit home with spaces was dropped from the sudo command.
      • installed the exact PR head and ran vp run dev --home-dir '/home/user/browser verification' in the background. only one task dev server ran at a time.
      • used repo Playwright and /usr/bin/google-chrome to pair, create the real pr23646-browser-check git project, and send real Codex gpt-6.1-sol turns. the provider checked the project, opened example.com through T3's browser tools, returned Example Domain, and closed its background tab. checked the actual browser tool output in the client.
      • ran the setup comparison in the app's terminal. fonts were hidden only inside a read-only bwrap mount namespace to trigger the real setup path. no mocked commands, fixtures, or demo data.
      • --base-dir and T3CODE_HOME both preserve the resolved home. an explicit flag overrides a conflicting environment value, relative paths become absolute, and the command without either home selection remains unchanged.
      • ran the printed sudo command using a temporary t3 launcher pointing at this checkout's real src/bin.ts. it returned This host is ready for T3's browser. separately confirmed with strace that root executed the real browser installed under /home/user/browser verification/tools/chrome-headless-shell/..., rather than root's default home.
      • blacksmith: vp run check:changed passed format, lint, knip, GraphQL, affected typechecks, and all eight CLI tests. existing CI has 21 successful and seven skipped checks, with no failures.

      short command transcript (same home and font namespace):

      $ timeout 60 bwrap --ro-bind / / --tmpfs /etc/fonts --tmpfs /usr/share/fonts \
          node <checkout>/apps/server/src/bin.ts browser setup \
          --base-dir '/home/user/browser verification'
      
      main prints:
        sudo env "PATH=$PATH" t3 browser setup
      
      PR prints:
        sudo env "PATH=$PATH" t3 browser setup --base-dir '/home/user/browser verification'
      
      PR with T3CODE_HOME only prints the same explicit --base-dir.
      PR with neither setting prints the original command without --base-dir.

      main drops the directory; the PR preserves it in the running app terminal

      real Codex turn and browser tools in the web client

      main and PR setup commands exercised in the app terminal

      Not verified

      • installing genuinely absent system packages or changing AppArmor policy: this VM already has the browser's libraries, fonts, and sandbox support. the root directory selection and healthy-browser path were exercised; package installation was not.
      • native desktop, iOS/Android, macOS/Windows, and relay/tunnel connections were not exercised. this change is Linux CLI behavior; the web client and real Codex provider path were exercised.
      • distribution through a newly packaged npm or standalone executable was not exercised; runtime verification used the checked-out source entrypoint.
    5. maria-rcks merged thiscf93019

    6. maria-rcks closed this

Sign in to join this conversation.