feat: add migration preview report

This commit is contained in:
muena
2026-09-24 19:21:07 +02:00
parent c1229e1d14
commit ae62c6f95c
3 changed files with 104 additions and 25 deletions

View File

@@ -16,11 +16,14 @@ it("migriert einen künstlichen Altbestand verlustarm ohne den Quellordner zu ä
const project = join(root, "Projekt");
const targetSupport = join(root, "VelumSupport");
const oldSupport = join(root, "OldSupport");
const previewFile = join(root, "Migrationsvorschau.md");
await fs.mkdir(project);
await fs.mkdir(join(oldSupport, "projects"), { recursive: true });
const legacyName = "KUNDE ALPHA.txt";
const legacyContent = "kundeAlphaService und KUNDE ALPHA";
await fs.writeFile(join(project, legacyName), legacyContent);
await fs.writeFile(join(project, "Handbuch.docx"), "office");
await fs.writeFile(join(project, "leer.txt"), "Ohne Platzhalter");
const projectId = createHash("sha1").update(project).digest("hex").slice(0, 16);
const manifestFile = join(oldSupport, "projects", `${projectId}.json`);
await fs.writeFile(manifestFile, JSON.stringify({
@@ -30,11 +33,24 @@ it("migriert einen künstlichen Altbestand verlustarm ohne den Quellordner zu ä
{ termId: "t1", termVariant: "muellerGmbh", placeholderVariant: "kundeAlpha", style: "camel", boundary: "identifier" },
],
}));
const preview = await migrate({ project, manifestFile, targetSupport });
const preview = await migrate({ project, manifestFile, targetSupport, previewFile });
expect(preview.applied).toBe(false);
expect(preview.summary.files).toBe(1);
expect(preview.summary.files).toBe(2);
expect(preview.summary.skipped).toBe(1);
const report = await fs.readFile(previewFile, "utf8");
expect(report).toContain('"KUNDE ALPHA.txt"');
expect(report).toContain('"KUNDE_100001.txt"');
expect(report).toContain('"kundeAlpha" → "KUNDE_100002" (1×)');
expect(report).toContain('"Handbuch.docx": Office- oder PDF-Datei');
expect(report).toContain("Keine Änderung.");
expect(report).not.toContain("Müller GmbH");
expect((await fs.stat(previewFile)).mode & 0o777).toBe(0o600);
expect(await fs.readFile(join(project, legacyName), "utf8")).toBe(legacyContent);
expect(await fs.readdir(root)).not.toContain("VelumSupport");
await expect(migrate({ project, manifestFile, targetSupport, previewFile })).rejects.toMatchObject({ code: "EEXIST" });
await expect(migrate({ project, manifestFile, targetSupport, previewFile, apply: true })).rejects.toThrow();
await expect(migrate({ project, manifestFile, targetSupport,
previewFile: join(project, "vorschau.md") })).rejects.toThrow();
const result = await migrate({ project, manifestFile, targetSupport, apply: true });
expect(result.applied).toBe(true);