Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
fix(cdp-smoke): validate CPU throttling capability errors
ldm0450c8f559b0e
diff --git a/moli-cdp-smoke/README.md b/moli-cdp-smoke/README.mdindex 43f50e00e..8c85f026a 100644--- a/moli-cdp-smoke/README.md+++ b/moli-cdp-smoke/README.md@@ -279,7 +279,7 @@ Covered well:JSHandle values, primitive/ElementHandle arguments, and timeout errors, plusPlaywright `page.wait_for_selector()` / `locator.wait_for()` attached,visible, hidden, detached, and enabled-click auto-wait behavior.-- Chromium inspector-protocol derived samples for `Page.domContentEventFired` before `Page.loadEventFired`, `Page.frameStartedLoading` / `Page.frameStoppedLoading`, non-empty `Page.frameAttached.parentFrameId`, `Page.getFrameTree`, dynamic and nested child-frame event fan-out across attached sessions with session-local lifecycle/disable state, `Page.navigate` fragment navigation, `Page.getAppManifest` default/loading/parsing/error/redirect/dynamic-link contracts, successful-result caching and link invalidation, plus its `Manifest` Network request and terminal lifecycle, `Page.getLayoutMetrics`, `Runtime.executionContextCreated`, `Runtime.evaluate(returnByValue)` and exception details, session-local `Input.setIgnoreInputEvents` aggregation/navigation/detach behavior, `Input.insertText` bypass, idle `Input.cancelDragging`, `Audits.issueAdded` Quirks/CSP shape, replay ordering, navigation storage reset and session-local enable/disable, `Log.entryAdded` network metadata, buffered replay ordering, session-local delivery cursors, target-shared `Log.clear`, violations-report state and validation, `IO.resolveBlob` session-local object resolution and reopenable `blob:<uuid>` streams, session-local `Performance.enable/disable`, strict time-domain transitions, disabled `Performance.getMetrics`, `Emulation.setCPUThrottlingRate`, `Profiler.start` / `Profiler.stop` CPU profiles and CPU-throttling profile workflow, error contracts, attached CDP-session profiler isolation across navigation and detach/reattach, `console.profile` / `console.profileEnd`, precise coverage / best-effort coverage including not-started error, counter reset, and detailed block coverage, `DOM.getAttributes`, `DOM.querySelector(All)` including default-depth node-path publication through ordered `DOM.setChildNodes` events, deep ancestry expansion, repeat suppression, and the chromedp `NodeReady` contract, live `DOMDebugger.getEventListeners`, session-owned event-listener breakpoint pause/re-pause/navigation/detach behavior, session-owned XHR/fetch breakpoint URL matching, synchronous pause data, navigation/child-frame/worker scope, multi-owner sequencing and detach behavior, live-node DOM mutation breakpoints for single-node and multi-child `DocumentFragment` insertion batches, connected-node removal/insertion phases with one pre-pause `DOM.childNodeRemoved`, same-value attributes and node removal with owner/peer data, parser mutation no-pause behavior, unbound-node path ordering, disable/navigation cleanup, and the `DOM.getNodeForLocation` hit-test capability boundary.+- Chromium inspector-protocol derived samples for `Page.domContentEventFired` before `Page.loadEventFired`, `Page.frameStartedLoading` / `Page.frameStoppedLoading`, non-empty `Page.frameAttached.parentFrameId`, `Page.getFrameTree`, dynamic and nested child-frame event fan-out across attached sessions with session-local lifecycle/disable state, `Page.navigate` fragment navigation, `Page.getAppManifest` default/loading/parsing/error/redirect/dynamic-link contracts, successful-result caching and link invalidation, plus its `Manifest` Network request and terminal lifecycle, `Page.getLayoutMetrics`, `Runtime.executionContextCreated`, `Runtime.evaluate(returnByValue)` and exception details, session-local `Input.setIgnoreInputEvents` aggregation/navigation/detach behavior, `Input.insertText` bypass, idle `Input.cancelDragging`, `Audits.issueAdded` Quirks/CSP shape, replay ordering, navigation storage reset and session-local enable/disable, `Log.entryAdded` network metadata, buffered replay ordering, session-local delivery cursors, target-shared `Log.clear`, violations-report state and validation, `IO.resolveBlob` session-local object resolution and reopenable `blob:<uuid>` streams, session-local `Performance.enable/disable`, strict time-domain transitions, disabled `Performance.getMetrics`, Moli's `Emulation.setCPUThrottlingRate` unsupported-rate errors and neutral resets across pages, `Profiler.start` / `Profiler.stop` CPU profiles and continued recording after rejected CPU throttling, error contracts, attached CDP-session profiler isolation across navigation and detach/reattach, `console.profile` / `console.profileEnd`, precise coverage / best-effort coverage including not-started error, counter reset, and detailed block coverage, `DOM.getAttributes`, `DOM.querySelector(All)` including default-depth node-path publication through ordered `DOM.setChildNodes` events, deep ancestry expansion, repeat suppression, and the chromedp `NodeReady` contract, live `DOMDebugger.getEventListeners`, session-owned event-listener breakpoint pause/re-pause/navigation/detach behavior, session-owned XHR/fetch breakpoint URL matching, synchronous pause data, navigation/child-frame/worker scope, multi-owner sequencing and detach behavior, live-node DOM mutation breakpoints for single-node and multi-child `DocumentFragment` insertion batches, connected-node removal/insertion phases with one pre-pause `DOM.childNodeRemoved`, same-value attributes and node removal with owner/peer data, parser mutation no-pause behavior, unbound-node path ordering, disable/navigation cleanup, and the `DOM.getNodeForLocation` hit-test capability boundary.- Raw `Input.dispatchKeyEvent` and `Input.dispatchMouseEvent` commands whose DOM handlers initiate a top-level Page replacement; both command responses must remain successful and the replacement Page must immediately accept follow-up CDP work. Focused Rust coverage separately holds the renderer ACK so the cleanup branch itself is deterministic.- Chromium-calibrated `Tracing` browser-global ownership, duplicate start and peer end errors, data-source start acknowledgement before the `Tracing.start` response, exactly-once synchronous start responses, stop-before-ack response/error ordering, response-before-data ordering, cross-session clock markers, bounded `ReportEvents`, JSON `ReturnAsStream` through `IO.read`, and owner-detach cleanup. The CPU-profiler configuration additionally requires real V8 `Profile` / `ProfileChunk` events, non-empty samples with aligned `timeDeltas`, and named hot functions across navigation replacement, dedicated/shared worker teardown, and closed page targets. The same content contract is applied to the real agent-browser profiler artifact. Proto, gzip, Perfetto, system tracing, and periodic buffer reporting remain explicit unsupported boundaries rather than mock output.- Chromium-calibrated live DOM mutation mirroring and editing: shallow/deep `DOM.getDocument` projections, `DOM.characterDataModified`, `DOM.childNodeCountUpdated`, `DOM.childNodeInserted`, `DOM.childNodeRemoved`, and event-before-response contracts for `DOM.moveTo`, `DOM.setAttributesAsText`, `DOM.setNodeName`, `DOM.setNodeValue`, and `DOM.setOuterHTML`, including same-value character-data writes, processing-instruction `xml` renaming, and returned frontend node identity.@@ -479,6 +479,9 @@ its own protocol-operation timeouts, so the wall limit is a final process-levelsafety boundary rather than the primary synchronization mechanism. Supervisedworker logs include the live `moli serve` stdout/stderr stream, so the lastrenderer messages survive even when the supervisor terminates a wedged worker.+For failed workers, the supervisor prints the saved error/traceback before the+log tail, so CI output includes the cause even when the worker log only reports+the exception type. The result JSON and summary retain the same diagnostics.External-client groups whose binaries or dependency environments are not ownedby this project remain explicit integration runs.diff --git a/moli-cdp-smoke/moli_cdp_smoke/groups/chromium_cdp.py b/moli-cdp-smoke/moli_cdp_smoke/groups/chromium_cdp.pyindex ead129401..27365c1c4 100644--- a/moli-cdp-smoke/moli_cdp_smoke/groups/chromium_cdp.py+++ b/moli-cdp-smoke/moli_cdp_smoke/groups/chromium_cdp.py@@ -40,9 +40,9 @@ async def run_chromium_cdp_group(state: SmokeState) -> None:await _verify_chromium_io_resolve_blob_sample(state)await _verify_chromium_performance_enable_sample(state)await _verify_chromium_performance_metrics_sample(state)- await _verify_chromium_cpu_throttling_multiple_pages_sample(state)+ await _verify_cpu_throttling_capability_multiple_pages_sample(state)await _verify_chromium_profiler_cpu_profile_sample(state)- await _verify_chromium_profiler_cpu_profile_with_throttling_sample(state)+ await _verify_profiler_after_rejected_cpu_throttling_sample(state)await _verify_chromium_profiler_stop_without_start_sample(state)await _verify_chromium_profiler_sampling_interval_contract_sample(state)await _verify_chromium_profiler_enable_disable_contract_sample(state)@@ -3790,7 +3790,7 @@ async def _verify_chromium_performance_metrics_sample(state: SmokeState) -> Nonestate.record("chromium_performance_metrics_sample")-async def _verify_chromium_cpu_throttling_multiple_pages_sample(state: SmokeState) -> None:+async def _verify_cpu_throttling_capability_multiple_pages_sample(state: SmokeState) -> None:await _navigate_with_cdp_until_dom_ready(state, f"{state.fixture}/plain")second_page = await state.context.new_page()second_cdp = await state.context.new_cdp_session(second_page)@@ -3800,20 +3800,28 @@ async def _verify_chromium_cpu_throttling_multiple_pages_sample(state: SmokeStatwait_until="load",timeout=10_000,)- await state.cdp.send("Emulation.setCPUThrottlingRate", {"rate": 2.0})- await second_cdp.send("Emulation.setCPUThrottlingRate", {"rate": 3.0})- await state.cdp.send("Emulation.setCPUThrottlingRate", {"rate": 1.0})- await second_cdp.send("Emulation.setCPUThrottlingRate", {"rate": 1.0})+ # Moli supports disabling throttling, but cannot throttle execution.+ # A successful no-op here would mislead clients about the CPU rate.+ for cdp, rate in [(state.cdp, 2.0), (second_cdp, 3.0)]:+ error = await _send_cdp_expect_optional_error(+ cdp, "Emulation.setCPUThrottlingRate", {"rate": rate}+ )+ if not error or "CPU throttling is not supported" not in str(error):+ raise SmokeError(f"CPU rate {rate} should report unsupported: {error}")+ for neutral_rate in [1.0, 0.5, 0.0, -1.0]:+ result = await cdp.send("Emulation.setCPUThrottlingRate", {"rate": neutral_rate})+ assert_equal(result, {}, f"CPU rate {neutral_rate} disables throttling")+ result = await cdp.send("Runtime.evaluate", {"expression": "1 + 1", "returnByValue": True})+ assert_equal(result.get("result", {}).get("value"), 2, "page remains usable after rejected throttling")finally:await second_page.close()- state.record("chromium_cpu_throttling_multiple_pages_sample")+ state.record("cpu_throttling_capability_multiple_pages_sample")async def _verify_chromium_profiler_cpu_profile_sample(state: SmokeState) -> None:await _navigate_with_cdp_until_dom_ready(state, f"{state.fixture}/plain")await state.cdp.send("Profiler.enable")await state.cdp.send("Profiler.setSamplingInterval", {"interval": 100})- await state.cdp.send("Emulation.setCPUThrottlingRate", {"rate": 2.0})await state.cdp.send("Profiler.start")try:burn = await state.cdp.send(@@ -3840,7 +3848,6 @@ async def _verify_chromium_profiler_cpu_profile_sample(state: SmokeState) -> Non)profile_result = await state.cdp.send("Profiler.stop")finally:- await state.cdp.send("Emulation.setCPUThrottlingRate", {"rate": 1.0})await state.cdp.send("Profiler.disable")profile = profile_result.get("profile") or {}@@ -3855,28 +3862,31 @@ async def _verify_chromium_profiler_cpu_profile_sample(state: SmokeState) -> Nonstate.record("chromium_profiler_cpu_profile_sample")-async def _verify_chromium_profiler_cpu_profile_with_throttling_sample(state: SmokeState) -> None:+async def _verify_profiler_after_rejected_cpu_throttling_sample(state: SmokeState) -> None:await _navigate_with_cdp_until_dom_ready(state, f"{state.fixture}/plain?profiler-cpu-throttling")- await state.cdp.send("Emulation.setCPUThrottlingRate", {"rate": 4.0})await state.cdp.send("Profiler.enable")await state.cdp.send("Profiler.setSamplingInterval", {"interval": 100})await state.cdp.send("Profiler.start")try:+ error = await _send_cdp_expect_optional_error(+ state.cdp, "Emulation.setCPUThrottlingRate", {"rate": 4.0}+ )+ if not error or "CPU throttling is not supported" not in str(error):+ raise SmokeError(f"CPU throttling while profiling should report unsupported: {error}")burn = await state.cdp.send("Runtime.evaluate",{"expression": """(() => {- function chromiumProfilerThrottledWork() {+ function profilerWorkAfterRejectedThrottle() {let count = 0;const limit = 10000000;const target = Date.now() + 1000;for (let i = 0; i < limit && Date.now() < target; ++i)count += i;- window.__chromiumProfilerThrottledCount = count;return count >= 0;}- return chromiumProfilerThrottledWork();+ return profilerWorkAfterRejectedThrottle();})()""","returnByValue": True,@@ -3885,21 +3895,20 @@ async def _verify_chromium_profiler_cpu_profile_with_throttling_sample(state: Smassert_equal(burn.get("result", {}).get("value"),True,- "Chromium Profiler throttled CPU work sample",+ "Profiler work after rejected CPU throttling",)profile_result = await state.cdp.send("Profiler.stop")finally:- await state.cdp.send("Emulation.setCPUThrottlingRate", {"rate": 1.0})await state.cdp.send("Profiler.disable")profile = profile_result.get("profile") or {}nodes = profile.get("nodes") or []if not isinstance(nodes, list) or not nodes:- raise SmokeError(f"Profiler.stop should return non-empty throttled profile nodes: {profile_result}")- _assert_profile_tree_shape(profile, "Profiler throttled CPU profile")- if "chromiumProfilerThrottledWork" not in _profile_function_names(profile):- raise SmokeError(f"Throttled CPU profile should include sampled work frame: {profile_result}")- state.record("chromium_profiler_cpu_profile_with_throttling_sample")+ raise SmokeError(f"Profiler.stop should return non-empty profile nodes after rejected throttling: {profile_result}")+ _assert_profile_tree_shape(profile, "Profiler after rejected CPU throttling")+ if "profilerWorkAfterRejectedThrottle" not in _profile_function_names(profile):+ raise SmokeError(f"CPU profile after rejected throttling should include sampled work frame: {profile_result}")+ state.record("profiler_after_rejected_cpu_throttling_sample")async def _verify_chromium_profiler_stop_without_start_sample(state: SmokeState) -> None:diff --git a/moli-cdp-smoke/moli_cdp_smoke/supervisor.py b/moli-cdp-smoke/moli_cdp_smoke/supervisor.pyindex baef20d3b..ea26131f6 100644--- a/moli-cdp-smoke/moli_cdp_smoke/supervisor.py+++ b/moli-cdp-smoke/moli_cdp_smoke/supervisor.py@@ -381,6 +381,11 @@ async def run_supervisor(args: argparse.Namespace) -> tuple[int, dict[str, Any]]for outcome in outcomes:if outcome.passed or outcome.status == "skipped":continue+ if outcome.error:+ print(+ f"\n--- {outcome.job.label} ({outcome.status}) error ---\n{outcome.error}",+ file=sys.stderr,+ )print(f"\n--- {outcome.job.label} ({outcome.status}) log tail ---\n"f"{_log_tail(outcome.log_path)}",diff --git a/moli-cdp-smoke/tests/test_supervisor.py b/moli-cdp-smoke/tests/test_supervisor.pyindex 7b9b31a57..51af6e9c0 100644--- a/moli-cdp-smoke/tests/test_supervisor.py+++ b/moli-cdp-smoke/tests/test_supervisor.py@@ -1,11 +1,13 @@from __future__ import annotationsimport asyncio+import ioimport jsonimport osimport sysimport tempfileimport unittest+from contextlib import redirect_stderrfrom pathlib import Pathfrom unittest.mock import patch@@ -162,6 +164,42 @@ time.sleep(30)class SupervisorSchedulingTests(unittest.IsolatedAsyncioTestCase):+ async def test_worker_error_is_reported_even_when_absent_from_log(self) -> None:+ with tempfile.TemporaryDirectory() as temporary:+ args = parse_args(["--group", "protocol", "--output-dir", temporary])+ error = (+ "CDPSession.send: Protocol error (Emulation.setCPUThrottlingRate): "+ "CPU throttling is not supported"+ )++ async def failed_worker(+ job: WorkerJob, output_dir: Path, _: float+ ) -> WorkerOutcome:+ log_path = output_dir / f"{job.file_stem}.log"+ log_path.write_text("group failed: Error\n", encoding="utf-8")+ return WorkerOutcome(+ job=job,+ status="failed",+ duration_seconds=0,+ exit_code=1,+ log_path=log_path,+ result_path=output_dir / f"{job.file_stem}.json",+ scenario_count=0,+ error=error,+ )++ stderr = io.StringIO()+ with (+ patch("moli_cdp_smoke.supervisor._run_worker_job", failed_worker),+ redirect_stderr(stderr),+ ):+ exit_code, summary = await run_supervisor(args)++ self.assertEqual(exit_code, 1)+ self.assertFalse(summary["ok"])+ self.assertIn(error, stderr.getvalue())+ self.assertIn("group failed: Error", stderr.getvalue())+async def test_jobs_bound_allows_isolated_workers_to_run_in_parallel(self) -> None:with tempfile.TemporaryDirectory() as temporary:args = parse_args(