fix: reapply saved person merges to project files

This commit is contained in:
muena
2026-10-15 09:09:26 +02:00
parent 8557a9b809
commit 1ac11988af
3 changed files with 96 additions and 3 deletions

View File

@@ -58,6 +58,36 @@ describe("Nachbearbeitung von Projektständen", () => {
expect(plan.mapping).toEqual({});
});
it("repariert bereits gespeicherte Personen-Zusammenführungen in Inhalt und Dateiname", async () => {
const root = await fs.mkdtemp(join(tmpdir(), "velum-merge-repair-"));
roots.push(root);
const source = join(root, "Quelle");
const support = join(root, "Raycast");
await fs.mkdir(source);
const saved = await project.createRun(source, support);
saved.run.mapping = {
PERSON_01: { type: "PERSON", original: "Franz Fuchs" },
PERSON_02: { type: "PERSON", original: "Hr. Fuchs", merged_into: "PERSON_01" },
};
saved.run.files = [{ source: "Bericht.md", output: "PERSON_02_Notiz.md", kind: "text" }];
expect(revision.planProjectRevision(saved.run.mapping, new Set(), {}).replacements)
.toEqual({ PERSON_02: { original: "PERSON_01", type: "PERSON" } });
await fs.writeFile(join(saved.directory, "files", "PERSON_02_Notiz.md"),
"Kommentar PERSON_02 und `PERSON_02_Entwurf.docx`; PERSON_020 bleibt unberührt.");
await project.saveRun(saved.directory, saved.run);
const result = await revision.reviseProjectRun({
previous: saved.run, previousDirectory: saved.directory, support,
release: new Set(), merges: {}, reapplyMerges: true,
rewriteDocument: async () => { throw new Error("Unerwartetes Office-Dokument"); },
});
expect(result.run.mapping.PERSON_02.merged_into).toBe("PERSON_01");
expect(result.run.files[0].output).toBe("PERSON_01_Notiz.md");
expect(await fs.readFile(join(result.directory, "files", "PERSON_01_Notiz.md"), "utf8"))
.toBe("Kommentar PERSON_01 und `PERSON_01_Entwurf.docx`; PERSON_020 bleibt unberührt.");
expect(await fs.readFile(join(saved.directory, "files", "PERSON_02_Notiz.md"), "utf8"))
.toContain("PERSON_02_Entwurf.docx");
});
it("ersetzt einen vorhandenen Projektordner nur, wenn er noch dem letzten Stand entspricht", async () => {
const root = await fs.mkdtemp(join(tmpdir(), "velum-revision-place-"));
roots.push(root);
@@ -118,6 +148,35 @@ describe("Nachbearbeitung von Projektständen", () => {
.toBe("changed office bytes");
});
it("übergibt eine ältere Personen-Zusammenführung erneut an die Office-Wiederherstellung", async () => {
const root = await fs.mkdtemp(join(tmpdir(), "velum-merge-doc-repair-"));
roots.push(root);
const source = join(root, "Quelle");
const support = join(root, "Raycast");
await fs.mkdir(source);
const saved = await project.createRun(source, support);
saved.run.mapping = {
PERSON_01: { type: "PERSON", original: "Franz Fuchs" },
PERSON_02: { type: "PERSON", original: "Hr. Fuchs", merged_into: "PERSON_01" },
};
saved.run.files = [{ source: "Bericht.docx", output: "PERSON_02_Bericht.docx", kind: "document" }];
await fs.writeFile(join(saved.directory, "files", "PERSON_02_Bericht.docx"), "synthetic office bytes");
await project.saveRun(saved.directory, saved.run);
const result = await revision.reviseProjectRun({
previous: saved.run, previousDirectory: saved.directory, support,
release: new Set(), merges: {}, reapplyMerges: true,
rewriteDocument: async (filename, data, mapping) => {
expect(filename).toBe("PERSON_02_Bericht.docx");
expect(data.toString()).toBe("synthetic office bytes");
expect(mapping).toEqual({ PERSON_02: { original: "PERSON_01", type: "PERSON" } });
return Buffer.from("rewritten office bytes");
},
});
expect(result.run.files[0].output).toBe("PERSON_01_Bericht.docx");
expect(await fs.readFile(join(result.directory, "files", "PERSON_01_Bericht.docx"), "utf8"))
.toBe("rewritten office bytes");
});
it("schützt längere importierte Platzhalter beim Freigeben eines Präfixes", async () => {
const root = await fs.mkdtemp(join(tmpdir(), "velum-revision-prefix-"));
roots.push(root);