vpf-runner 0.4.0

The reference runner of the Verifiable Plan Format (VPF): runs a plan step by step and proves each step.
Documentation
//! A proof for one answer of a choice is asked only on that path, and kept as skipped on the others.

mod common;

use vpf_runner::{Outcome, Runner};

use common::{Scripted, agent, plan, said};

const DESIGN: &str = r#"{ "$schema": "vpf/1.1", "wish": "A design",
     "steps": [
       { "id": "design", "do": "Design it, and say where it is tested.", "by": "agent", "choices": ["mac", "cloud"],
         "proof": [ { "by": "algorithm", "run": "true" },
                    { "by": "person", "ask": "Did it work on the Mac?", "when": { "design": "mac" } } ] },
       { "id": "build", "do": "Build.", "by": "algorithm", "run": "true",
         "proof": { "by": "person", "ask": "Is the Mac build good?", "when": { "design": "mac" } } }
     ] }"#;

#[test]
fn a_proof_for_another_path_is_not_asked_and_is_kept_as_skipped() {
    let folder = tempfile::tempdir().expect("a folder");
    let (agent, _) = agent(|_, _| said("cloud"));
    let mut person = Scripted::default();
    let record = Runner::new(folder.path(), &agent, &mut person).run(&plan(DESIGN), "");

    assert_eq!(record.outcome, Outcome::Done, "{}", person.all());
    assert!(person.asks.is_empty(), "no one is asked: {}", person.all());
    let proofs = &record.steps[0].attempts[0].proofs;
    assert_eq!(proofs.len(), 2);
    assert!(proofs[0].passed && !proofs[0].skipped);
    assert!(proofs[1].skipped && !proofs[1].passed);
    let kept = serde_json::to_value(&proofs[1]).expect("a proof kept");
    assert!(
        kept.get("passed").is_none(),
        "a skipped proof neither passed nor refused: {kept}"
    );
    assert_eq!(proofs[1].points, None);
    assert_eq!(
        proofs[1].reason.as_deref(),
        Some("Only when design answers “mac”; it answered “cloud”.")
    );
    let build = &record.steps[1].attempts[0].proofs;
    assert!(build.last().is_some_and(|proof| proof.skipped), "{build:?}");
}

#[test]
fn a_proof_for_the_path_taken_is_asked() {
    let folder = tempfile::tempdir().expect("a folder");
    let (agent, _) = agent(|_, _| said("I made it.\nmac"));
    let mut person = Scripted::new(&["no: it crashed", "yes", "yes"]);
    let record = Runner::new(folder.path(), &agent, &mut person).run(&plan(DESIGN), "");

    assert_eq!(record.outcome, Outcome::Done, "{}", person.all());
    assert_eq!(record.steps[0].attempts.len(), 2);
    assert_eq!(
        record.steps[0].attempts[0].proofs[1].points.as_deref(),
        Some("it crashed")
    );
    assert!(
        person.all().contains("Is the Mac build good?"),
        "{}",
        person.all()
    );
}