Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 38 additions & 14 deletions pkgs/id/src/world_fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ pub fn replay(
let verdict = verdict(
header,
records.as_deref(),
final_epoch_covered(&fixture.events),
final_epoch_covered(header, &fixture.events),
)?;
Ok(Replayed {
records,
Expand Down Expand Up @@ -477,7 +477,7 @@ fn replay_collecting(
let verdict = verdict(
header,
records.as_deref(),
final_epoch_covered(&fixture.events),
final_epoch_covered(header, &fixture.events),
)?;
let final_records = match records.as_deref() {
Some(text) => parse_records(text).context("the replayed records")?,
Expand Down Expand Up @@ -772,8 +772,14 @@ fn segments(events: &[FixtureEvent]) -> Result<Vec<&[FixtureEvent]>> {
/// its install, so replaying the final segment is a complete replay of
/// that epoch and its records can be compared with the header's.
#[cfg(feature = "sandbox")]
fn final_epoch_covered(events: &[FixtureEvent]) -> bool {
events.iter().any(is_install)
fn final_epoch_covered(header: &FixtureHeader, events: &[FixtureEvent]) -> bool {
let has_install = events.iter().any(is_install);
let reaches_head = events
.iter()
.rev()
.find(|event| event.sequence() != 0)
.is_some_and(|event| event.sequence() == header.current_sequence);
has_install && reaches_head
}

/// The event a replay feeds the program, or `None` for events it never sees.
Expand Down Expand Up @@ -1311,9 +1317,8 @@ mod tests {
#[test]
fn partial_fixture_covering_the_final_epoch_is_compared() {
let (runner, base) = checked_in_game();
// A partial window that still contains the last install covers
// the final epoch in full, so its records compare with the
// header's instead of reporting NotCompared.
// A front-truncated partial window still reaches the head and
// contains the last install, so its records remain comparable.
let mut live = runner.instantiate(7).unwrap();
live.update(2, b"3").unwrap();
live.update(1, b"4").unwrap();
Expand All @@ -1327,19 +1332,38 @@ mod tests {
records: Some(records),
..base.header
},
events: vec![
install(1),
input(2, 1, "0"),
install(3),
input(4, 2, "3"),
input(5, 1, "4"),
],
events: vec![install(3), input(4, 2, "3"), input(5, 1, "4")],
};
assert!(replay(&runner, 7, &partial, false).is_err());
let replayed = replay(&runner, 7, &partial, true).unwrap();
assert_eq!(replayed.verdict, Verdict::Match);
}

#[test]
fn partial_fixture_ending_before_header_sequence_is_not_compared() {
let (runner, base) = checked_in_game();
let mut live = runner.instantiate(7).unwrap();
live.update(2, b"3").unwrap();
live.update(1, b"4").unwrap();
let records =
parse_records(&String::from_utf8(live.records().unwrap().unwrap()).unwrap())
.unwrap();
let partial = Fixture {
header: FixtureHeader {
current_sequence: 5,
complete: false,
records: Some(records),
..base.header
},
// The retained window contains the final install, but ends
// before the head sequence recorded in the header.
events: vec![install(3), input(4, 2, "3")],
};

let replayed = replay(&runner, 7, &partial, true).unwrap();
assert_eq!(replayed.verdict, Verdict::NotCompared("partial history"));
}

#[test]
fn chat_before_the_install_does_not_block_replay() {
let (runner, base) = checked_in_game();
Expand Down
Loading