Aetherlight AL2a.1: delete the lens lane and the Ghostlight golden fixture

Remove lens.rs, LensWeights in genesis input, WorldState, snapshot and
creation, SetLensWeights, LensWeightsReplaced, LensWeightsNeverDraw and the
draw-rule shape check. The journal's lens replay tests are rewritten over an
owner AdvanceTime history (replays exactly; a forged caller fails replay).
The state shape changed, so Ghostlight's base_world fixture no longer decodes:
the golden replay test and its three fixtures go (AL4 adds Aetherlight's own).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-19 21:57:37 +01:00
commit 10f487dc16
10 changed files with 50 additions and 939 deletions

View file

@ -61,7 +61,6 @@ mod grammar;
#[cfg(test)]
mod import_key_tests;
mod journal;
mod lens;
mod patch;
pub(crate) use action::ActionMismatch;
@ -72,7 +71,6 @@ pub use grammar::{
GrammarBinding, GrammarError, GrammarIdentity, GrammarReferentKind, GrammarRole, GrammarVerb,
RenderPath,
};
pub use lens::{Lens, LensWeights};
pub use patch::{
CommitmentKey, DraftHandle, JurisdictionKey, Mismatch, PatchAnswer, Ref, RefKind, RefName, Role,
Site, Statement, WorldPatch,
@ -390,9 +388,6 @@ struct CreateWorld {
/// Authored once, here, and never mutated: `CommandBody::AdmitPatch` carries
/// no intent, so write-once is the command shape rather than a check.
scale_intent: WorldScaleIntentRef,
/// The world's flavor as genesis writes it. `SetLensWeights` may replace
/// it later; this command carries what the world began with.
lens_weights: LensWeights,
/// The grammar the world is bound to for its whole life, or none for an
/// open-catalog world. Authored here and nowhere else: genesis installs it.
#[serde(default, skip_serializing_if = "Option::is_none")]
@ -418,9 +413,6 @@ pub struct CreateWorldIntent {
/// The jurisdiction roots genesis declares beside the commons, because
/// `resolve_patch` only resolves roots the same patch declares.
pub jurisdictions: Vec<CreateJurisdictionIntent>,
/// Required. The library holds no default weights; a consumer states the
/// world's flavor or is refused.
pub lens_weights: LensWeights,
}
/// One jurisdiction root as ingress states it. The handle is a string here and
@ -666,15 +658,6 @@ pub enum CommandBody {
AdvanceTime {
minutes: TickMinutes,
},
/// Replaces the world's whole lens weight set. Owner only, in any phase,
/// under genesis admission: a set that never draws is refused, and a zero
/// weight is admitted and never draws. A set that weighs every lens as
/// the current one does, however its map is spelled, changes nothing
/// canonical and is refused with `NoCanonicalChange` after admission, so
/// nothing commits. A session that already drew keeps its recorded lens.
SetLensWeights {
weights: LensWeights,
},
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
@ -865,10 +848,6 @@ struct WorldState {
now: FictionalMinutes,
/// The authored scale target, written once by genesis and never mutated.
scale_intent: WorldScaleIntent,
/// Written by genesis and replaced only by `SetLensWeights`; read by the
/// elaborator's draw and by nothing that admits. It enters `state_digest`
/// and no `ScopePreimage`.
lens_weights: LensWeights,
controller_assignments: BTreeMap<DecisionScope, ControllerAssignment>,
/// What an affordance *is*. World-authored, Draft-only, written by
/// `admit_resolved` alone.
@ -920,11 +899,6 @@ enum WorldEffect {
to: FictionalMinutes,
motion: Motion,
},
/// The owner replaced the world's lens weights. `apply_effect` re-decides
/// the owner and the draw rule.
LensWeightsReplaced {
weights: LensWeights,
},
}
/// The exact raw command admitted by the world owner. This is the sole
@ -1211,7 +1185,6 @@ pub struct WorldSnapshot {
/// commitment gazetteer.
pub boundaries: Vec<CausalBoundary>,
pub scale_deficit: Vec<ScaleDeficitRow>,
pub lens_weights: LensWeights,
pub state_digest: String,
pub last_commit_digest: Option<String>,
}
@ -1437,7 +1410,6 @@ fn prepare_creation(
input.id,
&input.patch,
Some(&input.scale_intent),
Some(&input.lens_weights),
)
.map_err(KernelError::PatchRejected)?;
require_ruler(&CallerId::Principal(input.owner.clone()), &resolved)
@ -1799,7 +1771,7 @@ fn reduce(state: &WorldState, command: &CommandEnvelope) -> Result<WorldEffect,
!(patch.declarations.is_empty() && patch.evidence.is_empty()),
)?;
let confinement = require_patch_author(state, &command.caller, answers.as_ref())?;
let resolved = patch::resolve_patch(state, command.id, patch, None, None)
let resolved = patch::resolve_patch(state, command.id, patch, None)
.map_err(KernelError::PatchRejected)?;
require_ruler(&command.caller, &resolved).map_err(KernelError::PatchRejected)?;
if let Some(ground) = confinement {
@ -1810,25 +1782,6 @@ fn reduce(state: &WorldState, command: &CommandEnvelope) -> Result<WorldEffect,
resolved,
})
}
CommandBody::SetLensWeights { weights } => {
require_owner(state, &command.caller)?;
if !weights.draws() {
return Err(KernelError::PatchRejected(vec![
Mismatch::LensWeightsNeverDraw,
]));
}
// Admission first, then effect: a caller who may not set weights,
// or a set that never draws, is refused as such even when it
// equals the current set. Only an admitted set can be a no-op.
if weights.weighs_the_same_as(&state.lens_weights) {
return Err(KernelError::PatchRejected(vec![
Mismatch::NoCanonicalChange,
]));
}
Ok(WorldEffect::LensWeightsReplaced {
weights: weights.clone(),
})
}
}
}
@ -1974,9 +1927,6 @@ impl WorldState {
last_opportunity_at: BTreeMap::new(),
now: FictionalMinutes::default(),
scale_intent: WorldScaleIntent::default(),
// Never persisted: genesis overwrites it, and `verify_state_shape`
// refuses a stored set that never draws.
lens_weights: LensWeights::default(),
controller_assignments: BTreeMap::new(),
affordance_catalog: BTreeMap::new(),
affordance_grants: BTreeMap::new(),
@ -2019,7 +1969,6 @@ impl WorldState {
command.id,
&command.patch,
Some(&command.scale_intent),
Some(&command.lens_weights),
)
.map_err(KernelError::PatchRejected)?;
if &expected != resolved {
@ -2296,9 +2245,6 @@ fn admit_resolved(
if let Some(intent) = &resolved.scale_intent {
state.scale_intent = intent.clone();
}
if let Some(weights) = &resolved.lens_weights {
state.lens_weights = weights.clone();
}
apply_operations(state, &resolved.operations, &resolved.evidence, resolves_to)
}
@ -4217,7 +4163,6 @@ fn snapshot(state: &WorldState) -> Result<WorldSnapshot, KernelError> {
now: state.now,
boundaries: derive_boundaries(state)?,
scale_deficit: derive_scale_deficit(state)?,
lens_weights: state.lens_weights.clone(),
state_digest: state.state_digest.clone(),
last_commit_digest: state.last_commit_digest.clone(),
})
@ -5482,14 +5427,6 @@ fn apply_effect(
.insert(written.source, written.magnitude);
}
}
WorldEffect::LensWeightsReplaced { weights } => {
if caller != &CallerId::Principal(state.owner.clone()) || !weights.draws() {
return Err(KernelError::Invariant(
"lens weights effect does not satisfy owner admission".into(),
));
}
state.lens_weights = weights.clone();
}
}
Ok(())
}
@ -5595,11 +5532,6 @@ mod tests {
.expect("the fixture world declares this affordance")
}
/// Every stock lens at weight one.
pub(crate) fn stock_weights() -> LensWeights {
LensWeights::new(Lens::ALL.into_iter().map(|lens| (lens, 1)).collect())
}
pub(crate) fn creation(id: CommandId, title: &str) -> CreateWorld {
CreateWorld {
id,
@ -5664,7 +5596,6 @@ mod tests {
],
},
scale_intent: WorldScaleIntentRef::default(),
lens_weights: stock_weights(),
grammar: None,
}
}
@ -8899,7 +8830,6 @@ mod custody_tests {
let mut candidate = kernel.state.clone();
let forged = WorldEffect::PatchAdmitted {
resolved: ResolvedPatch {
lens_weights: None,
subjects: Vec::new(),
entities: Vec::new(),
routes: Vec::new(),
@ -9495,7 +9425,6 @@ mod custody_tests {
let forge = |operations: Vec<ResolvedOp>| WorldEffect::PatchAdmitted {
resolved: ResolvedPatch {
lens_weights: None,
subjects: Vec::new(),
entities: Vec::new(),
routes: Vec::new(),
@ -12210,7 +12139,6 @@ mod witness_tests {
evidence: Vec::new(),
},
None,
None,
)
.expect("the witness resolves over committed state");
for ground in [
@ -15271,7 +15199,7 @@ mod clock_tests {
panic!("the operations helper builds an admitted patch");
};
let resolved =
patch::resolve_patch(&kernel.state, CommandId::new(), patch, None, None).expect("resolves");
patch::resolve_patch(&kernel.state, CommandId::new(), patch, None).expect("resolves");
assert!(
resolved.scale_intent.is_none(),
"an Active patch resolved a scale intent"
@ -15281,54 +15209,6 @@ mod clock_tests {
assert_eq!(kernel.state.scale_intent, authored);
}
// ---- lens weights: world data, genesis, and the owner command --------
fn every_lens_at_zero() -> LensWeights {
LensWeights::new(Lens::ALL.into_iter().map(|lens| (lens, 0)).collect())
}
#[test]
fn genesis_writes_the_lens_weights_it_was_given() {
let directory = tempfile::tempdir().unwrap();
let path = directory.path().join("world.cc");
let given = LensWeights::new(BTreeMap::from([(Lens::Patina, 2), (Lens::Numen, 1)]));
let mut input = creation(CommandId::new(), "Flavored");
input.lens_weights = given.clone();
let (kernel, _) = WorldKernel::create(&path, input, &auth_principal(owner())).unwrap();
let created = kernel.snapshot().unwrap();
assert_eq!(created.lens_weights, given);
assert_eq!(kernel.state.lens_weights, given);
let world_id = created.world_id;
drop(kernel);
let replayed = WorldKernel::open(&path, world_id).unwrap();
assert_eq!(replayed.snapshot().unwrap(), created);
assert_eq!(replayed.state.state_digest, created.state_digest);
}
#[test]
fn a_genesis_lens_set_that_never_draws_is_refused() {
let directory = tempfile::tempdir().unwrap();
let path = directory.path().join("world.cc");
let mut input = creation(CommandId::new(), "Flavorless");
input.lens_weights = every_lens_at_zero();
let Err(error) = WorldKernel::create(&path, input, &auth_principal(owner())) else {
panic!("a genesis lens set that never draws was admitted");
};
let KernelError::PatchRejected(mismatches) = error else {
panic!("expected a rejected genesis patch, got {error:?}");
};
assert_eq!(mismatches, vec![Mismatch::LensWeightsNeverDraw]);
assert!(!path.exists(), "a refused genesis wrote a world file");
// The same creation with one real weight among the zeros is admitted.
let mut input = creation(CommandId::new(), "Flavorless");
let mut weights = BTreeMap::from_iter(every_lens_at_zero().iter());
weights.insert(Lens::Veil, 1);
input.lens_weights = LensWeights::new(weights);
WorldKernel::create(&path, input, &auth_principal(owner())).expect("one nonzero weight");
}
// ---- PA.f26: the genesis lane obeys `require_ruler` too ------------
/// PA.f26: `prepare_creation` and `WorldState::genesis` both call
@ -15415,7 +15295,6 @@ mod clock_tests {
input.id,
&input.patch,
Some(&input.scale_intent),
Some(&input.lens_weights),
)
.expect("the resolver is actor-blind and accepts a Ruled fact");
let effect = WorldEffect::WorldCreated {
@ -15444,7 +15323,6 @@ mod clock_tests {
input.id,
&input.patch,
Some(&input.scale_intent),
Some(&input.lens_weights),
)
.expect("the resolver is actor-blind and accepts a Mint");
let effect = WorldEffect::WorldCreated {
@ -15457,223 +15335,6 @@ mod clock_tests {
assert!(matches!(error, KernelError::Invariant(_)), "{error:?}");
}
/// Soul falsification, the lens twin of the scale intent's write-once
/// test: an Active patch resolves no weights; only the owner's
/// `SetLensWeights` replaces them, in Draft and in Active; every other
/// caller is `Unauthorized`; a set that never draws is refused; and
/// `apply_effect` re-decides the owner against a hand-built effect.
#[test]
fn soul_the_lens_weights_are_replaced_only_by_the_owner_command() {
let directory = tempfile::tempdir().unwrap();
let (mut kernel, _) = WorldKernel::create(
directory.path().join("world.cc"),
creation(CommandId::new(), "Owner Flavor"),
&auth_principal(owner()),
)
.unwrap();
let draft_weights = LensWeights::new(BTreeMap::from([
(Lens::Patina, 0),
(Lens::Charter, 3),
(Lens::Ledger, 1),
]));
let draft = kernel.snapshot().unwrap();
submit_owner(
&mut kernel,
&draft,
CommandBody::SetLensWeights {
weights: draft_weights.clone(),
},
);
assert_eq!(kernel.state.revision, draft.revision + 1);
assert_eq!(kernel.state.lens_weights, draft_weights);
let active = activate(&mut kernel);
let active_weights = LensWeights::new(BTreeMap::from([
(Lens::Hearth, 5),
(Lens::Tangle, 0),
(Lens::Ember, 2),
]));
submit_owner(
&mut kernel,
&active,
CommandBody::SetLensWeights {
weights: active_weights.clone(),
},
);
assert_eq!(kernel.state.revision, active.revision + 1);
assert_eq!(kernel.state.lens_weights, active_weights);
// An Active patch is handed no weights, so it cannot resolve any.
let resolved = patch::resolve_patch(
&kernel.state,
CommandId::new(),
&operations_patch(&kernel),
None,
None,
)
.expect("resolves");
assert!(resolved.lens_weights.is_none(), "an Active patch resolved lens weights");
let after_patch = kernel.snapshot().unwrap();
let patch = operations_patch(&kernel);
submit_owner(
&mut kernel,
&after_patch,
CommandBody::AdmitPatch {
answers: None,
patch,
},
);
assert_eq!(kernel.state.lens_weights, active_weights);
// Every caller but the owner, with real weights.
let proposed = super::tests::stock_weights();
let before = kernel.state.clone();
for caller in [
CallerId::Principal(human_principal()),
CallerId::Principal(PrincipalId::new("stranger@example.test")),
elaborator(JurisdictionKey::Uncovered),
CallerId::System(SystemCapability::Clock),
CallerId::System(SystemCapability::Consumer {
consumer: ConsumerId::of_name("lens-consumer"),
}),
] {
let result = submit_as(
&mut kernel,
caller.clone(),
CommandBody::SetLensWeights {
weights: proposed.clone(),
},
);
assert!(
matches!(result, Err(KernelError::Unauthorized)),
"{caller:?} replaced the lens weights: {result:?}"
);
}
assert_eq!(kernel.state, before);
// The owner, with every lens named at zero.
let result = submit_as(
&mut kernel,
CallerId::Principal(owner()),
CommandBody::SetLensWeights {
weights: every_lens_at_zero(),
},
);
let Err(KernelError::PatchRejected(mismatches)) = result else {
panic!("a lens set that never draws was admitted: {result:?}");
};
assert_eq!(mismatches, vec![Mismatch::LensWeightsNeverDraw]);
assert_eq!(kernel.state, before);
// The owner, with valid weights, against the revision before the
// last commit.
let stale = command(
&draft,
CommandId::new(),
CallerId::Principal(owner()),
CommandBody::SetLensWeights {
weights: proposed.clone(),
},
);
assert!(matches!(
kernel.submit(stale, &auth_principal(owner())),
Err(KernelError::RevisionMismatch { .. })
));
assert_eq!(kernel.state, before);
// `apply_effect` re-decides: a hand-built effect under a non-owner or
// a system caller never applies, and neither does one that never draws.
for (caller, weights) in [
(CallerId::Principal(human_principal()), proposed.clone()),
(CallerId::System(SystemCapability::Clock), proposed.clone()),
(CallerId::Principal(owner()), every_lens_at_zero()),
] {
let mut candidate = kernel.state.clone();
let error = apply_effect(
&mut candidate,
CommandId::new(),
&caller,
&WorldEffect::LensWeightsReplaced { weights },
)
.unwrap_err();
assert!(
matches!(
error,
KernelError::Invariant(_) | KernelError::Unauthorized
),
"{caller:?}: {error:?}"
);
assert_eq!(candidate, kernel.state);
}
// The honest effect applies through the same arm.
let mut candidate = kernel.state.clone();
apply_effect(
&mut candidate,
CommandId::new(),
&CallerId::Principal(owner()),
&WorldEffect::LensWeightsReplaced {
weights: proposed.clone(),
},
)
.expect("the owner's effect applies");
assert_eq!(candidate.lens_weights, proposed);
// Identical weights from the owner change nothing canonical: refused
// as `NoCanonicalChange`, and nothing commits.
let result = submit_as(
&mut kernel,
CallerId::Principal(owner()),
CommandBody::SetLensWeights {
weights: active_weights.clone(),
},
);
let Err(KernelError::PatchRejected(mismatches)) = result else {
panic!("identical lens weights were admitted: {result:?}");
};
assert_eq!(mismatches, vec![Mismatch::NoCanonicalChange]);
assert_eq!(kernel.state, before);
// The order is admission, then effect. Identical weights from a
// non-owner are `Unauthorized`; and against a state whose own set
// never draws (no store holds one, so the state is built by hand), an
// identical all-zero set is `LensWeightsNeverDraw`, not a no-op.
let result = submit_as(
&mut kernel,
CallerId::Principal(human_principal()),
CommandBody::SetLensWeights {
weights: active_weights.clone(),
},
);
assert!(
matches!(result, Err(KernelError::Unauthorized)),
"a non-owner's identical set: {result:?}"
);
assert_eq!(kernel.state, before);
let mut never = kernel.state.clone();
never.lens_weights = every_lens_at_zero();
let current = kernel.snapshot().unwrap();
let identical_zero = command(
&current,
CommandId::new(),
CallerId::Principal(owner()),
CommandBody::SetLensWeights {
weights: every_lens_at_zero(),
},
);
let result = reduce(&never, &identical_zero);
let Err(KernelError::PatchRejected(mismatches)) = result else {
panic!("an identical set that never draws: {result:?}");
};
assert_eq!(mismatches, vec![Mismatch::LensWeightsNeverDraw]);
// Replay across that history is unchanged: the refused attempts wrote
// nothing, and the store reopens to the same head.
let (path, world_id) = (directory.path().join("world.cc"), kernel.state.world_id);
drop(kernel);
let reopened = WorldKernel::open(path, world_id).expect("the history reopens");
assert_eq!(reopened.state, before);
}
/// An owner commit that adds a commitment to the first person: a real
/// Active patch with no answer, and nothing to do with lenses.
fn operations_patch(kernel: &WorldKernel) -> WorldPatch {
@ -15698,46 +15359,6 @@ mod clock_tests {
patch
}
#[test]
fn lens_weights_enter_the_state_digest_and_no_scope_digest() {
let directory = tempfile::tempdir().unwrap();
let (mut kernel, _) = WorldKernel::create(
directory.path().join("world.cc"),
creation(CommandId::new(), "Digest Flavor"),
&auth_principal(owner()),
)
.unwrap();
let active = activate(&mut kernel);
let mut other = kernel.state.clone();
other.lens_weights =
LensWeights::new(BTreeMap::from([(Lens::Patina, 1), (Lens::Veil, 7)]));
assert_ne!(
state_digest(&other).unwrap(),
state_digest(&kernel.state).unwrap(),
"lens weights did not enter the state digest"
);
let digests = |kernel: &WorldKernel| -> BTreeMap<SubjectId, ScopeDigest> {
derive_opportunities(&kernel.state)
.unwrap()
.into_iter()
.map(|opportunity| (opportunity.scope.subject_id, opportunity.scope_digest))
.collect()
};
let before = digests(&kernel);
assert!(!before.is_empty(), "the active fixture derives opportunities");
submit_owner(
&mut kernel,
&active,
CommandBody::SetLensWeights {
weights: other.lens_weights.clone(),
},
);
assert_ne!(kernel.state.state_digest, active.state_digest);
assert_eq!(digests(&kernel), before, "lens weights entered a scope digest");
}
/// Soul falsification: a discharge names one subject's own live key.
#[test]
fn soul_discharging_a_foreign_or_already_discharged_commitment_is_refused() {
@ -16385,7 +16006,6 @@ mod clock_tests {
command_id,
&shed_under(clockwork.dead_end, "shed"),
None,
None,
)
.expect("the patch resolves");
let effect = WorldEffect::PatchAdmitted {
@ -17532,7 +17152,7 @@ mod clock_tests {
}],
evidence: Vec::new(),
};
let resolved = patch::resolve_patch(&kernel.state, command_id, &patch, None, None)
let resolved = patch::resolve_patch(&kernel.state, command_id, &patch, None)
.expect("the patch resolves; the resolver is actor-blind");
let effect = WorldEffect::PatchAdmitted {
answers: Some(PatchAnswer::Boundary(answered)),
@ -17569,7 +17189,7 @@ mod clock_tests {
let answered = dead_end_boundary(&kernel);
let command_id = CommandId::issue();
let patch = ruled_fact_patch("rule");
let resolved = patch::resolve_patch(&kernel.state, command_id, &patch, None, None)
let resolved = patch::resolve_patch(&kernel.state, command_id, &patch, None)
.expect("the patch resolves; the resolver is actor-blind");
let effect = WorldEffect::PatchAdmitted {
answers: Some(PatchAnswer::Boundary(answered)),