Files
rea/src/browser/ElectronCaptureCleanup.boundary.test.ts
T
morluto 49e67aa1d9 fix(process): retain native ownership evidence through cleanup
Keep a run-scoped evidence owner from acquisition through settlement and
cleanup retry. Bind token observations to native generations and retain
related generations and unresolved identity lookups across table omissions,
reparenting and process-group changes without treating PID hints as authority.

Use native effective UID facts for withholding decisions, corroborate Linux
procfs absence, and share the Linux stat parser with sampling and debugger
identity checks. Signal only after current token and group revalidation.
Complete swept cleanup across all groups with one bounded final family check;
retain unresolved owners and successful-peer completion across retries.

Validation: npm run check, docs:check and test discovery passed. Focused
ownership/consumer coverage totals 513 passed and 1 skipped across 35 files,
including the corrected Electron cancellation test rerun independently. Darwin helper compilation, real
owned Node child cleanup, CLI/MCP capture and retained cleanup retries ran.
Real Electron applications, native Linux races/PID reuse and Windows cleanup
were not qualified. The original Linux reports remain open for that work.

Fixes #5238
Refs #4322, #5206
2026-10-19 20:04:00 +08:00

79 lines
2.7 KiB
TypeScript

import { randomUUID } from "node:crypto";
import { once } from "node:events";
import { expect, it, vi } from "vitest";
import { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
import {
spawnOwnedProviderProcess,
ProviderProcessSupervisor,
} from "../process/ProviderProcess.js";
import { observeOwnedProcessLineage } from "../process/ProcessOwnershipObservation.js";
import { ElectronCaptureCleanup } from "./ElectronCaptureCleanup.js";
// An authored idle Node fixture exercises POSIX ownership; it is not Electron.
it.skipIf(process.platform === "win32")(
"retains transport recovery after real owned process-family cleanup",
async () => {
const spawned = await spawnOwnedProviderProcess({
command: process.execPath,
arguments: [
"-e",
"process.stdout.write('ready'); setInterval(() => {}, 1000)",
],
expectedCommand: null,
runId: randomUUID(),
sweepTokenOwnedProcesses: true,
});
const supervisor = new ProviderProcessSupervisor({
...spawned,
ownsProcessLifetime: true,
});
const scope = new ArtifactResourceScope();
let denied = true;
const close = vi.fn(async () => {
if (denied) throw new Error("authored transport close denial");
});
try {
await once(spawned.process.stdout!, "data");
const lineage = await observeOwnedProcessLineage(spawned.ownership);
expect(lineage.status).toBe("verified");
const evidenceOwner = spawned.ownership.evidenceOwner;
if (evidenceOwner === undefined)
throw new Error("owned spawn omitted persistent ownership evidence");
const owner = new ElectronCaptureCleanup(
{ close },
{ ...spawned.ownership, evidenceOwner },
lineage,
);
expect(await owner.release(scope)).toMatchObject({
transport: { kind: "failed" },
processes: { kind: "released" },
});
expect(await supervisor.waitForExit(1000)).toBe(true);
const error = new ProviderCleanupError(
"rea-playwright-electron-active",
owner.pendingResources,
{},
);
owner.bind(error);
expect(error.cleanupResources).toEqual(["browser_transport"]);
denied = false;
await scope.close();
expect(error.cleanupIncomplete).toBe(false);
expect(close).toHaveBeenCalledTimes(2);
} finally {
denied = false;
try {
await scope.close();
} finally {
try {
const stopped = await supervisor.stop();
expect(stopped.status).not.toBe("incomplete");
} finally {
supervisor.dispose();
}
}
}
},
);