| 1 | import assert from "node:assert/strict" |
| 2 | import { readFile } from "node:fs/promises" |
| 3 | import { describe, it } from "node:test" |
| 4 | import { pathToFileURL } from "node:url" |
| 5 | import { loadRegistry, scenarioBatchSize } from "../utils.mts" |
| 6 | |
| 7 | describe("runtimeperf registry", () => { |
| 8 | it("uses the Effect calibration for every implementation in a scenario", () => { |
| 9 | const zod = { implementation: "zod4-compiled" } |
| 10 | const effect = { implementation: "effect" } |
| 11 | assert.equal(scenarioBatchSize([zod, effect], new Map([ |
| 12 | [zod, { batchSize: 4_096 }], |
| 13 | [effect, { batchSize: 256 }] |
| 14 | ])), 256) |
| 15 | }) |
| 16 | |
| 17 | it("uses unique fixture targets and valid implementations", () => { |
| 18 | const { fixtures } = loadRegistry() |
| 19 | assert.equal(new Set(fixtures.map((fixture) => fixture.target)).size, fixtures.length) |
| 20 | for (const fixture of fixtures) { |
| 21 | assert.ok([ |
| 22 | "effect", |
| 23 | "effect-aot", |
| 24 | "effect-jit", |
| 25 | "fast-check-v4", |
| 26 | "valibot", |
| 27 | "zod4", |
| 28 | "zod4-compiled", |
| 29 | "zod4-jitless", |
| 30 | "zod4-validate" |
| 31 | ].includes(fixture.implementation)) |
| 32 | } |
| 33 | }) |
| 34 | |
| 35 | it("pairs every Arbitrary scenario across the native and fast-check implementations", () => { |
| 36 | const { fixtures } = loadRegistry() |
| 37 | const scenarios = Map.groupBy( |
| 38 | fixtures.filter((fixture) => fixture.suite === "arbitrary"), |
| 39 | (fixture) => fixture.scenario |
| 40 | ) |
| 41 | assert.equal(scenarios.size, 33) |
| 42 | for (const fixtures of scenarios.values()) { |
| 43 | assert.deepEqual(fixtures.map((fixture) => fixture.implementation).sort(), ["effect", "fast-check-v4"]) |
| 44 | const metadata = (fixture) => ({ |
| 45 | export: fixture.export, |
| 46 | family: fixture.family, |
| 47 | operation: fixture.operation, |
| 48 | path: fixture.path, |
| 49 | scenario: fixture.scenario, |
| 50 | size: fixture.size, |
| 51 | tier: fixture.tier |
| 52 | }) |
| 53 | assert.deepEqual(metadata(fixtures[0]), metadata(fixtures[1])) |
| 54 | } |
| 55 | }) |
| 56 | |
| 57 | it("keeps the focused Schema diagnostics Effect-only", () => { |
| 58 | const { fixtures } = loadRegistry() |
| 59 | const diagnostics = fixtures.filter((fixture) => fixture.suite === "schema") |
| 60 | assert.ok(diagnostics.length > 0) |
| 61 | assert.equal(diagnostics.every((fixture) => fixture.implementation === "effect"), true) |
| 62 | }) |
| 63 | |
| 64 | it("includes the complete effect@beta Schema Benchmarks matrix", () => { |
| 65 | const { fixtures } = loadRegistry() |
| 66 | assert.deepEqual( |
| 67 | fixtures |
| 68 | .filter((fixture) => fixture.suite === "schema-benchmarks" && fixture.implementation === "effect") |
| 69 | .map((fixture) => fixture.name) |
| 70 | .sort(), |
| 71 | [ |
| 72 | "codec-typed-decode", |
| 73 | "codec-typed-encode", |
| 74 | "codec-unknown-decode", |
| 75 | "codec-unknown-encode", |
| 76 | "initialization-decoder", |
| 77 | "initialization-schema", |
| 78 | "parsing-all-invalid", |
| 79 | "parsing-all-valid", |
| 80 | "parsing-first-invalid", |
| 81 | "parsing-first-valid", |
| 82 | "standard-all-invalid", |
| 83 | "standard-all-valid", |
| 84 | "standard-first-invalid", |
| 85 | "standard-first-valid", |
| 86 | "validation-invalid", |
| 87 | "validation-valid" |
| 88 | ] |
| 89 | ) |
| 90 | }) |
| 91 | |
| 92 | it("includes the complete Valibot and Zod Schema Benchmarks matrices", () => { |
| 93 | const { fixtures } = loadRegistry() |
| 94 | const names = (implementation) => |
| 95 | fixtures |
| 96 | .filter((fixture) => fixture.suite === "schema-benchmarks" && fixture.implementation === implementation) |
| 97 | .map((fixture) => fixture.name) |
| 98 | .sort() |
| 99 | assert.deepEqual(names("valibot"), [ |
| 100 | "initialization-schema-valibot", |
| 101 | "parsing-all-invalid-valibot", |
| 102 | "parsing-all-valid-valibot", |
| 103 | "parsing-first-invalid-valibot", |
| 104 | "parsing-first-valid-valibot", |
| 105 | "standard-all-invalid-valibot", |
| 106 | "standard-all-valid-valibot", |
| 107 | "validation-invalid-valibot", |
| 108 | "validation-valid-valibot" |
| 109 | ]) |
| 110 | assert.deepEqual(names("zod4"), [ |
| 111 | "codec-typed-decode-zod4", |
| 112 | "codec-typed-encode-zod4", |
| 113 | "initialization-schema-zod4", |
| 114 | "parsing-all-invalid-zod4", |
| 115 | "parsing-all-valid-zod4", |
| 116 | "standard-all-invalid-zod4", |
| 117 | "standard-all-valid-zod4" |
| 118 | ]) |
| 119 | }) |
| 120 | |
| 121 | it("uses Zod 4 standard and jitless safeParse for the zod4 fixtures", async () => { |
| 122 | const { fixtures } = loadRegistry() |
| 123 | const zodFiles = new Set( |
| 124 | fixtures |
| 125 | .filter((fixture) => fixture.suite === "schema-benchmarks" && fixture.implementation === "zod4") |
| 126 | .map((fixture) => fixture.fixturePath) |
| 127 | ) |
| 128 | assert.ok(zodFiles.size > 0) |
| 129 | for (const path of zodFiles) { |
| 130 | const source = await readFile(path, "utf8") |
| 131 | assert.match(source, /from "zod\/v4"/) |
| 132 | assert.doesNotMatch(source, /from "zod\/v4-mini"/) |
| 133 | assert.match(source, /jitless:\s*true/) |
| 134 | } |
| 135 | }) |
| 136 | |
| 137 | it("uses strict Zod compilation for the compiler comparison fixtures", async () => { |
| 138 | const { fixtures } = loadRegistry() |
| 139 | const compiled = fixtures.filter((fixture) => |
| 140 | fixture.suite === "compiler-rebuild" && fixture.implementation === "zod4-compiled" |
| 141 | ) |
| 142 | assert.equal(compiled.length, 19) |
| 143 | const paths = new Set(compiled.map((fixture) => fixture.fixturePath)) |
| 144 | assert.equal(paths.size, 1) |
| 145 | const source = await readFile([...paths][0], "utf8") |
| 146 | assert.match(source, /from "\.\/zod-cases\.ts"/) |
| 147 | const shared = await readFile(new URL("../suites/compiler-rebuild/fixtures/zod-cases.ts", import.meta.url), "utf8") |
| 148 | assert.match(shared, /from "zod\/v4"/) |
| 149 | assert.match(shared, /z\.compile\(value\.schema, \{ strict: true \}\)/) |
| 150 | }) |
| 151 | |
| 152 | it("uses interpreted Zod for the jitless compiler comparison fixtures", async () => { |
| 153 | const { fixtures } = loadRegistry() |
| 154 | const jitless = fixtures.filter((fixture) => |
| 155 | fixture.suite === "compiler-rebuild" && fixture.implementation === "zod4-jitless" |
| 156 | ) |
| 157 | assert.equal(jitless.length, 11) |
| 158 | const paths = new Set(jitless.map((fixture) => fixture.fixturePath)) |
| 159 | assert.equal(paths.size, 1) |
| 160 | const source = await readFile(new URL("../suites/compiler-rebuild/fixtures/zod-cases.ts", import.meta.url), "utf8") |
| 161 | assert.match(source, /z\.validate\(value\.schema, input, \{ jitless: true \}\)/) |
| 162 | assert.match(source, /value\.schema\.parse\(input, \{ jitless: true \}\)/) |
| 163 | }) |
| 164 | |
| 165 | it("loads, runs and validates every fixture export", async () => { |
| 166 | const { fixtures } = loadRegistry() |
| 167 | const modules = new Map() |
| 168 | for (const fixture of fixtures) { |
| 169 | let module = modules.get(fixture.fixturePath) |
| 170 | if (module === undefined) { |
| 171 | module = await import(pathToFileURL(fixture.fixturePath)) |
| 172 | modules.set(fixture.fixturePath, module) |
| 173 | } |
| 174 | assert.equal(typeof module[fixture.export], "function", fixture.target) |
| 175 | const runtimeCase = module[fixture.export]() |
| 176 | const result = runtimeCase.run() |
| 177 | assert.equal(typeof result?.then, "undefined", fixture.target) |
| 178 | runtimeCase.validate(result) |
| 179 | } |
| 180 | }) |
| 181 | }) |