//! 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); } }