fix(browser): release scenario listeners and allow bounded Chrome close (#2441)

* fix(browser): release scenario event listeners on finish

* fix(browser): allow Chrome cleanup to complete within bounded deadline

* style(browser): format cleanup deadline regression

* test(browser): expect popup cleanup listener

---------

Co-authored-by: LcokHcak <268763621+LcokHcak@users.noreply.github.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
LcokHcak
2026-10-13 22:16:25 +08:00
committed by GitHub
co-authored by LcokHcak morluto
parent 9b08c2b1cb
commit c9982ad8bf
5 changed files with 263 additions and 36 deletions
@@ -1,4 +1,5 @@
import { Cli } from "incur";
import { resolve } from "node:path";
import { expect, it, vi } from "vitest";
import type { BrowserScenarioCapturePort } from "../../src/application/BrowserScenarioCapturePort.js";
@@ -32,7 +33,7 @@ vi.mock("../../src/composition/browserScenario.js", () => ({
}));
const scenario = browserScenarioSchema.parse({
browser: { mode: "launch", executable_path: "/fixture/chromium" },
browser: { mode: "launch", executable_path: resolve("/fixture/chromium") },
start_url: { url: "https://app.example.test/" },
actions: [{ step_id: "wait", action: "wait_for_timeout", duration_ms: 1 }],
storage: {},
@@ -111,6 +112,22 @@ class RetrySession implements BrowserScenarioSessionPort {
}
}
it("waits for a slow but successful browser close before removing its profile", async () => {
const stages: string[] = [];
const cleanup = new PlaywrightScenarioBrowserCleanupOwner({
closeBrowser: async () => {
await new Promise((resolve) => setTimeout(resolve, 1_250));
stages.push("browser-closed");
},
removeProfile: async () => {
stages.push("profile-removed");
},
});
await cleanup.close();
expect(stages).toEqual(["browser-closed", "profile-removed"]);
});
const serveScenario = async () => {
const cli = Cli.create("browser-cleanup-test", { sync: false });
registerBrowserScenarioCommands(cli, silentLogger, {});