/*
RFC-0512: 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-0512: 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 { rfc0512Migrator } from "./rfc-0512.ts";
import type { SternsystemData, MigrationContext } from "./types.ts";
const ctx: MigrationContext = {
systemId: "test",
missionId: "test-mission",
logger: { info: () => {} },
};
test("rfc-0512 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 rfc0512Migrator.transform(data as SternsystemData, ctx);
const twice = await rfc0512Migrator.transform(once, ctx);
expect(twice).toEqual(once);
});
});
test("rfc-0512 migrator is a no-op: returns data unchanged", async () => {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "rfc-0512-pbt-"));
try {
const data: SternsystemData = { rootPath: dir, dataPaths: [] };
const result = await rfc0512Migrator.transform(data, ctx);
expect(result).toBe(data);
} finally {
await fs.rm(dir, { recursive: true, force: true });
}
});