← Files Software & AI CopilotARCHIVED FILE

scripts/check_evidence.py

2.56 KB · Nov 9, 2026 · 00:42 UTC

↓ Download file

See the change to this file →

#!/usr/bin/env python3
"""Deterministically assess a local engineering evidence report; no external access."""
import json, sys
from pathlib import Path

VALID_STATUS={'passed','failed','not_run','blocked'}

def evaluate(report):
    problems=[]
    if not isinstance(report,dict):return {'ready':False,'problems':['Report must be a JSON object.']}
    for field in ('task','changes','checks','approvals'):
        if field not in report:problems.append(f'Missing {field}.')
    changes=report.get('changes')
    if not isinstance(changes,list) or not changes:problems.append('No changed artifacts identified.')
    elif any(not isinstance(c,str) or not c.strip() for c in changes):problems.append('Invalid changed artifact entry.')
    checks=report.get('checks')
    if not isinstance(checks,list) or not checks:
        problems.append('No check results recorded.')
    else:
        for n,c in enumerate(checks):
            if not isinstance(c,dict):problems.append(f'Check {n} is not an object.');continue
            status=c.get('status')
            if status not in VALID_STATUS:problems.append(f'Check {n} invalid status.');continue
            if status=='passed' and (not isinstance(c.get('command'),str) or not c.get('command','').strip() or c.get('exit_code')!=0 or not isinstance(c.get('evidence'),str) or not c.get('evidence','').strip()):
                problems.append(f'Check {n} claimed pass without executed command, successful exit code, and evidence.')
            if status in ('failed','not_run','blocked'):problems.append(f'Check {n} status {status}.')
    approvals=report.get('approvals',{})
    if not isinstance(approvals,dict) or type(approvals.get('required')) is not bool:
        problems.append('Approval requirement must be explicitly classified.')
    elif approvals.get('required') is True and approvals.get('granted') is not True:
        problems.append('Required approval not evidenced.')
    blockers=report.get('blockers',[])
    if not isinstance(blockers,list):problems.append('Blockers must be a list.')
    elif blockers:problems.append('Unresolved blockers remain.')
    return {'ready':not problems,'problems':problems}

def main(argv):
    if len(argv)!=2:print('Usage: check_evidence.py <report.json>',file=sys.stderr);return 2
    try:report=json.loads(Path(argv[1]).read_text(encoding='utf-8'))
    except (OSError,json.JSONDecodeError) as ex:print('Failed to read evidence:',str(ex),file=sys.stderr);return 2
    result=evaluate(report)
    print(json.dumps(result,indent=2))
    return 0 if result['ready'] else 1

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

SHA-256: 21edefeb520f18abe63fa599e502d209792cb08546d8676ac705734a9797eb7c