Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
test(cdp): lock renderer reply ordering in smoke
ldm013877aa2bf63
diff --git a/moli-cdp-smoke/README.md b/moli-cdp-smoke/README.mdindex dd793016c..c0b2b41e6 100644--- a/moli-cdp-smoke/README.md+++ b/moli-cdp-smoke/README.md@@ -25,6 +25,33 @@ observed, but it does not replace the executable probe when one can be run. IfChromium cannot be tested, document that limitation explicitly instead ofpresenting an inferred expectation as verified behavior.+The default `cdp-ordering` group locks down Renderer native and Inspector wire+publication order. It pipelines Page trees/layout, DOMSnapshot, DOM queries and+objects, CSS, AX, and a native backend error before `Runtime.enable`; stylesheet+and isolated-world context notifications must precede their corresponding+responses. Trees must reflect the preceding pipelined history mutation even+when its response has not been consumed. The effective URL includes Chromium's+separate `urlFragment` field; Moli currently includes the fragment in `url`.+Deferred Promise evaluation must allow its later resolver to run,+ordinary pause must allow native queries and synchronous focus callback reentry,+and instrumentation pause must leave Main work pending while IO remains live.+All scenarios use local fixture documents, match the navigation's loader and+`DOMContentLoaded` before setup, track the original response session+and exactly one terminal per command, retain the full wire transcript, and use+protocol events/responses instead of sleeps or retries.++Four mutation cases explicitly preserve Moli's current VM entry boundary:+`DOM.setAttributeValue`, `CSS.setStyleSheetText`, `Page.setDocumentContent`, and+`Emulation.setHardwareConcurrencyOverride` wait for resume in Moli but complete+during ordinary pause in Chromium. This is a Moli implementation limitation,+not a CDP requirement; supporting nested mutation later must deliberately update+this expectation. CSS editing checks effective computed color, since Chromium+changes CSSOM without rewriting the style element's DOM text. The group is+calibrated against `/usr/bin/chromium` 145.0.7632.116 and can run unchanged using+`uv run moli-cdp-smoke --group cdp-ordering --endpoint URL`. Run a bounded stress+check with `--group cdp-ordering --repeat 20 --jobs 4`; any failed run fails the+suite.+The `history-worlds` group was calibrated on 2026-09-25 against macOS GoogleChrome 154.0.8037.57 using a fresh headless profile. It uses a real CDP WebSocketand `Page.createIsolatedWorld` to cover the PR #818 regressions: entry wrapperdiff --git a/moli-cdp-smoke/moli_cdp_smoke/groups/cdp_ordering.py b/moli-cdp-smoke/moli_cdp_smoke/groups/cdp_ordering.pynew file mode 100644index 000000000..5413c78aa--- /dev/null+++ b/moli-cdp-smoke/moli_cdp_smoke/groups/cdp_ordering.py@@ -0,0 +1,414 @@+"""Renderer publication contracts calibrated against Chromium 145.0.7632.116.++Use the actual WebSocket order, retaining replies received while waiting for+another id. Timeouts only bound liveness; no sleep or retry proves ordering.+The four mutation cases explicitly distinguish Moli's current owner-only entry+from Chromium's ordinary-pause capability. They are not CDP-wide requirements.+"""++from __future__ import annotations++import asyncio+import contextlib+import sys+from dataclasses import dataclass, field+from typing import Any, Callable++from ..assertions import SmokeError, assert_equal, record_contract+from ..raw_cdp import RawCdpClient, connect_raw_cdp, discover_websocket_url+++CHROMIUM_SOURCE = "Chromium 145.0.7632.116 raw CDP calibration, 2026-09-30"+++@dataclass+class _Wire:+ client: RawCdpClient+ scenario: str+ requests: dict[int, tuple[str, str | None]] = field(default_factory=dict)+ messages: list[dict[str, Any]] = field(default_factory=list)+ trace: list[dict[str, Any]] = field(default_factory=list)++ async def send(+ self, method: str, params: dict[str, Any] | None = None, session: str | None = None+ ) -> int:+ print(f"[moli-cdp-smoke] CHECKPOINT cdp-ordering/{self.scenario}/{method}",+ file=sys.stderr, flush=True)+ rid = await self.client.send(method, params, session_id=session)+ self.requests[rid] = (method, session)+ self.trace.append({"direction": "send", "id": rid, "method": method,+ "params": params, "sessionId": session})+ return rid++ async def until(+ self, predicate: Callable[[dict[str, Any]], bool], label: str, *, after: int = 0+ ) -> dict[str, Any]:+ try:+ async with asyncio.timeout(10):+ for message in self.messages[after:]:+ if predicate(message):+ return message+ while True:+ message = await self.client.recv()+ # Retain rejected frames too, so routing/duplicate failures+ # preserve the actual wire evidence in the artifact.+ self.trace.append({"direction": "receive", "message": message})+ rid = message.get("id")+ if isinstance(rid, int):+ if rid not in self.requests:+ raise SmokeError(f"unrecognized response id: {message!r}")+ assert_equal(message.get("sessionId"), self.requests[rid][1],+ f"{self.requests[rid][0]} original response session")+ if self.has_response(rid):+ raise SmokeError(f"duplicate response id={rid}: {message!r}")+ self.messages.append(message)+ if predicate(message):+ return message+ except TimeoutError as error:+ raise SmokeError(f"timed out waiting for {label}; seen={self.messages[-20:]!r}") from error++ async def response(self, rid: int, *, allow_error: bool = False) -> dict[str, Any]:+ message = await self.until(lambda m: m.get("id") == rid, self.requests[rid][0])+ if "error" in message and not allow_error:+ raise SmokeError(f"{self.requests[rid][0]} failed: {message!r}")+ return message++ async def call(+ self, method: str, params: dict[str, Any] | None = None, session: str | None = None+ ) -> dict[str, Any]:+ message = await self.response(await self.send(method, params, session))+ result = message.get("result")+ if not isinstance(result, dict) or result.get("exceptionDetails") is not None:+ raise SmokeError(f"{method} returned an invalid result: {message!r}")+ return result++ async def evaluate(self, session: str, expression: str) -> Any:+ result = await self.call("Runtime.evaluate", {+ "expression": expression, "returnByValue": True+ }, session)+ return result.get("result", {}).get("value")++ def has_response(self, rid: int) -> bool:+ return any(m.get("id") == rid for m in self.messages)++ def index(self, rid: int) -> int:+ return next(i for i, m in enumerate(self.messages) if m.get("id") == rid)++ def assert_all_replied(self) -> None:+ assert_equal(sorted(m["id"] for m in self.messages if isinstance(m.get("id"), int)),+ sorted(self.requests), "each admitted command has exactly one terminal")+++@dataclass(frozen=True)+class _Page:+ session: str+ url: str+ frame: str+ node: int+ sheet: str+ css_event_index: int+ css_reply_index: int+++async def _fixture(wire: _Wire, session: str, url: str) -> _Page:+ await wire.call("Page.enable", session=session)+ await wire.call("Page.setLifecycleEventsEnabled", {"enabled": True}, session)+ start = len(wire.messages)+ navigation = await wire.call("Page.navigate", {"url": url}, session)+ if navigation.get("errorText") or not navigation.get("loaderId"):+ raise SmokeError(f"local fixture navigation failed: {navigation!r}")+ # A navigate response does not promise a parsed Document. Match this+ # navigation's loader so initial-document replay cannot release the gate.+ await wire.until(lambda m: m.get("sessionId") == session+ and m.get("method") == "Page.lifecycleEvent"+ and m["params"].get("loaderId") == navigation["loaderId"]+ and m["params"].get("name") == "DOMContentLoaded",+ "fixture Document parsed", after=start)+ await wire.evaluate(session,+ "document.head.innerHTML = '<style>input {color: red}</style>';"+ "document.body.innerHTML = '<input id=probe>'; void 0")+ await wire.call("DOM.enable", session=session)+ document = await wire.call("DOM.getDocument", session=session)+ node = await wire.call("DOM.querySelector", {+ "nodeId": document["root"]["nodeId"], "selector": "#probe"+ }, session)+ if not node.get("nodeId"):+ raise SmokeError(f"inline fixture node is missing: {node!r}")+ tree = await wire.call("Page.getFrameTree", session=session)+ frame = tree["frameTree"]["frame"]["id"]+ start = len(wire.messages)+ enable = await wire.send("CSS.enable", session=session)+ await wire.response(enable)+ event = await wire.until(lambda m: m.get("sessionId") == session+ and m.get("method") == "CSS.styleSheetAdded"+ and m.get("params", {}).get("header", {}).get("frameId") == frame,+ "fixture stylesheet event", after=start)+ event_index = wire.messages.index(event)+ if event_index >= wire.index(enable):+ raise SmokeError("CSS.styleSheetAdded must precede CSS.enable response")+ return _Page(session, url, frame, node["nodeId"], event["params"]["header"]["styleSheetId"],+ event_index, wire.index(enable))+++async def _native_prefix(wire: _Wire, page: _Page, _is_moli: bool) -> dict[str, Any]:+ session = page.session+ start = len(wire.messages)+ replacement = await wire.send("Runtime.evaluate", {+ "expression": "history.replaceState(null, '', '#ordering'); void 0"+ }, session)+ commands = [+ ("Page.getFrameTree", {}),+ ("Page.getResourceTree", {}),+ ("Page.getLayoutMetrics", {}),+ ("DOMSnapshot.captureSnapshot", {"computedStyles": ["display"]}),+ ("DOM.describeNode", {"nodeId": page.node}),+ ("CSS.getComputedStyleForNode", {"nodeId": page.node}),+ ("Accessibility.getFullAXTree", {}),+ ("DOM.resolveNode", {"nodeId": page.node, "objectGroup": "cdp-ordering"}),+ ("DOM.describeNode", {"backendNodeId": 2147483647}),+ ]+ ids = [await wire.send(method, params, session) for method, params in commands]+ enable = await wire.send("Runtime.enable", session=session)+ # Reading replies in reverse must never dictate their wire publication order.+ replies = {rid: await wire.response(rid, allow_error=rid == ids[-1]) for rid in reversed(ids)}+ replaced = await wire.response(replacement)+ if replaced["result"].get("exceptionDetails") is not None:+ raise SmokeError(f"same-document fixture mutation failed: {replaced!r}")+ await wire.response(enable)+ context = await wire.until(lambda m: m.get("sessionId") == session+ and m.get("method") == "Runtime.executionContextCreated"+ and m["params"]["context"].get("auxData", {}).get("isDefault") is True,+ "Runtime default context replay", after=start)+ indexes = [wire.index(rid) for rid in ids]+ assert_equal(indexes, sorted(indexes), "ready native terminals retain Main publication order")+ if wire.index(replacement) >= min(indexes):+ raise SmokeError("native snapshots overtook the preceding synchronous history mutation")+ context_index = wire.messages.index(context)+ if not max(indexes) < context_index < wire.index(enable):+ raise SmokeError(f"native terminals/context/enable order: {indexes}, {context_index}, {wire.index(enable)}")+ assert_equal(replies[ids[-1]].get("error", {}).get("code"), -32000,+ "native backend failure retains its ordered terminal")+ for rid in ids[:2]:+ frame = replies[rid]["result"]["frameTree"]["frame"]+ # Chromium represents the fragment separately; Moli currently includes+ # it in url. Check the effective URL without assuming identical fields.+ assert_equal(frame["url"] + frame.get("urlFragment", ""),+ f"{page.url}#ordering", "tree reports live renderer URL")+ if not replies[ids[3]]["result"]["documents"] or not replies[ids[6]]["result"]["nodes"]:+ raise SmokeError("native DOM/AX snapshot unexpectedly empty")+ assert_equal(replies[ids[4]]["result"]["node"]["nodeName"], "INPUT", "native node snapshot")+ color = next(p["value"] for p in replies[ids[5]]["result"]["computedStyle"] if p["name"] == "color")+ assert_equal(color, "rgb(255, 0, 0)", "native computed style")+ object_id = replies[ids[7]]["result"]["object"]["objectId"]+ resolved = await wire.call("Runtime.callFunctionOn", {+ "objectId": object_id, "functionDeclaration": "function() { return this.id; }",+ "returnByValue": True+ }, session)+ assert_equal(resolved["result"].get("value"), "probe", "object is usable immediately after native reply")+ await wire.call("Runtime.releaseObjectGroup", {"objectGroup": "cdp-ordering"}, session)+ return {"historyReplyIndex": wire.index(replacement),+ "nativeReplyIndexes": indexes, "contextEventIndex": context_index,+ "enableReplyIndex": wire.index(enable), "cssEventIndex": page.css_event_index,+ "cssEnableReplyIndex": page.css_reply_index}+++async def _world_prefix(wire: _Wire, page: _Page, _is_moli: bool) -> dict[str, Any]:+ await wire.call("Runtime.enable", session=page.session)+ start = len(wire.messages)+ rid = await wire.send("Page.createIsolatedWorld", {+ "frameId": page.frame, "worldName": "cdp-ordering-world"+ }, page.session)+ reply = await wire.response(rid)+ context = reply["result"]["executionContextId"]+ event = await wire.until(lambda m: m.get("sessionId") == page.session+ and m.get("method") == "Runtime.executionContextCreated"+ and m["params"]["context"]["id"] == context,+ "isolated world context", after=start)+ if wire.messages.index(event) >= wire.index(rid):+ raise SmokeError("isolated context notification must precede world response")+ return {"eventIndex": wire.messages.index(event), "replyIndex": wire.index(rid)}+++async def _deferred_reply(wire: _Wire, page: _Page, _is_moli: bool) -> dict[str, Any]:+ await wire.evaluate(page.session, "globalThis.__gate = new Promise(r => globalThis.__resolve = r); void 0")+ held = await wire.send("Runtime.evaluate", {+ "expression": "__gate", "awaitPromise": True, "returnByValue": True+ }, page.session)+ later = await wire.send("Runtime.evaluate", {"expression": "6 * 7", "returnByValue": True}, page.session)+ reply = await wire.response(later)+ assert_equal(reply["result"]["result"].get("value"), 42, "later command proceeds while Promise pending")+ if wire.has_response(held):+ raise SmokeError("unresolved Promise replied before its resolver was sent")+ resolver = await wire.send("Runtime.evaluate", {"expression": "__resolve(42)"}, page.session)+ await wire.response(resolver)+ held_reply = await wire.response(held)+ assert_equal(held_reply["result"]["result"].get("value"), 42, "deferred command resolves")+ return {"laterReplyIndex": wire.index(later), "heldReplyIndex": wire.index(held)}+++async def _pause(wire: _Wire, page: _Page, *, instrumentation: bool = False) -> int:+ await wire.call("Debugger.enable", session=page.session)+ if instrumentation:+ await wire.call("Debugger.setInstrumentationBreakpoint", {+ "instrumentation": "beforeScriptExecution"+ }, page.session)+ start = len(wire.messages)+ outer = await wire.send("Runtime.evaluate", {+ "expression": "21 * 2" if instrumentation else "(() => { debugger; return 42; })()",+ "returnByValue": True+ }, page.session)+ paused = await wire.until(lambda m: m.get("sessionId") == page.session+ and m.get("method") == "Debugger.paused",+ "Debugger pause", after=start)+ if instrumentation:+ assert_equal(paused["params"].get("reason"), "instrumentation", "instrumentation pause reason")+ if wire.has_response(outer):+ raise SmokeError("outer evaluation completed while paused")+ return outer+++async def _normal_pause(wire: _Wire, page: _Page, _is_moli: bool) -> dict[str, Any]:+ outer = await _pause(wire, page)+ commands = [("Page.getFrameTree", {}), ("DOM.describeNode", {"nodeId": page.node}),+ ("CSS.getComputedStyleForNode", {"nodeId": page.node})]+ ids = [await wire.send(method, params, page.session) for method, params in commands]+ for rid in reversed(ids):+ await wire.response(rid)+ if wire.has_response(outer):+ raise SmokeError("native queries must leave the outer evaluation paused")+ await wire.call("Debugger.resume", session=page.session)+ reply = await wire.response(outer)+ assert_equal(reply["result"]["result"].get("value"), 42, "outer evaluation resumes")+ return {"nestedReplyIndexes": [wire.index(rid) for rid in ids], "outerReplyIndex": wire.index(outer)}+++async def _instrumentation_pause(wire: _Wire, page: _Page, _is_moli: bool) -> dict[str, Any]:+ outer = await _pause(wire, page, instrumentation=True)+ query = await wire.send("Page.getFrameTree", session=page.session)+ io = await wire.send("Performance.getMetrics", session=page.session)+ await wire.response(io)+ # IO is a liveness observation, not a general Main/IO ordering barrier.+ if wire.has_response(query) or wire.has_response(outer):+ raise SmokeError("instrumentation pause admitted ordinary Main work at the IO observation")+ resume = await wire.send("Debugger.resume", session=page.session)+ await wire.response(resume)+ await wire.response(query)+ reply = await wire.response(outer)+ assert_equal(reply["result"]["result"].get("value"), 42, "instrumented evaluation resumes")+ if wire.index(query) < wire.index(io):+ raise SmokeError("ordinary Main query overtook the instrumentation IO observation")+ return {"ioReplyIndex": wire.index(io), "queryReplyIndex": wire.index(query),+ "outerReplyIndex": wire.index(outer)}+++async def _focus_reentry(wire: _Wire, page: _Page, _is_moli: bool) -> dict[str, Any]:+ await wire.evaluate(page.session, "document.getElementById('probe').addEventListener('focus', () => {"+ "debugger; globalThis.__focusFinished = true; }); void 0")+ await wire.call("Debugger.enable", session=page.session)+ start = len(wire.messages)+ focus = await wire.send("DOM.focus", {"nodeId": page.node}, page.session)+ await wire.until(lambda m: m.get("sessionId") == page.session and m.get("method") == "Debugger.paused",+ "focus callback pause", after=start)+ query = await wire.send("Page.getFrameTree", session=page.session)+ await wire.response(query)+ if wire.has_response(focus):+ raise SmokeError("DOM.focus must remain pending during its paused callback")+ await wire.call("Debugger.resume", session=page.session)+ await wire.response(focus)+ assert_equal(await wire.evaluate(page.session, "__focusFinished"), True, "focus callback finished")+ return {"nestedReplyIndex": wire.index(query), "focusReplyIndex": wire.index(focus)}+++async def _paused_mutation(wire: _Wire, page: _Page, is_moli: bool) -> dict[str, Any]:+ method, params, expression, expected = {+ "paused_dom_attribute": ("DOM.setAttributeValue", {+ "nodeId": page.node, "name": "data-probe", "value": "done"+ }, "document.getElementById('probe').getAttribute('data-probe')", "done"),+ "paused_stylesheet_edit": ("CSS.setStyleSheetText", {+ "styleSheetId": page.sheet, "text": "input {color: blue}"+ }, "getComputedStyle(document.getElementById('probe')).color", "rgb(0, 0, 255)"),+ "paused_document_content": ("Page.setDocumentContent", {+ "frameId": page.frame, "html": "<!doctype html><body>replacement</body>"+ }, "document.body.textContent", "replacement"),+ "paused_navigator_configuration": ("Emulation.setHardwareConcurrencyOverride", {+ "hardwareConcurrency": 4+ }, "navigator.hardwareConcurrency", 4),+ }[wire.scenario]+ outer = await _pause(wire, page)+ mutation = await wire.send(method, params, page.session)+ if not is_moli:+ # Chromium must actually finish the mutation before we send resume.+ await wire.response(mutation)+ io = await wire.send("Performance.getMetrics", session=page.session)+ await wire.response(io)+ assert_equal(wire.has_response(mutation), not is_moli,+ f"{method} {'Moli owner-only' if is_moli else 'Chromium nested'} entry at IO observation")+ if wire.has_response(outer):+ raise SmokeError(f"{method} unexpectedly resumed the outer evaluation")+ resume_send_index = len(wire.trace)+ resume = await wire.send("Debugger.resume", session=page.session)+ await wire.response(resume)+ await wire.response(mutation)+ reply = await wire.response(outer)+ assert_equal(reply["result"]["result"].get("value"), 42, "paused evaluation resumes exactly once")+ assert_equal(await wire.evaluate(page.session, expression), expected, f"{method} mutation takes effect")+ return {"mutation": method, "engine": "moli" if is_moli else "chromium",+ "replyDuringPause": not is_moli, "ioReplyIndex": wire.index(io),+ "resumeSendTraceIndex": resume_send_index, "mutationReplyIndex": wire.index(mutation),+ "outerReplyIndex": wire.index(outer), "value": expected}+++async def run_cdp_ordering_group(endpoint: str, fixture_url: str, results: list[dict[str, Any]]) -> None:+ is_moli = (await discover_websocket_url(endpoint)).endswith("/devtools/browser/moli-browser")+ scenarios = [+ ("native_terminal_notification_prefix", _native_prefix),+ ("isolated_world_notification_prefix", _world_prefix),+ ("deferred_reply_later_resolver", _deferred_reply),+ ("normal_pause_native_queries", _normal_pause),+ ("instrumentation_pause_io_only", _instrumentation_pause),+ ("native_focus_callback_reentry", _focus_reentry),+ ("paused_dom_attribute", _paused_mutation),+ ("paused_stylesheet_edit", _paused_mutation),+ ("paused_document_content", _paused_mutation),+ ("paused_navigator_configuration", _paused_mutation),+ ]+ failures = []+ for name, scenario in scenarios:+ client = await connect_raw_cdp(endpoint)+ wire = _Wire(client, name)+ context_id = None+ session = None+ try:+ context = await wire.call("Target.createBrowserContext")+ context_id = context["browserContextId"]+ target = await wire.call("Target.createTarget", {"url": "about:blank", "browserContextId": context_id})+ attached = await wire.call("Target.attachToTarget", {"targetId": target["targetId"], "flatten": True})+ session = attached["sessionId"]+ page = await _fixture(wire, session, f"{fixture_url}/plain")+ observed = await scenario(wire, page, is_moli)+ # A same-Main renderer follower drains earlier ready terminals; a+ # Browser-only response would not be such a publication boundary.+ await wire.call("Page.getFrameTree", session=session)+ await wire.call("Target.disposeBrowserContext", {"browserContextId": context_id})+ context_id = None+ wire.assert_all_replied()+ record_contract(results, f"cdp_ordering_{name}",+ contract=("Moli owner-only mutations wait for resume; Chromium completes them in ordinary pause."+ if scenario is _paused_mutation else "Renderer ready replies and notifications retain causal order without blocking deferred work."),+ source=(f"{CHROMIUM_SOURCE}; Moli owner-only VM entry limitation" if scenario is _paused_mutation else CHROMIUM_SOURCE),+ commands=list(dict.fromkeys(method for method, _session in wire.requests.values())),+ observed={**observed, "wire": wire.trace})+ except Exception as error:+ failures.append(f"{name}: {type(error).__name__}: {error}")+ results.append({"name": f"cdp_ordering_{name}", "ok": False,+ "error": str(error), "wire": wire.trace})+ finally:+ if context_id is not None:+ with contextlib.suppress(Exception):+ async with asyncio.timeout(3):+ if session:+ await wire.call("Debugger.resume", session=session)+ await wire.call("Target.disposeBrowserContext", {"browserContextId": context_id})+ await client.websocket.close()+ if failures:+ raise SmokeError("CDP ordering contracts failed: " + "; ".join(failures))diff --git a/moli-cdp-smoke/moli_cdp_smoke/runner.py b/moli-cdp-smoke/moli_cdp_smoke/runner.pyindex 218cf46af..3b208daf4 100644--- a/moli-cdp-smoke/moli_cdp_smoke/runner.py+++ b/moli-cdp-smoke/moli_cdp_smoke/runner.py@@ -21,6 +21,7 @@ from .groups.action_window import run_action_window_groupfrom .groups.agent_browser import run_agent_browser_groupfrom .groups.agent_episode import run_agent_episode_groupfrom .groups.browser_semantics import run_browser_semantics_group+from .groups.cdp_ordering import run_cdp_ordering_groupfrom .groups.classic_scrollbar import run_classic_scrollbar_groupfrom .groups.cdp_use import run_cdp_use_groupfrom .groups.chrome_remote_interface import run_chrome_remote_interface_group@@ -135,6 +136,12 @@ RAW_GROUPS: tuple[SmokeGroup, ...] = ("raw",run_inspector_routing_group,),+ SmokeGroup(+ "cdp-ordering",+ "Renderer native/Inspector reply and notification order, deferred resolvers, pause reentry, and explicit Moli owner-only mutation boundaries.",+ "raw",+ run_cdp_ordering_group,+ ),SmokeGroup("action-window","Moli raw-CDP wheel batching, overflow-container axes, screenshot flush/reset, and exact-Document retirement contracts.",diff --git a/moli-cdp-smoke/tests/test_cdp_ordering.py b/moli-cdp-smoke/tests/test_cdp_ordering.pynew file mode 100644index 000000000..6f9ad5d05--- /dev/null+++ b/moli-cdp-smoke/tests/test_cdp_ordering.py@@ -0,0 +1,73 @@+from __future__ import annotations++import unittest+from typing import Any++from moli_cdp_smoke.assertions import SmokeError+from moli_cdp_smoke.groups.cdp_ordering import _Page, _Wire, _world_prefix+++class _ScriptedClient:+ def __init__(self, messages: list[dict[str, Any]]) -> None:+ self.messages = iter(messages)+ self.next_id = 0++ async def send(self, *_args: Any, **_kwargs: Any) -> int:+ self.next_id += 1+ return self.next_id++ async def recv(self) -> dict[str, Any]:+ return next(self.messages)+++class OrderingTranscriptTests(unittest.IsolatedAsyncioTestCase):+ async def test_reverse_waiter_retains_earlier_response_without_reading_again(self) -> None:+ client = _ScriptedClient([+ {"id": 1, "sessionId": "page", "result": {"first": True}},+ {"id": 2, "sessionId": "page", "result": {"second": True}},+ ])+ wire = _Wire(client, "reverse-waiter") # type: ignore[arg-type]+ first = await wire.send("Page.getFrameTree", session="page")+ second = await wire.send("Runtime.enable", session="page")+ await wire.response(second)+ self.assertEqual((await wire.response(first))["result"], {"first": True})+ self.assertLess(wire.index(first), wire.index(second))+ wire.assert_all_replied()++ async def test_duplicate_terminal_is_rejected_while_waiting_for_later_command(self) -> None:+ client = _ScriptedClient([+ {"id": 1, "result": {}},+ {"id": 1, "result": {}},+ {"id": 2, "result": {}},+ ])+ wire = _Wire(client, "duplicate") # type: ignore[arg-type]+ await wire.call("Browser.getVersion")+ with self.assertRaisesRegex(SmokeError, "duplicate response id=1"):+ await wire.call("Target.getTargets")+ self.assertEqual(wire.trace[-1], {"direction": "receive", "message": {"id": 1, "result": {}}})+ self.assertEqual(sum(frame["direction"] == "receive" for frame in wire.trace), 2)++ async def test_response_cannot_be_claimed_by_a_different_session(self) -> None:+ client = _ScriptedClient([{"id": 1, "sessionId": "replacement", "result": {}}])+ wire = _Wire(client, "session-owner") # type: ignore[arg-type]+ with self.assertRaisesRegex(SmokeError, "original response session"):+ await wire.call("Page.getFrameTree", session="original")+ self.assertEqual(wire.trace[-1], {+ "direction": "receive", "message": {"id": 1, "sessionId": "replacement", "result": {}}+ })++ async def test_callback_reply_cannot_overtake_its_context_notification(self) -> None:+ client = _ScriptedClient([+ {"id": 1, "sessionId": "page", "result": {}},+ {"id": 2, "sessionId": "page", "result": {"executionContextId": 7}},+ {"method": "Runtime.executionContextCreated", "sessionId": "page",+ "params": {"context": {"id": 7}}},+ ])+ wire = _Wire(client, "late-context") # type: ignore[arg-type]+ page = _Page("page", "http://fixture/plain", "frame", 1, "sheet", 0, 0)+ with self.assertRaisesRegex(SmokeError, "notification must precede world response"):+ await _world_prefix(wire, page, False)+++if __name__ == "__main__":+ unittest.main()diff --git a/moli-cdp-smoke/tests/test_group_selection.py b/moli-cdp-smoke/tests/test_group_selection.pyindex 0d31398c5..24ee069b1 100644--- a/moli-cdp-smoke/tests/test_group_selection.py+++ b/moli-cdp-smoke/tests/test_group_selection.py@@ -30,6 +30,7 @@ class GroupSelectionTests(unittest.TestCase):self.assertIn("runtime-exception", DEFAULT_GROUP_NAMES)self.assertIn("file-chooser", DEFAULT_GROUP_NAMES)self.assertIn("inspector-routing", DEFAULT_GROUP_NAMES)+ self.assertIn("cdp-ordering", DEFAULT_GROUP_NAMES)self.assertIn("navigation-outcomes", DEFAULT_GROUP_NAMES)self.assertIn("media-error", DEFAULT_GROUP_NAMES)self.assertIn("locale-timezone-inputs", DEFAULT_GROUP_NAMES)