Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(desktop): cover native browser handoff and failure preservation

Eloi Torrentsf95a97736112
diff --git a/crates/openhuman-app/src/external_navigation.rs b/crates/openhuman-app/src/external_navigation.rs
index eda07d3eb6..a7c33f7085 100644
--- a/crates/openhuman-app/src/external_navigation.rs
+++ b/crates/openhuman-app/src/external_navigation.rs
@@ -21,22 +21,33 @@ pub fn init() -> TauriPlugin<crate::AppRuntime> {
} else {
None
};
- if webview.label() != "main" || !is_external(url, dev_url) {
- return true;
- }
- log::debug!("[external-navigation] handing main-window navigation to OS");
let app = webview.app_handle().clone();
- let target = url.to_string();
- tauri::async_runtime::spawn_blocking(move || {
- if app.opener().open_url(target, None::<&str>).is_err() {
- log::warn!("[external-navigation] OS opener failed; retained main window");
- }
- });
- false
+ handle_navigation(webview.label(), url, dev_url, move |target| {
+ app.opener().open_url(target, None::<&str>).is_ok()
+ })
})
.build()
}
+fn handle_navigation(
+ label: &str,
+ url: &Url,
+ dev_url: Option<&Url>,
+ open: impl FnOnce(String) -> bool + Send + 'static,
+) -> bool {
+ if label != "main" || !is_external(url, dev_url) {
+ return true;
+ }
+ log::debug!("[external-navigation] handing main-window navigation to OS");
+ let target = url.to_string();
+ tauri::async_runtime::spawn_blocking(move || {
+ if !open(target) {
+ log::warn!("[external-navigation] OS opener failed; retained main window");
+ }
+ });
+ false
+}
+
#[cfg(test)]
#[path = "external_navigation_tests.rs"]
mod tests;
diff --git a/crates/openhuman-app/src/external_navigation_tests.rs b/crates/openhuman-app/src/external_navigation_tests.rs
index 12519785ac..50ee72fd34 100644
--- a/crates/openhuman-app/src/external_navigation_tests.rs
+++ b/crates/openhuman-app/src/external_navigation_tests.rs
@@ -26,3 +26,31 @@ fn remote_navigation_is_external_but_app_origins_are_preserved() {
}
assert!(is_external(&dev, None));
}
+
+#[test]
+fn internal_routes_and_child_webviews_do_not_invoke_the_os_opener() {
+ for (label, href) in [
+ ("main", "tauri://localhost/#/chat"),
+ ("preview", "https://example.com/preview"),
+ ] {
+ assert!(handle_navigation(
+ label,
+ &Url::parse(href).unwrap(),
+ None,
+ |_| { panic!("an internal route or child webview must not be handed to the OS") }
+ ));
+ }
+}
+
+#[tokio::test]
+async fn external_navigation_is_cancelled_even_when_the_os_opener_fails() {
+ for opens_successfully in [true, false] {
+ let (tx, rx) = tokio::sync::oneshot::channel();
+ let url = Url::parse("https://example.com/repo/pull/1").unwrap();
+ assert!(!handle_navigation("main", &url, None, move |target| {
+ tx.send(target).unwrap();
+ opens_successfully
+ }));
+ assert_eq!(rx.await.unwrap(), url.as_str());
+ }
+}