diff --git a/src/browser/ElectronCaptureCleanup.boundary.test.ts b/src/browser/ElectronCaptureCleanup.boundary.test.ts index d5ea847c87..0457cf3c4c 100644 --- a/src/browser/ElectronCaptureCleanup.boundary.test.ts +++ b/src/browser/ElectronCaptureCleanup.boundary.test.ts @@ -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, diff --git a/src/browser/ElectronCaptureCleanup.test.ts b/src/browser/ElectronCaptureCleanup.test.ts index f461f455a3..e2376fe0f3 100644 --- a/src/browser/ElectronCaptureCleanup.test.ts +++ b/src/browser/ElectronCaptureCleanup.test.ts @@ -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, diff --git a/src/browser/PlaywrightElectronActiveProvider.test.ts b/src/browser/PlaywrightElectronActiveProvider.test.ts index 5f2c956d16..5e7370cfad 100644 --- a/src/browser/PlaywrightElectronActiveProvider.test.ts +++ b/src/browser/PlaywrightElectronActiveProvider.test.ts @@ -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(); diff --git a/tests/support/providerLifecycleCoverage.ts b/tests/support/providerLifecycleCoverage.ts index 41ac09252a..7e7cd44878 100644 --- a/tests/support/providerLifecycleCoverage.ts +++ b/tests/support/providerLifecycleCoverage.ts @@ -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(