test-driver/tests/test_reference_scenario.py

71 lines
2.2 KiB
Python
Raw Normal View History

"""The reference scenario must run deterministically and be replayable."""
from __future__ import annotations
import json
import pytest
from testdriver import Runner, Stratum, Verdict
from scenarios.alice_bob_carol import build
def run_once(*mutations: str):
world, driver, observer, asset, oracle = build(*mutations)
return Runner(world, driver, observer, oracle).run(asset), world
def test_reference_scenario_passes():
result, _ = run_once()
assert result.verdict is Verdict.PASS, [
j.as_dict() for j in result.judgments if j.verdict is not Verdict.PASS
]
def test_every_claim_is_judged():
result, _ = run_once()
judged = {j.assertion_id for j in result.judgments}
assert {"c-bob-reads", "c-carol-denied", "c-bob-revoked"} <= judged
def test_invariants_are_evaluated_after_every_step():
result, _ = run_once()
per_step = [j for j in result.judgments if j.assertion_id == "i-audit-append-only"]
assert len(per_step) == 3
def test_run_is_replayable_from_known_initial_state():
"""Two runs from the same seed produce identical judgments."""
first, _ = run_once()
second, _ = run_once()
assert [(j.assertion_id, j.verdict) for j in first.judgments] == [
(j.assertion_id, j.verdict) for j in second.judgments
]
assert first.run_id != second.run_id
def test_evidence_is_stratified_and_serializable():
result, _ = run_once()
pack = result.evidence
assert pack.of_stratum(Stratum.SURFACE)
assert pack.of_stratum(Stratum.REALIZATION)
assert pack.of_stratum(Stratum.JUDGMENT)
parsed = json.loads(pack.to_json())
assert parsed["run_id"] == result.run_id
assert parsed["sut_version"] == "lab-0.2.0-baseline"
def test_evidence_records_claim_provenance():
"""A verdict must be auditable for the independence of the claim behind it."""
result, _ = run_once()
assert result.evidence.provenance_index["c-bob-revoked"] == "human"
def test_actors_hold_isolated_credentials_and_memory():
_, world = run_once()
alice, bob = world.cast["alice"], world.cast["bob"]
assert alice.credentials["token"] != bob.credentials["token"]
alice.remember("secret", "only alice knows this")
assert bob.recall("secret") is None
assert bob.known_keys() == ()