use super::*;
#[test]
fn test_default_guard_config_values() {
let config = DefaultGuardConfig::default();
assert_eq!(config.reasoning_only_max_strikes, 3);
assert_eq!(config.empty_response_max_strikes, 3);
assert!(config.use_llm_judge);
assert_eq!(config.judge_timeout_secs, 10);
assert_eq!(config.judge_skip_threshold, 256);
assert!(!config.judge_fail_open);
assert!(config.detect_short_response);
assert_eq!(config.short_response_min_input, 128);
assert_eq!(config.short_response_max_output, 64);
assert_eq!(config.recent_user_count, 5);
}
#[tokio::test]
async fn test_text_only_with_tools_judge_disabled_returns_complete() {
let config = DefaultGuardConfig {
use_llm_judge: false,
..DefaultGuardConfig::default()
};
let guard = DefaultGuard::new(config);
let ctx = make_ctx(0, 0, true, false, false, true);
let decision = guard.on_turn(&ctx).await;
assert!(
matches!(decision, GuardDecision::Complete),
"tools + judge disabled → Complete, got: {:?}",
decision
);
}
#[tokio::test]
async fn test_text_only_short_response_without_tools_nudge() {
let long_input = "a".repeat(200);
let short_output = "done";
let guard = DefaultGuard::new(DefaultGuardConfig::default());
let ctx = make_ctx_with_text(&long_input, short_output, false, true);
let decision = guard.on_turn(&ctx).await;
match &decision {
GuardDecision::Continue { nudge } => {
let msg = nudge.as_ref().unwrap();
assert!(
msg.contains("incomplete"),
"should use short_response_nudge: {}",
msg
);
}
other => panic!(
"expected Continue for short response without tools, got: {:?}",
other
),
}
}
#[tokio::test]
async fn test_text_only_input_shorter_than_output_not_short() {
let short_input = "hi";
let long_output = "a".repeat(200);
let guard = DefaultGuard::new(DefaultGuardConfig::default());
let ctx = make_ctx_with_text(short_input, &long_output, false, true);
let decision = guard.on_turn(&ctx).await;
assert!(
matches!(decision, GuardDecision::Complete),
"short input + long output + no tools → Complete, got: {:?}",
decision
);
}
#[tokio::test]
async fn test_text_only_short_response_exact_min_input() {
let input = "a".repeat(128);
let output = "x"; let guard = DefaultGuard::new(DefaultGuardConfig::default());
let ctx = make_ctx_with_text(&input, output, false, true);
let decision = guard.on_turn(&ctx).await;
assert!(
matches!(decision, GuardDecision::Complete),
"exact min_input (128 > 128 is false) → not short → Complete, got: {:?}",
decision
);
}
#[tokio::test]
async fn test_text_only_short_response_just_above_min_input() {
let input = "a".repeat(129);
let output = "x";
let guard = DefaultGuard::new(DefaultGuardConfig::default());
let ctx = make_ctx_with_text(&input, output, false, true);
let decision = guard.on_turn(&ctx).await;
match &decision {
GuardDecision::Continue { nudge } => {
assert!(nudge.is_some(), "just above min_input → short → nudge");
}
other => panic!(
"expected Continue for just above boundary, got: {:?}",
other
),
}
}
#[tokio::test]
async fn test_text_only_not_short_response_just_below_min_input() {
let input = "a".repeat(127);
let output = "x";
let guard = DefaultGuard::new(DefaultGuardConfig::default());
let ctx = make_ctx_with_text(&input, output, false, true);
let decision = guard.on_turn(&ctx).await;
assert!(
matches!(decision, GuardDecision::Complete),
"below min_input → not short → Complete, got: {:?}",
decision
);
}
#[tokio::test]
async fn test_text_only_short_response_output_at_max() {
let input = "a".repeat(200);
let output = "a".repeat(64); let guard = DefaultGuard::new(DefaultGuardConfig::default());
let ctx = make_ctx_with_text(&input, &output, false, true);
let decision = guard.on_turn(&ctx).await;
assert!(
matches!(decision, GuardDecision::Complete),
"output at max_output → not short → Complete, got: {:?}",
decision
);
}
#[tokio::test]
async fn test_custom_nudge_messages() {
let config = DefaultGuardConfig {
reasoning_only_nudge: "custom reasoning nudge".to_string(),
empty_response_nudge: "custom empty nudge".to_string(),
..DefaultGuardConfig::default()
};
let guard = DefaultGuard::new(config);
let ctx = make_ctx(1, 0, false, true, false, false);
let decision = guard.on_turn(&ctx).await;
match &decision {
GuardDecision::Continue { nudge } => {
assert_eq!(nudge.as_deref(), Some("custom reasoning nudge"));
}
other => panic!("expected Continue, got: {:?}", other),
}
let ctx = make_ctx(0, 1, false, false, true, false);
let decision = guard.on_turn(&ctx).await;
match &decision {
GuardDecision::Continue { nudge } => {
assert_eq!(nudge.as_deref(), Some("custom empty nudge"));
}
other => panic!("expected Continue, got: {:?}", other),
}
}