use super::*;
#[test]
fn test_subsumption_verification_soundness() {
let old_ast = serde_json::json!({
"abstract_spec": {
"invariants": {
"preconditions": ["pre_a", "pre_b"],
"postconditions": ["post_x"]
}
}
});
let compliant_new_ast = serde_json::json!({
"abstract_spec": {
"invariants": {
"preconditions": ["pre_a"],
"postconditions": ["post_x", "post_y"]
}
}
});
let res = verify_subsumption(&old_ast, &compliant_new_ast);
assert!(res.is_ok());
let report = res.unwrap();
assert!(report.pre_subsumed);
assert!(report.post_subsumed);
assert!(report.subsumption_valid);
let breaking_pre_ast = serde_json::json!({
"abstract_spec": {
"invariants": {
"preconditions": ["pre_a", "pre_c"],
"postconditions": ["post_x"]
}
}
});
assert!(verify_subsumption(&old_ast, &breaking_pre_ast).is_err());
let breaking_post_ast = serde_json::json!({
"abstract_spec": {
"invariants": {
"preconditions": ["pre_a"],
"postconditions": ["post_z"]
}
}
});
assert!(verify_subsumption(&old_ast, &breaking_post_ast).is_err());
}
#[test]
fn test_dynamic_baldwin_fiber_lifecycle() {
let ctx = crate::fiber::Context::root();
let fiber = ctx.create_fiber("test_fiber", vec!["effect_1".to_string()]).unwrap();
assert_eq!(fiber.get_state(), crate::fiber::FiberState::Pending);
augment_fiber(&ctx, "test_fiber", "effect_1").unwrap();
assert_eq!(fiber.get_state(), crate::fiber::FiberState::Active);
let split_res = split_fiber(&ctx, "test_fiber", &["effect_1"]);
assert!(split_res.is_ok());
exclude_fiber(&ctx, "test_fiber").unwrap();
assert!(ctx.get_fiber("test_fiber").is_none());
}
#[test]
fn test_baldwin_v1_vectors_positive_negative_and_idempotence() {
let fixture_path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../../tests/fixtures/baldwin_operations_v1.json");
let raw = std::fs::read_to_string(&fixture_path)
.expect("failed to read baldwin_operations_v1.json");
let doc: serde_json::Value = serde_json::from_str(&raw).expect("invalid JSON fixture");
let vectors = doc.get("vectors").and_then(|v| v.as_array()).expect("vectors array");
for vec in vectors {
let before = vec.get("initial_state").cloned();
let res1 = crate::baldwin::baldwin_augment::evaluate_baldwin_vector(vec).expect("positive vector should succeed");
let res2 = crate::baldwin::baldwin_augment::evaluate_baldwin_vector(vec).expect("retry should succeed");
assert_eq!(vec.get("initial_state").cloned(), before);
assert_eq!(res1.after_canonical_json, vec["expected_after_canonical_json"].as_str().unwrap());
assert_eq!(res1.after_hash, vec["expected_after_hash"].as_str().unwrap());
assert_eq!(res1.witness_canonical_json, vec["expected_witness_canonical_json"].as_str().unwrap());
assert_eq!(res1.witness_hash, vec["expected_witness_hash"].as_str().unwrap());
assert_eq!(res1.after_hash, res2.after_hash);
assert_eq!(res1.witness_hash, res2.witness_hash);
}
let neg_vectors = doc.get("negative_vectors").and_then(|v| v.as_array()).expect("negative_vectors array");
for neg in neg_vectors {
let before = neg.get("initial_state").cloned();
let err = crate::baldwin::baldwin_augment::evaluate_baldwin_vector(neg).expect_err("negative vector should fail");
assert_eq!(neg.get("initial_state").cloned(), before);
assert_eq!(err.code, neg["expected_error_code"].as_str().unwrap());
}
}