"""Independent native inputs for actual RSSD FK dates and numeric forms."""
from pathlib import Path
import json,subprocess,hashlib
root=Path(__file__).resolve().parents[1];dest=root/'target/kernel-date-rounding-edges-native';dest.mkdir(exist_ok=False)
oracle=root/'target/frame-kernel-errors-native-0.1.9-extended/kernel-pool-oracle.exe'
provenance=json.loads((root/'target/kernel-dates-expanded-native-0.1.25/capture.json').read_text());assert hashlib.sha256(oracle.read_bytes()).hexdigest()==provenance['oracle_sha256']
literals=['@2000-JAN-0.49999999999999994', '@2000-JAN-1.4999999999999998', '@2000-JAN-0.499999999999999999', '@2000-JAN-0.5000000000000001', '@2000-JAN-0.00000000000000001']
commands=[]
for index,literal in enumerate(literals):
 path=dest/f'date-{index:03}.tf';path.write_bytes(('KPL/FK\n\\begindata\nEPOCH='+literal+'\n\\begintext\n').encode('ascii'))
 commands.extend(['C','L|'+str(path),'D|EPOCH'])
data=('\n'.join(commands)+'\n').encode('ascii');native=subprocess.run([str(oracle)],input=data,capture_output=True)
assert native.returncode==0 and native.stderr.startswith(b'CRT_FMA:1\r\n')
for name,raw in [('stdin',data),('stdout',native.stdout),('stderr',native.stderr)]: (dest/('native-'+name+'.bin')).write_bytes(raw)
replies=native.stdout.decode('ascii').splitlines();assert len(replies)==len(commands)
records=[dict(literal=literal,load=replies[3*i+1],value=replies[3*i+2]) for i,literal in enumerate(literals)]
(dest/'dates.json').write_text(json.dumps(records,indent=2)+'\n',encoding='ascii')
print(json.dumps(dict(cases=len(records),native_accepted=sum(r['load']=='OK' for r in records))))
