mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 19:23:24 +00:00
* refactor(browser): send only CDP commands with registered result schemas * refactor(browser): open Playwright CDP sessions only through the registered-command owner * fix(browser): keep the restore obligation for an applied override with a malformed reply A schema-rejected success reply means the browser applied the Emulation override, so the attached environment owner records the reset obligation before reporting the protocol error. Only a rejected or unanswered command leaves no obligation. * refactor(browser): open verifier-script CDP sessions through the registered-command owner (#10710) * fix(browser): register the CDP commands JavaScript verifiers send The verifier scripts send Browser.close, Page.createIsolatedWorld, Page.navigate, Page.reload, Target.activateTarget, Target.closeTarget and Target.createTarget through CdpConnection, which now admits every reply through its command's result schema. Register those schemas, refuse an unregistered run-time name as a typed malformed reply instead of a TypeError, and check script send literals against the registry. * fix(browser): keep Target.closeTarget's success member for the verifiers
83 lines
2.9 KiB
JavaScript
83 lines
2.9 KiB
JavaScript
#!/usr/bin/env node
|
|
import assert from "node:assert/strict";
|
|
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { chromium } from "playwright-core";
|
|
import { ArtifactResourceScope } from "../dist/artifacts/ArtifactResourceScope.js";
|
|
import { AnalysisCleanupLease } from "../dist/artifacts/AnalysisCleanupLease.js";
|
|
import { newPlaywrightCdpSession } from "../dist/browser/PlaywrightCdpSession.js";
|
|
import { startBrowserVerifierSite } from "./fixtures/browser-verifier-site.mjs";
|
|
import { verifyBrowserDomDestinations } from "./lib/browser-dom-destinations-e2e.mjs";
|
|
import { withVerifierCleanup } from "./lib/verifier-cleanup.mjs";
|
|
import { requireOrdinaryWindowsVerifierCaller } from "./lib/windows-ordinary-user-verifier.mjs";
|
|
|
|
const executable = process.env.REA_BROWSER_EXECUTABLE;
|
|
if (!executable)
|
|
throw new Error("verify:browser:dom requires REA_BROWSER_EXECUTABLE");
|
|
await requireOrdinaryWindowsVerifierCaller();
|
|
let profile;
|
|
let site;
|
|
let context;
|
|
let report;
|
|
const browserResources = new ArtifactResourceScope();
|
|
await withVerifierCleanup(async () => {
|
|
profile = await mkdtemp(join(tmpdir(), "rea-browser-dom-"));
|
|
browserResources.retain({
|
|
kind: "lease",
|
|
resource: profile,
|
|
lease: AnalysisCleanupLease.forCloseOwner(
|
|
{
|
|
close: async () => {
|
|
// The browser owns files in this profile until shutdown is confirmed.
|
|
await context?.close();
|
|
context = undefined;
|
|
await rm(profile, { recursive: true, force: true });
|
|
},
|
|
},
|
|
profile,
|
|
),
|
|
});
|
|
site = await startBrowserVerifierSite();
|
|
context = await chromium.launchPersistentContext(profile, {
|
|
executablePath: executable,
|
|
headless: true,
|
|
args: ["--remote-debugging-port=0"],
|
|
});
|
|
const page = context.pages()[0] ?? (await context.newPage());
|
|
await page.goto(`${site.origin}/app?selected=fixture#section`);
|
|
const native = await page.evaluate(() =>
|
|
[
|
|
...document.querySelectorAll("form,button[formaction],input[formaction]"),
|
|
].map((element) =>
|
|
element.tagName === "FORM" ? element.action : element.formAction,
|
|
),
|
|
);
|
|
assert.deepEqual(native, Array(4).fill(page.url()));
|
|
const session = await newPlaywrightCdpSession(
|
|
context,
|
|
page,
|
|
"inspect_web_page",
|
|
);
|
|
const { targetInfo } = await session.send("Target.getTargetInfo");
|
|
await session.detach();
|
|
const [port] = (
|
|
await readFile(join(profile, "DevToolsActivePort"), "utf8")
|
|
).split("\n");
|
|
const result = await verifyBrowserDomDestinations(
|
|
{
|
|
cdp_endpoint: `http://127.0.0.1:${port}`,
|
|
target_id: targetInfo.targetId,
|
|
},
|
|
process.argv[2],
|
|
page.url(),
|
|
);
|
|
report = {
|
|
...result,
|
|
browser: context.browser().version(),
|
|
native_oracle: true,
|
|
verified: true,
|
|
};
|
|
}, [() => browserResources.close(), () => site?.close()]);
|
|
process.stdout.write(`${JSON.stringify(report)}\n`);
|