Aetherlight AL2b-1: Act door tests (only Play, Draft refusal, acted chain)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
cfad9819cf
commit
d512a6706a
2 changed files with 108 additions and 3 deletions
|
|
@ -2324,6 +2324,45 @@ mod custody_tests {
|
|||
);
|
||||
}
|
||||
|
||||
/// A chain holding `Acted` commits recovers and verifies on reopen, and an
|
||||
/// event whose actor is no subject is corrupt at the shape check.
|
||||
#[test]
|
||||
fn an_acted_chain_reopens_and_a_foreign_actor_is_corrupt() {
|
||||
use crate::tests::{
|
||||
act, activate, auth_principal, creation, first_grant, owner, speak,
|
||||
};
|
||||
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let path = directory.path().join("world.cc");
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
&path,
|
||||
creation(CommandId::new(), "ActedChain"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
let active = activate(&mut kernel);
|
||||
let actor = *active.subjects.first().map(|subject| &subject.id).unwrap();
|
||||
act(
|
||||
&mut kernel,
|
||||
actor,
|
||||
speak(first_grant(&active, actor), "The chain holds."),
|
||||
)
|
||||
.unwrap();
|
||||
let accepted = kernel.snapshot().unwrap();
|
||||
let world_id = accepted.world_id;
|
||||
drop(kernel);
|
||||
let reopened = WorldKernel::open(&path, world_id).expect("the acted chain recovers");
|
||||
assert_eq!(reopened.snapshot().unwrap(), accepted);
|
||||
verify_state_shape(&reopened.state).expect("an honest event passes the shape check");
|
||||
|
||||
let mut forged = reopened.state.clone();
|
||||
forged.events[0].actor = crate::SubjectId::issue();
|
||||
assert!(
|
||||
matches!(verify_state_shape(&forged), Err(JournalError::Corrupt(_))),
|
||||
"an event naming no subject passed the shape check"
|
||||
);
|
||||
}
|
||||
|
||||
/// Absence is zero and one slot holds one pair, so a stored zero, an empty
|
||||
/// holder, and a holding on something that is not a resource are each
|
||||
/// corrupt at replay.
|
||||
|
|
|
|||
|
|
@ -10637,9 +10637,9 @@ mod witness_tests {
|
|||
mod clock_tests {
|
||||
use super::patch::{PreconditionRef, PressureSourceRef};
|
||||
use super::tests::{
|
||||
act, play_caller, activate, affordance_named, authority_kind, auth_principal, command, creation, office,
|
||||
operations, owner, human_principal, reject_owner, speech_world,
|
||||
submit_owner,
|
||||
act, act_as, activate, affordance_named, auth_principal, authority_kind, command, creation,
|
||||
human_principal, office, operations, owner, play_caller, reject_owner, speak,
|
||||
speech_world, submit_owner,
|
||||
};
|
||||
use super::*;
|
||||
use std::path::Path;
|
||||
|
|
@ -12355,6 +12355,72 @@ mod clock_tests {
|
|||
assert!(kernel.state.now > active.now);
|
||||
}
|
||||
|
||||
/// Act is Play's alone: the owner, the clock, a controller and a
|
||||
/// non-owner principal are refused and commit nothing; Play applies.
|
||||
#[test]
|
||||
fn only_play_may_act() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let (mut kernel, clockwork, _) = clock_kernel(directory.path(), "OnlyPlayActs");
|
||||
let invocation = DecisionInvocation {
|
||||
affordance: clockwork.threaten,
|
||||
bindings: vec![binding("target", Target::Subject(clockwork.farmer))],
|
||||
proposed: vec![ProposedEffect {
|
||||
slot: 0,
|
||||
magnitude: Magnitude::None,
|
||||
}],
|
||||
speech: None,
|
||||
display: None,
|
||||
};
|
||||
let before = kernel.state.clone();
|
||||
for caller in [
|
||||
CallerId::Principal(owner()),
|
||||
CallerId::Principal(human_principal()),
|
||||
clock_caller(),
|
||||
CallerId::Controller(ControllerId::issue()),
|
||||
] {
|
||||
let error =
|
||||
act_as(&mut kernel, caller.clone(), clockwork.reeve, invocation.clone())
|
||||
.unwrap_err();
|
||||
assert!(
|
||||
matches!(error, KernelError::Unauthorized),
|
||||
"{caller:?}: {error:?}"
|
||||
);
|
||||
}
|
||||
assert_eq!(kernel.state, before, "a refused act commits nothing");
|
||||
let receipt = act(&mut kernel, clockwork.reeve, invocation).expect("Play acts");
|
||||
assert!(matches!(receipt, SubmitReceipt::Applied(_)));
|
||||
assert_eq!(kernel.state.events.len(), before.events.len() + 1);
|
||||
assert_eq!(kernel.state.events.last().unwrap().actor, clockwork.reeve);
|
||||
}
|
||||
|
||||
/// There is no acting before activation.
|
||||
#[test]
|
||||
fn act_in_draft_is_wrong_phase() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let (mut kernel, _) = WorldKernel::create(
|
||||
directory.path().join("world.cc"),
|
||||
creation(CommandId::new(), "ActInDraft"),
|
||||
&auth_principal(owner()),
|
||||
)
|
||||
.unwrap();
|
||||
let error = act(
|
||||
&mut kernel,
|
||||
SubjectId::issue(),
|
||||
speak(AffordanceId::issue(), "Too soon."),
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(
|
||||
matches!(
|
||||
error,
|
||||
KernelError::WrongPhase {
|
||||
expected: WorldPhase::Active,
|
||||
actual: WorldPhase::Draft,
|
||||
}
|
||||
),
|
||||
"{error:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// P3.6: the play authority may not approve or activate.
|
||||
/// `require_system_capability`, at the top of `reduce`, refuses both
|
||||
/// before any body-specific arm is read.
|
||||
|
|
|
|||
Loading…
Reference in a new issue