"""80 reproducible cross-runtime cases. Requires Python 3.9+ and Node.js."""
import json
from pathlib import Path
import random
import subprocess
from reference_runtime import execute

rng=random.Random(6)
cases=[]
for i in range(80):
    terms=rng.sample(['alpha','交付','node','😀','Ä','<b>'],rng.randrange(1,7))
    lines=[' '.join(rng.choices(['ALPHA','交付','node','😀','ä','<b>',''],k=rng.randrange(1,7))) for _ in range(rng.randrange(1,20))]
    cases.append({'version':'0.2','operation':'literal-line-search','document':rng.choice(['\n','\r\n','\r']).join(lines) or ' ','terms':terms,'top_k':rng.randrange(1,11)})
runtime=Path(__file__).with_name('reference-runtime.mjs')
if not runtime.exists():runtime=Path(__file__).resolve().parents[1]/'dist/reference-runtime.mjs'
code='import {execute} from '+json.dumps(runtime.resolve().as_uri())+'; let text=""; for await (const c of process.stdin) text+=c; console.log(JSON.stringify(JSON.parse(text).map(execute)));'
run=subprocess.run(['node','--input-type=module','-e',code],input=json.dumps(cases),capture_output=True,text=True,check=True)
actual=json.loads(run.stdout)
for i,task in enumerate(cases):
    if actual[i]!=execute(task):raise AssertionError('Cross-runtime mismatch at case '+str(i))
print('PASS: 80 independent Python / JavaScript comparisons (seed 6).')
