Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(shell): escape backslashes in fish login-shell PATH capture commands #48171

Mergedsaphid(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/48171/headmerged by juliusmarminge View on GitHub

Problem

A literal trailing backslash in the inherited PATH breaks fish's login-shell capture command, so server startup falls back without loading the fish profile's environment. Embedded backslashes next to each other or a quote are also not preserved in the fallback printenv lookup argument.

Deterministic repro on origin/main (e0661db2c851d1c8c2f126d37c40dc3e665e5ec6)

From the repo root with dependencies and fish installed, run:

node --input-type=module -e 'import { buildEnvironmentCaptureCommand } from "./packages/shared/src/shell.ts"; process.env.PATH = "/usr/bin:/tmp/dir\\"; console.log(buildEnvironmentCaptureCommand("/usr/bin/fish", ["PATH"]));' | fish --no-config --no-execute

For the startup repro, use the same inherited PATH, set SHELL to real fish, and give it an isolated config.fish with set -gx PATH /usr/sbin $PATH and set -gx JAVA_HOME /opt/t3-fish-fixture-jdk. Run the transcript's Node probe from apps/server: it calls the same fixPath() used by layerMakeServer, which runs readEnvironmentFromLoginShell before applying the captured values to the server process.

  • Observed: fish reports unbalanced quotes. Falling back preserves the inherited PATH, but the server misses /usr/sbin from the fish profile and leaves JAVA_HOME unset.
  • Expected: fish parses the command, the server loads the profile values, and the inherited /tmp/dir\ entry keeps its trailing backslash.

Change

Escape backslashes and single quotes in fish's inherited PATH argument, leaving POSIX sh quoting unchanged. The shared builder covers both server startup and refresh probes and Electron's login-shell probe on Linux and macOS; no client or wire changes are needed.

Scope

Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.

Verification

  • Base: both fish assertions failed; the POSIX control passed. Patched: all three passed.
  • Linux fish and server startup before/after transcript: base missed both profile values; patched loaded both and preserved the literal backslash.
  • vp run check:changed exited 0 (format, lint, Knip, 37 package typechecks, and 92 affected tests passed with 4 skips).
  • Not shown: full server launch, live provider discovery, Electron runtime, and macOS runtime.

Authored by GPT-6.2 Sol (Codex); reviewed by Gemini 4 Neon (Antigravity).

    1. Pushed739c1bc

    2. Additional comments: 1

      packages/shared/src/shell.test.ts: 1

      195-195: Trivial · Maintainability & Code Quality · Quick win

      **Unverified finding** Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

      Exercise fallback argument preservation in the existing fish test.

      The command contains the special-character PATH, but the child receives path without those characters. The assertion also expects only path. This checks that fish can parse the command, not that fish delivers the escaped fallback argument intact.

      Extend this case with a controlled printenv fixture that requires the inherited fallback PATH. Assert that backslashes and the quote reach that lookup unchanged. Keep --no-config.

      As per coding guidelines, “Test behavior that can break” and “Extend before you add.”

      Source: Coding guidelines

      Review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 6255798969f17d50831d7e3ddf85ae8e29c3de32 and 739c1bcc62b7ded65e5653859a4e660b64c6af7d.

      Files selected for processing: 1

      • packages/shared/src/shell.test.ts

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

    3. Evidence

      Evidence\n\nSteps: set an inherited PATH ending in a literal backslash directory; configure fish login startup to prepend profilebin and export JAVA_HOME; run the generated environment-capture command with fish -ilc; compare exit status, stderr, PATH, and JAVA_HOME on both commits.\n\n| Before — base 4b8199987c | After — head 739c1bcc62 |\n|---|---|\n| Base capture: fish reports Unexpected end of string, quotes are not balanced, exits 127, and captures no environment. | Head capture: fish exits 0; captured PATH retains the literal trailing backslash and includes the fish profilebin prefix, and JAVA_HOME is /opt/fake-jdk-from-fish-profile. |\n\nDriver: driver-public.mts.

      Not shown:

      • The embedded backslash-plus-quote case was also run successfully on the base, consistent with the report; the decisive trailing-backslash failure and fixed behavior are captured above.
    4. juliusmarminge added labelstakeover:ready

    5. juliusmarminge removed labelstakeover:in-progress

    6. juliusmarminge merged this02fab0a

    7. juliusmarminge closed this

    8. juliusmarminge removed labelstakeover:ready

Sign in to join this conversation.