feat: add browser script skill execution

This commit is contained in:
zyl
2026-03-30 02:15:07 +08:00
parent f7e2ff256e
commit d2c9902966
22 changed files with 1775 additions and 249 deletions

View File

@@ -8,7 +8,7 @@ use serde_json::{json, Value};
use sgclaw::security::MacPolicy;
use sgclaw::{
compat::browser_tool_adapter::ZeroClawBrowserTool,
pipe::{Action, AgentMessage, BrowserMessage, BrowserPipeTool, Timing},
pipe::{Action, AgentMessage, BrowserMessage, BrowserPipeTool, ExecutionSurfaceKind, Timing},
};
use zeroclaw::tools::Tool;
@@ -51,6 +51,17 @@ fn zeroclaw_browser_tool_schema_exposes_only_supported_safe_actions() {
assert_eq!(schema["required"], json!(["action", "expected_domain"]));
}
#[test]
fn zeroclaw_browser_tool_marks_browser_action_as_privileged_surface() {
let (_, tool) = build_adapter(vec![]);
let metadata = tool.surface_metadata();
assert_eq!(metadata.kind, ExecutionSurfaceKind::PrivilegedBrowserPipe);
assert!(metadata.privileged);
assert!(!metadata.defines_runtime_identity);
assert_eq!(metadata.guard, "mac_policy");
}
#[tokio::test]
async fn zeroclaw_browser_tool_executes_supported_actions_and_returns_observation_payload() {
let (transport, tool) = build_adapter(vec![
@@ -202,6 +213,63 @@ async fn zeroclaw_browser_tool_keeps_domain_validation_in_mac_policy() {
);
}
#[tokio::test]
async fn zeroclaw_browser_tool_normalizes_expected_domain_before_sending_command() {
let (transport, tool) = build_adapter(vec![
BrowserMessage::Response {
seq: 1,
success: true,
data: json!({ "navigated": true }),
aom_snapshot: vec![],
timing: Timing {
queue_ms: 1,
exec_ms: 11,
},
},
BrowserMessage::Response {
seq: 2,
success: true,
data: json!({ "clicked": true }),
aom_snapshot: vec![],
timing: Timing {
queue_ms: 2,
exec_ms: 12,
},
},
]);
let navigate = tool
.execute(json!({
"action": "navigate",
"expected_domain": "https://www.baidu.com/s?wd=天气",
"url": "https://www.baidu.com/s?wd=天气"
}))
.await
.unwrap();
let click = tool
.execute(json!({
"action": "click",
"expected_domain": "https://www.baidu.com/s?wd=天气",
"selector": "#su"
}))
.await
.unwrap();
let sent = transport.sent_messages();
assert!(navigate.success);
assert!(click.success);
assert!(matches!(
&sent[0],
AgentMessage::Command { security, .. }
if security.expected_domain == "www.baidu.com"
));
assert!(matches!(
&sent[1],
AgentMessage::Command { security, .. }
if security.expected_domain == "www.baidu.com"
));
}
#[tokio::test]
async fn zeroclaw_browser_tool_rejects_missing_required_action_parameters() {
let (transport, tool) = build_adapter(vec![]);