open-standards/jouleclaw/jouleclaw-rs/crates/jouleclaw-stack/tests/ledger_breakdown_example.rs
Transaction Science 12b9f4c080 jouleclaw-stack: ledger_breakdown's simulated workload is sealed as estimates
The ledger_breakdown example simulates a workload — no tier runs, no
meter reads — and sealed its tool touches HwShunt at the cheap tiers and
ModelBased at the model tier, so the printed summary's rows claimed
hardware readings and an energy model's figures for work that never ran.

Every touch now comes from `simulated_touch`, graded Estimator, and the
module docs say the workload is simulated. The printed floor and rows
read [Estimator].

tests/ledger_breakdown_example.rs compiles the example in as a module,
seals touches at three tiers through its `simulated_touch`, and checks
each touch, the summary's floor, and every by-tier and by-tool row are
Estimator.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-10 17:47:12 -04:00

36 lines
1.9 KiB
Rust

//! The `ledger_breakdown` example simulates its workload: no tier runs and
//! no meter reads a figure, so every tool touch it seals must be graded
//! `Estimator`, and so must the ledger summary's provenance floor and every
//! row of it — at the model tier as at the cheap ones. The example file is
//! compiled in here as a module, so its own `simulated_touch` builds what is
//! sealed.
#[allow(dead_code)]
#[path = "../examples/ledger_breakdown.rs"]
mod ledger_breakdown;
use jouleclaw_energy::Provenance;
use jouleclaw_ledger::{InMemoryLedger, Ledger, LedgerStore, ProvenanceFloor, Window};
use jouleclaw_prov::{input_hash, CascadeTier, ReceiptBuilder};
#[test]
fn the_simulated_workload_is_sealed_as_estimates() {
let mut ledger = InMemoryLedger::new();
for (q, tier, uj, tool) in [
("explain the cascade", CascadeTier::L0Cache, 5, "cache.lookup"),
("what does jouleclaw-prov do?", CascadeTier::L1Lawful, 12, "iac:lawful.lookup"),
("write a hello-world fn", CascadeTier::L3Model, 1_200_000, "model:any"),
] {
let touch = ledger_breakdown::simulated_touch(tool, uj);
eprintln!("{tool}: {} µJ [{:?}]", touch.joules_uj, touch.energy_provenance);
assert_eq!(touch.energy_provenance, Provenance::Estimator, "{tool}: a simulated figure graded {:?}", touch.energy_provenance);
let receipt = ReceiptBuilder::new().input_hash(input_hash(q)).tier(tier).account_tool(touch).seal().expect("seal");
ledger.append(receipt).expect("append");
}
let summary = Ledger::new(&ledger).summary(&Window::any());
eprintln!("summary floor {:?} over {} receipts", summary.provenance_floor, summary.receipt_count);
assert_eq!(summary.provenance_floor, ProvenanceFloor::Estimator, "the simulated ledger's floor");
for r in summary.by_tier.iter().chain(&summary.by_tool) {
assert_eq!(r.provenance_floor, ProvenanceFloor::Estimator, "row {}: {:?}", r.key, r.provenance_floor);
}
}