"""Lightweight checksum-specific upload gate; no model import in uploader.""" import json from pathlib import Path import sqlite3 ROOT=Path(__file__).resolve().parents[1] STATE=ROOT/'experiments/minor-safety' MINOR_GROUPS={'baby','preschool','younger_schoolchild','older_schoolchild','younger_teen','older_teen'} def approved_shard(source_connection,name): if not (STATE/'request.json').exists():return True rows=list(source_connection.execute("SELECT id,metadata FROM images WHERE shard=?",(name,))) selected=[(r['id'],json.loads(r['metadata'])['image_sha256']) for r in rows if json.loads(r['metadata'])['age_group'] in MINOR_GROUPS] if not selected:return True if any('safety_regeneration_attempt' in json.loads(r['metadata']) for r in rows) and not (STATE/'repair-quality-gate-passed.json').exists():return False if not (STATE/'scores.sqlite').exists():return False policy=json.loads((STATE/'policy.json').read_text())['policy_sha256'] if any(json.loads(r['metadata']).get('safety_regeneration_policy_sha256')==policy for r in rows): if not (STATE/f'repair-quality-gate-{policy}.json').exists():return False c=sqlite3.connect(STATE/'scores.sqlite') try: for ident,digest in selected: row=c.execute('SELECT decision FROM scores WHERE id=? AND image_sha256=? AND policy_sha256=?',(ident,digest,policy)).fetchone() if row is None or row[0]!='pass':return False return True finally:c.close()