test(electron): consolidate capture cleanup coverage (#12958)

* test(electron): consolidate capture cleanup coverage

* test(electron): point lifecycle coverage to retained cleanup proof
This commit is contained in:
morluto authored and GitHub committed 2026-11-20 23:39:35 +00:00
1 parent 32e5f5bc1c
commit 6d74dbe5cc
4 files changed
+54 -128

No files matched your search

@@ -49,7 +49,9 @@ it.skipIf(process.platform === "win32")(
transport: { kind: "failed" },
processes: { kind: "released" },
});
expect(await supervisor.waitForExit(1000)).toBe(true);
await expect
.poll(() => spawned.process.exitCode ?? spawned.process.signalCode)
.not.toBeNull();
const error = new ProviderCleanupError(
"rea-playwright-electron-active",
owner.pendingResources,
@@ -56,30 +56,6 @@ const bindFailure = (owner: ElectronCaptureCleanup) => {
return error;
};
it("retries only the failed transport while preserving confirmed process release", async () => {
vi.spyOn(
ownershipObservation,
"observeOwnedProcessLineage",
).mockResolvedValue(verified);
const processes = vi
.spyOn(processCleanup, "cleanupElectronProcesses")
.mockResolvedValue({ cleaned: true, signaled: false });
let denied = true;
const close = vi.fn(async () => {
if (denied) throw new Error("transport denied");
});
const owner = new ElectronCaptureCleanup({ close }, ownership, verified);
const scope = new ArtifactResourceScope();
await owner.release(scope);
const original = bindFailure(owner);
expect(original.cleanupResources).toEqual(["browser_transport"]);
denied = false;
await scope.close();
expect(close).toHaveBeenCalledTimes(2);
expect(processes).toHaveBeenCalledOnce();
expect(original.cleanupIncomplete).toBe(false);
});
it("shrinks mixed cleanup and aggregate errors without repeating a released peer", async () => {
vi.spyOn(
ownershipObservation,
@@ -1235,111 +1235,53 @@ const stubCompletedCapture = () => {
);
};
it("cancels a completed capture when cancellation arrives during application close", async () => {
stubVerifiedElectronCleanup();
stubCompletedCapture();
const controller = new AbortController();
const reason = new Error("SIGTERM during close");
const application = {
process: () => ({ pid: 424242 }),
close: vi.fn(async () => {
controller.abort(reason);
}),
windows: () => [],
};
const result = await captureWithController(controller, application, []);
expect(application.close).toHaveBeenCalledOnce();
if (result.ok) throw new Error("Expected the capture to be cancelled");
expect(result.error).toMatchObject({
_tag: "BrowserObservationError",
reason: "cancelled",
partialObservation: {
kind: "electron-active-observation",
capture: { application: { electron_version: "44.0.0" } },
},
});
expect(result.error.cause).toBe(reason);
});
it("cancels a completed capture when cancellation arrives during process cleanup", async () => {
stubVerifiedElectronCleanup();
stubCompletedCapture();
const controller = new AbortController();
const reason = new Error("SIGTERM during process cleanup");
// POSIX cleanup owns the final sweep; Windows uses tree termination.
vi.spyOn(processOwnership, "cleanupOwnedProcessGroup").mockImplementation(
async () => {
controller.abort(reason);
return {
cleaned: true,
signaled: false,
unverified: [{ pid: 777, diagnostic: "command line unavailable" }],
it.each(["transport", "process"] as const)(
"retains completed capture evidence when cancellation arrives during %s cleanup",
async (phase) => {
stubVerifiedElectronCleanup();
stubCompletedCapture();
const controller = new AbortController();
const reason = new Error(`cancel during ${phase} cleanup`);
if (phase === "process") {
const finishProcesses = async () => {
controller.abort(reason);
return {
cleaned: true as const,
signaled: false,
unverified: [{ pid: 777, diagnostic: "command line unavailable" }],
};
};
},
);
vi.spyOn(processOwnership, "cleanupWindowsProcessTree").mockImplementation(
async () => {
controller.abort(reason);
return { cleaned: true, signaled: true };
},
);
const application = {
process: () => ({ pid: 424242 }),
close: vi.fn(async () => undefined),
windows: () => [],
};
vi.spyOn(processOwnership, "cleanupOwnedProcessGroup").mockImplementation(
finishProcesses,
);
vi.spyOn(
processOwnership,
"cleanupWindowsProcessTree",
).mockImplementation(finishProcesses);
}
const application = {
process: () => ({ pid: 424242 }),
close: vi.fn(async () => {
if (phase === "transport") controller.abort(reason);
}),
windows: () => [],
};
const result = await captureWithController(controller, application, []);
const result = await captureWithController(controller, application, []);
if (result.ok) throw new Error("Expected the capture to be cancelled");
expect(result.error).toMatchObject({
_tag: "BrowserObservationError",
reason: "cancelled",
partialObservation: {
kind: "electron-active-observation",
capture: { application: { electron_version: "44.0.0" } },
},
});
expect(result.error.cause).toBe(reason);
});
it("keeps cleanup failure precedence over cancellation observed during cleanup", async () => {
stubVerifiedElectronCleanup();
stubCompletedCapture();
const controller = new AbortController();
const failed = async () => {
controller.abort(new Error("SIGTERM during process cleanup"));
return { cleaned: false as const, reason: "process group still alive" };
};
vi.spyOn(processOwnership, "cleanupOwnedProcessGroup").mockImplementation(
failed,
);
vi.spyOn(processOwnership, "cleanupWindowsProcessTree").mockImplementation(
failed,
);
const application = {
process: () => ({ pid: 424242 }),
close: vi.fn(async () => undefined),
windows: () => [],
};
const result = await captureWithController(controller, application, []);
if (result.ok) throw new Error("Expected cleanup to fail");
expect(result.error).toMatchObject({
cleanupIncomplete: true,
partialObservation: {
kind: "electron-active-observation",
capture: { application: { cleanup: "unverified" } },
},
});
expect(result.error.cleanupPrimary).toMatchObject({
_tag: "BrowserObservationError",
reason: "cancelled",
});
});
expect(application.close).toHaveBeenCalledOnce();
if (result.ok) throw new Error("Expected the capture to be cancelled");
expect(result.error).toMatchObject({
_tag: "BrowserObservationError",
reason: "cancelled",
partialObservation: {
kind: "electron-active-observation",
capture: { application: { electron_version: "44.0.0" } },
},
});
expect(result.error.cause).toBe(reason);
},
);
it.each(["process", "transport"] as const)(
"preserves cancellation that preceded a %s cleanup failure",
@@ -1528,6 +1470,12 @@ it.each(["process", "transport"] as const)(
expect(result.error.cleanupPrimary?.cause).toBe(reason);
expect(result.error.partialObservation).toMatchObject({
kind: "electron-active-observation",
capture: {
application: {
cleanup:
phase === "process" ? "unverified" : "terminated-owned-process",
},
},
});
denied = false;
await provider.close();
+1 -1
View File
@@ -1615,7 +1615,7 @@ export const PROVIDER_LIFECYCLE_COVERAGE: Readonly<
cleanup: covered(
test(
"src/browser/PlaywrightElectronActiveProvider.test.ts",
"keeps cleanup failure precedence over cancellation observed during cleanup",
"retains cancellation first observed during failed %s cleanup through retry",
),
),
retry: covered(