self-session-live tests: the journal's idle seconds and the wake for a waiting brief

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-31 16:09:23 +01:00
commit 6d210bd3f2
2 changed files with 10 additions and 0 deletions

View file

@ -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);

View file

@ -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);