diff --git a/crates/ghostlight/src/verse/run.rs b/crates/ghostlight/src/verse/run.rs index 7b78198..be4a9d8 100644 --- a/crates/ghostlight/src/verse/run.rs +++ b/crates/ghostlight/src/verse/run.rs @@ -820,30 +820,45 @@ async fn run_tick( } let spent = port.spent(); + // The act listing is the tick's report to the operator: a log that cannot + // be read ends the run after the tick's checkpoint, closed or not. + let checkpoint_closed = open.is_none(); + let acts = match acts_since(mailbox.operator_log().await, snapshot.revision) { + Some(acts) => acts, + None => { + open = Some(failed("operator_log_unavailable")); + Vec::new() + } + }; let report = TickReport { checkpoint: TickCheckpoint { tick: ordinal, - closed: open.is_none(), + closed: checkpoint_closed, cells: tick.cells.len() as u32, committed, refusals, tokens: spent.saturating_sub(spent_before), }, - acts: mailbox - .operator_log() - .await - .map(|log| { - log.into_iter() - .filter(|event| event.revision > snapshot.revision) - .collect() - }) - .unwrap_or_default(), + acts, spent, remaining: port.cap().saturating_sub(spent), }; (open.map_or(TickEnd::Closed, TickEnd::Open), Some(report)) } +/// The acts a tick committed: the operator log's events past the tick's +/// opening revision. A log that cannot be read is `None`, never an empty tick. +fn acts_since( + log: Result, MailboxError>, + since: u64, +) -> Option> { + log.ok().map(|log| { + log.into_iter() + .filter(|event| event.revision > since) + .collect() + }) +} + /// The tick document for `ordinal`: the open one a run left, or a new one /// frozen from a cover derived now. An open tick the world has moved past is /// closed as the world's first. A document already closed at the world's diff --git a/crates/ghostlight/src/verse/run/tests.rs b/crates/ghostlight/src/verse/run/tests.rs index fab6367..0698484 100644 --- a/crates/ghostlight/src/verse/run/tests.rs +++ b/crates/ghostlight/src/verse/run/tests.rs @@ -1037,6 +1037,30 @@ async fn a_port_opened_for_another_run_is_refused_before_anything_is_written() { assert!(verse.runs.runs(world.world_id).unwrap().is_empty()); } +#[tokio::test] +async fn an_unreadable_operator_log_is_no_tick_report() { + let (_dir, verse) = Harness::fresh().await; + verse.run_quietly(ScriptedPort::speaking(), u64::MAX, 2).await; + let log = verse.mailbox.operator_log().await.unwrap(); + assert!(log.len() >= 4, "two ticks of two cells acted"); + + // A log that cannot be read is no tick report, whatever the revision. + assert!(acts_since(Err(MailboxError::Unavailable), 0).is_none()); + assert!(acts_since(Err(MailboxError::Unavailable), u64::MAX).is_none()); + + // A log that can is cut at the tick's opening revision. + assert_eq!(acts_since(Ok(log.clone()), 0), Some(log.clone())); + let middle = log[1].revision; + let later: Vec<_> = log.iter().filter(|e| e.revision > middle).cloned().collect(); + assert!(!later.is_empty() && later.len() < log.len()); + assert_eq!(acts_since(Ok(log.clone()), middle), Some(later)); + assert_eq!( + acts_since(Ok(log), u64::MAX), + Some(Vec::new()), + "an empty tick is a readable one" + ); +} + fn record(world: WorldId, sequence: u64) -> VerseRunRecord { VerseRunRecord { world_id: world,