From 104a8f3f52b79a9ab8771bb5b91bdc9b87a2f6e1 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 25 Apr 2026 06:01:56 +0100 Subject: [PATCH] test(browser): handle oom wrapper in chrome launch assertion --- .../src/browser/chrome.internal.test.ts | 48 +++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/extensions/browser/src/browser/chrome.internal.test.ts b/extensions/browser/src/browser/chrome.internal.test.ts index 0a4e16a3dd2..3b9d340fb24 100644 --- a/extensions/browser/src/browser/chrome.internal.test.ts +++ b/extensions/browser/src/browser/chrome.internal.test.ts @@ -82,6 +82,20 @@ function makeFakeProc(overrides: Partial = {}): FakeProc { return Object.assign(proc, overrides); } +function effectiveSpawnCommand(call: unknown[] | undefined): unknown { + const command = call?.[0]; + const args = call?.[1]; + if ( + command === "/bin/sh" && + Array.isArray(args) && + args[0] === "-c" && + typeof args[2] === "string" + ) { + return args[2]; + } + return command; +} + async function withMockChromeCdpServer(params: { wsPath: string; onConnection?: (wss: WebSocketServer) => void; @@ -388,6 +402,7 @@ describe("chrome.ts internal", () => { }); it("uses profile executablePath over global executablePath when launching", async () => { + const originalPlatform = process.platform; vi.spyOn(fs, "existsSync").mockImplementation((p) => { const s = String(p); if (s === "/tmp/profile-chrome" || s.endsWith("Local State") || s.endsWith("Preferences")) { @@ -397,20 +412,25 @@ describe("chrome.ts internal", () => { }); spawnMock.mockImplementation(() => makeFakeProc()); - await withMockChromeCdpServer({ - wsPath: "/devtools/browser/PROFILE_EXE", - run: async (baseUrl) => { - const port = new URL(baseUrl).port; - const profile = { ...makeProfile(Number(port)), executablePath: "/tmp/profile-chrome" }; - const resolved = { - ...makeResolved(), - executablePath: "/tmp/global-chrome", - } as ResolvedBrowserConfig; - const running = await launchOpenClawChrome(resolved, profile); - expect(spawnMock.mock.calls[0]?.[0]).toBe("/tmp/profile-chrome"); - running.proc.kill?.("SIGTERM"); - }, - }); + Object.defineProperty(process, "platform", { value: "linux" }); + try { + await withMockChromeCdpServer({ + wsPath: "/devtools/browser/PROFILE_EXE", + run: async (baseUrl) => { + const port = new URL(baseUrl).port; + const profile = { ...makeProfile(Number(port)), executablePath: "/tmp/profile-chrome" }; + const resolved = { + ...makeResolved(), + executablePath: "/tmp/global-chrome", + } as ResolvedBrowserConfig; + const running = await launchOpenClawChrome(resolved, profile); + expect(effectiveSpawnCommand(spawnMock.mock.calls[0])).toBe("/tmp/profile-chrome"); + running.proc.kill?.("SIGTERM"); + }, + }); + } finally { + Object.defineProperty(process, "platform", { value: originalPlatform }); + } }); it("throws with stderr hint + sandbox hint when CDP never becomes reachable", async () => {