/* RFC-0757: PBT test for the no-op migrator — verifies idempotency (f(f(x)) == f(x)) over arbitrary SternsystemData. Not a contract source of truth — the module under test owns the authoritative behavior; fixtures are minimal scaffolding only. RFC-0757: initial PBT test for no-op migrator. */ import { test, expect } from "vitest"; import fc from "fast-check"; import fs from "node:fs/promises"; import path from "node:path"; import os from "node:os"; import { rfc0757Migrator } from "./rfc-0757.ts"; import type { SternsystemData, MigrationContext } from "./types.ts"; const ctx: MigrationContext = { systemId: "test", missionId: "test-mission", logger: { info: () => {} }, }; test("rfc-0757 migrator is idempotent: f(f(x)) == f(x) for arbitrary data", async () => { const dataArbitrary = fc.record({ rootPath: fc.string({ minLength: 1, maxLength: 100 }), dataPaths: fc.array(fc.string({ minLength: 1, maxLength: 100 }), { maxLength: 10 }), }); await fc.asyncProperty(dataArbitrary, async (data) => { const once = await rfc0757Migrator.transform(data as SternsystemData, ctx); const twice = await rfc0757Migrator.transform(once, ctx); expect(twice).toEqual(once); }); }); test("rfc-0757 migrator is a no-op: returns data unchanged", async () => { const dir = await fs.mkdtemp(path.join(os.tmpdir(), "rfc-0757-pbt-")); try { const data: SternsystemData = { rootPath: dir, dataPaths: [] }; const result = await rfc0757Migrator.transform(data, ctx); expect(result).toBe(data); } finally { await fs.rm(dir, { recursive: true, force: true }); } }); test("rfc-0757 migrator is registered in the registry", async () => { const { migratorRegistry } = await import("./registry.ts"); const registered = migratorRegistry.find((m) => m.id === "rfc-0757"); expect(registered).toBeDefined(); expect(registered?.id).toBe(rfc0757Migrator.id); });