fix(shell): escape backslashes in fish login-shell PATH capture commands #48171
main fromrefs/pull/48171/head·merged by juliusmarminge View on GitHubProblem#
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/sbinfrom the fish profile and leavesJAVA_HOMEunset. - 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:changedexited 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
- 2
Pushed739c1bc
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
pathwithout those characters. The assertion also expects onlypath. This checks that fish can parse the command, not that fish delivers the escaped fallback argument intact.Extend this case with a controlled
printenvfixture 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-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: 4b81999
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
67be7406-cda2-4113-a4b3-ff0b911a5fd3
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.
-
-
Evidence#
Evidence\n\nSteps: set an inherited PATH ending in a literal backslash directory; configure fish login startup to prepend
profilebinand exportJAVA_HOME; run the generated environment-capture command withfish -ilc; compare exit status, stderr, PATH, and JAVA_HOME on both commits.\n\n| Before — base4b8199987c| After — head739c1bcc62|\n|---|---|\n| Base capture: fish reportsUnexpected 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 fishprofilebinprefix, andJAVA_HOMEis/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.
juliusmarminge added labelstakeover:ready
juliusmarminge removed labelstakeover:in-progress
juliusmarminge merged this02fab0a
juliusmarminge closed this
juliusmarminge removed labelstakeover:ready
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes