"""Run: python3 source-check.py [source-check.json]. Standard library; no network.

This checks whether a supplied quote is on a supplied page. It does not
generate answers, establish entailment, test an LLM or measure production AI.
"""
import json
import sys
from pathlib import Path

def check(pages, case):
    if case['page'] is None or not case['quote']:
        return 'needs-human-answer'
    return 'quote-present' if case['quote'] in pages.get(case['page'], '') else 'quote-not-found'

def main():
    path = Path(sys.argv[1]) if len(sys.argv) > 1 else Path(__file__).with_suffix('.json')
    data = json.loads(path.read_text())
    failures = 0
    for case in data['cases']:
        actual = check(data['pages'], case)
        print(f"{case['id']}: {actual}")
        failures += actual != case['expected']
    print(f"{len(data['cases']) - failures}/{len(data['cases'])} fixture checks passed")
    return bool(failures)

if __name__ == '__main__':
    sys.exit(main())
