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 <noreply@anthropic.com>
This commit is contained in:
木炎
2026-04-14 20:27:09 +08:00
parent bd83d92480
commit e8d7d6b796

View File

@@ -144,12 +144,34 @@ fn start_callback_host_hotlist_browser_server(
.send(CallbackHostBrowserEvent::BrowserFrame(first_action.clone())) .send(CallbackHostBrowserEvent::BrowserFrame(first_action.clone()))
.unwrap(); .unwrap();
let Some(values) = first_action.as_array() else { let second_action = match websocket.read().unwrap() {
Message::Text(text) => serde_json::from_str::<Value>(&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(); websocket.close(None).ok();
return; return;
}; };
let is_helper_open = values.len() >= 3 let is_helper_open = values.len() >= 3
&& values[1] == json!("sgBrowerserOpenPage") && values[1] == json!("sgHideBrowerserOpenPage")
&& values[2] && values[2]
.as_str() .as_str()
.is_some_and(|url| url.ends_with("/sgclaw/browser-helper.html")); .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(); browser_server.join().unwrap();
let register = event_rx.recv_timeout(Duration::from_secs(2)).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 bootstrap = event_rx.recv_timeout(Duration::from_secs(2)).unwrap();
let pre_ready = 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(); 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" })); 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 { let bootstrap = match bootstrap {
CallbackHostBrowserEvent::BrowserFrame(value) => value, CallbackHostBrowserEvent::BrowserFrame(value) => value,
other => panic!("expected helper bootstrap frame, got {other:?}"), other => panic!("expected helper bootstrap frame, got {other:?}"),
}; };
assert_eq!(bootstrap[0], json!("https://www.zhihu.com")); assert_eq!(bootstrap[0], json!("https://www.zhihu.com"));
assert_eq!(bootstrap[1], json!("sgBrowerserOpenPage")); assert_eq!(bootstrap[1], json!("sgHideBrowerserOpenPage"));
assert!(bootstrap[2] assert!(bootstrap[2]
.as_str() .as_str()
.is_some_and(|url| url.ends_with("/sgclaw/browser-helper.html"))); .is_some_and(|url| url.ends_with("/sgclaw/browser-helper.html")));