From 6d210bd3f27b718f7ea455423176b474486322b9 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 31 Oct 2026 16:09:23 +0100 Subject: [PATCH] self-session-live tests: the journal's idle seconds and the wake for a waiting brief Co-Authored-By: Claude Sonnet 5.5 --- crates/mind-body/src/self_run/decide/tests.rs | 8 ++++++++ crates/mind-body/src/self_run/tests.rs | 2 ++ 2 files changed, 10 insertions(+) diff --git a/crates/mind-body/src/self_run/decide/tests.rs b/crates/mind-body/src/self_run/decide/tests.rs index b5ba1da..615bd01 100644 --- a/crates/mind-body/src/self_run/decide/tests.rs +++ b/crates/mind-body/src/self_run/decide/tests.rs @@ -82,6 +82,14 @@ fn a_result_ends_a_turn_and_never_closes_the_input_while_a_brief_waits_or_the_ca assert_eq!(last(vec![(RESULT, 0), (Event::Inbox { pending: true }, 10), (Event::Told, 10), (Event::Tick, 11)]), Action::None); let waiting = |seconds: i64| last(vec![(RESULT, 0), (Event::Inbox { pending: true }, 10), (Event::Tick, seconds)]); assert_eq!(waiting(TTL_1H_S * 3), Action::WriteTells, "a waiting brief outranks the cache's end"); + // The loop is woken at once for a waiting brief, and for a finished flush, not at the cache's end. + let (state, _) = run(vec![(RESULT, 5), (Event::Inbox { pending: true }, 6)]); + assert_eq!(next_deadline(&state), Some(t(5))); + let (state, _) = run(vec![(RESULT, 5), (Event::Tick, 5 + TTL_1H_S - TTL_MARGIN_S)]); + assert_eq!(next_deadline(&state), Some(t(5 + TTL_1H_S - TTL_MARGIN_S + GRACE)), "the flush's own grace: the turn runs"); + let (state, _) = run(vec![(RESULT, 5), (Event::Tick, 5 + TTL_1H_S - TTL_MARGIN_S), (SHORT_RESULT, 6 + TTL_1H_S)]); + assert_eq!(state.idle_s(t(10 + TTL_1H_S)), Some(4)); + assert_eq!(working().idle_s(t(1)), None); // Mid-turn, a brief is the hook's: the actuator writes nothing, and the next result comes. assert_eq!(last(vec![(Event::Inbox { pending: true }, 10)]), Action::None); assert_eq!(last(vec![(Event::Inbox { pending: true }, 10), (RESULT, 20), (Event::Tick, 20)]), Action::WriteTells); diff --git a/crates/mind-body/src/self_run/tests.rs b/crates/mind-body/src/self_run/tests.rs index 78e51bc..e48a52d 100644 --- a/crates/mind-body/src/self_run/tests.rs +++ b/crates/mind-body/src/self_run/tests.rs @@ -1603,6 +1603,8 @@ fn the_session_ends_where_the_cache_would_be_evicted_with_a_flush_and_a_waiting_ let flush_at = hour.events.iter().position(|event| matches!(event, Event::Wrote(line) if line.contains(FLUSH_MESSAGE))).unwrap(); let closed_at = hour.events.iter().position(|event| *event == Event::InputClosed).unwrap(); assert!(flush_at < closed_at && hour.count(&Event::InputClosed) == 1, "{:?}", hour.events); + assert!(hour.out.contains("decision WriteFlush prefix 10 ttl_s 3600 idle_s 3540 inbox false +"), "{}", hour.out); // Five minutes' cache: the flush at 240 s. let short = go(vec![Out(five_minute_request("m1", 10)), Out(result_line()), Idle(239), Idle(1), Out(result_line()), Idle(1)]); assert_eq!(flushes(&short), 1);