#!/usr/bin/env python3 """Check a JSON result for this run. Python standard library; no network or n8n API. Contract: an object with the expected run_id and an items list. An empty list is valid. This does not validate every item or any media file mentioned by an item. """ import argparse,json,sys from pathlib import Path def check(path,run_id): try: with Path(path).open(encoding='utf-8') as f: value=json.load(f) except FileNotFoundError:return False,'missing_file' except (OSError,UnicodeError,json.JSONDecodeError):return False,'unreadable_json' if not isinstance(value,dict):return False,'expected_object' if value.get('run_id')!=run_id:return False,'wrong_run' if not isinstance(value.get('items'),list):return False,'expected_items_list' return True,'valid_empty' if not value['items'] else 'valid_items' if __name__=='__main__': p=argparse.ArgumentParser(description=__doc__);p.add_argument('path');p.add_argument('--run-id',required=True);a=p.parse_args() ok,reason=check(a.path,a.run_id);print(json.dumps({'ok':ok,'reason':reason}));sys.exit(0 if ok else 2)