mirror of
https://github.com/morluto/rea.git
synced 2026-12-01 02:49:12 +00:00
* fix(process): preserve producer-owned inspection cancellation Prototype the explicit inspection origin and retained file/batch owner protocol. Downstream adapter migration and lease binding remain required before integration. * fix(process): type inspection ownership handoffs precisely * fix(process): retain plain inspection preparation cancellation * fix(process): retain explicit inspection cleanup and cancellation facts * fix(process): require explicit inspection facts and cleanup scope * refactor(process): remove redundant cleanup forwarding wrapper * fix(firmware): retain inspection cancellation and cleanup ownership * fix(wakaru): retain typed inspection outcomes and caller scope * fix(ghidra): preserve inspection facts and launch cleanup scope * fix(providers): preserve typed process inspection outcomes * refactor(process): remove obsolete inspection cancellation re-export * fix(native): preserve inspection preparation cleanup and cancellation * fix(registration): retain typed inspection cleanup during Git discovery * fix(process): preserve inspection deadline origin in adapter handoff * fix(process): consume the canonical inspection selector in binding * fix(native): preserve inspection deadlines and cleanup retry completion * test(process): narrow the retained Darwin preparation owner * fix(providers): preserve preparation ownership and timeout policy Narrow preparation facts through their canonical owner, preserve actual cleanup capabilities and recorded cancellation, and keep enclosing command deadlines authoritative. Retain raw inspection records through Java refusal and configuration projections without changing availability fallback policy. * refactor(process): use one inspection failure type owner * fix(providers): retain recorded secondary failures when rebinding * fix(ghidra): preserve normalized inspection facts through public projection * fix(process): normalize native process listing cancellation * docs(development): clarify failure provenance and cleanup verification * fix(process): preserve direct inspection cancellation facts * fix(process): retain inspection owners through termination * fix(process): preserve command inspection cleanup provenance * fix(desktop): preserve inspection facts after cleanup retry * refactor(process)!: migrate desktop capture with inspection producers * fix(desktop)!: preserve capture failure origins and cleanup owners (#10115) * fix(desktop): preserve capture failure origins and cleanup * fix(desktop): type keyring cleanup cancellation * fix(kuna)!: retain copy cleanup before retiring workspaces (#10114) * fix(kuna): own copy cancellation and descriptor cleanup * fix(kuna): close copy descriptors before workspace removal * test(kuna): type copy lifecycle gates for project library * docs(kuna): explain retained copy-file cleanup and staging ownership * docs(kuna): separate cache publication, integrity and cleanup guidance * fix(desktop): retain sampling inspection owners before release * fix(process): preserve capture file read cancellation origin * fix(process): retain capture inspection cancellation and cleanup owners * fix(process): retain sampling inspection failures in capture scope * fix(process): retain inspection failures through mandatory cleanup * fix(process): distinguish sampler shutdown from capture cancellation * fix(browser): retain startup EOF before later cancellation * fix(process): bind capture inspection cleanup to the owning run * test(process): migrate cancellation fixtures to typed owners Record explicit preparation and command cancellation facts, retain exact opaque reasons and physical causes, and guard the mocked version probe from native preparation. Keep the live Wakaru command control while adding a recording equivalent for bounded source verification. * fix(process): own sampling reads and settle inspection peers * fix(errors): retain authored recovery through cleanup composition * fix(process): retain all sampling inspection leaves for final cleanup * test(browser): report recording cleanup signal outcome * fix(process): keep inspection error context out of implicit JSON * fix(desktop): retain normalized sampling cleanup ownership * test(process): assert tagged startup cancellation
214 lines
7.2 KiB
TypeScript
214 lines
7.2 KiB
TypeScript
import { projectAnalysisError } from "../../domain/analysisErrorProjection.js";
|
|
import { expect, it, vi } from "vitest";
|
|
import { failedInspectionDescriptor } from "../../../tests/fixtures/processInspectionCleanup.js";
|
|
import {
|
|
cleanupOwnedProcessGroup,
|
|
type ProcessOwnershipHost,
|
|
} from "../ProcessOwnership.js";
|
|
import {
|
|
ProcessOwnershipIdentityBatchFailure,
|
|
ProcessOwnershipInspectionCancelled,
|
|
} from "../ProcessInspectionCancellation.js";
|
|
import {
|
|
ProcessCaptureError,
|
|
ProcessCaptureInspectionFailure,
|
|
} from "./ProcessCaptureError.js";
|
|
import {
|
|
ProcessCaptureResourceScope,
|
|
resolveProcessResult,
|
|
type ProcessCaptureCleanupOutcome,
|
|
} from "./ProcessCaptureLifecycle.js";
|
|
|
|
const failureFor = (
|
|
outcome: ProcessCaptureCleanupOutcome,
|
|
primary?: ProcessCaptureError,
|
|
): ProcessCaptureError => {
|
|
try {
|
|
resolveProcessResult(undefined, primary, outcome);
|
|
} catch (cause: unknown) {
|
|
if (cause instanceof ProcessCaptureError) return cause;
|
|
throw cause;
|
|
}
|
|
throw new Error("Expected controlled cleanup failure");
|
|
};
|
|
|
|
it("retries this run's inspection owner before fresh group queries while still disposing its renderer", async () => {
|
|
const file = await failedInspectionDescriptor();
|
|
const resources = new ProcessCaptureResourceScope();
|
|
const inspection = resources.retainInspectionFailure(file.failure);
|
|
if (inspection === undefined)
|
|
throw new Error("Expected explicit descriptor failure");
|
|
const query = vi.fn(async () => ({
|
|
cleaned: true as const,
|
|
signaled: false,
|
|
}));
|
|
const dispose = vi.fn(async () => undefined);
|
|
const remove = vi.fn(async () => undefined);
|
|
const cleanup = await resources.release({
|
|
timers: new Set(),
|
|
terminal: { pid: 321 },
|
|
renderer: { dispose },
|
|
runId: "selected-run",
|
|
temporaryRoot: "/fixture/selected-root",
|
|
inspectionFailures: [inspection],
|
|
host: {
|
|
platform: "linux",
|
|
cleanupProcessGroup: query,
|
|
removeTemporaryRoot: remove,
|
|
},
|
|
});
|
|
const failure = failureFor(cleanup);
|
|
expect(query).not.toHaveBeenCalled();
|
|
expect(dispose).toHaveBeenCalledOnce();
|
|
expect(remove).not.toHaveBeenCalled();
|
|
expect(failure.cleanupResources).toContain(file.path);
|
|
await expect(resources.close()).rejects.toMatchObject({
|
|
cleanupIncomplete: true,
|
|
});
|
|
expect(query).not.toHaveBeenCalled();
|
|
expect(file.handle.fd).not.toBe(-1);
|
|
file.allow();
|
|
await resources.close();
|
|
expect(file.handle.fd).toBe(-1);
|
|
expect(query).toHaveBeenCalledOnce();
|
|
expect(dispose).toHaveBeenCalledOnce();
|
|
expect(remove).toHaveBeenCalledOnce();
|
|
expect(failure.cleanupIncomplete).toBe(false);
|
|
});
|
|
|
|
it.each([false, true])(
|
|
"projects cancellation from mixed group-cleanup batch with prior physical failure: %s",
|
|
async (hasPrimary) => {
|
|
const file = await failedInspectionDescriptor();
|
|
const reason = { caller: "recorded cleanup interruption" };
|
|
const batch = new ProcessOwnershipIdentityBatchFailure(
|
|
[
|
|
{ pid: 41, requestIndex: 0, cause: file.failure },
|
|
{
|
|
pid: 42,
|
|
requestIndex: 1,
|
|
cause: new ProcessOwnershipInspectionCancelled(reason),
|
|
},
|
|
],
|
|
new Map([
|
|
[43, { state: "absent" as const, reason: "not-in-snapshot" as const }],
|
|
]),
|
|
);
|
|
let ready = false;
|
|
const host: ProcessOwnershipHost = {
|
|
platform: "linux",
|
|
listProcesses: async () => {
|
|
if (!ready) throw batch;
|
|
return [];
|
|
},
|
|
environment: async () => {
|
|
throw new Error("Unexpected environment inspection");
|
|
},
|
|
signalGroup: () => {
|
|
throw new Error(
|
|
"Empty controlled process table grants no signal authority",
|
|
);
|
|
},
|
|
};
|
|
const resources = new ProcessCaptureResourceScope();
|
|
const query = vi.fn(
|
|
(ownership: Parameters<typeof cleanupOwnedProcessGroup>[0]) =>
|
|
cleanupOwnedProcessGroup(ownership, host),
|
|
);
|
|
const dispose = vi.fn(async () => undefined);
|
|
const cleanup = await resources.release({
|
|
timers: new Set(),
|
|
terminal: { pid: 321 },
|
|
renderer: { dispose },
|
|
runId: "selected-run",
|
|
temporaryRoot: "/fixture/selected-root",
|
|
host: {
|
|
platform: "linux",
|
|
cleanupProcessGroup: query,
|
|
removeTemporaryRoot: async () => undefined,
|
|
},
|
|
});
|
|
const prior = hasPrimary
|
|
? new ProcessCaptureError("prior physical capture failure", {
|
|
cause: new Error("physical before cleanup"),
|
|
})
|
|
: undefined;
|
|
const failure = failureFor(cleanup, prior);
|
|
const cleanupFailure =
|
|
prior === undefined
|
|
? failure
|
|
: failure.secondaryFailures.find(
|
|
(error) =>
|
|
error instanceof ProcessCaptureError &&
|
|
error.reason === "cleanup_incomplete",
|
|
);
|
|
const inspection = cleanupFailure?.secondaryFailures.find(
|
|
(error) => error instanceof ProcessCaptureInspectionFailure,
|
|
);
|
|
expect(inspection).toBeInstanceOf(ProcessCaptureInspectionFailure);
|
|
if (!(inspection instanceof ProcessCaptureInspectionFailure))
|
|
throw new Error("Group cleanup discarded explicit inspection facts");
|
|
expect(inspection.inspectionFailure).toBe(batch);
|
|
expect(inspection.reason).toBe("capture_failed");
|
|
expect(inspection.secondaryFailures.map((error) => error.cause)).toEqual([
|
|
reason,
|
|
]);
|
|
expect(projectAnalysisError(failure)).toMatchObject({
|
|
details: {
|
|
secondary_failures: expect.arrayContaining([
|
|
expect.objectContaining({ code: "cancelled" }),
|
|
]),
|
|
},
|
|
});
|
|
if (prior !== undefined) expect(failure.cleanupPrimary).toBe(prior);
|
|
expect(failure.cleanupResources).toContain(file.path);
|
|
await expect(resources.close()).rejects.toMatchObject({
|
|
cleanupIncomplete: true,
|
|
});
|
|
expect(query).toHaveBeenCalledOnce();
|
|
expect(dispose).toHaveBeenCalledOnce();
|
|
ready = true;
|
|
file.allow();
|
|
await resources.close();
|
|
expect(file.handle.fd).toBe(-1);
|
|
expect(query).toHaveBeenCalledTimes(2);
|
|
expect(failure.cleanupIncomplete).toBe(false);
|
|
expect(inspection.inspectionFailure).toBe(batch);
|
|
expect(batch.observations.get(43)).toEqual({
|
|
state: "absent",
|
|
reason: "not-in-snapshot",
|
|
});
|
|
},
|
|
);
|
|
|
|
it("does not borrow another active capture's inspection failure for group cleanup", async () => {
|
|
const file = await failedInspectionDescriptor();
|
|
const resources = new ProcessCaptureResourceScope();
|
|
const other = resources.retainInspectionFailure(file.failure);
|
|
if (other === undefined)
|
|
throw new Error("Expected other capture's held inspection");
|
|
const query = vi.fn(async () => ({
|
|
cleaned: true as const,
|
|
signaled: false,
|
|
}));
|
|
const cleanup = await resources.release({
|
|
timers: new Set(),
|
|
terminal: { pid: 987 },
|
|
renderer: undefined,
|
|
runId: "unrelated-run",
|
|
temporaryRoot: "/fixture/unrelated-root",
|
|
inspectionFailures: [],
|
|
host: {
|
|
platform: "linux",
|
|
cleanupProcessGroup: query,
|
|
removeTemporaryRoot: async () => undefined,
|
|
},
|
|
});
|
|
expect(query).toHaveBeenCalledOnce();
|
|
expect(cleanup.report.owned_process_group.state).toBe("cleaned");
|
|
expect(cleanup.cleanupLease?.released).toBe(true);
|
|
expect(file.handle.fd).not.toBe(-1);
|
|
file.allow();
|
|
await resources.close();
|
|
});
|