//! A mail date no message can carry, stored before the readers bounded every //! date they read (the owner's Google notice drawn as "Mon 16 Sep 2611", 14 //! Oct 2026), is put right by the reader's own re-read of the message — and //! a believable date is never moved by one. //! //! Every value is invented ([nothing-real-ever-goes-in-cotton-s-public-tree]). mod support; use rusqlite::types::Value as SqlValue; use serde_json::{json, Value}; use support::harness::Harness; use support::mcp::{call_tool, mint_token}; fn mail(key: &str, id: &str, at: &str) -> Value { json!({ "threadKey": key, "subject": "An invented notice", "sentAt": at, "body": "An invented body.", "messageId": format!("<{id}@example.invalid>"), "from": { "email": "notices@example.invalid", "name": "Invented notices" }, "to": [{ "email": "owner@example.invalid" }], }) } fn sent_at(h: &Harness) -> String { let row = h.one("SELECT sent_at FROM cotton_emails WHERE subject = 'An invented notice'", &[]).expect("the one email"); row["sent_at"].as_str().unwrap().to_string() } fn span(h: &Harness, key: &str) -> (String, String) { let row = h .one("SELECT first_at, last_at FROM cotton_email_threads WHERE external_key = ?1", &[SqlValue::Text(key.into())]) .expect("the thread"); (row["first_at"].as_str().unwrap().to_string(), row["last_at"].as_str().unwrap().to_string()) } /// RULE: a re-read of a message stored with a date outside 1900–2100 dates it /// as the re-read does, and its thread spans its messages' dates again. #[test] fn a_re_read_dates_a_message_stored_in_the_wrong_century() { let mut h = Harness::new(); let secret = mint_token(&mut h, &["read", "write"], "Claude"); call_tool(&h, &secret, "ingest_emails", json!({ "emails": [mail("notice", "notice-1", "2611-09-16T18:03:30.000Z")] })); assert_eq!(sent_at(&h), "2611-09-16T18:03:30.000Z"); assert_eq!(span(&h, "notice").1, "2611-09-16T18:03:30.000Z"); call_tool(&h, &secret, "ingest_emails", json!({ "emails": [mail("notice", "notice-1", "2025-03-24T21:03:30.000Z")] })); assert_eq!(sent_at(&h), "2025-03-24T21:03:30.000Z"); assert_eq!(span(&h, "notice"), ("2025-03-24T21:03:30.000Z".to_string(), "2025-03-24T21:03:30.000Z".to_string())); // A believable date stands: a re-read never moves it. call_tool(&h, &secret, "ingest_emails", json!({ "emails": [mail("notice", "notice-1", "2025-03-25T10:00:00.000Z")] })); assert_eq!(sent_at(&h), "2025-03-24T21:03:30.000Z"); }