"""Run the unmodified campaign dry_run checks and serialize T616 locally.

sage -python validate.py
No API writes. Capturing the loaded generator preserves its in-memory
computation cache while serializing the same checked results afterward.
"""
from pathlib import Path
import json,sys
import numberdb.sage as numberdb
from numberdb._write import to_text
import dry_run
original_load=dry_run.load
captured=[]
def capture(path):
    generator=original_load(path)
    captured.append(generator)
    return generator
dry_run.load=capture
status=dry_run.main([str(Path(__file__).with_name('generate.py'))])
if status:raise SystemExit(status)
g=captured[0];rows={}
for params in g.enumerate():
    val=g.value(params,g.digits)
    if isinstance(val,dict):rows[params['n']]={**val,'number':to_text(val['number'],g.digits)}
    else:rows[params['n']]=to_text(val,g.digits)
print('DATA '+json.dumps({'Numbers':rows,'versions':{'numberdb':numberdb.__version__,'python':sys.version}}))
