fix(bash): preserve configured shell behavior

This commit is contained in:
jb
2026-09-04 17:11:46 -04:00
parent 3cf354b74b
commit e1c5c55c15
4 changed files with 85 additions and 20 deletions
+52 -4
View File
@@ -1,6 +1,13 @@
import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import { access, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
import {
access,
chmod,
mkdir,
mkdtemp,
rm,
writeFile,
} from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
@@ -29,7 +36,7 @@ async function executeIn(
cwd?: string,
) {
const params = cwd === undefined ? { command } : { command, cwd };
return createContextualBashTool().execute(
return createContextualBashTool({}).execute(
"bash-cwd-test",
params,
undefined,
@@ -91,14 +98,55 @@ test("bash honors hidden-worktree and nested-package cwd arguments", async (t) =
await assert.rejects(access(sentinel));
});
test("bash preserves configured command prefixes and shell paths", async (t) => {
const directory = await mkdtemp(join(tmpdir(), "pi-bash-cwd-options-"));
t.after(() => rm(directory, { recursive: true, force: true }));
const shellMarker = join(directory, "custom-shell-used");
const shell = join(directory, "custom-shell");
await writeFile(
shell,
`#!/bin/sh\nprintf used > "${shellMarker}"\nexec /bin/bash "$@"\n`,
);
await chmod(shell, 0o755);
await mkdir(join(directory, ".pi"));
await writeFile(
join(directory, ".pi", "settings.json"),
JSON.stringify({
shellCommandPrefix: "printf prefix-",
shellPath: shell,
}),
);
const tool = createContextualBashTool();
const result = await tool.execute(
"bash-cwd-options-test",
{ command: "printf command", cwd: directory },
undefined,
undefined,
{
cwd: directory,
sessionManager: {
getSessionId: () => "bash-cwd-test-session",
getSessionFile: () => undefined,
},
isProjectTrusted: () => true,
} as ExtensionContext,
);
assert.equal(getOutput(result), "prefix-command");
await access(shellMarker);
});
test("bash exposes cwd without changing existing arguments", () => {
const schema = createContextualBashTool().parameters;
const schema = createContextualBashTool({}).parameters;
assert.deepEqual(Object.keys(schema.properties), ["command", "cwd", "timeout"]);
assert.deepEqual(schema.required, ["command"]);
});
test("bash fails before execution when Pi omits the tool context", async () => {
const tool = createContextualBashTool();
const tool = createContextualBashTool({});
await assert.rejects(
tool.execute(
"bash-cwd-test",