"""Rerun the unchanged T610 checks and program before a prose-only repair.

    sage -python repair_checks.py > repair-checks.json

Place generate.py, checks.py, check.py, argument-selection.md, source-notes.md,
skill-evidence.json, and repair-skill-evidence.json beside this file. Supply its owner's
NumberDB API key on stdin while the table is private. This script only reads
NumberDB; it never fills, offers, publishes, or reviews a table.
"""
import contextlib, hashlib, io, json, os, re, sys
from pathlib import Path
key=sys.stdin.read().strip()
if re.match(r'^[A-Z_][A-Z0-9_]*\s*=',key):
    key=key.split('=',1)[1].strip().strip('\"\'')
assert key and not any(c.isspace() for c in key)
os.environ['NUMBERDB_API_KEY']=key
import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.rings.number_field.number_field import CyclotomicField
from sage.rings.real_arb import RealBallField
import checks
from generate import GlobalDimensions, categories
HERE=Path(__file__).resolve().parent
with contextlib.redirect_stdout(io.StringIO()):
    result=checks.main(live=True)
result['stage']='repair'
result['reviewer_run']='20261029T141456Z'
result['skill']=json.loads((HERE/'repair-skill-evidence.json').read_text())
document=numberdb.table('T610')
namespace=dict(ZZ=ZZ,QQ=QQ,CyclotomicField=CyclotomicField,RealBallField=RealBallField)
exec(document['Programs']['Sage']['code'],namespace)
assert namespace['global_dimension'](3,3)==36
for N,k in categories():
    answer=namespace['global_dimension'](N,k)
    expected=GlobalDimensions().value({'N':N,'k':k,'normalisation':'global'},100)
    if hasattr(answer,'is_finite'):
        assert answer.is_finite() and answer>0 and answer.accuracy()>=400
        assert answer.overlaps(expected)
    else:
        assert answer==expected
result['program_categories_checked']=117
result['program_example']='G(3,3)=36 exactly'
result['repair_checker_sha256']=hashlib.sha256(Path(__file__).read_bytes()).hexdigest()
result['scope']='Rerun of existing build checks plus every program output; not a new independent argument-selection critique. No new values.'
print(json.dumps(result,indent=2))
