fix(browser): scope CDP events and fail closed

This commit is contained in:
morluto
2026-07-14 04:53:29 +00:00
parent 2c1ceabbf1
commit 5279d7755c
5 changed files with 106 additions and 38 deletions
+25 -21
View File
@@ -84,27 +84,31 @@ describe("browser CLI parity", () => {
INTEGRATION_TEST_TIMEOUT_MS,
);
it("requires explicit approval before opening the CDP endpoint", async () => {
const browser = await startFakeCdpBrowser();
browsers.push(browser);
const result = await runCli(
["list-browser-targets", browser.endpoint, "--json"],
{
...process.env,
REA_BROWSER_OBSERVE_ENABLED: "true",
REA_BROWSER_CDP_ENDPOINTS_JSON: JSON.stringify([browser.endpoint]),
REA_BROWSER_ALLOWED_ORIGINS_JSON: JSON.stringify([
browser.allowedOrigin,
]),
},
);
expect(result).toMatchObject({
error: "Browser observation failed",
code: "invalid_request",
category: "invalid_input",
});
expect(browser.commands).toHaveLength(0);
});
it(
"requires explicit approval before opening the CDP endpoint",
async () => {
const browser = await startFakeCdpBrowser();
browsers.push(browser);
const result = await runCli(
["list-browser-targets", browser.endpoint, "--json"],
{
...process.env,
REA_BROWSER_OBSERVE_ENABLED: "true",
REA_BROWSER_CDP_ENDPOINTS_JSON: JSON.stringify([browser.endpoint]),
REA_BROWSER_ALLOWED_ORIGINS_JSON: JSON.stringify([
browser.allowedOrigin,
]),
},
);
expect(result).toMatchObject({
error: "Browser observation failed",
code: "invalid_request",
category: "invalid_input",
});
expect(browser.commands).toHaveLength(0);
},
INTEGRATION_TEST_TIMEOUT_MS,
);
});
const runCli = async (