fsi-anomaly / tests /test_verify_loop.py
FerrellSyntheticIntelligence's picture
backup all: 37 files (final)
97c39f2 verified
Raw
History Blame Contribute Delete
5.6 kB
"""Standalone unit tests for research/verify_loop.py.
Run: .venv/bin/python tests/test_verify_loop.py
"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from research.verify_loop import plan_checks, run_checks, verify_case
def _verified_sources():
return [
{"source_id": "dot", "url": "https://records.example/dot",
"retrieved_at": "2026-08-12T12:00:00Z", "content_sha256": "a" * 64,
"independent": True, "retrievable": True,
"triage": {"independence": 3, "proximity": 3, "recency": 2, "track": 3, "interest": 3}},
{"source_id": "archive", "url": "https://archive.example/bridge",
"retrieved_at": "2026-08-12T12:01:00Z", "content_sha256": "b" * 64,
"independent": True, "retrievable": True,
"triage": {"independence": 2, "proximity": 2, "recency": 2, "track": 2, "interest": 2}},
]
def test_plan_checks_extracts_values():
checks = plan_checks('Claim: "the bridge opened in 2010" and cost $4.2M at 9:30am.')
kinds = [c["kind"] for c in checks]
assert "quote" in kinds and "number" in kinds and "time" in kinds
assert len(checks) <= 8
def test_run_checks_supports():
checks = [{"kind": "number", "value": "2010"}]
res = run_checks(checks, lambda v: "The DOT file lists the bridge opening year as 2010.")
assert res[0]["verdict"] == "supports"
def test_run_checks_refutes():
checks = [{"kind": "number", "value": "2010"}]
res = run_checks(checks, lambda v: "The DOT file lists the bridge opening year as 2012.")
assert res[0]["verdict"] == "refutes"
def test_run_checks_no_evidence():
checks = [{"kind": "quote", "value": "classified"}]
res = run_checks(checks, lambda v: "")
assert res[0]["verdict"] == "not enough information"
assert res[0]["kind"] == "no-evidence"
def test_verify_case_rule_refuted_wins():
d = verify_case('Claim: "the bridge opened in 2010"',
draft_verdict="true", draft_conf="HIGH",
retrieve=lambda v: "The DOT file lists the bridge opening year as 2012.",
require_source_policy=False)
assert d["verdict"] == "false"
assert d["confidence"] == "HIGH"
assert d["basis"] == "rule-refuted"
def test_verify_case_rule_verified():
d = verify_case('Claim: "the bridge opened in 2010"',
draft_verdict="true", draft_conf="MEDIUM",
retrieve=lambda v: "The DOT file lists the bridge opening year as 2010.",
require_source_policy=False)
assert d["verdict"] == "true"
assert d["confidence"] == "HIGH"
assert d["basis"] == "rule-verified"
def test_verify_case_unresolved_downgrades_high():
d = verify_case("Claim: the memo is significant.",
draft_verdict="overclaim", draft_conf="HIGH",
retrieve=lambda v: "", require_source_policy=False)
assert d["confidence"] == "MEDIUM"
assert d["basis"] == "draft-high-downgraded-unverified"
def test_verify_case_unresolved_keeps_low():
d = verify_case("Claim: the memo is significant.",
draft_verdict="not enough information", draft_conf="LOW",
retrieve=lambda v: "", require_source_policy=False)
assert d["verdict"] == "not enough information"
assert d["confidence"] == "LOW"
assert d["abstained"]
def test_strict_policy_overrides_an_incorrect_model_draft():
d = verify_case('Claim: "the bridge opened in 2010"',
draft_verdict="false", draft_conf="HIGH",
retrieve=lambda v: {
"evidence": "The DOT filing lists the bridge opening year as 2010.",
"sources": _verified_sources(), "claim_relation": "supports"},
require_source_policy=True)
assert d["verdict"] == "true"
assert d["confidence"] == "HIGH"
assert d["basis"] == "source-policy-verified"
assert set(d["sources"]) == {"dot", "archive"}
def test_strict_policy_fails_closed_on_a_single_untraceable_lead():
d = verify_case('Claim: "the bridge opened in 2010"',
draft_verdict="true", draft_conf="HIGH",
retrieve=lambda v: {
"evidence": "An anonymous post says the bridge opened in 2010.",
"sources": [{"source_id": "forum", "url": "https://forum.example/post",
"retrieved_at": "", "content_sha256": "bad",
"independent": True, "retrievable": True,
"triage": {"independence": 1, "proximity": 0,
"recency": 1, "track": 0, "interest": 0}}],
"claim_relation": "supports"},
require_source_policy=True)
assert d["verdict"] == "not enough information"
assert d["confidence"] == "LOW"
assert d["abstained"]
def test_verify_case_defaults_to_fail_closed_source_policy():
d = verify_case('Claim: "the bridge opened in 2010"',
draft_verdict="true", draft_conf="HIGH",
retrieve=lambda v: "A copied page says the bridge opened in 2010.")
assert d["verdict"] == "not enough information"
assert d["confidence"] == "LOW"
assert d["abstained"]
if __name__ == "__main__":
fns = [v for k, v in sorted(globals().items()) if k.startswith("test_")]
for fn in fns:
fn()
print(f"PASS {fn.__name__}")
print(f"\n{len(fns)} tests passed")