fix(coding-agent): preserve pi.exec spawn errors

Fixes #11085
This commit is contained in:
muyiyr 2026-10-22 16:15:33 +08:00 • committed by Petr Houška
parent 1c720d2850
commit c60de42e98
2 changed files with 24 additions and 2 deletions

View file

@ -96,12 +96,12 @@ export async function execCommand(
}
resolve({ stdout, stderr, code: code ?? 0, killed });
})
.catch((_err) => {
.catch((error: Error) => {
if (timeoutId) clearTimeout(timeoutId);
if (options?.signal) {
options.signal.removeEventListener("abort", killProcess);
}
resolve({ stdout, stderr, code: 1, killed });
resolve({ stdout, stderr: stderr || error.message, code: 1, killed });
});
});
}

View file

@ -0,0 +1,22 @@
import { describe, expect, it } from "vitest";
import { execCommand } from "../src/core/exec.ts";
describe("execCommand", () => {
// Regression test for https://github.com/earendil-works/pi/issues/11085
it("reports spawn errors in stderr", async () => {
const result = await execCommand("pi-command-that-does-not-exist-11085", [], process.cwd());
expect(result).toMatchObject({
code: 1,
killed: false,
stdout: "",
});
expect(result.stderr).toMatch(/ENOENT/);
});
it("keeps stderr empty when a command exits silently", async () => {
const result = await execCommand(process.execPath, ["-e", "process.exit(1)"], process.cwd());
expect(result).toEqual({ stdout: "", stderr: "", code: 1, killed: false });
});
});