diff --git a/crates/ghostlight-dungeon/src/world/journal.rs b/crates/ghostlight-dungeon/src/world/journal.rs index 6a297b5..aab73ad 100644 --- a/crates/ghostlight-dungeon/src/world/journal.rs +++ b/crates/ghostlight-dungeon/src/world/journal.rs @@ -1384,9 +1384,7 @@ mod custody_tests { // An empty target set is the second representation of nothing, and there // is only supposed to be one. let mut emptied = kernel.state.clone(); - emptied - .dependencies - .insert(custody.holder, BTreeSet::new()); + emptied.dependencies.insert(custody.holder, BTreeSet::new()); assert!(matches!( verify_state_shape(&emptied), Err(JournalError::Corrupt(_)) diff --git a/crates/ghostlight-dungeon/src/world/mod.rs b/crates/ghostlight-dungeon/src/world/mod.rs index a8d1d8b..81b154a 100644 --- a/crates/ghostlight-dungeon/src/world/mod.rs +++ b/crates/ghostlight-dungeon/src/world/mod.rs @@ -1282,18 +1282,32 @@ fn admit_resolved(state: &mut WorldState, resolved: &ResolvedPatch) -> Result<() } } } - // A forged `PatchAdmitted` reaches this function without ever passing the - // resolver, so conservation is re-derived here over the committed - // partitions, against the same equation, with `before` read from state - // rather than from anything the effect asserts. + apply_operations(state, &resolved.operations, &resolved.evidence) +} + +/// The component writer for every lane: snapshot the before-totals for every +/// resource the operations name, apply each operation, accumulate the ledger +/// deltas, and prove conservation once. Declaration admission calls it after its +/// declaration loops; an exercised affordance's lowered effects call it +/// directly. One writer, one conservation statement. +/// +/// A forged effect reaches this function without ever passing the resolver, so +/// conservation is re-derived over the committed partitions, against the same +/// equation, with `before` read from state rather than from anything the effect +/// asserts. +fn apply_operations( + state: &mut WorldState, + operations: &[ResolvedOp], + evidence: &[EvidenceRef], +) -> Result<(), KernelError> { let mut deltas: BTreeMap = BTreeMap::new(); - for operation in &resolved.operations { + for operation in operations { for resource in operation_resources(operation) { deltas.entry(resource).or_default().before = resource_total(state, resource); } } - for operation in &resolved.operations { - apply_operation(state, operation, &resolved.evidence)?; + for operation in operations { + apply_operation(state, operation, evidence)?; match operation { ResolvedOp::Transform { from_resource,