use ag_contracts::AgentRequestKind;
use crate::agent::instruction::{
InstructionDeliveryMode, instruction_bootstrap_key, plan_instruction_delivery,
};
#[test]
fn missing_conversation_ids_require_full_bootstrap() {
let ids = [None, Some(""), Some(" ")];
for current_id in ids {
let mode =
plan_instruction_delivery(&AgentRequestKind::SessionStart, current_id, None, false);
assert_eq!(mode, InstructionDeliveryMode::BootstrapFull);
}
}
#[test]
fn test_plan_instruction_delivery_uses_delta_only_for_matching_state() {
let persisted_instruction_conversation_id = instruction_bootstrap_key(Some("thread-123"));
let mode = plan_instruction_delivery(
&AgentRequestKind::SessionResume,
Some("thread-123"),
persisted_instruction_conversation_id.as_deref(),
false,
);
assert_eq!(mode, InstructionDeliveryMode::DeltaOnly);
}
#[test]
fn test_plan_instruction_delivery_uses_bootstrap_with_replay_after_reset() {
let persisted_instruction_conversation_id = instruction_bootstrap_key(Some("thread-123"));
let mode = plan_instruction_delivery(
&AgentRequestKind::SessionResume,
Some("thread-456"),
persisted_instruction_conversation_id.as_deref(),
true,
);
assert_eq!(mode, InstructionDeliveryMode::BootstrapWithReplay);
}
#[test]
fn test_plan_instruction_delivery_bootstraps_full_for_new_context() {
let persisted_instruction_conversation_id = instruction_bootstrap_key(Some("thread-123"));
let mode = plan_instruction_delivery(
&AgentRequestKind::SessionResume,
Some("thread-456"),
persisted_instruction_conversation_id.as_deref(),
false,
);
assert_eq!(mode, InstructionDeliveryMode::BootstrapFull);
}
#[test]
fn test_plan_instruction_delivery_bootstraps_full_for_utility_prompt() {
let persisted_instruction_conversation_id = instruction_bootstrap_key(Some("thread-123"));
let mode = plan_instruction_delivery(
&AgentRequestKind::UtilityPrompt,
Some("thread-123"),
persisted_instruction_conversation_id.as_deref(),
false,
);
assert_eq!(mode, InstructionDeliveryMode::BootstrapFull);
}
#[test]
fn legacy_or_changed_policy_keys_force_bootstrap() {
let current = instruction_bootstrap_key(Some("thread-123")).expect("key");
let stale = current.replace("v1:", "v0:");
let stale_fingerprint = "v1:0000000000000000:10:thread-123";
for key in ["thread-123", stale.as_str(), stale_fingerprint] {
let mode = plan_instruction_delivery(
&AgentRequestKind::SessionResume,
Some("thread-123"),
Some(key),
false,
);
assert_eq!(mode, InstructionDeliveryMode::BootstrapFull);
}
assert_eq!(instruction_bootstrap_key(None), None);
assert_eq!(instruction_bootstrap_key(Some(" ")), None);
assert_eq!(
instruction_bootstrap_key(Some(" thread-123 ")),
Some(current)
);
}