From d549919805d63e7a7bffe97ab12b2988dee6577c Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 21 Jul 2026 12:06:06 +0000 Subject: [PATCH] test: map BROWSER_LAUNCH_FAILED to companion HTTP 503 Ensure launch failures share the not-installed recovery status path so operators get a consistent 503 + lifecycle code. Co-authored-by: esadrianno --- services/companion/src/server.test.ts | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/services/companion/src/server.test.ts b/services/companion/src/server.test.ts index bdce8ad..4863ea8 100644 --- a/services/companion/src/server.test.ts +++ b/services/companion/src/server.test.ts @@ -417,4 +417,34 @@ describe("createCompanionApp", () => { expect(body.lifecycle?.code).toBe("BROWSER_NOT_INSTALLED"); await app.close(); }); + + it("returns 503 when runtime reports browser launch failure", async () => { + const runtime = mockRuntime({ + createSession: vi.fn(async () => { + throw new WebchainRuntimeError( + "BROWSER_LAUNCH_FAILED", + "chromium exited on launch", + ); + }), + }); + const { app } = await createCompanionApp({ + runtime, + logger: false, + localToken: "tok", + }); + + const res = await app.inject({ + method: "POST", + url: "/sessions", + headers: { "x-webchain-token": "tok" }, + }); + + expect(res.statusCode).toBe(503); + const body = parseApiError(res); + expect(body.code).toBe("BROWSER_LAUNCH_FAILED"); + expect(body.error).toContain("chromium exited on launch"); + expect(body.lifecycle?.kind).toBe("command_error"); + expect(body.lifecycle?.code).toBe("BROWSER_LAUNCH_FAILED"); + await app.close(); + }); });