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: fix macOS workspace test failures
ldm0261b4f30520e
diff --git a/moli-cookie-import/src/sqlite.rs b/moli-cookie-import/src/sqlite.rsindex ef202d31a..57764d665 100644--- a/moli-cookie-import/src/sqlite.rs+++ b/moli-cookie-import/src/sqlite.rs@@ -1,4 +1,8 @@-use std::{fs, io::ErrorKind, path::Path};+use std::{+ fs,+ io::ErrorKind,+ path::{Path, PathBuf},+};use anyhow::{Context, Result};use rusqlite::{Connection, OpenFlags};@@ -20,8 +24,7 @@ impl SqliteSnapshot {fs::copy(source, &database).with_context(|| format!("failed to snapshot {label} `{}`", source.display()))?;for suffix in ["-wal", "-shm"] {- let mut companion = source.as_os_str().to_owned();- companion.push(suffix);+ let companion = companion_path(source, suffix);match fs::copy(&companion,directory.path().join(format!("database.sqlite{suffix}")),@@ -30,10 +33,7 @@ impl SqliteSnapshot {Err(error) if error.kind() == ErrorKind::NotFound => {}Err(error) => {return Err(error).with_context(|| {- format!(- "failed to snapshot {label} `{}`",- Path::new(&companion).display()- )+ format!("failed to snapshot {label} `{}`", companion.display())});}}@@ -47,6 +47,12 @@ impl SqliteSnapshot {}}+fn companion_path(source: &Path, suffix: &str) -> PathBuf {+ let mut companion = source.as_os_str().to_owned();+ companion.push(suffix);+ companion.into()+}+#[cfg(test)]mod tests {use super::*;@@ -56,10 +62,37 @@ mod tests {check_wal_snapshot(Path::new("cookies.sqlite"))}+ #[test]+ fn snapshot_reads_wal_with_unicode_file_names() -> Result<()> {+ check_wal_snapshot(Path::new("cookies-浏览器.sqlite"))+ }+#[cfg(unix)]#[test]+ fn companion_paths_preserve_non_utf8_file_names() {+ use std::os::unix::ffi::OsStrExt;++ // Check byte preservation without requiring the filesystem to accept+ // invalid UTF-8 names: APFS rejects them before SQLite can open a file.+ let source = Path::new(std::ffi::OsStr::from_bytes(b"cookies-\xff.sqlite"));+ for (suffix, expected) in [+ ("-wal", b"cookies-\xff.sqlite-wal"),+ ("-shm", b"cookies-\xff.sqlite-shm"),+ ] {+ assert_eq!(+ companion_path(source, suffix).as_os_str().as_bytes(),+ expected+ );+ }+ }++ // Apple's filesystems require UTF-8 names. Keep the real non-UTF-8 I/O+ // coverage on Unix platforms that support such names as well.+ #[cfg(all(unix, not(target_vendor = "apple")))]+ #[test]fn snapshot_preserves_non_utf8_paths_when_finding_wal_files() -> Result<()> {use std::os::unix::ffi::OsStrExt;+check_wal_snapshot(Path::new(std::ffi::OsStr::from_bytes(b"cookies-\xff.sqlite",)))diff --git a/moli-curl/src/proxy.rs b/moli-curl/src/proxy.rsindex 8e2131dfb..0288698d2 100644--- a/moli-curl/src/proxy.rs+++ b/moli-curl/src/proxy.rs@@ -519,7 +519,10 @@ mod tests {#[test]fn no_proxy_routes_match_libcurl() {- use std::{net::TcpListener, time::Duration};+ use std::{+ net::TcpListener,+ time::{Duration, Instant},+ };use curl::easy::{Easy, List};@@ -576,7 +579,23 @@ mod tests {assert!(connected_port == origin_port || connected_port == proxy_port);let curl_uses_proxy = connected_port == proxy_port;let listener = if curl_uses_proxy { &proxy } else { &origin };- let _connection = listener.accept().unwrap();+ // A completed client connect can precede the listener's+ // accept readiness on macOS. Bound that handoff explicitly.+ let deadline = Instant::now() + Duration::from_secs(2);+ let _connection = loop {+ match listener.accept() {+ Ok(connection) => break connection,+ Err(error)+ if error.kind() == std::io::ErrorKind::WouldBlock+ && Instant::now() < deadline =>+ {+ std::thread::sleep(Duration::from_millis(1));+ }+ Err(error) => {+ panic!("accept {host} with NO_PROXY={no_proxy:?}: {error}")+ }+ }+ };for (scheme, proxy_env) in [("http", "http_proxy"),diff --git a/moli-layout/tests/phase4_layout_contract.rs b/moli-layout/tests/phase4_layout_contract.rsindex ed1f8ac1b..f77a572fa 100644--- a/moli-layout/tests/phase4_layout_contract.rs+++ b/moli-layout/tests/phase4_layout_contract.rs@@ -1564,9 +1564,28 @@ fn inline_blocks_use_their_internal_last_line_baseline_and_overflow_fallback() {.primary.insert(5, nav_item_style(BLUE, 19.0, Overflow::Hidden));let fallback = render(&source, &mut styles, 300, 100);- assert_close(rect(&fallback, RED).y, 45.0);- assert_close(rect(&fallback, GREEN).y, 45.0);- assert_close(rect(&fallback, BLUE).y, 19.0);+ let more = rect(&fallback, BLUE);+ assert_close(more.y, 19.0);+ assert_close(more.height, 42.0);+ assert_close(rect(&fallback, RED).y, rect(&fallback, GREEN).y);+ // A clipped inline-block uses its bottom margin edge as the baseline.+ // Check the adjacent text's actual baselines: its box top depends on the+ // platform font's ascent, even with an explicit font size and line height.+ let baselines = fallback+ .fragments+ .iter()+ .filter_map(|fragment| match fragment {+ PaintFragment::GlyphRun(run) => run.glyphs_in_surface().first().map(|glyph| glyph.y),+ _ => None,+ })+ .collect::<Vec<_>>();+ assert_eq!(+ baselines.len(),+ 3,+ "each nav item should paint one text run"+ );+ assert_close(baselines[0], more.y + more.height);+ assert_close(baselines[1], more.y + more.height);}#[test]diff --git a/moli-layout/tests/phase5_output_contract.rs b/moli-layout/tests/phase5_output_contract.rsindex 300a1c654..408f34afe 100644--- a/moli-layout/tests/phase5_output_contract.rs+++ b/moli-layout/tests/phase5_output_contract.rs@@ -788,7 +788,9 @@ fn scrollbar_feedback_rebreaks_the_reused_inline_layout_at_its_final_width() {height: length(40.0),},overflow: Point {- x: Overflow::Scroll,+ // Only vertical feedback is needed to narrow the text.+ // Horizontal overflow depends on platform font advances.+ x: Overflow::Hidden,y: Overflow::Scroll,},..Style::default()@@ -800,7 +802,7 @@ fn scrollbar_feedback_rebreaks_the_reused_inline_layout_at_its_final_width() {assert_eq!(feedback.metrics.numeric_layout_pass_count, 2);assert_eq!(feedback.element_metrics_for_source(1).unwrap().client_size,- moli_layout::LayoutSize::new(85.0, 25.0),+ moli_layout::LayoutSize::new(85.0, 40.0),);let feedback_text = feedback.client_rects_for_source(2);diff --git a/moli-renderer-v8/src/runtime/page_vm/tests/fetch_xhr.rs b/moli-renderer-v8/src/runtime/page_vm/tests/fetch_xhr.rsindex db53ee70c..4736a575b 100644--- a/moli-renderer-v8/src/runtime/page_vm/tests/fetch_xhr.rs+++ b/moli-renderer-v8/src/runtime/page_vm/tests/fetch_xhr.rs@@ -3703,6 +3703,10 @@ fn spawn_repeated_synchronous_xhr_server(}Err(error) => panic!("accept repeated synchronous XHR: {error}"),};+ // Accepted sockets inherit nonblocking mode on macOS.+ stream+ .set_nonblocking(false)+ .expect("use blocking synchronous XHR request I/O");stream.set_read_timeout(Some(Duration::from_secs(2))).expect("bound synchronous XHR request read");diff --git a/moli-renderer-v8/src/runtime/phase_one/document_write_resource_tests.rs b/moli-renderer-v8/src/runtime/phase_one/document_write_resource_tests.rsindex 4c894bcb9..1c2101195 100644--- a/moli-renderer-v8/src/runtime/phase_one/document_write_resource_tests.rs+++ b/moli-renderer-v8/src/runtime/phase_one/document_write_resource_tests.rs@@ -844,6 +844,11 @@ globalThis.__documentWriteVisibleIds = ids.join("|");#[test]fn document_write_external_runaway_script_is_terminated_and_parser_recovers() {super::tests::run_phase_one_large_stack_test("document-write-script-watchdog", || {+ let _watchdog_timeout =+ crate::v8_execution_watchdog::V8ExecutionWatchdog::override_timeout_for_test(+ crate::v8_execution_watchdog::V8ExecutionWatchdogKind::ScriptTurn,+ std::time::Duration::from_millis(500),+ );let runtime = tokio::runtime::Builder::new_current_thread().enable_all().build()diff --git a/moli-renderer-v8/src/script_vm/tests/mod.rs b/moli-renderer-v8/src/script_vm/tests/mod.rsindex 72dedf026..4577f2271 100644--- a/moli-renderer-v8/src/script_vm/tests/mod.rs+++ b/moli-renderer-v8/src/script_vm/tests/mod.rs@@ -5082,7 +5082,10 @@ async fn advance_page_task_executor_until_eval_equals(expected: &str,context: &str,) {- let deadline = tokio::time::Instant::now() + std::time::Duration::from_secs(2);+ // A selected lifecycle task may perform the first real layout, including+ // CoreText font discovery on macOS. Give the complete behavior the same+ // budget as a production lifecycle task, including its follow-up events.+ let deadline = tokio::time::Instant::now() + std::time::Duration::from_secs(8);loop {let value = page.eval(expression)diff --git a/moli-renderer-v8/src/v8_execution_watchdog.rs b/moli-renderer-v8/src/v8_execution_watchdog.rsindex e5385ee6c..a2b5c9b0f 100644--- a/moli-renderer-v8/src/v8_execution_watchdog.rs+++ b/moli-renderer-v8/src/v8_execution_watchdog.rs@@ -17,13 +17,10 @@ use std::time::{Duration, Instant};use parking_lot::{Condvar, Mutex};-#[cfg(not(test))]+// Behavior tests use the production budget: native work such as CoreText's+// first font scan can exceed a shorter test-only deadline. Runaway-script+// tests select a short timeout explicitly with override_timeout_for_test.pub(crate) const SCRIPT_TURN_WATCHDOG_TIMEOUT: Duration = Duration::from_secs(8);-#[cfg(test)]-// Keep runaway-script tests substantially faster than production without-// terminating finite debug-build checkpoints merely because workspace-// nextest is concurrently running other V8-heavy processes.-pub(crate) const SCRIPT_TURN_WATCHDOG_TIMEOUT: Duration = Duration::from_secs(2);#[derive(Clone, Copy, Debug, Eq, PartialEq)]pub(crate) enum V8ExecutionWatchdogKind {