Stop promising an order between a command's two pipes

stdout and stderr are separate pipes read as they arrive, so a line from
one can land before a line the other already had. The test asked for
stdout first every time and lost that race on CI; it now checks one
stream's order and that stderr comes back beside stdout.
This commit is contained in:
2026-11-19 17:08:47 +01:00
parent 09039bee22
commit 984ad702d6
2 changed files with 15 additions and 2 deletions
+12 -1
View File
@@ -10,13 +10,24 @@ const base = {
describe("runCommand", () => {
test("returns output in order and the exit code", async () => {
const result = await runCommand({ ...base, command: "echo one; echo two >&2; exit 3" });
const result = await runCommand({ ...base, command: "echo one; echo two; exit 3" });
expect(result.output).toBe("one\ntwo\n");
expect(result.exit_code).toBe(3);
expect(result.timed_out).toBe(false);
});
/**
* stdout and stderr are two pipes read as they arrive, so which of
* them a line from each lands first is the scheduler's call: both come
* back, each in its own order.
*/
test("brings stderr back together with stdout", async () => {
const result = await runCommand({ ...base, command: "echo out; echo err >&2" });
expect(result.output.split("\n").filter(Boolean).sort()).toEqual(["err", "out"]);
});
test("reads no input", async () => {
const result = await runCommand({ ...base, command: "read -r line; echo \"got:$line:$?\"" });
+3 -1
View File
@@ -34,7 +34,9 @@ export type CommandResult = {
/**
* Runs one command in its own `bash -c`, in its own process group, with
* no input (a prompt fails at once instead of waiting). stdout and stderr
* come back together, in order, cut at `max_output_bytes`. Past its
* come back together, each in its own order (they are two pipes, read as
* they arrive, so neither is held back for the other), cut at
* `max_output_bytes`. Past its
* timeout (when it has one), or when aborted, the whole group gets TERM,
* then KILL 5s later. It resolves when bash exits, not when every pipe
* closes, so work left in the background (`nohup ... &`) keeps running