use crate::utils::plan_files::recent_archive_in_dir;
use std::time::Duration;
#[test]
fn recent_archive_in_dir_missing_dir_is_false() {
let tmp =
std::env::temp_dir().join(format!("oc1158-missing-{}", uuid::Uuid::new_v4().simple()));
assert!(!recent_archive_in_dir(&tmp, Duration::from_secs(120)));
}
#[test]
fn recent_archive_in_dir_fresh_file_is_true() {
let tmp = std::env::temp_dir().join(format!("oc1158-fresh-{}", uuid::Uuid::new_v4().simple()));
std::fs::create_dir_all(&tmp).unwrap();
std::fs::write(tmp.join("20260101-000000.md"), "# done").unwrap();
assert!(recent_archive_in_dir(&tmp, Duration::from_secs(120)));
std::fs::remove_dir_all(&tmp).ok();
}
#[test]
fn recent_archive_in_dir_stale_file_is_false() {
let tmp = std::env::temp_dir().join(format!("oc1158-stale-{}", uuid::Uuid::new_v4().simple()));
std::fs::create_dir_all(&tmp).unwrap();
let path = tmp.join("20250101-000000.md");
std::fs::write(&path, "# done long ago").unwrap();
let f = std::fs::OpenOptions::new()
.append(true)
.open(&path)
.unwrap();
let old = std::time::SystemTime::now() - Duration::from_secs(3600);
f.set_modified(old).unwrap();
drop(f);
assert!(!recent_archive_in_dir(&tmp, Duration::from_secs(120)));
std::fs::remove_dir_all(&tmp).ok();
}
#[tokio::test]
async fn finalize_untrack_is_one_shot() {
let state = crate::channels::telegram::state::TelegramState::new();
let session_id = uuid::Uuid::new_v4();
let chat = teloxide::types::ChatId(1158);
let mid = teloxide::types::MessageId(42);
let thread: Option<teloxide::types::ThreadId> = None;
state
.set_plan_card(session_id, chat, thread, mid, "sig".to_string())
.await;
assert!(
state.plan_card(session_id).await.is_some(),
"tracked card must be visible to finalize"
);
assert_eq!(state.take_plan_card(session_id).await, Some(mid));
assert!(state.plan_card(session_id).await.is_none());
}