/*
RFC-0498: snapshot test for the no-op migrator — verifies that
applying the migrator to a representative workpiece leaves all files unchanged.
- Not a contract source of truth — the module under test owns the authoritative behavior; fixtures are minimal scaffolding only.
- RFC-0498: initial snapshot test for no-op migrator.
*/
import { test, expect } from "vitest";
import fs from "node:fs/promises";
import path from "node:path";
import os from "node:os";
import { rfc0498Migrator } from "./rfc-0498.ts";
import type { SternsystemData, MigrationContext } from "./types.ts";
const ctx: MigrationContext = {
systemId: "test",
missionId: "test-mission",
logger: { info: () => {} },
};
async function withTempWorkpiece(fn: (dir: string) => Promise): Promise {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "rfc-0498-snap-"));
const contentDir = path.join(dir, "src", "content");
await fs.mkdir(contentDir, { recursive: true });
await fs.writeFile(path.join(contentDir, "system.md"), "---\n---\n");
try {
await fn(dir);
} finally {
await fs.rm(dir, { recursive: true, force: true });
}
}
test("rfc-0498 snapshot: no-op migrator leaves all files unchanged", async () => {
await withTempWorkpiece(async (dir) => {
const data: SternsystemData = { rootPath: dir, dataPaths: [] };
const filePath = path.join(dir, "src", "content", "system.md");
const before = await fs.readFile(filePath, "utf8");
await rfc0498Migrator.transform(data, ctx);
const after = await fs.readFile(filePath, "utf8");
expect(after).toEqual(before);
});
});
test("rfc-0498 snapshot: no-op migrator is idempotent", async () => {
await withTempWorkpiece(async (dir) => {
const data: SternsystemData = { rootPath: dir, dataPaths: [] };
const filePath = path.join(dir, "src", "content", "system.md");
const once = await rfc0498Migrator.transform(data, ctx);
const content1 = await fs.readFile(filePath, "utf8");
const twice = await rfc0498Migrator.transform(once, ctx);
const content2 = await fs.readFile(filePath, "utf8");
expect(content2).toEqual(content1);
expect(twice).toEqual(once);
});
});