Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion plugins/codex/scripts/lib/process.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ export function terminateProcessTree(pid, options = {}) {
if (platform === "win32") {
const result = runCommandImpl("taskkill", ["/PID", String(pid), "/T", "/F"], {
cwd: options.cwd,
env: options.env
env: options.env,
// runCommand prefers process.env.SHELL on Windows, so under Git Bash this
// ran as `bash -c "taskkill /PID ..."` and MSYS path conversion rewrote
// the /PID switch into C:/Program Files/Git/PID, failing every kill with
// "ERROR: Invalid argument/option". taskkill takes /-switches and an
// argument array, so it does not need a shell.
shell: false
});

if (!result.error && result.status === 0) {
Expand Down
9 changes: 6 additions & 3 deletions tests/process.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ test("terminateProcessTree uses taskkill on Windows", () => {
let captured = null;
const outcome = terminateProcessTree(1234, {
platform: "win32",
runCommandImpl(command, args) {
captured = { command, args };
runCommandImpl(command, args, options) {
captured = { command, args, shell: options?.shell };
return {
command,
args,
Expand All @@ -26,7 +26,10 @@ test("terminateProcessTree uses taskkill on Windows", () => {

assert.deepEqual(captured, {
command: "taskkill",
args: ["/PID", "1234", "/T", "/F"]
args: ["/PID", "1234", "/T", "/F"],
// Not through a shell: under Git Bash, MSYS path conversion turns the /PID
// switch into C:/Program Files/Git/PID and taskkill rejects it.
shell: false
});
assert.equal(outcome.delivered, true);
assert.equal(outcome.method, "taskkill");
Expand Down