focus/crates/focus-core/tests/batch_tests.rs

38 lines
1.0 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! agent 批处理规划(`plan_batches`)的集成测试。
//! Integration tests for agent batch planning (`plan_batches`).
use focus_core::agent::plan_batches;
use focus_core::model::ToolCall;
use focus_core::tool::ToolEffects;
use focus_json::JsonValue;
fn tc(name: &str) -> ToolCall {
ToolCall {
id: name.into(),
name: name.into(),
arguments: JsonValue::obj(),
}
}
#[test]
fn two_reads_share_a_batch() {
let calls = vec![(tc("a"), ToolEffects::READ), (tc("b"), ToolEffects::READ)];
let batches = plan_batches(&calls);
assert_eq!(batches, vec![vec![0, 1]]);
}
#[test]
fn write_isolated() {
let calls = vec![
(tc("a"), ToolEffects::READ),
(tc("b"), ToolEffects::WRITE),
(tc("c"), ToolEffects::READ),
];
let batches = plan_batches(&calls);
// a、c 一起读b 单独写。
// a+c read together, b write alone
assert_eq!(batches.len(), 2);
assert!(batches.iter().any(|b| b == &vec![0, 2]));
assert!(batches.iter().any(|b| b == &vec![1]));
}