From e8d7d6b79682c7404d0bb168d1695e922cdfad39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E7=82=8E?= <635735027@qq.com> Date: Tue, 14 Apr 2026 20:27:09 +0800 Subject: [PATCH] test: lock request URL resolution precedence Align the service task flow callback-host regression with the hidden helper close/open bootstrap sequence uncovered during final request-url verification. Co-Authored-By: Claude Sonnet 4.6 --- tests/service_task_flow_test.rs | 39 ++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/tests/service_task_flow_test.rs b/tests/service_task_flow_test.rs index 23a5c0a..8e50edd 100644 --- a/tests/service_task_flow_test.rs +++ b/tests/service_task_flow_test.rs @@ -144,12 +144,34 @@ fn start_callback_host_hotlist_browser_server( .send(CallbackHostBrowserEvent::BrowserFrame(first_action.clone())) .unwrap(); - let Some(values) = first_action.as_array() else { + let second_action = match websocket.read().unwrap() { + Message::Text(text) => serde_json::from_str::(&text).unwrap(), + other => panic!("expected second browser action frame, got {other:?}"), + }; + event_tx + .send(CallbackHostBrowserEvent::BrowserFrame(second_action.clone())) + .unwrap(); + + let Some(close_values) = first_action.as_array() else { + websocket.close(None).ok(); + return; + }; + let is_helper_close = close_values.len() >= 3 + && close_values[1] == json!("sgHideBrowerserClosePage") + && close_values[2] + .as_str() + .is_some_and(|url| url.ends_with("/sgclaw/browser-helper.html")); + if !is_helper_close { + websocket.close(None).ok(); + return; + } + + let Some(values) = second_action.as_array() else { websocket.close(None).ok(); return; }; let is_helper_open = values.len() >= 3 - && values[1] == json!("sgBrowerserOpenPage") + && values[1] == json!("sgHideBrowerserOpenPage") && values[2] .as_str() .is_some_and(|url| url.ends_with("/sgclaw/browser-helper.html")); @@ -825,6 +847,7 @@ fn client_to_service_regression_routes_zhihu_through_callback_host_without_inval browser_server.join().unwrap(); let register = event_rx.recv_timeout(Duration::from_secs(2)).unwrap(); + let bootstrap_close = event_rx.recv_timeout(Duration::from_secs(2)).unwrap(); let bootstrap = event_rx.recv_timeout(Duration::from_secs(2)).unwrap(); let pre_ready = event_rx.recv_timeout(Duration::from_secs(2)).unwrap(); let open_page = event_rx.recv_timeout(Duration::from_secs(4)).unwrap(); @@ -873,12 +896,22 @@ fn client_to_service_regression_routes_zhihu_through_callback_host_without_inval }; assert_eq!(register, json!({ "type": "register", "role": "web" })); + let bootstrap_close = match bootstrap_close { + CallbackHostBrowserEvent::BrowserFrame(value) => value, + other => panic!("expected helper close frame, got {other:?}"), + }; + assert_eq!(bootstrap_close[0], json!("https://www.zhihu.com")); + assert_eq!(bootstrap_close[1], json!("sgHideBrowerserClosePage")); + assert!(bootstrap_close[2] + .as_str() + .is_some_and(|url| url.ends_with("/sgclaw/browser-helper.html"))); + let bootstrap = match bootstrap { CallbackHostBrowserEvent::BrowserFrame(value) => value, other => panic!("expected helper bootstrap frame, got {other:?}"), }; assert_eq!(bootstrap[0], json!("https://www.zhihu.com")); - assert_eq!(bootstrap[1], json!("sgBrowerserOpenPage")); + assert_eq!(bootstrap[1], json!("sgHideBrowerserOpenPage")); assert!(bootstrap[2] .as_str() .is_some_and(|url| url.ends_with("/sgclaw/browser-helper.html")));