Falsify the seed lane: five reproducers, eight bounds
Soul's pass over the seed producer. Tests only. Five claims fail and are committed as ignored reproducers, each naming its defect in the ignore reason: - `collect_notes` follows a directory junction out of the vault root, and `strip_prefix` then dresses the escaped note in a vault-relative reference. - `VaultError::Root` carries the server's absolute path into the owner's command receipt. - `require_answer`'s `declares` reads declarations and evidence and not operations, so an operations-only patch passes the Active gate through `submit_seed`. The runner's phase check is the only gate, not the first of two. - A `Goal` derives no boundary, so a world seeded to full strength out of goals alone activates with nothing for the elaborator. - The mailbox never re-verifies principal evidence: a revoked session's evidence still commits as the owner. Eight bounds hold and are asserted: an oversized note is never read and the reader never writes, the receipt cap survives the link fanout, `require_answer` still owns both phase rules, a session that never submits stops at the shared round budget and its row stays a fixed point, one derived id commits once, two landed sessions hold two ids, `valid_seed_progression` refuses every backward transition, and the custody probe counts a seed row. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
e73ef5c8f8
commit
697ed07081
3 changed files with 799 additions and 0 deletions
|
|
@ -3875,4 +3875,89 @@ mod tests {
|
|||
);
|
||||
assert!(encoded.contains("world.seed"), "the button is missing");
|
||||
}
|
||||
|
||||
/// Soul. `SeedPort` holds one `VerifiedPrincipalEvidence` for the whole
|
||||
/// session, and the question is what happens when the session behind it
|
||||
/// dies mid-run. The answer is nothing: the evidence is an account hash
|
||||
/// with no expiry, no session id, and no revision, and `submit_principal`
|
||||
/// mints `CallerId::Principal` straight from it without consulting the
|
||||
/// session store. So the gate is the evidence value's own lifetime in
|
||||
/// memory, and nothing else.
|
||||
///
|
||||
/// Today that lifetime is one request, because `seed_once` builds the port
|
||||
/// from the request that carried the cookie and drops it at the end. The
|
||||
/// bound is the construction site, not a check.
|
||||
#[tokio::test]
|
||||
#[ignore = "FALSIFIED: the mailbox never re-verifies principal evidence; a revoked session still commits"]
|
||||
async fn soul_verified_evidence_outlives_the_session_that_minted_it() {
|
||||
let fixture = fixture().await;
|
||||
two_cell_world(
|
||||
&fixture.state,
|
||||
&fixture.cookie,
|
||||
BTreeMap::new(),
|
||||
Vec::new(),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
let principal = fixture
|
||||
.state
|
||||
.sessions
|
||||
.lock()
|
||||
.await
|
||||
.account_for_cookie(&fixture.cookie, Utc::now())
|
||||
.unwrap()
|
||||
.expect("the fixture cookie names a live session");
|
||||
|
||||
// The session the evidence came from is destroyed.
|
||||
assert!(
|
||||
fixture
|
||||
.state
|
||||
.sessions
|
||||
.lock()
|
||||
.await
|
||||
.revoke_cookie(&fixture.cookie)
|
||||
.unwrap()
|
||||
);
|
||||
assert!(
|
||||
fixture
|
||||
.state
|
||||
.sessions
|
||||
.lock()
|
||||
.await
|
||||
.account_for_cookie(&fixture.cookie, Utc::now())
|
||||
.unwrap()
|
||||
.is_none(),
|
||||
"the cookie survived revocation"
|
||||
);
|
||||
|
||||
let before = fixture.state.world.snapshot().await.unwrap();
|
||||
let committed = fixture
|
||||
.state
|
||||
.world
|
||||
.submit_principal(
|
||||
PrincipalCommandIntent {
|
||||
id: CommandId::new(),
|
||||
world_id: before.world_id,
|
||||
expected_revision: before.revision,
|
||||
// `ApproveDraft`, because it is refused for anyone but a
|
||||
// required approver and its effect is visible in the
|
||||
// snapshot. What is under test is who the kernel believes
|
||||
// the caller is.
|
||||
body: CommandBody::ApproveDraft,
|
||||
},
|
||||
&principal,
|
||||
)
|
||||
.await;
|
||||
assert!(
|
||||
committed.is_err(),
|
||||
"a revoked session's evidence still committed as the owner: {committed:?}, approvals {:?}",
|
||||
fixture
|
||||
.state
|
||||
.world
|
||||
.snapshot()
|
||||
.await
|
||||
.unwrap()
|
||||
.draft_approvals
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9383,4 +9383,544 @@ mod tests {
|
|||
drop(fixture.mailbox);
|
||||
fixture.task.await.unwrap();
|
||||
}
|
||||
|
||||
// ---- Soul: the seed lane under falsification ------------------------
|
||||
|
||||
/// Soul. The lane's claim is that Active is refused twice: once by the
|
||||
/// runner's phase gate and once by the kernel, "if that check is ever
|
||||
/// removed". The second refusal is `require_answer`'s
|
||||
/// `(Active, None) if declares` arm, and `declares` is
|
||||
/// `!(declarations.is_empty() && evidence.is_empty())` — operations are not
|
||||
/// in it. So a patch made only of operations passes the kernel's Active
|
||||
/// gate through `submit_seed`, and it is a patch that moves world state and
|
||||
/// the scale deficit.
|
||||
///
|
||||
/// This is not an authority escalation: the owner may write in Active. It
|
||||
/// falsifies the defence-in-depth claim, not the ownership one.
|
||||
#[tokio::test]
|
||||
#[ignore = "FALSIFIED: require_answer ignores operations, so the Active second gate does not fire"]
|
||||
async fn soul_the_seed_lane_admits_an_operations_only_patch_in_active() {
|
||||
let fixture = seed_mailbox(6).await;
|
||||
let authenticated =
|
||||
AuthenticatedCaller::fixture(CallerId::Principal(fixture.owner.clone()));
|
||||
let mut snapshot = fixture.mailbox.snapshot().await.unwrap();
|
||||
for body in [CommandBody::ApproveDraft, CommandBody::ActivateWorld] {
|
||||
fixture
|
||||
.mailbox
|
||||
.submit_fixture(
|
||||
CommandEnvelope {
|
||||
id: CommandId::new(),
|
||||
world_id: snapshot.world_id,
|
||||
expected_revision: snapshot.revision,
|
||||
caller: CallerId::Principal(fixture.owner.clone()),
|
||||
body,
|
||||
},
|
||||
&authenticated,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
snapshot = fixture.mailbox.snapshot().await.unwrap();
|
||||
}
|
||||
assert_eq!(snapshot.phase, WorldPhase::Active);
|
||||
let owner_subject = snapshot
|
||||
.subjects
|
||||
.iter()
|
||||
.find(|subject| subject.label == "The Owner")
|
||||
.expect("the first person")
|
||||
.id;
|
||||
|
||||
let admitted = seed_port(&fixture)
|
||||
.submit_seed(
|
||||
CommandId::new(),
|
||||
snapshot.world_id,
|
||||
snapshot.revision,
|
||||
WorldPatch {
|
||||
declarations: Vec::new(),
|
||||
operations: vec![crate::world::patch::ComponentOp::CreateCommitment {
|
||||
subject: Ref::Existing(owner_subject),
|
||||
counterparty: None,
|
||||
kind: CommitmentKind::Goal,
|
||||
due: crate::world::FictionalMinutes(600),
|
||||
period: None,
|
||||
checks: Vec::new(),
|
||||
}],
|
||||
evidence: Vec::new(),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
let after = fixture.mailbox.snapshot().await.unwrap();
|
||||
assert!(
|
||||
admitted.is_err(),
|
||||
"an Active seed submission committed: revision {} -> {}, owner qualified {}",
|
||||
snapshot.revision,
|
||||
after.revision,
|
||||
after
|
||||
.subjects
|
||||
.iter()
|
||||
.any(|subject| subject.id == owner_subject && subject.qualified)
|
||||
);
|
||||
|
||||
drop(fixture.mailbox);
|
||||
fixture.task.await.unwrap();
|
||||
}
|
||||
|
||||
/// Soul. What the deleted phase clause used to be blamed for, checked
|
||||
/// directly: `require_answer` still refuses every Draft answer, and still
|
||||
/// demands one from every Active patch that declares. The seed lane meets
|
||||
/// only the first, because `submit_seed` hardcodes `answers: None`.
|
||||
#[tokio::test]
|
||||
async fn soul_require_answer_still_owns_the_phase_rule_the_clause_did_not() {
|
||||
let fixture = seed_mailbox(6).await;
|
||||
let authenticated =
|
||||
AuthenticatedCaller::fixture(CallerId::Principal(fixture.owner.clone()));
|
||||
let mut snapshot = fixture.mailbox.snapshot().await.unwrap();
|
||||
let shed = || WorldPatch {
|
||||
declarations: vec![Declaration::Entity(EntityDeclaration {
|
||||
handle: DraftHandle::new("shed"),
|
||||
label: "A Shed".into(),
|
||||
kind: EntityKind::Place,
|
||||
container: None,
|
||||
})],
|
||||
operations: Vec::new(),
|
||||
evidence: Vec::new(),
|
||||
};
|
||||
|
||||
// Draft refuses an answer outright, whatever the answer names.
|
||||
let refused = fixture
|
||||
.mailbox
|
||||
.submit_fixture(
|
||||
CommandEnvelope {
|
||||
id: CommandId::new(),
|
||||
world_id: snapshot.world_id,
|
||||
expected_revision: snapshot.revision,
|
||||
caller: CallerId::Principal(fixture.owner.clone()),
|
||||
body: CommandBody::AdmitPatch {
|
||||
answers: Some(crate::world::PatchAnswer::Deficit(
|
||||
JurisdictionKey::PlaceSubtree(fixture.sere),
|
||||
)),
|
||||
patch: shed(),
|
||||
},
|
||||
},
|
||||
&authenticated,
|
||||
)
|
||||
.await;
|
||||
assert!(
|
||||
matches!(
|
||||
refused,
|
||||
Err(MailboxError::Kernel(KernelError::AnswerNotDerived))
|
||||
),
|
||||
"{refused:?}"
|
||||
);
|
||||
assert_eq!(
|
||||
fixture.mailbox.snapshot().await.unwrap().revision,
|
||||
snapshot.revision
|
||||
);
|
||||
|
||||
for body in [CommandBody::ApproveDraft, CommandBody::ActivateWorld] {
|
||||
fixture
|
||||
.mailbox
|
||||
.submit_fixture(
|
||||
CommandEnvelope {
|
||||
id: CommandId::new(),
|
||||
world_id: snapshot.world_id,
|
||||
expected_revision: snapshot.revision,
|
||||
caller: CallerId::Principal(fixture.owner.clone()),
|
||||
body,
|
||||
},
|
||||
&authenticated,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
snapshot = fixture.mailbox.snapshot().await.unwrap();
|
||||
}
|
||||
|
||||
// Active refuses a declaring patch that carries none.
|
||||
let refused = seed_port(&fixture)
|
||||
.submit_seed(
|
||||
CommandId::new(),
|
||||
snapshot.world_id,
|
||||
snapshot.revision,
|
||||
shed(),
|
||||
)
|
||||
.await;
|
||||
assert!(
|
||||
matches!(
|
||||
refused,
|
||||
Err(MailboxError::Kernel(KernelError::AnswerRequired))
|
||||
),
|
||||
"{refused:?}"
|
||||
);
|
||||
|
||||
drop(fixture.mailbox);
|
||||
fixture.task.await.unwrap();
|
||||
}
|
||||
|
||||
/// Soul. One session's round loop is bounded by the elaboration budget it
|
||||
/// shares, not by anything the seed lane holds: a model that keeps calling
|
||||
/// tools and never submits stops at `ELABORATION_ROUND_BUDGET` rounds and
|
||||
/// leaves a `NoPatch` row, and a second sweep over the same store spends
|
||||
/// nothing, because that row is the row's fixed point.
|
||||
#[tokio::test]
|
||||
async fn soul_a_session_that_never_submits_is_bounded_by_the_round_budget() {
|
||||
// `elaboration::ELABORATION_ROUND_BUDGET`, which is file-private to the
|
||||
// lane that owns it. Restated here so that raising the budget fails
|
||||
// this bound loudly rather than silently widening it.
|
||||
const SHARED_ROUND_BUDGET: usize = 6;
|
||||
|
||||
let fixture = seed_mailbox(6).await;
|
||||
let genesis = fixture.mailbox.snapshot().await.unwrap().revision;
|
||||
let store = fresh_store();
|
||||
let scripted = seed_script(
|
||||
(0..SHARED_ROUND_BUDGET + 4)
|
||||
.map(|round| {
|
||||
tool_round(
|
||||
vec![(
|
||||
"declare_place",
|
||||
json!({
|
||||
"handle": format!("shed{round}"),
|
||||
"label": "A Shed",
|
||||
"container": null
|
||||
}),
|
||||
)],
|
||||
&format!("r{round}"),
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
let runner = seed_runner(
|
||||
&fixture,
|
||||
scripted.clone(),
|
||||
store.clone(),
|
||||
Arc::new(NullEvidenceSource),
|
||||
);
|
||||
assert_eq!(runner.step().await.unwrap(), SeedOutcome::NoPatch);
|
||||
assert_eq!(
|
||||
scripted.seen.lock().unwrap().len(),
|
||||
SHARED_ROUND_BUDGET,
|
||||
"the round loop is not bounded by the shared budget"
|
||||
);
|
||||
assert_eq!(
|
||||
fixture.mailbox.snapshot().await.unwrap().revision,
|
||||
genesis,
|
||||
"a session that never submitted moved the world"
|
||||
);
|
||||
|
||||
// The row is now a fixed point: a fresh sweep re-derives the same id,
|
||||
// finds `NoPatch`, and does not spend a round.
|
||||
let resumed = seed_runner(
|
||||
&fixture,
|
||||
scripted.clone(),
|
||||
store.clone(),
|
||||
Arc::new(NullEvidenceSource),
|
||||
);
|
||||
assert_eq!(resumed.sweep(4).await.unwrap(), SeedOutcome::NoPatch);
|
||||
assert_eq!(
|
||||
scripted.seen.lock().unwrap().len(),
|
||||
SHARED_ROUND_BUDGET,
|
||||
"a NoPatch row was reopened against the endpoint"
|
||||
);
|
||||
assert_eq!(store.work.lock().unwrap().len(), 1, "one row per session");
|
||||
|
||||
drop(runner);
|
||||
drop(resumed);
|
||||
drop(fixture.mailbox);
|
||||
fixture.task.await.unwrap();
|
||||
}
|
||||
|
||||
/// Soul. The derived id is the whole idempotency story, so it has to hold
|
||||
/// at the ledger and not only at the store: the same id submitted twice
|
||||
/// commits once.
|
||||
#[tokio::test]
|
||||
async fn soul_one_derived_seed_id_commits_once() {
|
||||
let fixture = seed_mailbox(6).await;
|
||||
let port = seed_port(&fixture);
|
||||
let snapshot = port.snapshot().await.unwrap();
|
||||
let command_id = CommandId::new();
|
||||
let shed = || WorldPatch {
|
||||
declarations: vec![Declaration::Entity(EntityDeclaration {
|
||||
handle: DraftHandle::new("shed"),
|
||||
label: "A Shed".into(),
|
||||
kind: EntityKind::Place,
|
||||
container: None,
|
||||
})],
|
||||
operations: Vec::new(),
|
||||
evidence: Vec::new(),
|
||||
};
|
||||
let first = port
|
||||
.submit_seed(command_id, snapshot.world_id, snapshot.revision, shed())
|
||||
.await
|
||||
.unwrap();
|
||||
let after = port.snapshot().await.unwrap();
|
||||
assert_eq!(after.revision, snapshot.revision + 1);
|
||||
let again = port
|
||||
.submit_seed(command_id, snapshot.world_id, snapshot.revision, shed())
|
||||
.await
|
||||
.unwrap();
|
||||
let (SubmitReceipt::Applied(landed), SubmitReceipt::AlreadyApplied(replayed)) =
|
||||
(&first, &again)
|
||||
else {
|
||||
panic!("a replayed seed id was not recognised: {first:?} then {again:?}");
|
||||
};
|
||||
assert_eq!(
|
||||
landed, replayed,
|
||||
"a replayed seed id returned a different commit"
|
||||
);
|
||||
assert_eq!(
|
||||
port.snapshot().await.unwrap().revision,
|
||||
after.revision,
|
||||
"one derived id committed twice"
|
||||
);
|
||||
|
||||
drop(port);
|
||||
drop(fixture.mailbox);
|
||||
fixture.task.await.unwrap();
|
||||
}
|
||||
|
||||
/// Soul. Two rows in one Draft world, answered in sequence, leave two store
|
||||
/// rows under two ids. The ancestry in the key is what makes each landed
|
||||
/// patch open a fresh session rather than resubmitting one id.
|
||||
#[tokio::test]
|
||||
async fn soul_two_seed_sessions_in_one_world_hold_two_ids() {
|
||||
let fixture = seed_mailbox(2).await;
|
||||
let store = fresh_store();
|
||||
let scripted = seed_script(vec![
|
||||
author_persons("r0", fixture.sere, fixture.speak, &["a1"]),
|
||||
author_persons("r1", fixture.sere, fixture.speak, &["a2"]),
|
||||
]);
|
||||
let runner = seed_runner(
|
||||
&fixture,
|
||||
scripted,
|
||||
store.clone(),
|
||||
Arc::new(NullEvidenceSource),
|
||||
);
|
||||
assert_eq!(runner.sweep(4).await.unwrap(), SeedOutcome::Clean);
|
||||
let ids: BTreeSet<CommandId> = store.work.lock().unwrap().keys().copied().collect();
|
||||
assert_eq!(ids.len(), 2, "two landed sessions shared one derived id");
|
||||
|
||||
drop(runner);
|
||||
drop(fixture.mailbox);
|
||||
fixture.task.await.unwrap();
|
||||
}
|
||||
|
||||
/// Soul. `valid_seed_progression` is what stops a resumed session from
|
||||
/// rewriting its own history. The forward extension is allowed; a repair
|
||||
/// with an empty mismatch set, a rewritten row, and every transition out of
|
||||
/// the terminal stage are not.
|
||||
#[tokio::test]
|
||||
async fn soul_valid_seed_progression_refuses_every_backward_transition() {
|
||||
let fixture = seed_mailbox(6).await;
|
||||
let store = fresh_store();
|
||||
let runner = seed_runner(
|
||||
&fixture,
|
||||
seed_script(vec![tool_round(
|
||||
vec![
|
||||
(
|
||||
"declare_subject",
|
||||
json!({
|
||||
"handle": "digger",
|
||||
"label": "Sere digger",
|
||||
"kind": "person",
|
||||
"controller": {"type": "narrative_persona"},
|
||||
"affordances": [{
|
||||
"ref": "existing",
|
||||
"value": serde_json::to_value(fixture.speak).unwrap()
|
||||
}],
|
||||
"position": {"ref": "draft", "value": "nowhere"},
|
||||
}),
|
||||
),
|
||||
("submit", json!({})),
|
||||
],
|
||||
"r0",
|
||||
)]),
|
||||
store.clone(),
|
||||
Arc::new(NullEvidenceSource),
|
||||
);
|
||||
assert_eq!(runner.step().await.unwrap(), SeedOutcome::Rejected);
|
||||
drop(runner);
|
||||
|
||||
let stored = store.work.lock().unwrap().values().next().unwrap().clone();
|
||||
let ControllerWork::Seed(repair) = stored else {
|
||||
panic!("the rejection left no seed row");
|
||||
};
|
||||
let SeedCheckpoint::SeedInFlight {
|
||||
command_id,
|
||||
session,
|
||||
agent_prompt,
|
||||
last_mismatches,
|
||||
completed,
|
||||
invocation,
|
||||
} = repair.clone()
|
||||
else {
|
||||
panic!("a rejection must reopen the session in flight");
|
||||
};
|
||||
assert!(!last_mismatches.is_empty());
|
||||
assert!(completed.is_empty());
|
||||
|
||||
let ready = SeedCheckpoint::ReadyToSubmit {
|
||||
command_id,
|
||||
session: session.clone(),
|
||||
agent_prompt: agent_prompt.clone(),
|
||||
last_mismatches: last_mismatches.clone(),
|
||||
completed: completed.clone(),
|
||||
};
|
||||
let unrepaired = SeedCheckpoint::SeedInFlight {
|
||||
command_id,
|
||||
session: session.clone(),
|
||||
agent_prompt: agent_prompt.clone(),
|
||||
last_mismatches: Vec::new(),
|
||||
completed: completed.clone(),
|
||||
invocation: invocation.clone(),
|
||||
};
|
||||
let no_patch = SeedCheckpoint::NoPatch {
|
||||
command_id,
|
||||
session: session.clone(),
|
||||
agent_prompt: agent_prompt.clone(),
|
||||
completed: completed.clone(),
|
||||
gaps: Vec::new(),
|
||||
};
|
||||
let other_row = SeedCheckpoint::SeedInFlight {
|
||||
command_id,
|
||||
session: {
|
||||
let mut moved = session.clone();
|
||||
moved.target += 1;
|
||||
moved
|
||||
},
|
||||
agent_prompt,
|
||||
last_mismatches,
|
||||
completed,
|
||||
invocation,
|
||||
};
|
||||
|
||||
// A submitted session reopens only with a repair set.
|
||||
assert!(!valid_seed_progression(&ready, &unrepaired));
|
||||
// Nothing follows the terminal stage.
|
||||
assert!(!valid_seed_progression(&no_patch, &repair));
|
||||
assert!(!valid_seed_progression(&no_patch, &ready));
|
||||
// The row a session bound to is not rewritable.
|
||||
assert!(!valid_seed_progression(&repair, &other_row));
|
||||
// And the forward move the lane actually needs is still allowed.
|
||||
assert!(valid_seed_progression(&repair, &ready));
|
||||
|
||||
drop(fixture.mailbox);
|
||||
fixture.task.await.unwrap();
|
||||
}
|
||||
|
||||
/// Soul. The pass claims a seeded world hands the Active elaborator at
|
||||
/// least one boundary. It is the obligations that do that, never the goals:
|
||||
/// `derive_boundaries` skips a commitment with no counterparty, and a goal
|
||||
/// cannot carry one. A world seeded to full strength out of goals alone
|
||||
/// activates with nothing for the elaborator to answer.
|
||||
#[tokio::test]
|
||||
#[ignore = "FALSIFIED: a Goal derives no boundary, so a goals-only seed leaves the elaborator nothing"]
|
||||
async fn soul_a_world_seeded_out_of_goals_alone_hands_the_elaborator_nothing() {
|
||||
let fixture = seed_mailbox(2).await;
|
||||
let entry = serde_json::to_value(fixture.speak).unwrap();
|
||||
let place = serde_json::to_value(fixture.sere).unwrap();
|
||||
let mut calls: Vec<(&str, Value)> = Vec::new();
|
||||
for handle in ["a1", "a2"] {
|
||||
calls.push((
|
||||
"declare_subject",
|
||||
json!({
|
||||
"handle": handle,
|
||||
"label": format!("Sere {handle}"),
|
||||
"kind": "person",
|
||||
"controller": {"type": "narrative_persona"},
|
||||
"affordances": [{"ref": "existing", "value": entry}],
|
||||
"position": {"ref": "existing", "value": place},
|
||||
}),
|
||||
));
|
||||
calls.push((
|
||||
"create_commitment",
|
||||
json!({
|
||||
"subject": {"ref": "draft", "value": handle},
|
||||
"counterparty": null,
|
||||
"kind": "goal",
|
||||
"due": 600,
|
||||
"period": null,
|
||||
"checks": [],
|
||||
}),
|
||||
));
|
||||
}
|
||||
calls.push(("submit", json!({})));
|
||||
let runner = seed_runner(
|
||||
&fixture,
|
||||
seed_script(vec![tool_round(calls, "r0")]),
|
||||
fresh_store(),
|
||||
Arc::new(NullEvidenceSource),
|
||||
);
|
||||
assert_eq!(runner.sweep(4).await.unwrap(), SeedOutcome::Clean);
|
||||
drop(runner);
|
||||
|
||||
let authenticated =
|
||||
AuthenticatedCaller::fixture(CallerId::Principal(fixture.owner.clone()));
|
||||
let mut snapshot = fixture.mailbox.snapshot().await.unwrap();
|
||||
assert!(snapshot.scale_deficit.iter().all(|row| row.deficit == 0));
|
||||
for body in [CommandBody::ApproveDraft, CommandBody::ActivateWorld] {
|
||||
fixture
|
||||
.mailbox
|
||||
.submit_fixture(
|
||||
CommandEnvelope {
|
||||
id: CommandId::new(),
|
||||
world_id: snapshot.world_id,
|
||||
expected_revision: snapshot.revision,
|
||||
caller: CallerId::Principal(fixture.owner.clone()),
|
||||
body,
|
||||
},
|
||||
&authenticated,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
snapshot = fixture.mailbox.snapshot().await.unwrap();
|
||||
}
|
||||
assert_eq!(snapshot.phase, WorldPhase::Active);
|
||||
assert!(
|
||||
!snapshot.boundaries.is_empty(),
|
||||
"a fully seeded world activated with nothing for the elaborator to answer"
|
||||
);
|
||||
|
||||
drop(fixture.mailbox);
|
||||
fixture.task.await.unwrap();
|
||||
}
|
||||
|
||||
/// Soul. The custody discriminator has to see the new lane, or a seed row
|
||||
/// is a row nobody counts.
|
||||
#[tokio::test]
|
||||
async fn soul_the_custody_probe_counts_a_seed_row() {
|
||||
let fixture = seed_mailbox(6).await;
|
||||
let store = fresh_store();
|
||||
assert_eq!(
|
||||
store.custody_probe().await.unwrap(),
|
||||
ControllerWorkCustody::Owned {
|
||||
narrative_commands: 0,
|
||||
operational_commands: 0,
|
||||
elaboration_commands: 0,
|
||||
seed_commands: 0,
|
||||
}
|
||||
);
|
||||
let runner = seed_runner(
|
||||
&fixture,
|
||||
seed_script(vec![author_persons(
|
||||
"r0",
|
||||
fixture.sere,
|
||||
fixture.speak,
|
||||
&["digger"],
|
||||
)]),
|
||||
store.clone(),
|
||||
Arc::new(NullEvidenceSource),
|
||||
);
|
||||
assert_eq!(runner.step().await.unwrap(), SeedOutcome::Committed);
|
||||
assert_eq!(
|
||||
store.custody_probe().await.unwrap(),
|
||||
ControllerWorkCustody::Owned {
|
||||
narrative_commands: 0,
|
||||
operational_commands: 0,
|
||||
elaboration_commands: 0,
|
||||
seed_commands: 1,
|
||||
}
|
||||
);
|
||||
|
||||
drop(runner);
|
||||
drop(fixture.mailbox);
|
||||
fixture.task.await.unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -537,6 +537,180 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
/// Soul. The scope check runs once, at `open`, against the scope string.
|
||||
/// The walk that follows does not: `collect_notes` recurses through
|
||||
/// anything `is_dir()` answers for, which follows a directory junction, and
|
||||
/// `strip_prefix(&root)` then runs against the uncanonicalized path, so a
|
||||
/// note outside the root comes back wearing a vault-relative reference.
|
||||
///
|
||||
/// A junction needs no privilege on Windows, so this is reachable by
|
||||
/// anyone who can write inside the configured vault.
|
||||
#[cfg(windows)]
|
||||
#[tokio::test]
|
||||
#[ignore = "FALSIFIED: collect_notes follows a directory junction out of the vault root"]
|
||||
async fn soul_a_junction_inside_the_root_reads_a_note_outside_it() {
|
||||
let directory = fixture();
|
||||
let outside = tempfile::tempdir().unwrap();
|
||||
write(
|
||||
outside.path(),
|
||||
"Secret.md",
|
||||
"The vault root does not cover me.\n",
|
||||
);
|
||||
let link = directory.path().join("Public").join("Escape");
|
||||
let made = std::process::Command::new("cmd")
|
||||
.args([
|
||||
"/C",
|
||||
"mklink",
|
||||
"/J",
|
||||
&link.display().to_string(),
|
||||
&outside.path().display().to_string(),
|
||||
])
|
||||
.output();
|
||||
if made.is_err() || !link.exists() {
|
||||
eprintln!("skipped: this environment cannot create a directory junction");
|
||||
return;
|
||||
}
|
||||
|
||||
let source = VaultEvidenceSource::open(directory.path(), "Public").unwrap();
|
||||
let receipts = source.retrieve(&query(&["Secret"])).await.unwrap();
|
||||
assert!(
|
||||
receipts.is_empty(),
|
||||
"a note outside the configured root was read and handed back as {:?}",
|
||||
receipts
|
||||
.iter()
|
||||
.map(|receipt| receipt.reference.text().to_owned())
|
||||
.collect::<Vec<_>>()
|
||||
);
|
||||
}
|
||||
|
||||
/// Soul. Two bounds and one promise. A note over `MAX_NOTE_BYTES` is
|
||||
/// skipped on its metadata, so it is never read into memory and never
|
||||
/// reaches a receipt; and neither `open` nor `retrieve` writes anything,
|
||||
/// asserted against the tree's own bytes and modification times rather than
|
||||
/// against the doc comment.
|
||||
#[tokio::test]
|
||||
async fn soul_an_oversized_note_is_never_read_and_the_reader_never_writes() {
|
||||
let directory = fixture();
|
||||
let root = directory.path();
|
||||
let huge = format!(
|
||||
"---\ntitle: The Long Note\n---\n{}\n",
|
||||
"obese ".repeat(usize::try_from(MAX_NOTE_BYTES).unwrap() / 4)
|
||||
);
|
||||
assert!(u64::try_from(huge.len()).unwrap() > MAX_NOTE_BYTES);
|
||||
write(root, "Public/Places/Long Note.md", &huge);
|
||||
|
||||
let before = tree(root);
|
||||
let source = VaultEvidenceSource::open(root, "").unwrap();
|
||||
for name in ["Long Note", "The Long Note", "obese"] {
|
||||
let receipts = source.retrieve(&query(&[name])).await.unwrap();
|
||||
assert!(
|
||||
receipts
|
||||
.iter()
|
||||
.all(|receipt| receipt.reference
|
||||
!= EvidenceRef::new("Public/Places/Long Note.md")),
|
||||
"{name} returned a note over the byte cap"
|
||||
);
|
||||
}
|
||||
assert_eq!(before, tree(root), "the reader changed the vault");
|
||||
}
|
||||
|
||||
/// Every file under `root`, by relative path, length, and modification
|
||||
/// time: what a read-only reader must leave exactly as it found it.
|
||||
fn tree(root: &Path) -> BTreeMap<String, (u64, std::time::SystemTime)> {
|
||||
let mut found = BTreeMap::new();
|
||||
let mut paths = Vec::new();
|
||||
collect_all(root, &mut paths);
|
||||
for path in paths {
|
||||
let metadata = std::fs::metadata(&path).unwrap();
|
||||
found.insert(
|
||||
path.strip_prefix(root).unwrap().display().to_string(),
|
||||
(metadata.len(), metadata.modified().unwrap()),
|
||||
);
|
||||
}
|
||||
found
|
||||
}
|
||||
|
||||
fn collect_all(directory: &Path, into: &mut Vec<PathBuf>) {
|
||||
for entry in std::fs::read_dir(directory).unwrap().flatten() {
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
collect_all(&path, into);
|
||||
} else {
|
||||
into.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Soul. `MAX_VAULT_RECEIPTS` is the cap the module names, and the reason
|
||||
/// it gives is that a session citing everything still fits in one patch.
|
||||
/// The link fanout overshoots it: the guard is checked before a link is
|
||||
/// resolved and not before each receipt that link produces, so one
|
||||
/// keyword-resolving link adds up to `MAX_HITS_PER_REFERENT` past the cap.
|
||||
#[tokio::test]
|
||||
async fn soul_the_link_fanout_overshoots_the_receipt_cap() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let root = directory.path();
|
||||
// Enough plain notes to walk the receipt count up to the cap, each one
|
||||
// resolving by its own stem and linking nowhere.
|
||||
for index in 0..MAX_VAULT_RECEIPTS {
|
||||
write(root, &format!("plain{index}.md"), "A plain note.\n");
|
||||
}
|
||||
// One note whose single wikilink resolves by keyword, not by key, to
|
||||
// three notes at once.
|
||||
write(root, "hub.md", "See [[quarry stone]].\n");
|
||||
for index in 0..MAX_HITS_PER_REFERENT {
|
||||
write(
|
||||
root,
|
||||
&format!("quarry{index}.md"),
|
||||
"quarry stone quarry stone\n",
|
||||
);
|
||||
}
|
||||
let source = VaultEvidenceSource::open(root, "").unwrap();
|
||||
|
||||
let mut referents: Vec<String> = (0..MAX_VAULT_RECEIPTS - 1)
|
||||
.map(|index| format!("plain{index}"))
|
||||
.collect();
|
||||
referents.push("hub".to_owned());
|
||||
let receipts = source.retrieve(&EvidenceQuery { referents }).await.unwrap();
|
||||
assert!(
|
||||
receipts.len() <= MAX_VAULT_RECEIPTS,
|
||||
"one call returned {} receipts against a cap of {MAX_VAULT_RECEIPTS}",
|
||||
receipts.len()
|
||||
);
|
||||
}
|
||||
|
||||
/// Soul. A vault error carries the server's absolute filesystem paths, and
|
||||
/// `seed_once` maps `VaultError` straight into `RuntimeCommandError::Payload`,
|
||||
/// so the string reaches the owner's command receipt. The reference format
|
||||
/// is deliberately vault-relative; these strings are not.
|
||||
#[test]
|
||||
#[ignore = "FALSIFIED: VaultError::Root carries the server absolute path into the owner receipt"]
|
||||
fn soul_a_vault_error_carries_an_absolute_path() {
|
||||
let directory = fixture();
|
||||
let root = directory.path();
|
||||
for (case, opened) in [
|
||||
(
|
||||
"an escaping scope",
|
||||
VaultEvidenceSource::open(root, "Public/../.."),
|
||||
),
|
||||
// The reachable misconfiguration: `GHOSTLIGHT_SEED_VAULT_ROOT`
|
||||
// naming something that is not a directory.
|
||||
(
|
||||
"a root that is a file",
|
||||
VaultEvidenceSource::open(&root.join("Public/index.md"), ""),
|
||||
),
|
||||
] {
|
||||
let Err(error) = opened else {
|
||||
panic!("{case} was admitted");
|
||||
};
|
||||
let message = error.to_string();
|
||||
assert!(
|
||||
!message.contains(&root.display().to_string()) && !message.contains(":\\"),
|
||||
"{case} handed back an absolute path: {message}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Spec test 15. The scope is a corner of a configured vault, never a read
|
||||
/// primitive over the filesystem.
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue