fix(native): share command supervision and retain failure output
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { EventEmitter } from "node:events";
|
||||
import { PassThrough } from "node:stream";
|
||||
import { setTimeout as delay } from "node:timers/promises";
|
||||
import { beforeAll, expect, it } from "vitest";
|
||||
import { beforeAll, expect, it, vi } from "vitest";
|
||||
import {
|
||||
OwnedCommandFailure,
|
||||
runOwnedCommand,
|
||||
@@ -93,6 +95,60 @@ it("collects a real owned command and verifies its exit before returning diagnos
|
||||
});
|
||||
});
|
||||
|
||||
it("fails an accepted nonzero command when an output stream errors and cleans it up", async () => {
|
||||
const stdout = new PassThrough();
|
||||
const stderr = new PassThrough();
|
||||
class FakeProcess extends EventEmitter {
|
||||
readonly stdout = stdout;
|
||||
readonly stderr = stderr;
|
||||
exitCode: number | null = null;
|
||||
signalCode: NodeJS.Signals | null = null;
|
||||
readonly pid = 41234;
|
||||
kill(): boolean {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
const child = new FakeProcess();
|
||||
const cleanup = vi.fn(async () => ({
|
||||
cleaned: true as const,
|
||||
signaled: false,
|
||||
}));
|
||||
const request = command("unused fake launcher command");
|
||||
|
||||
const failure = runOwnedCommand(
|
||||
request,
|
||||
{ timeoutMs: 2_000, diagnosticBytes: 1024, acceptNonZeroExit: true },
|
||||
{
|
||||
launcher: async () => {
|
||||
setImmediate(() => {
|
||||
stdout.write("partial output");
|
||||
stdout.destroy(new Error("fixture read failure"));
|
||||
stderr.end();
|
||||
child.exitCode = 7;
|
||||
child.emit("exit", 7, null);
|
||||
child.emit("close", 7, null);
|
||||
});
|
||||
return {
|
||||
process: child,
|
||||
ownership: {
|
||||
runId: request.runId,
|
||||
leaderPid: child.pid,
|
||||
processGroupId: child.pid,
|
||||
},
|
||||
cleanup,
|
||||
};
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
await expect(failure).rejects.toMatchObject({
|
||||
reason: "process",
|
||||
message: "stdout stream failed: fixture read failure",
|
||||
snapshot: { stdout: { text: "partial output" }, exitCode: 7 },
|
||||
});
|
||||
expect(cleanup).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("cancels a real acquired process and independently releases it", async () => {
|
||||
const controller = new AbortController();
|
||||
let pid: number | undefined;
|
||||
|
||||
Reference in New Issue
Block a user