Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 4 additions & 6 deletions pkgs/id/benches/world_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2750,12 +2750,10 @@ fn ensure_stress_fixture(quick: bool) -> Result<StressFixture> {
/// retained window and the bench program's snapshot, then the
/// committed tail past the checkpoint. The shape mirrors what
/// `WorldCore::checkpoint_entries` writes on compaction, in the
/// legacy admin-history form (`admin_history: None`): the current
/// form's `JournalAdminHistory` has crate-private fields and no
/// public constructor, so a bench outside `id-worlds` cannot build
/// one — restore supports the legacy form explicitly, and the
/// retained window (the checkpoint's dominant term) is carried in
/// full. The retained window at these sizes serializes under the
/// legacy admin-history form (`admin_history: None`): restore
/// supports the legacy form explicitly, and the retained window
/// (the checkpoint's dominant term) is carried in full. The
/// retained window at these sizes serializes under the
/// writer's own inline bound (`MAX_CHECKPOINT_PART_BYTES`), so the
/// single inline entry is the form the writer itself would choose
/// for a checkpoint of this size without the admin window.
Expand Down
33 changes: 33 additions & 0 deletions pkgs/id/crates/id-worlds/src/world/journal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,39 @@ pub struct JournalAdminHistory {
pub(crate) complete: bool,
}

impl JournalAdminHistory {
/// Build an admin-history window for a checkpoint.
///
/// This is the public construction path for code outside
/// `id-worlds` — benches, integration tests and downstream
/// tooling writing journal fixtures (#13421): the fields stay
/// crate-private so the window's contents are only ever set
/// whole, here or by the journal writer itself. `events` is the
/// ordered sequenced and host-originated window the checkpoint
/// carries; `complete` states whether that window reaches back
/// to the start of the world's history, the same claim the
/// writer records from its own admin-history state.
pub const fn new(events: Vec<WorldEvent>, complete: bool) -> Self {
Self { events, complete }
}

/// The ordered events this window carries.
pub fn events(&self) -> &[WorldEvent] {
&self.events
}

/// Whether this window reaches back to the start of the
/// world's history.
pub const fn is_complete(&self) -> bool {
self.complete
}

/// Consume the window, returning its events.
pub fn into_events(self) -> Vec<WorldEvent> {
self.events
}
}

/// Version written in a new journal's [`JournalEntry::Created`] header.
///
/// Journal upgrade/rollback contract (issue #227): a journal is created at
Expand Down
4 changes: 2 additions & 2 deletions pkgs/id/crates/id-worlds/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ pub use hotness::{FiredSignal, HotnessBand, HotnessReport, HotnessSignal};
/// The F12.14 portal policy types (code#1068), re-exported so the
/// handle/hub portal surface names the same types the kernel checks.
pub use id_caps::portal::{PortalGrantState, PortalGrants, PortalRefusal};
pub(crate) use journal::JournalAdminHistory;
pub use journal::{
CoordinatorJournalEntry, JOURNAL_VERSION, JOURNAL_VERSION_BLOB,
JOURNAL_VERSION_CHECKPOINT_PARTS, JOURNAL_VERSION_EXECUTION_PROFILE,
JOURNAL_VERSION_JOIN_TIMES, JOURNAL_VERSION_KV, JOURNAL_VERSION_NOTIFY,
JOURNAL_VERSION_OPEN_PRESENCE, JOURNAL_VERSION_PORTALS, JOURNAL_VERSION_PROGRAM_BUNDLE,
JOURNAL_VERSION_REGION_HANDOFF, JOURNAL_VERSION_SCHEDULE_RECURRENCE,
JOURNAL_VERSION_SIGNED_PLAY, JOURNAL_VERSION_WORLD_BUDGET, JOURNAL_VERSION_WRITE_LEASE,
JournalAckMode, JournalEntry, JournalSignedMove, JournalSnapshot, JournalSnapshotSource,
JournalAckMode, JournalAdminHistory, JournalEntry, JournalSignedMove, JournalSnapshot,
JournalSnapshotSource,
MAX_JOURNAL_VERSION, TrustBasis, TrustDecision, WorldJournal, journal_version_required_by,
};
pub use metrics::{
Expand Down
79 changes: 79 additions & 0 deletions pkgs/id/tests/journal_admin_history.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//! External-construction coverage for `JournalAdminHistory` (#13421).
//!
//! Benches, integration tests and downstream tooling live outside
//! `id-worlds`; before #13421 they could not build the current-form
//! checkpoint admin history at all, because the type's fields were
//! crate-private and it had no public constructor — the `stress_join`
//! bench fixtures could only write the legacy inline-checkpoint form
//! (`admin_history: None`). This test uses only the `id` facade's
//! public surface — the same surface a bench writes journal fixtures
//! through — to build a current-form checkpoint, serialize it in the
//! journal's line format, and read it back unchanged.
//!
//! Oracle: the public constructor and accessors round-trip the exact
//! events and completeness flag, and a `JournalEntry::Checkpoint`
//! carrying the built history survives the journal's on-disk line
//! format byte-for-value.

#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]

use id::world::{JournalAdminHistory, JournalEntry, WorldEvent, WorldEventKind};

fn chat(sequence: u64, text: &str) -> WorldEvent {
WorldEvent {
sequence,
participant_id: 7,
kind: WorldEventKind::Chat(text.to_owned()),
}
}

#[test]
fn external_code_can_build_a_current_form_checkpoint_admin_history() {
let admin_events = vec![chat(1, "first"), chat(2, "second")];
let history = JournalAdminHistory::new(admin_events.clone(), true);
assert_eq!(history.events(), admin_events.as_slice());
assert!(history.is_complete());
assert_eq!(history.clone().into_events(), admin_events);

let entry = JournalEntry::Checkpoint {
sequence: 2,
module_hash: "fixture-program".to_owned(),
seed: 42,
provenance: None,
execution_profile: None,
caps_ceiling: None,
schedules: None,
kv: None,
blobs: None,
transfers: None,
lease: None,
snapshot: "2".to_owned(),
events: admin_events.clone(),
admin_history: Some(history),
open_presence: Some(Vec::new()),
};

// The journal's on-disk line format: one JSON value per entry.
let line = serde_json::to_string(&entry).unwrap();
let decoded: JournalEntry = serde_json::from_str(&line).unwrap();
assert_eq!(decoded, entry);
let JournalEntry::Checkpoint {
admin_history: Some(decoded_history),
..
} = decoded
else {
panic!("checkpoint lost its admin history on the wire");
};
assert_eq!(decoded_history.events(), admin_events.as_slice());
assert!(decoded_history.is_complete());
}

#[test]
fn incomplete_admin_history_round_trips_as_incomplete() {
let history = JournalAdminHistory::new(Vec::new(), false);
assert!(history.events().is_empty());
assert!(!history.is_complete());
let line = serde_json::to_string(&history).unwrap();
let decoded: JournalAdminHistory = serde_json::from_str(&line).unwrap();
assert_eq!(decoded, history);
}