import { describe, expect, it } from "vitest"; import { composeUniqueRecord } from "../../src/platform/cardinality/compose-unique-record.ts"; import { COMPOSITION_WORKLOADS, createUniqueRegistryParts, } from "../../scripts/scale/composition-workloads.ts"; import { runCompositionScale } from "../../scripts/scale/run-composition-scale.ts"; describe("registry/composition scale (S0-S2)", () => { it.each([100, 1_000, 10_000])( "composes %i unique entries without duplicates", (count) => { const parts = createUniqueRegistryParts(count); const result = composeUniqueRecord(parts, () => "route"); expect(Object.keys(result)).toHaveLength(count); }, ); it("rejects a duplicate at the largest profile deterministically", () => { const parts = [...createUniqueRegistryParts(10_000), { "route-42": -1 }]; expect(() => composeUniqueRecord(parts, () => "route")).toThrow( "Duplicate route key: route-42", ); }); it("runs every production workload at every profile", () => { for (const workload of COMPOSITION_WORKLOADS) { for (const n of [100, 1_000, 10_000]) { expect(workload.prepare(n)()).toBeDefined(); } } }); it( "keeps the S0/S1/S2 composition series linear-or-better with machine-readable results", async () => { const measure = () => runCompositionScale(["S0", "S1", "S2"], { samples: 5, warmup: 1, // This suite runs beside other suites; see `statistic` in the runner. statistic: "min", }); // Review focus: one noisy measurement must not fail a linear path. A // real super-linear path fails every independent re-measurement. let report = await measure(); if (!report.passed) report = await measure(); expect(report.checks.filter((check) => !check.passed)).toEqual([]); expect(report.results).toHaveLength(COMPOSITION_WORKLOADS.length * 3); for (const result of report.results) { expect(result.samples).toHaveLength(5); expect(result.metadata["implementation"]).toBeTypeOf("string"); } }, 60_000, ); });