// node verify_engine.js data/replay.json data/requests.jsonl pyref.json (pyref.json from: python pyref.py data/replay.json data/requests.jsonl pyref.json) : JS port vs Python executor, every version x request. const fs = require("fs"); require("./engine.js"); const E = globalThis.RCEngine; const [rp, qp, pp] = process.argv.slice(2); const R = JSON.parse(fs.readFileSync(rp)); const ref = JSON.parse(fs.readFileSync(pp)); const reqs = fs.readFileSync(qp, "utf8").trim().split("\n").map(JSON.parse); let n = 0, bad = 0, badc = 0, shown = 0; R.versions.slice(1).forEach((v, i) => { for (const r of v.rules) if (!E.compile(r.regex)) { badc++; console.log("no compile", r.regex); } const tr = v.rules.filter((r) => r.trusted).map((r) => r.dict), al = v.rules.map((r) => r.dict); for (const q of reqs) { const [pa, pb, pu] = ref[i][q.id]; const a = E.applyRules(tr, q.text).map((s) => [s.start, s.end, s.type, s.text]); const b = E.applyRules(al, q.text).map((s) => [s.start, s.end, s.type, s.text]); const u = E.unexplained(v.gate, q.text, E.applyRules(tr, q.text)); n++; if (JSON.stringify(a) !== JSON.stringify(pa) || JSON.stringify(b) !== JSON.stringify(pb) || JSON.stringify(u) !== JSON.stringify(pu)) { bad++; if (shown++ < 5) console.log("MISMATCH v" + v.v, q.id, q.text, JSON.stringify([a, pa]), JSON.stringify([b, pb]), JSON.stringify([u, pu])); } } }); console.log("checked", n, "mismatches", bad, "uncompilable", badc);