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:
@@ -3,7 +3,6 @@ import { processScenarioSchema } from "../../domain/process/processScenario.js";
|
||||
import { AnalysisCapabilityUnavailableError } from "../../domain/analysisErrorCore.js";
|
||||
import {
|
||||
captureProcessScenario,
|
||||
normalizeCaptureFailure,
|
||||
ProcessCaptureError,
|
||||
} from "./ProcessHarness.js";
|
||||
import { settleProcessCaptureJournal } from "./ProcessCaptureLifecycle.js";
|
||||
@@ -16,14 +15,105 @@ import { EMPTY_PROCESS_CAPTURE_EXAMPLE } from "../../domain/process/processCaptu
|
||||
import { projectAnalysisError } from "../../domain/analysisErrorProjection.js";
|
||||
import { emptyProcessCapture } from "../../domain/process/processCapture.fixture.js";
|
||||
import { analysisErrorProjectionSchema } from "../../contracts/errorSchemas.js";
|
||||
import { processCaptureCancelled } from "./ProcessCaptureError.js";
|
||||
import {
|
||||
normalizeCaptureFailure,
|
||||
processCaptureCancelled,
|
||||
} from "./ProcessCaptureError.js";
|
||||
import {
|
||||
releaseProcessResources,
|
||||
prepareProcessCapture,
|
||||
resolveProcessResult,
|
||||
type ProcessCaptureCleanupHost,
|
||||
} from "./ProcessCaptureLifecycle.js";
|
||||
import { DarwinProcessOwnershipInspectionError } from "../DarwinProcessRunTokenReader.js";
|
||||
|
||||
it("retains cancellation and cleanup facts when ownership baseline inspection aborts", async () => {
|
||||
const controller = new AbortController();
|
||||
const scenario = processScenarioSchema.parse({
|
||||
executable: process.execPath,
|
||||
});
|
||||
await expect(
|
||||
prepareProcessCapture(
|
||||
scenario,
|
||||
controller.signal,
|
||||
async () => ({ files: [], truncated: false, completeRoots: [] }),
|
||||
{
|
||||
createTemporaryRoot: async () => "/fixture/allocated-root",
|
||||
captureOwnershipBaseline: async () => {
|
||||
controller.abort();
|
||||
controller.signal.throwIfAborted();
|
||||
return [];
|
||||
},
|
||||
cleanup: async () => undefined,
|
||||
},
|
||||
),
|
||||
).rejects.toMatchObject({
|
||||
reason: "cancelled",
|
||||
message: "process capture was cancelled",
|
||||
cleanupReport: {
|
||||
temporary_root: { state: "cleaned", reason: null },
|
||||
},
|
||||
partialObservation: {
|
||||
observations: {
|
||||
filesystem_snapshots: {
|
||||
before: {
|
||||
state: "available",
|
||||
value: { files: [], truncated: false },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps prelaunch snapshot evidence and the ownership failure when root cleanup throws", async () => {
|
||||
const ownershipFailure = new Error("process identity baseline denied");
|
||||
const scenario = processScenarioSchema.parse({
|
||||
executable: process.execPath,
|
||||
});
|
||||
try {
|
||||
await prepareProcessCapture(
|
||||
scenario,
|
||||
undefined,
|
||||
async () => ({ files: [], truncated: true, completeRoots: [] }),
|
||||
{
|
||||
createTemporaryRoot: async () => "/fixture/allocated-root",
|
||||
captureOwnershipBaseline: async () => {
|
||||
throw ownershipFailure;
|
||||
},
|
||||
cleanup: async () => {
|
||||
throw new Error("root removal denied");
|
||||
},
|
||||
},
|
||||
);
|
||||
throw new Error("expected preparation failure");
|
||||
} catch (cause: unknown) {
|
||||
if (!(cause instanceof ProcessCaptureError)) throw cause;
|
||||
expect(cause.cause).toBe(ownershipFailure);
|
||||
expect(
|
||||
analysisErrorProjectionSchema.parse(projectAnalysisError(cause)),
|
||||
).toMatchObject({
|
||||
code: "cleanup_incomplete",
|
||||
details: {
|
||||
execution_failure: ownershipFailure.message,
|
||||
cleanup_report: {
|
||||
temporary_root: { state: "failed", reason: "root removal denied" },
|
||||
},
|
||||
partial_observation: {
|
||||
observations: {
|
||||
filesystem_snapshots: {
|
||||
before: {
|
||||
state: "available",
|
||||
value: { files: [], truncated: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects legacy replay output instead of silently discarding it", () => {
|
||||
expect(
|
||||
processCaptureSchema.safeParse({
|
||||
@@ -100,6 +190,74 @@ it("keeps empty cleanup exception messages actionable in the report", async () =
|
||||
expect(report.temporary_root).toEqual({ state: "failed", reason: "Error" });
|
||||
});
|
||||
|
||||
it.each(["termination", "verification"] as const)(
|
||||
"retains observations and releases the temporary root when process %s throws",
|
||||
async (stage) => {
|
||||
const cleanupFailure = new Error(`${stage} inspection failed`);
|
||||
const removeTemporaryRoot = vi.fn(async () => undefined);
|
||||
const host: ProcessCaptureCleanupHost = {
|
||||
platform: "linux",
|
||||
cleanupProcessGroup: async () => {
|
||||
if (stage === "termination") throw cleanupFailure;
|
||||
return {
|
||||
cleaned: true,
|
||||
signaled: true,
|
||||
unverified: [{ pid: 900, diagnostic: "environment unavailable" }],
|
||||
};
|
||||
},
|
||||
verifyTokenOwnedProcesses: async () => {
|
||||
throw cleanupFailure;
|
||||
},
|
||||
removeTemporaryRoot,
|
||||
};
|
||||
const cleanup = await releaseProcessResources({
|
||||
timers: new Set(),
|
||||
terminal: { pid: 321 },
|
||||
renderer: undefined,
|
||||
runId: "fixture-run",
|
||||
temporaryRoot: "/fixture/root",
|
||||
host,
|
||||
});
|
||||
|
||||
expect(removeTemporaryRoot).toHaveBeenCalledWith("/fixture/root");
|
||||
expect(cleanup.temporary_root).toEqual({ state: "cleaned", reason: null });
|
||||
expect(cleanup.owned_process_group).toMatchObject({
|
||||
state: "failed",
|
||||
reason: cleanupFailure.message,
|
||||
});
|
||||
if (stage === "verification")
|
||||
expect(cleanup.owned_process_group.unverified_processes).toEqual([
|
||||
{ pid: 900, reason: "environment unavailable" },
|
||||
]);
|
||||
|
||||
const executionFailure = new Error("capture snapshot failed");
|
||||
const capture = parseProcessCapture({
|
||||
...emptyProcessCapture(),
|
||||
frames: [{ sequence: 0, at_ms: 0, data: "collected before failure" }],
|
||||
event_journal: [],
|
||||
});
|
||||
try {
|
||||
resolveProcessResult(capture, executionFailure, cleanup);
|
||||
throw new Error("expected cleanup failure");
|
||||
} catch (cause: unknown) {
|
||||
if (!(cause instanceof ProcessCaptureError)) throw cause;
|
||||
expect(cause.cause).toBe(executionFailure);
|
||||
expect(
|
||||
analysisErrorProjectionSchema.parse(projectAnalysisError(cause)),
|
||||
).toMatchObject({
|
||||
code: "cleanup_incomplete",
|
||||
details: {
|
||||
cleanup_report: cleanup,
|
||||
execution_failure: "capture snapshot failed",
|
||||
partial_observation: {
|
||||
capture: { frames: [{ data: "collected before failure" }] },
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("waits for token-owned processes to exit after one cleanup signal", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user