fix(process)!: require current captures and preserve cleanup failures
Remove v3 capture conversion and require explicit executable identity and event journals. Preserve cancellation, execution diagnostics, snapshots, and cleanup outcomes from preparation through CLI delivery.
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
captureProcessScenarioFile,
|
||||
projectProcessCliError,
|
||||
} from "./ProcessCli.js";
|
||||
|
||||
const roots: string[] = [];
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
roots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
const fixture = async (): Promise<string> => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-process-cli-diagnostics-"));
|
||||
roots.push(root);
|
||||
return root;
|
||||
};
|
||||
|
||||
describe("process CLI input diagnostics", () => {
|
||||
it("preserves local diagnostics for unexpected process failures", () => {
|
||||
const projected = projectProcessCliError(
|
||||
new Error("SECRET internal failure /private/path"),
|
||||
);
|
||||
expect(projected).toEqual({
|
||||
error: "Process command failed",
|
||||
category: "execution_failure",
|
||||
message:
|
||||
"Process command could not complete: SECRET internal failure /private/path",
|
||||
});
|
||||
expect(JSON.stringify(projected)).not.toContain("stack");
|
||||
});
|
||||
|
||||
it("projects missing, malformed JSON, and invalid scenario files", async () => {
|
||||
const root = await fixture();
|
||||
const malformed = join(root, "malformed.json");
|
||||
const invalid = join(root, "invalid.json");
|
||||
const invalidUtf8 = join(root, "invalid-utf8.json");
|
||||
await writeFile(malformed, "not-json");
|
||||
await writeFile(invalid, "{}");
|
||||
await writeFile(
|
||||
invalidUtf8,
|
||||
Buffer.concat([
|
||||
Buffer.from('{"executable":"'),
|
||||
Buffer.from([0xff]),
|
||||
Buffer.from('"}'),
|
||||
]),
|
||||
);
|
||||
|
||||
expect(
|
||||
await captureProcessScenarioFile(join(root, "missing.json")),
|
||||
).toEqual({
|
||||
error: "Process command failed",
|
||||
category: "invalid_input",
|
||||
message: expect.stringContaining(
|
||||
`Process input file could not be read: ${join(root, "missing.json")} (ENOENT`,
|
||||
),
|
||||
});
|
||||
expect(await captureProcessScenarioFile(malformed)).toEqual({
|
||||
error: "Process command failed",
|
||||
category: "invalid_input",
|
||||
message: expect.stringContaining(
|
||||
`Process input file is not valid UTF-8 JSON: ${malformed}`,
|
||||
),
|
||||
});
|
||||
expect(await captureProcessScenarioFile(invalidUtf8)).toEqual({
|
||||
error: "Process command failed",
|
||||
category: "invalid_input",
|
||||
message: expect.stringContaining(
|
||||
`Process input file is not valid UTF-8 JSON: ${invalidUtf8}`,
|
||||
),
|
||||
});
|
||||
expect(await captureProcessScenarioFile(invalid)).toEqual({
|
||||
error: "Process command failed",
|
||||
code: "invalid_request",
|
||||
category: "invalid_input",
|
||||
message: "Analysis input is invalid. Check the arguments and try again.",
|
||||
retryable: true,
|
||||
remediation: { action: "Correct the listed arguments and retry." },
|
||||
details: expect.objectContaining({
|
||||
operation: "capture_process_scenario",
|
||||
issues: expect.arrayContaining([
|
||||
expect.objectContaining({ path: ["executable"] }),
|
||||
]),
|
||||
}),
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -175,10 +175,9 @@ const readJson = async (path: string): Promise<unknown> => {
|
||||
try {
|
||||
bytes = await readFile(path);
|
||||
} catch (cause: unknown) {
|
||||
void cause;
|
||||
throw new ProcessCliFailure(
|
||||
"invalid_input",
|
||||
"Process input file could not be read. Check that the path exists and is readable.",
|
||||
`Process input file could not be read: ${path} (${describeValidationFailure(cause)}). Check the reported filesystem constraint and retry.`,
|
||||
);
|
||||
}
|
||||
try {
|
||||
@@ -189,10 +188,9 @@ const readJson = async (path: string): Promise<unknown> => {
|
||||
const parsed: unknown = JSON.parse(text);
|
||||
return parsed;
|
||||
} catch (cause: unknown) {
|
||||
void cause;
|
||||
throw new ProcessCliFailure(
|
||||
"invalid_input",
|
||||
"Process input file is not valid JSON. Repair the file, then try again.",
|
||||
`Process input file is not valid UTF-8 JSON: ${path} (${describeValidationFailure(cause)}). Repair the file, then try again.`,
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -211,7 +209,7 @@ const cliAnalysisError = (error: AnalysisError): ProcessCliErrorOutput => ({
|
||||
...projectAnalysisError(error),
|
||||
});
|
||||
|
||||
/** Project any process CLI failure without exposing its cause. */
|
||||
/** Preserve typed failures and local diagnostics at the process CLI boundary. */
|
||||
export const projectProcessCliError = (
|
||||
cause: unknown,
|
||||
): ProcessCliErrorOutput => {
|
||||
@@ -225,7 +223,6 @@ export const projectProcessCliError = (
|
||||
return {
|
||||
error: "Process command failed",
|
||||
category: "execution_failure",
|
||||
message:
|
||||
"Process command could not complete. Check the input files and run `rea doctor`, then try again.",
|
||||
message: `Process command could not complete: ${describeValidationFailure(cause)}`,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user