Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(shared): capture shell values after profiles replace PATH #35617

MergedLucenx9(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/35617/headmerged by juliusmarminge View on GitHub

Showing 2 changed files with 37 additions and 7 deletions.

x
0 of 2 viewed, 2 left
15 additions and 4 deletionspackages/shared/src/shell.test.tsModified
View file
@@ -119,16 +119,26 @@
​
it.runIf(NodeFS.existsSync("/bin/bash"))(
- "ignores probe markers a bash DEBUG trap echoes into the terminal title",
+ "captures values when the profile replaces PATH and a DEBUG trap echoes commands",
() => {
const home = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-bash-env-"));
try {
- const shellPath = `${NodePath.join(home, "bin")}:/usr/bin:/bin`;
+ const tools = NodePath.join(home, "tools 'quoted $dir");
+ NodeFS.mkdirSync(tools);
+ const printenv = NodeChildProcess.execFileSync("/bin/bash", ["-c", "type -P printenv"], {
+ encoding: "utf8",
+ env: { PATH: process.env.PATH },
+ }).trim();
+ NodeFS.copyFileSync(printenv, NodePath.join(tools, "printenv"));
+ vi.stubEnv("PATH", tools);
+ const shellPath = NodePath.join(home, "bin");
const bashEnv = NodePath.join(home, "env.bash");
NodeFS.writeFileSync(
bashEnv,
- `export PATH=${JSON.stringify(shellPath)}`,
+ `export PATH='${shellPath.replaceAll("'", "'\\''")}'`,
+ // Simulate a non-FHS host while retaining the real executable in its private prefix.
+ "function /usr/bin/printenv { return 127; }",
`trap 'echo -ne "\\033]0;\${BASH_COMMAND}\\007"' DEBUG`,
].join("\n"),