#![cfg(feature = "dangerous-test-hooks")]
use bvisor::__sim::{reconciliation_replay_seed, run_reconciliation_matrix, ReconCell, ReconClass};
fn assert_legal_classification(cell: &ReconCell) -> Result<(), String> {
if matches!(
cell.class,
ReconClass::Completed | ReconClass::RolledBack | ReconClass::CanonicalRefusal
) {
Ok(())
} else {
Err(format!(
"ILLEGAL RECONCILED STATE: crash boundary `{}` classified as {:?}",
cell.boundary, cell.class
))
}
}
#[test]
fn reconciliation_matrix_is_legal_and_deterministic() -> Result<(), String> {
let seed = reconciliation_replay_seed(0x0B13_DEAD_BEEF);
let first = run_reconciliation_matrix(seed)?;
let second = run_reconciliation_matrix(seed)?;
assert!(
first.len() >= 4,
"the matrix must cover all four crash boundaries (>= 4 cells), got {}",
first.len()
);
assert_eq!(
first, second,
"PROPERTY: identical seed (0x{seed:X}) must sweep to the identical classification + \
digest set (replay with BVISOR_SEED={seed})"
);
for cell in &first {
assert_legal_classification(cell)?;
}
Ok(())
}
#[test]
fn sacred_window_is_a_typed_refusal_never_a_loss() -> Result<(), String> {
let cells = run_reconciliation_matrix(0x0B13_0001)?;
let sacred = cells
.iter()
.find(|c| c.boundary == "artifact-committed-pre-report")
.ok_or_else(|| "the matrix must include the sacred-window cell".to_string())?;
if sacred.class == ReconClass::CanonicalRefusal {
Ok(())
} else {
Err(format!(
"SACRED RULE: committed-artifact-without-report must be CanonicalRefusal, got {:?}",
sacred.class
))
}
}
#[test]
fn reconciliation_matrix_diverges_across_seeds() -> Result<(), String> {
let a = run_reconciliation_matrix(0x0B13_0001)?;
let b = run_reconciliation_matrix(0x0B13_0002)?;
let da: Vec<u64> = a.iter().map(|c| c.digest).collect();
let db: Vec<u64> = b.iter().map(|c| c.digest).collect();
assert_ne!(
da, db,
"PROPERTY: distinct seeds should (almost surely) sweep to divergent per-cell digests"
);
Ok(())
}
#[cfg(gauntlet_red_fixture)]
#[test]
fn reconciliation_red_fixture_undead_boundary_must_fail() -> Result<(), String> {
let cells = run_reconciliation_matrix(0x0B13_0003)?;
let sacred = cells
.iter()
.find(|c| c.boundary == "artifact-committed-pre-report")
.ok_or_else(|| "the matrix must include the sacred-window cell".to_string())?;
assert_eq!(
sacred.class,
ReconClass::Completed,
"RED FIXTURE: asserts the (illegal) UndeadBoundary outcome (Completed with no sealed \
report); MUST fail because the sacred window reconciles to a typed CanonicalRefusal"
);
Ok(())
}