use crate::brain::agent::service::AgentService;
use crate::brain::agent::service::tool_loop::check_intra_turn_time_marker;
use std::fs;
use tempfile::TempDir;
use uuid::Uuid;
#[tokio::test]
async fn subagent_or_worker_turn_ingress_carries_time_marker() {
let dir = TempDir::new().unwrap();
let user_md = dir.path().join("USER.md");
fs::write(&user_md, "Timezone: Europe/Paris\n").unwrap();
let session_id = Uuid::new_v4();
let prompt = "Examine repo health and run diagnostics";
let augmented = AgentService::augment_user_message(session_id, prompt, Some(dir.path())).await;
assert!(augmented.starts_with("[Current time: "));
assert!(augmented.contains("UTC"));
assert!(augmented.contains("user:"));
assert!(augmented.ends_with(prompt));
}
#[test]
fn intra_turn_evaluator_handles_subagent_and_compaction_cadence() {
let start = chrono::Utc::now();
let interval = 900u64;
assert!(
check_intra_turn_time_marker(
start,
start + chrono::Duration::seconds(300),
interval,
None
)
.is_none()
);
let after_15m = start + chrono::Duration::seconds(901);
let marker = check_intra_turn_time_marker(start, after_15m, interval, None);
assert!(marker.is_some());
let (notice, updated) = marker.unwrap();
assert_eq!(updated, after_15m);
assert!(notice.starts_with("[System: Current time: "));
assert!(notice.contains("UTC"));
assert!(
check_intra_turn_time_marker(
updated,
updated + chrono::Duration::seconds(60),
interval,
None
)
.is_none()
);
let next_cycle = updated + chrono::Duration::seconds(905);
let marker2 = check_intra_turn_time_marker(updated, next_cycle, interval, None);
assert!(marker2.is_some());
let (notice2, updated2) = marker2.unwrap();
assert_eq!(updated2, next_cycle);
assert!(notice2.starts_with("[System: Current time: "));
}