42 lines
1.6 KiB
Rust
42 lines
1.6 KiB
Rust
use goose::tool_monitor::RepetitionInspector;
|
|
use rmcp::model::CallToolRequestParam;
|
|
use rmcp::object;
|
|
|
|
// This test targets RepetitionInspector::check_tool_call
|
|
// It verifies that:
|
|
// - consecutive identical tool calls are allowed up to max_repetitions times
|
|
// - the (max_repetitions + 1)th identical call is denied (returns false)
|
|
// - changing the parameters resets the repetition count and allows the call
|
|
#[test]
|
|
fn test_repetition_inspector_denies_after_exceeding_and_resets_on_param_change() {
|
|
// Allow at most 2 consecutive identical calls
|
|
let mut inspector = RepetitionInspector::new(Some(2));
|
|
|
|
// First identical call → allowed
|
|
let call_v1 = CallToolRequestParam {
|
|
name: "fetch_user".into(),
|
|
arguments: Some(object!({"id": 123})),
|
|
};
|
|
assert!(inspector.check_tool_call(call_v1.clone()));
|
|
|
|
// Second identical call → still allowed (at limit)
|
|
assert!(inspector.check_tool_call(call_v1.clone()));
|
|
|
|
// Third identical call → should be denied (exceeds limit)
|
|
assert!(!inspector.check_tool_call(call_v1.clone()));
|
|
|
|
// Change parameters; this should reset the consecutive counter
|
|
let call_v2 = CallToolRequestParam {
|
|
name: "fetch_user".into(),
|
|
arguments: Some(object!({"id": 456})),
|
|
};
|
|
|
|
assert!(inspector.check_tool_call(call_v2.clone()));
|
|
|
|
// Another identical call with new params → allowed (second in a row for this variant)
|
|
assert!(inspector.check_tool_call(call_v2.clone()));
|
|
|
|
// One more identical call with new params → denied again
|
|
assert!(!inspector.check_tool_call(call_v2));
|
|
}
|