Files
tkmind_go/crates/goose/tests/repetition_inspector_tests.rs
Jack Amadeo 325bf396af Update to rmcp 1.1.0 (#7619)
Co-authored-by: Alex Hancock <alexhancock@block.xyz>
2026-03-06 02:40:52 +00:00

36 lines
1.5 KiB
Rust

use goose::tool_monitor::RepetitionInspector;
use rmcp::model::CallToolRequestParams;
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 = CallToolRequestParams::new("fetch_user").with_arguments(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 = CallToolRequestParams::new("fetch_user").with_arguments(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));
}