#!/usr/bin/env python3
"""
SFT Audit: Witness Obstruction (WOB)

Checks:
- required fields exist
- obstruction_code matches canonical pattern
- evidence and recommended_next_moves are non-empty lists
"""
import json, re, sys
from pathlib import Path

PAT = re.compile(r"^WOB-[0-9]{2}(-[a-z0-9]+)*$")

def fail(msg):
    print("FAIL:", msg)
    sys.exit(1)

def main():
    if len(sys.argv) != 2:
        fail("Usage: audit_wob.py path/to/WOB.json")
    p = Path(sys.argv[1])
    if not p.exists():
        fail(f"File not found: {p}")
    data = json.loads(p.read_text(encoding="utf-8"))

    for k in ["sft_version","obstruction_id","witness_tier","obstruction_code","description","evidence","recommended_next_moves"]:
        if k not in data:
            fail(f"Missing required field: {k}")

    if not isinstance(data["evidence"], list) or len(data["evidence"]) == 0:
        fail("evidence must be a non-empty list")

    if not isinstance(data["recommended_next_moves"], list) or len(data["recommended_next_moves"]) == 0:
        fail("recommended_next_moves must be a non-empty list")

    if not PAT.match(data["obstruction_code"]):
        fail(f"obstruction_code not canonical: {data['obstruction_code']}")

    print("PASS: Basic WOB checks succeeded")
    print("Summary")
    print("  obstruction_id:", data["obstruction_id"])
    print("  code:", data["obstruction_code"])
    print("  tier:", data["witness_tier"])

if __name__ == "__main__":
    main()
