B3 fix: pin the route-proof rules, and delete guards another owner already holds

Tests for each rule the Soul pass found unpinned, each written to fail
under its own mutation:
- a stateful route-proof target through the Engine, Fencing to commit: the
  lease is prepared and granted, Ready is refused without the exact lease
  and recorded with it, boot re-authenticates the store at every stage and
  Odin is never read;
- Warming challenges once and then advances on every tick;
- a stateful candidate may not answer its Warming challenge active;
- a presence holds the write lease exactly when it is not warming, and is
  minted after its challenge;
- direct Warming evidence is bound to the bytes and digest it authenticated;
- candidate-vouched evidence is refused on a target Odin reports on;
- a pre-B3 transaction and a pre-B3 generation over a route-proof target are
  held and reported once, not stepped every tick, and not re-derived;
- a stored record with no declared readiness is held;
- Odin is the class OdinSelf, not the name "odin";
- admission refuses an undeclared recipe with a typed error, before the
  source is frozen; a recipe that declares its proof is planned;
- the driver's challenge failures: silence waits, every bad answer and every
  local configuration error is an error;
- the capacity shortfall is read as a typed PresenceDisagrees.

Deleted because another owner already holds them, so no test can reach them:
the Routing and commit "route-proof Ready evidence" ensures (validation
refuses a missing receipt, the hold refuses the other party's), the write
lease comparison's warming arm (the authenticator refuses a warming presence
that claims a lease), and the direct-Warming refresh check (rehydration
authenticates the recorded answer as Odin's first).

Engine.source is a SourcePort, the seam the admission test needs.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-29 13:32:42 +02:00
commit e11b457458
3 changed files with 1334 additions and 61 deletions

File diff suppressed because it is too large Load diff

View file

@ -1566,6 +1566,69 @@ nodes = ["yggdrasil"]
);
}
#[test]
fn a_plan_names_how_its_target_proves_readiness_and_agrees_with_its_expected() {
use crate::control_plane::UndeclaredReadiness;
let unrouted_binding = {
let (head, tail) = BINDING.split_once("[route]").unwrap();
format!("{head}[brakes]{}", tail.split_once("[brakes]").unwrap().1)
};
let unrouted = |recipe: &str| {
recipe
.replace("route_required = true", "route_required = false")
.replace(
r#"["GAMECULT_IDUNN_CANDIDATE_BIND", "GAMECULT_IDUNN_RUNTIME_BUNDLE"]"#,
r#"["GAMECULT_IDUNN_RUNTIME_BUNDLE"]"#,
)
};
let without_odin = RECIPE.split("[[dependencies]]").next().unwrap().to_owned();
let provides_odin = |recipe: &str| {
recipe.replace("capability = \"service.runtime\"", "capability = \"odin.verse-rendezvous\"")
};
let cases: [(&str, String, &str, Option<u16>, Result<ReadinessClass, ()>); 5] = [
("depends on Odin, routed", RECIPE.to_owned(), BINDING, Some(18001), Ok(ReadinessClass::OdinCorrelated)),
("routed, no Odin", without_odin.clone(), BINDING, Some(18001), Ok(ReadinessClass::RouteProof)),
("unrouted, no Odin", unrouted(&without_odin), &unrouted_binding, None, Err(())),
("provides Odin, unrouted", provides_odin(&unrouted(&without_odin)), &unrouted_binding, None, Ok(ReadinessClass::OdinSelf)),
("depends on Odin, unrouted", unrouted(RECIPE), &unrouted_binding, None, Ok(ReadinessClass::OdinCorrelated)),
];
for (name, recipe, binding, port, outcome) in cases {
let providers = [ready_odin_provider("odin", "odin-yggdrasil", 1)];
let plan = compile_deployment_plan(
recipe.as_bytes(),
binding.as_bytes(),
source(&recipe),
"service-incarnation-1",
port,
110,
if recipe.contains("[[dependencies]]") { &providers } else { &[] },
)
.unwrap_or_else(|error| panic!("{name}: {error:#}"));
let release = SealedRelease::new(
&plan,
vec![artifact_receipt()],
vec![external_input_receipt()],
120,
)
.unwrap();
let expected = release.expected_projection(&plan).unwrap();
match outcome {
Ok(class) => {
assert_eq!(plan.readiness_class().unwrap(), class, "{name}");
assert_eq!(ReadinessClass::of(&expected), Ok(class), "{name}");
}
Err(()) => {
let error = plan.readiness_class().expect_err(name);
let undeclared = UndeclaredReadiness {
target: "service".into(),
};
assert_eq!(error.downcast_ref::<UndeclaredReadiness>(), Some(&undeclared), "{name}");
assert_eq!(ReadinessClass::of(&expected), Err(undeclared), "{name}");
}
}
}
}
#[test]
fn expected_projection_is_sanitized_and_names_the_selected_graph() {
let plan = plan();

View file

@ -8118,6 +8118,279 @@ fn apply_identity(command: &mut Command, identity: Option<ProcessIdentity>) -> R
mod tests {
use super::*;
// ---------------------------------------------------------------------
// A direct challenge fails one of two ways. Silence waits; a bad answer,
// or a challenge that cannot be made, is an error.
// ---------------------------------------------------------------------
/// A peer that reads one snapshot request and writes back whatever `reply`
/// builds from the challenge id. Returns the port it listens on.
fn scripted_peer(reply: impl FnOnce(&str) -> Vec<u8> + Send + 'static) -> u16 {
let listener = std::net::TcpListener::bind("127.0.0.1:0").expect("a free port");
let port = listener.local_addr().expect("a bound port").port();
thread::spawn(move || {
let Ok((mut stream, _)) = listener.accept() else {
return;
};
let mut request = Vec::new();
let mut chunk = [0_u8; 4096];
let message_id = loop {
let Ok(read) = stream.read(&mut chunk) else {
return;
};
if read == 0 {
return;
}
request.extend_from_slice(&chunk[..read]);
let Some(end) = request.windows(4).position(|window| window == b"\r\n\r\n") else {
continue;
};
if let Ok(CultNetMessage::SnapshotRequest { message_id, .. }) =
decode_cultnet_message_from_slice(
&request[end + 4..],
CultNetWireContract::CultNetSchemaV0,
)
{
break message_id;
}
};
let _ = stream.write_all(&reply(&message_id));
});
port
}
fn http_ok(body: &[u8]) -> Vec<u8> {
let mut response = format!(
"HTTP/1.1 200 OK\r\nContent-Length: {}\r\nConnection: close\r\n\r\n",
body.len()
)
.into_bytes();
response.extend_from_slice(body);
response
}
fn raw_snapshot(message_id: &str, schema: &str, key: &str, payload: Vec<u8>) -> Vec<u8> {
http_ok(
&encode_cultnet_message_to_vec(
&CultNetMessage::SnapshotResponseRaw {
message_id: message_id.into(),
documents: vec![cultnet_rs::CultNetRawDocumentRecord {
schema_id: schema.into(),
record_key: key.into(),
stored_at: "1970-01-01T00:00:00.100Z".into(),
payload_encoding: cultnet_rs::CultNetRawPayloadEncoding::Messagepack,
payload,
source_runtime_id: None,
source_agent_id: None,
source_role: None,
tags: None,
}],
},
CultNetWireContract::CultNetSchemaV0,
)
.expect("an encodable response"),
)
}
fn honest(message_id: &str) -> Vec<u8> {
raw_snapshot(
message_id,
cultnet_rs::GAMECULT_RUNTIME_PRESENCE_HEALTH_SCHEMA,
"service",
vec![1, 2, 3],
)
}
/// One candidate challenge to `port`, with the Expected adjusted by `adjust`.
fn challenge(
port: u16,
adjust: impl FnOnce(&mut IdunnExpectedIncarnationRecord),
) -> Result<RouteSnapshotResponse, ChallengeFailure> {
let temp = tempfile::tempdir().expect("a temporary directory");
let mut candidate = expected();
candidate.route = Some(cultnet_rs::IdunnExpectedRoute {
route_id: "service".into(),
transport: "http".into(),
stable_endpoint: "http://127.0.0.1:17999".into(),
candidate_endpoint: format!("http://127.0.0.1:{port}"),
});
adjust(&mut candidate);
NginxRouteDriver::new(RouteBinding {
driver: RouteDriver::NginxStreamTcp,
route_id: "service".into(),
stable_endpoint: "http://127.0.0.1:17999".into(),
private_host: "127.0.0.1".into(),
private_port_start: port,
private_port_end: port,
config_path: temp.path().join("service.conf"),
reload_unit: "nginx.service".into(),
})
.request_candidate_runtime_presence(&candidate, "candidate-probe")
}
fn assert_silent(outcome: Result<RouteSnapshotResponse, ChallengeFailure>, why: &str) {
assert!(
matches!(outcome, Err(ChallengeFailure::Silent(_))),
"{why} must read as silence: {outcome:?}"
);
}
fn assert_refused(outcome: Result<RouteSnapshotResponse, ChallengeFailure>, why: &str) {
assert!(
matches!(outcome, Err(ChallengeFailure::Refused(_))),
"{why} must be an error, not a wait: {outcome:?}"
);
}
#[test]
fn an_exact_answer_is_taken() {
let port = scripted_peer(honest);
let answer = challenge(port, |_| {}).expect("the exact answer");
assert_eq!(answer.message_id, "candidate-probe");
assert_eq!(answer.canonical_presence, [1, 2, 3]);
}
#[test]
fn a_challenge_that_nothing_answers_is_silence() {
assert_silent(challenge(scripted_peer(|_| Vec::new()), |_| {}), "a peer that hangs up");
// Half a response, then the peer is gone.
assert_refused(
challenge(scripted_peer(|_| b"HTTP/1.1 200 OK\r\nContent-Le".to_vec()), |_| {}),
"a response that never finished its headers",
);
// Nothing listens.
let reservation = std::net::TcpListener::bind("127.0.0.1:0").expect("a free port");
let port = reservation.local_addr().expect("a bound port").port();
drop(reservation);
assert_silent(challenge(port, |_| {}), "a closed port");
}
#[test]
fn a_bad_answer_is_refused_not_waited_on() {
assert_refused(
challenge(
scripted_peer(|_| {
raw_snapshot(
"candidate-another",
cultnet_rs::GAMECULT_RUNTIME_PRESENCE_HEALTH_SCHEMA,
"service",
vec![1],
)
}),
|_| {},
),
"an answer to another challenge",
);
assert_refused(
challenge(
scripted_peer(|id| raw_snapshot(id, "some.other.schema", "service", vec![1])),
|_| {},
),
"a substituted document schema",
);
assert_refused(
challenge(
scripted_peer(|id| {
raw_snapshot(
id,
cultnet_rs::GAMECULT_RUNTIME_PRESENCE_HEALTH_SCHEMA,
"another-target",
vec![1],
)
}),
|_| {},
),
"a substituted record key",
);
assert_refused(
challenge(
scripted_peer(|id| {
raw_snapshot(
id,
cultnet_rs::GAMECULT_RUNTIME_PRESENCE_HEALTH_SCHEMA,
"service",
vec![0; ROUTE_SNAPSHOT_MAX_BYTES + 1],
)
}),
|_| {},
),
"an oversized payload",
);
assert_refused(
challenge(
scripted_peer(|id| {
http_ok(
&encode_cultnet_message_to_vec(
&CultNetMessage::SnapshotRequest {
message_id: id.into(),
schema_ids: None,
record_keys: None,
},
CultNetWireContract::CultNetSchemaV0,
)
.expect("an encodable message"),
)
}),
|_| {},
),
"a response that is not a raw snapshot",
);
assert_refused(
challenge(
scripted_peer(|_| {
b"HTTP/1.1 503 Service Unavailable\r\nContent-Length: 0\r\nConnection: close\r\n\r\n"
.to_vec()
}),
|_| {},
),
"an HTTP error",
);
assert_refused(
challenge(scripted_peer(|_| http_ok(b"not a cultnet message")), |_| {}),
"a body that is not CultNet",
);
assert_refused(
challenge(scripted_peer(|_| b"HTTP/1.1 200 OK
Content-Le".to_vec()), |_| {}),
"a response that never finished its headers",
);
}
#[test]
fn a_challenge_that_cannot_be_made_is_an_error_not_a_wait() {
let port = scripted_peer(honest);
assert_refused(
challenge(port, |candidate| {
candidate.route.as_mut().unwrap().route_id = "another-route".into();
}),
"a binding that differs from Expected",
);
assert_refused(
challenge(port, |candidate| {
candidate.route.as_mut().unwrap().transport = "smtp".into();
}),
"an unsupported transport",
);
assert_refused(
challenge(port, |candidate| {
candidate.route.as_mut().unwrap().candidate_endpoint =
format!("http://candidate.example:{port}");
}),
"a host that is not an IP address",
);
assert_refused(
challenge(port, |candidate| {
candidate.route.as_mut().unwrap().candidate_endpoint =
format!("http://127.0.0.1:{}", port.wrapping_add(1));
}),
"a candidate endpoint outside the route binding",
);
assert_refused(
challenge(port, |candidate| candidate.route = None),
"an Expected with no route",
);
}
#[test]
fn route_connect_retries_connection_refused_until_listener_is_ready() -> Result<()> {
let reservation = std::net::TcpListener::bind("127.0.0.1:0")?;