test: verify committed string oracle

- Regenerate the string case oracle with the active Node executable.\n- Compare the checked-in fixture byte-for-byte before native runtime checks.\n- Keep the Linux parseInt ULP allowance scoped to native output.
This commit is contained in:
Chris Tate
2026-08-31 16:18:37 -05:00
parent 714042b1f9
commit e47fdbdcc1
+16 -3
View File
@@ -1,5 +1,5 @@
import { execFile } from "node:child_process";
import { mkdir } from "node:fs/promises";
import { mkdir, readFile } from "node:fs/promises";
import { join } from "node:path";
import { promisify } from "node:util";
import { beforeAll, expect, test } from "vitest";
@@ -33,8 +33,10 @@ beforeAll(async () => {
]);
});
// Runs against the committed case file (generated once from Node via
// gen-string-cases.mjs — see that file to regenerate). Covers UTF-16
// Runs against the committed case file generated from Node via
// gen-string-cases.mjs. The test below also verifies the checked-in oracle
// against the generator, so an accidental stale result cannot be masked by
// the platform-specific native-runtime allowlist. Covers UTF-16
// length/charCodeAt/indexOf/includes/startsWith/endsWith/slice/repeat/
// trim/trimStart/trimEnd/split/padStart/padEnd/charAt plus parseInt over
// ASCII, Latin-1, CJK, astral, and combining-mark strings, including the
@@ -63,6 +65,17 @@ const LINUX_PARSEINT_ULP: ReadonlyMap<string, string> = new Map([
],
]);
test("committed string oracle matches Node", async () => {
const caseFile = join(testDir, "string-cases.txt");
const [{ stdout }, committed] = await Promise.all([
execFileAsync(process.execPath, [join(testDir, "gen-string-cases.mjs")], {
maxBuffer: 2 * 1024 * 1024,
}),
readFile(caseFile, "utf8"),
]);
expect(committed).toBe(stdout);
});
test("string methods match Node on committed oracle cases", async () => {
const r = await execFileAsync(bin, [join(testDir, "string-cases.txt")]).then(
(v) => ({ stderr: v.stderr }),