"""Independent literal response/input oracle; never imports PrefixOK or a scan."""
import json
from pathlib import Path

def assess(observed, cases_file):
    cases = json.loads(Path(cases_file).read_text())['cases']
    literal = {case['id']: case for case in cases}
    rows = []
    for call in observed['calls']:
        case = literal[call['case']]
        values = [] if case['input'] is None else case['input']
        wanted = {'nil': case['input'] is None, 'values': values}
        actual = call['returnedIndex']
        response_ok = type(actual) is int and actual == case['expectedIndex']
        def exact(a, b):
            if type(a) is not type(b): return False
            if isinstance(a, dict): return a.keys() == b.keys() and all(exact(a[k],b[k]) for k in a)
            if isinstance(a, list): return len(a)==len(b) and all(exact(x,y) for x,y in zip(a,b))
            return a == b
        state_ok = exact(call['argumentBefore'], wanted) and exact(call['argumentAfter'], wanted)
        rows.append({'variant':call['variant'],'case':call['case'],'expectedIndex':case['expectedIndex'],'actualIndex':actual,'responseMatches':response_ok,'inputUnchangedIncludingNilness':state_ok,'accepted':response_ok and state_ok})
    assert len(rows) == 21
    assert {(r['variant'],r['case']) for r in rows} == {(v,c['id']) for v in ['baseline','corrected','weak'] for c in cases}
    return {'oracle':'Independent before-execution literal cases and recursive exact Python types/keys/values; no expected index is computed from implementation or PrefixOK.','rows':rows,'casesPerVariant':7,'operationCalls':21,'passedByVariant':{v:sum(r['accepted'] for r in rows if r['variant']==v) for v in ['baseline','corrected','weak']}}
