mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
fix(verifiers): share package command and workspace ownership
Join canonical owned command cleanup before releasing package verifier workspaces. Replace raw package command wrappers, the updater supervisor, WASM cleanup composite, and boolean-only retention with explicit capability ownership. Preserve selected environments, npm arguments, no-deadline calls, clean exit status, and distinct aggregate/per-stream output budgets. Exercise actual timeout descendants, cancellation, retained cleanup retry, and workspace admission.
This commit is contained in:
1 parent
de9a8898dc
commit
d9660eb032
47 files changed
+2551
-1061
No files matched your search
@@ -1,7 +1,10 @@
|
||||
import { EventEmitter } from "node:events";
|
||||
import { PassThrough } from "node:stream";
|
||||
import { expect, it, vi } from "vitest";
|
||||
import { ProviderProcessSupervisor } from "./ProviderProcess.js";
|
||||
import {
|
||||
ProviderProcessSupervisor,
|
||||
type ProcessDiagnosticBudget,
|
||||
} from "./ProviderProcess.js";
|
||||
import { redactCapturedTransportCredential } from "./ProviderDiagnosticRedaction.js";
|
||||
|
||||
it("retains final stderr between verified exit and output close during stop", async () => {
|
||||
@@ -332,6 +335,169 @@ it("scopes output checkpoints to raw bytes on one supervisor and epoch", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it.each<{ budget: ProcessDiagnosticBudget; stderr: string }>([
|
||||
{ budget: 4, stderr: "" },
|
||||
{ budget: { stdout: 4, stderr: 4 }, stderr: "wxyz" },
|
||||
])(
|
||||
"distinguishes aggregate and per-stream output budgets: $budget",
|
||||
({ budget, stderr }) => {
|
||||
const producer = Object.assign(new EventEmitter(), {
|
||||
stdout: new PassThrough(),
|
||||
stderr: new PassThrough(),
|
||||
exitCode: null,
|
||||
signalCode: null,
|
||||
kill: () => false,
|
||||
});
|
||||
const supervisor = new ProviderProcessSupervisor(
|
||||
{ process: producer, ownsProcessLifetime: false },
|
||||
{ maxDiagnosticBytes: budget },
|
||||
);
|
||||
try {
|
||||
const checkpoint = supervisor.checkpointOutput();
|
||||
producer.stdout.write("abcd");
|
||||
producer.stderr.write("wxyz");
|
||||
expect(supervisor.snapshot().stdout).toEqual({
|
||||
text: "abcd",
|
||||
bytes: 4,
|
||||
observedBytes: 4,
|
||||
});
|
||||
expect(supervisor.snapshot().stderr).toEqual({
|
||||
text: stderr,
|
||||
bytes: stderr.length,
|
||||
observedBytes: 4,
|
||||
});
|
||||
expect(supervisor.snapshot().diagnosticTruncated === true).toBe(
|
||||
stderr === "",
|
||||
);
|
||||
expect(supervisor.snapshotOutputSince(checkpoint).complete).toBe(
|
||||
stderr !== "",
|
||||
);
|
||||
} finally {
|
||||
supervisor.dispose();
|
||||
producer.stdout.destroy();
|
||||
producer.stderr.destroy();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["stdout", "stderr"] as const)(
|
||||
"drains and reports overflowing %s without consuming the other stream's budget",
|
||||
(stream) => {
|
||||
const producer = Object.assign(new EventEmitter(), {
|
||||
stdout: new PassThrough(),
|
||||
stderr: new PassThrough(),
|
||||
exitCode: null,
|
||||
signalCode: null,
|
||||
kill: () => false,
|
||||
});
|
||||
const events: unknown[] = [];
|
||||
const supervisor = new ProviderProcessSupervisor(
|
||||
{ process: producer, ownsProcessLifetime: false },
|
||||
{
|
||||
maxDiagnosticBytes: { stdout: 4, stderr: 4 },
|
||||
onDiagnostic: (event) => {
|
||||
if (event.type === "output") events.push(event);
|
||||
},
|
||||
},
|
||||
);
|
||||
const other = stream === "stdout" ? "stderr" : "stdout";
|
||||
try {
|
||||
producer[stream].write("abcde");
|
||||
producer[stream].write("fg");
|
||||
producer[other].write("wxyz");
|
||||
expect(supervisor.snapshot()).toMatchObject({
|
||||
diagnosticTruncated: true,
|
||||
[stream]: { text: "abcd", bytes: 4, observedBytes: 7 },
|
||||
[other]: { text: "wxyz", bytes: 4, observedBytes: 4 },
|
||||
});
|
||||
expect(events).toEqual([
|
||||
{ type: "output", stream, bytes: 5, totalBytes: 5, truncated: true },
|
||||
{ type: "output", stream, bytes: 2, totalBytes: 7, truncated: true },
|
||||
{ type: "output", stream: other, bytes: 4, totalBytes: 4 },
|
||||
]);
|
||||
} finally {
|
||||
supervisor.dispose();
|
||||
producer.stdout.destroy();
|
||||
producer.stderr.destroy();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("tightens aggregate retention without replacing or relaxing the original stream caps", () => {
|
||||
const producer = Object.assign(new EventEmitter(), {
|
||||
stdout: new PassThrough(),
|
||||
stderr: new PassThrough(),
|
||||
exitCode: null,
|
||||
signalCode: null,
|
||||
kill: () => false,
|
||||
});
|
||||
const supervisor = new ProviderProcessSupervisor(
|
||||
{ process: producer, ownsProcessLifetime: false },
|
||||
{ maxDiagnosticBytes: { stdout: 4, stderr: 10 } },
|
||||
);
|
||||
try {
|
||||
producer.stdout.write("abc");
|
||||
producer.stderr.write("de");
|
||||
supervisor.limitAdditionalOutputBytes(4);
|
||||
producer.stdout.write("fgh");
|
||||
producer.stderr.write("ijklmn");
|
||||
expect(supervisor.snapshot()).toMatchObject({
|
||||
diagnosticTruncated: true,
|
||||
stdout: { text: "abcf", bytes: 4, observedBytes: 6 },
|
||||
stderr: { text: "deijk", bytes: 5, observedBytes: 8 },
|
||||
});
|
||||
supervisor.limitAdditionalOutputBytes(100);
|
||||
producer.stderr.write("op");
|
||||
expect(supervisor.snapshot().stderr).toEqual({
|
||||
text: "deijk",
|
||||
bytes: 5,
|
||||
observedBytes: 10,
|
||||
});
|
||||
} finally {
|
||||
supervisor.dispose();
|
||||
producer.stdout.destroy();
|
||||
producer.stderr.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
it.each(["stdout", "stderr"] as const)(
|
||||
"retains raw UTF-8 and checkpoint facts while scanning %s markers past its stream cap",
|
||||
(stream) => {
|
||||
const producer = Object.assign(new EventEmitter(), {
|
||||
stdout: new PassThrough(),
|
||||
stderr: new PassThrough(),
|
||||
exitCode: null,
|
||||
signalCode: null,
|
||||
kill: () => false,
|
||||
});
|
||||
const supervisor = new ProviderProcessSupervisor(
|
||||
{ process: producer, ownsProcessLifetime: false },
|
||||
{ maxDiagnosticBytes: { stdout: 4, stderr: 4 }, outputToken: "DONE" },
|
||||
);
|
||||
try {
|
||||
const checkpoint = supervisor.checkpointOutput();
|
||||
const bytes = Buffer.from("é🧭 DONE\n");
|
||||
producer[stream].write(bytes.subarray(0, 3));
|
||||
producer[stream].write(bytes.subarray(3));
|
||||
const scoped = supervisor.snapshotOutputSince(checkpoint);
|
||||
expect(scoped.complete).toBe(false);
|
||||
expect(scoped.snapshot[stream]).toEqual({
|
||||
text: "é\ufffd",
|
||||
bytes: 4,
|
||||
observedBytes: 12,
|
||||
invalidUtf8: true,
|
||||
});
|
||||
expect(scoped.markers).toEqual([
|
||||
{ stream, offset: 7, line: "é🧭 DONE", truncated: false },
|
||||
]);
|
||||
} finally {
|
||||
supervisor.dispose();
|
||||
producer.stdout.destroy();
|
||||
producer.stderr.destroy();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["stdout", "stderr"] as const)(
|
||||
"redacts a budget-cut credential in scoped %s after prior output",
|
||||
(stream) => {
|
||||
|
||||
Reference in new issue
Block a user