Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
refactor(test): share CDP completion with renderer events
ldm04a5e28d119bc
diff --git a/moli-protocol/src/domains/accessibility/tests.rs b/moli-protocol/src/domains/accessibility/tests.rsindex 077fb5aae..647f20c25 100644--- a/moli-protocol/src/domains/accessibility/tests.rs+++ b/moli-protocol/src/domains/accessibility/tests.rs@@ -7,35 +7,21 @@ use serde_json::{Value, json};async fn complete_pending_command_task_for_test(ctx: &mut TestContext,- mut pending: crate::conn::PendingCdpCommandDispatch,+ pending: crate::conn::PendingCdpCommandDispatch,) -> (Vec<Value>, Vec<CdpSchedulerEvent>) {- loop {- let completed = pending.wait().await;- match ctx.conn.complete_pending_command_dispatch(completed).await {- CdpCommandTaskStep::Pending(next) => pending = *next,- CdpCommandTaskStep::Complete(outcome) => {- return ctx.route_completed_command_outcome_for_test(outcome).await;- }- }- }+ ctx.complete_command_task_step_with_events_for_test(CdpCommandTaskStep::Pending(Box::new(+ pending,+ )))+ .await}async fn complete_command_task_for_test(ctx: &mut TestContext,step: CdpCommandTaskStep,) -> Vec<Value> {- match step {- CdpCommandTaskStep::Complete(outcome) => {- ctx.route_completed_command_outcome_for_test(outcome)- .await- .0- }- CdpCommandTaskStep::Pending(pending) => {- complete_pending_command_task_for_test(ctx, *pending)- .await- .0- }- }+ ctx.complete_command_task_step_with_events_for_test(step)+ .await+ .0}async fn load_page_async(ctx: &mut TestContext, html: &str) {diff --git a/moli-protocol/src/domains/css.rs b/moli-protocol/src/domains/css.rsindex 524f9925f..d0cb2300b 100644--- a/moli-protocol/src/domains/css.rs+++ b/moli-protocol/src/domains/css.rs@@ -762,17 +762,12 @@ mod tests {async fn complete_pending_command_task_for_test(ctx: &mut TestContext,- mut pending: crate::conn::PendingCdpCommandDispatch,+ pending: crate::conn::PendingCdpCommandDispatch,) -> (Vec<Value>, Vec<CdpSchedulerEvent>) {- loop {- let completed = pending.wait().await;- match ctx.conn.complete_pending_command_dispatch(completed).await {- CdpCommandTaskStep::Pending(next) => pending = *next,- CdpCommandTaskStep::Complete(outcome) => {- return ctx.route_completed_command_outcome_for_test(outcome).await;- }- }- }+ ctx.complete_command_task_step_with_events_for_test(CdpCommandTaskStep::Pending(Box::new(+ pending,+ )))+ .await}async fn with_loaded_document_async(ctx: &mut TestContext, html: &str) {diff --git a/moli-protocol/src/domains/dom/tests/mod.rs b/moli-protocol/src/domains/dom/tests/mod.rsindex a6e793b84..2808f5c6b 100644--- a/moli-protocol/src/domains/dom/tests/mod.rs+++ b/moli-protocol/src/domains/dom/tests/mod.rs@@ -249,16 +249,11 @@ async fn complete_pending_command_task_for_test(ctx: &mut TestContext,pending: PendingCdpCommandDispatch,) -> Vec<Value> {- let sent_start = ctx.sent.len();- let (messages, _) = ctx- .complete_command_task_step_for_test(CdpCommandTaskStep::Pending(Box::new(pending)))- .await;- // Native handlers publish node-path events and their response together.- // The scheduler helper returns the response while retaining journal events- // in `sent`; include that prefix so these tests inspect the wire order.- let mut published: Vec<_> = ctx.sent.drain(sent_start..).collect();- published.extend(messages);- published+ ctx.complete_command_task_step_with_events_for_test(CdpCommandTaskStep::Pending(Box::new(+ pending,+ )))+ .await+ .0}async fn complete_command_dispatch_without_legacy_fallback_for_test(@@ -268,11 +263,9 @@ async fn complete_command_dispatch_without_legacy_fallback_for_test() -> Vec<Value> {let raw = command.to_string();let step = ctx.conn.start_command_dispatch(&raw);- let sent_start = ctx.sent.len();- let (messages, _) = ctx.complete_command_task_step_for_test(step).await;- let mut published: Vec<_> = ctx.sent.drain(sent_start..).collect();- published.extend(messages);- published+ ctx.complete_command_task_step_with_events_for_test(step)+ .await+ .0}fn child_element_by_node_name<'a>(node: &'a Value, node_name: &str) -> &'a Value {diff --git a/moli-protocol/src/testing.rs b/moli-protocol/src/testing.rsindex f041ff3ac..55bb3652b 100644--- a/moli-protocol/src/testing.rs+++ b/moli-protocol/src/testing.rs@@ -607,6 +607,21 @@ impl TestContext {}}+ /// Collects the renderer events routed during completion together with+ /// the command messages. Domain tests need that prefix to inspect native+ /// notifications rather than observing only the terminal response.+ #[cfg(test)]+ pub(crate) async fn complete_command_task_step_with_events_for_test(+ &mut self,+ step: CdpCommandTaskStep,+ ) -> (Vec<Value>, Vec<CdpSchedulerEvent>) {+ let sent_start = self.sent.len();+ let (messages, scheduler_events) = self.complete_command_task_step_for_test(step).await;+ let mut published: Vec<_> = self.sent.drain(sent_start..).collect();+ published.extend(messages);+ (published, scheduler_events)+ }+#[cfg(test)]pub(crate) async fn complete_command_task_step_for_test(&mut self,