sprawling-storage 0.0.12

The append-only, hash-chained Ledger of a sprawling city, its content store, checkpoints and worktrees.
Documentation
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// Copyright (c) 2026 2youg1 and the sprawling contributors

//! The one city the bundle tests export, restore and weigh.
//!
//! One fixture for the three bundle test modules, so they assert
//! against one shape of a city (`crates/storage/spec/Bundle.lean` ยง8-21).

#![allow(
    clippy::unwrap_used,
    clippy::expect_used,
    clippy::panic,
    clippy::indexing_slicing,
    reason = "test code"
)]

use std::path::Path;

use kernel::{EventDraft, EventKind, Ledger, Payload, RunId, TimeMs};

use crate::jsonl::JsonlLedger;

/// A city with `records` lines in its history, two files a bundle has to
/// carry, and a content store. The chain is walked as it is written,
/// which is what proves the records are one history rather than a pile.
pub(crate) fn city_with(records: u64, root: &Path) {
    let layout = kernel::layout::CityLayout::new(root);
    let dir = layout.ledger();
    let (mut ledger, _report) = JsonlLedger::open(&dir, TimeMs::new(1)).unwrap();
    for step in 0..records {
        ledger
            .append(EventDraft {
                run: RunId::CITY,
                t: TimeMs::new(step.saturating_add(1)),
                who: "owner".to_owned(),
                addr: None,
                kind: EventKind::CityInitialized,
                data: Payload::empty(),
                ig: false,
            })
            .unwrap();
    }
    std::fs::create_dir_all(root.join("lab")).unwrap();
    std::fs::write(root.join("City.md"), b"# City.md\n").unwrap();
    std::fs::write(root.join("lab").join("Roadmap.md"), b"# Roadmap\n").unwrap();
    let cas = crate::Cas::open(&layout.cas()).unwrap();
    drop(cas);
}