diff --git a/docs/superpowers/plans/2026-04-13-expected-domain-arg-fix.md b/docs/superpowers/plans/2026-04-13-expected-domain-arg-fix.md new file mode 100644 index 0000000..3c92e74 --- /dev/null +++ b/docs/superpowers/plans/2026-04-13-expected-domain-arg-fix.md @@ -0,0 +1,52 @@ +# Expected Domain Arg Fix Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Fix browser_script_skill_tool to pass expected_domain to wrapped JS scripts. + +**Architecture:** Insert the normalized expected_domain back into args HashMap after domain normalization, before script wrapping. + +**Tech Stack:** Rust, serde_json + +--- + +## Files + +- Modify: `src/compat/browser_script_skill_tool.rs:210` - Insert expected_domain back into args + +--- + +### Task 1: Insert expected_domain into args + +**Files:** +- Modify: `src/compat/browser_script_skill_tool.rs:210` + +- [ ] **Step 1: Add expected_domain to args after normalization** + +Edit `src/compat/browser_script_skill_tool.rs`, insert after line 209 (`eprintln!("[execute_browser_script_impl] expected_domain: {}", expected_domain);`): + +```rust + args.insert("expected_domain".to_string(), Value::String(expected_domain.clone())); +``` + +The context around line 209-211 should look like this after the edit: + +```rust + eprintln!("[execute_browser_script_impl] expected_domain: {}", expected_domain); + args.insert("expected_domain".to_string(), Value::String(expected_domain.clone())); + + for required_arg in tool.args.keys() { +``` + +- [ ] **Step 2: Run tests to verify the fix** + +Run: `cargo test browser_script_skill_tool --no-fail-fast -- --nocapture` + +Expected: All tests pass, including `execute_browser_script_tool_runs_packaged_script_with_expected_domain` + +- [ ] **Step 3: Commit** + +```bash +git add src/compat/browser_script_skill_tool.rs +git commit -m "fix: pass expected_domain to wrapped browser scripts" +``` diff --git a/src/compat/browser_script_skill_tool.rs b/src/compat/browser_script_skill_tool.rs index caec565..3450aa3 100644 --- a/src/compat/browser_script_skill_tool.rs +++ b/src/compat/browser_script_skill_tool.rs @@ -207,6 +207,7 @@ fn execute_browser_script_impl( } }; eprintln!("[execute_browser_script_impl] expected_domain: {}", expected_domain); + args.insert("expected_domain".to_string(), Value::String(expected_domain.clone())); for required_arg in tool.args.keys() { if !args.contains_key(required_arg) { @@ -233,6 +234,8 @@ fn execute_browser_script_impl( let wrapped_script = wrap_browser_script(&script_body, &Value::Object(args.clone())); eprintln!("[execute_browser_script_impl] 包装后脚本长度: {} 字节", wrapped_script.len()); + eprintln!("[execute_browser_script_impl] 包装后脚本前500字符: {}", + if wrapped_script.len() > 500 { &wrapped_script[..500] } else { &wrapped_script }); eprintln!("[execute_browser_script_impl] 调用 browser_tool.invoke(Action::Eval)..."); let target_url = format!("http://{}", expected_domain); diff --git a/tests/browser_script_skill_tool_test.rs b/tests/browser_script_skill_tool_test.rs index 264b694..b75b8ed 100644 --- a/tests/browser_script_skill_tool_test.rs +++ b/tests/browser_script_skill_tool_test.rs @@ -105,7 +105,8 @@ async fn execute_browser_script_tool_runs_packaged_script_with_expected_domain() .. } if action == &Action::Eval && security.expected_domain == "www.zhihu.com" - && params["script"].as_str().unwrap().contains("const args = {\"top_n\":\"10\"};") + && params["script"].as_str().unwrap().contains("\"expected_domain\":\"www.zhihu.com\"") + && params["script"].as_str().unwrap().contains("\"top_n\":\"10\"") && params["script"].as_str().unwrap().contains("source: \"packaged script\"") )); } @@ -278,7 +279,8 @@ return { .. } if action == &Action::Eval && security.expected_domain == "www.zhihu.com" - && params["script"].as_str().unwrap().contains("const args = {\"top_n\":\"10\"};") + && params["script"].as_str().unwrap().contains("\"expected_domain\":\"www.zhihu.com\"") + && params["script"].as_str().unwrap().contains("\"top_n\":\"10\"") && params["script"].as_str().unwrap().contains("return {") )); } @@ -360,7 +362,8 @@ return { .. } if action == &Action::Eval && security.expected_domain == "www.zhihu.com" - && params["script"].as_str().unwrap().contains("const args = {\"top_n\":\"10条\"};") + && params["script"].as_str().unwrap().contains("\"expected_domain\":\"www.zhihu.com\"") + && params["script"].as_str().unwrap().contains("\"top_n\":\"10条\"") && params["script"].as_str().unwrap().contains("rows: [[1, \"标题\", args.top_n]]") )); } @@ -444,7 +447,8 @@ return { .. } if action == &Action::Eval && security.expected_domain == "www.zhihu.com" - && params["script"].as_str().unwrap().contains("const args = {\"period\":\"2026-04\"};") + && params["script"].as_str().unwrap().contains("\"expected_domain\":\"www.zhihu.com\"") + && params["script"].as_str().unwrap().contains("\"period\":\"2026-04\"") && params["script"].as_str().unwrap().contains("sheet_name") )); }