feat: add phase1 task planner flow
This commit is contained in:
41
tests/planner_test.rs
Normal file
41
tests/planner_test.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use serde_json::json;
|
||||
use sgclaw::agent::planner::{plan_instruction, PlannerError};
|
||||
use sgclaw::pipe::Action;
|
||||
|
||||
#[test]
|
||||
fn planner_converts_baidu_search_instruction_into_three_steps() {
|
||||
let plan = plan_instruction("打开百度搜索天气").unwrap();
|
||||
|
||||
assert_eq!(plan.summary, "已在百度搜索天气");
|
||||
assert_eq!(plan.steps.len(), 3);
|
||||
assert_eq!(plan.steps[0].action, Action::Navigate);
|
||||
assert_eq!(
|
||||
plan.steps[0].params,
|
||||
json!({ "url": "https://www.baidu.com" })
|
||||
);
|
||||
assert_eq!(plan.steps[1].action, Action::Type);
|
||||
assert_eq!(
|
||||
plan.steps[1].params,
|
||||
json!({ "selector": "#kw", "text": "天气", "clear_first": true })
|
||||
);
|
||||
assert_eq!(plan.steps[2].action, Action::Click);
|
||||
assert_eq!(plan.steps[2].params, json!({ "selector": "#su" }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn planner_supports_baidu_search_variant_with_conjunction() {
|
||||
let plan = plan_instruction("打开百度并搜索电网调度").unwrap();
|
||||
|
||||
assert_eq!(plan.summary, "已在百度搜索电网调度");
|
||||
assert_eq!(plan.steps[1].params["text"], "电网调度");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn planner_rejects_unrelated_instruction() {
|
||||
let err = plan_instruction("打开谷歌搜索天气").unwrap_err();
|
||||
|
||||
assert_eq!(
|
||||
err,
|
||||
PlannerError::UnsupportedInstruction("打开谷歌搜索天气".to_string())
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user