/** * models/engine/fixtures.ts — PORT-FIDELITY self-test (GENERATED expectations). * * At start-up the engine converts a deterministic set of test inputs for each * encoding and compares a SHA-256 of all the outputs with EXPECTED_SHA256. The * expected hashes were produced by running the ORIGINAL, unmodified upstream * OdiaWikimedia/Converter scripts (commit 76664f0) on exactly the same inputs in a * JavaScript sandbox. A match proves the port gives byte-identical output to * upstream; it does NOT prove linguistic accuracy, which needs proof-read * reference text typed in each font. * * Inputs: a seeded pseudo-random mix of every mapping key of the table, every * character used in those keys, spaces, tabs, line feeds and some English; * FIXTURE_SPEC.short cases of 1-60 tokens and FIXTURE_SPEC.long cases of * 7,000-9,000 tokens (long enough to cross the 6,000-character chunk boundary). * Before release the port was also compared with upstream on 6,008 further * generated inputs with no difference. */ import type { LegacyTable } from "./tables"; export const FIXTURE_SPEC = { seed: 20261111, short: 60, long: 2 }; /** mulberry32 — a small deterministic PRNG, so the same inputs can be rebuilt anywhere. */ function prng(seed: number): () => number { let a = seed >>> 0; return () => { a = (a + 0x6d2b79f5) >>> 0; let t = a; t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; } export function fixtureInputs(table: LegacyTable): string[] { const tokens: string[] = []; for (const [k] of table.pairs) tokens.push(k); const seen = new Set(); for (const [k] of table.pairs) for (const ch of k) if (!seen.has(ch)) { seen.add(ch); tokens.push(ch); } tokens.push(" ", " ", "\n", "\t", "Hello", ".", ", "); const r = prng(FIXTURE_SPEC.seed); const out: string[] = []; const make = (n: number) => { let s = ""; for (let i = 0; i < n; i++) s += tokens[Math.floor(r() * tokens.length)]; return s; }; for (let i = 0; i < FIXTURE_SPEC.short; i++) out.push(make(1 + Math.floor(r() * 60))); for (let i = 0; i < FIXTURE_SPEC.long; i++) out.push(make(7000 + Math.floor(r() * 2000))); out.push("English only, 123.\n\tTabbed line", ""); return out; } /** SHA-256 of JSON.stringify(outputs) from the unmodified upstream scripts. */ export const EXPECTED_SHA256: Record = { akruti_sarala: "daf813da863efbca113fce63a14aab7e82ed64b0431c9928cefa01e9ab1cae17", apranta: "3bf7c9a517562ee13b573a3742d2028cdd41e71ff49c3debbcfe1663c131fd2b", ortt_sarala: "bf87ce25fe1c563cf24987dc4edc27f97737b0043f74f96669dfdaeef285f832", sreelipi: "206e5ea3ae316711d82289909bbe993bf4eb0727cd9546afe6cff1ab39d3a8c0", };