fix: guide project mapping recovery and allow manual table entries

This commit is contained in:
muena
2026-10-15 09:24:26 +02:00
parent 1ac11988af
commit 4801908faf
4 changed files with 337 additions and 46 deletions

View File

@@ -201,6 +201,54 @@ describe("Velum-Projektstände", () => {
expect(project.isMarkdownFile("Notizen.MD")).toBe(true);
});
it("löst eine wiederverwendete ID nur über eine identische gespeicherte Datei auf", async () => {
const root = await fs.mkdtemp(join(tmpdir(), "velum-exact-snapshot-"));
roots.push(root);
const first = await project.createRun(join(root, "Quelle"), root);
const second = await project.createRun(join(root, "Quelle"), root);
const relPath = "Fragenliste.md";
first.run.files = [{ source: relPath, output: relPath, kind: "text" }];
second.run.files = [{ source: relPath, output: relPath, kind: "text" }];
first.run.mapping = { PERSON_61: { original: "Alex Beispiel", type: "PERSON" } };
second.run.mapping = { PERSON_61: { original: "Mara Muster", type: "PERSON" } };
const source = Buffer.from("Kommentar PERSON_61");
await fs.writeFile(join(first.directory, "files", relPath), source);
await fs.writeFile(join(second.directory, "files", relPath), "anderer Inhalt");
const exact = await project.mappingForMatchingSnapshots(relPath, project.digest(source), [first, second]);
expect(exact.PERSON_61?.original).toBe("Alex Beispiel");
const unknown = await project.mappingForMatchingSnapshots(relPath, project.digest(Buffer.from("neu")), [first, second]);
expect(unknown.PERSON_61).toBeUndefined();
});
it("ergänzt einen fehlenden Platzhalter in einem neuen Projektstand ohne alte Daten zu ändern", async () => {
const root = await fs.mkdtemp(join(tmpdir(), "velum-manual-mapping-"));
roots.push(root);
const source = join(root, "Quelle");
await fs.mkdir(source);
const saved = await project.createRun(source, root);
saved.run.mapping = { PERSON_01: { original: "Alex Beispiel", type: "PERSON" } };
saved.run.files = [{ source: "Notiz.md", output: "Notiz.md", kind: "text" }];
await fs.writeFile(join(saved.directory, "files", "Notiz.md"), "PERSON_61");
await project.saveRun(saved.directory, saved.run);
const updated = await project.addProjectMappingEntry(source,
{ placeholder: "PERSON_61", original: "Mara Muster", type: "PERSON" }, root);
expect(updated.mapping.PERSON_61?.original).toBe("Mara Muster");
expect((await project.listRuns(source, root))[0].run.id).toBe(updated.id);
expect(await fs.readFile(join(saved.directory, "files", "Notiz.md"), "utf8")).toBe("PERSON_61");
expect((await project.listRuns(source, root))[1].run.mapping.PERSON_61).toBeUndefined();
expect(await fs.readFile(join(project.projectDataRoot(source, root), "runs", updated.id, "files", "Notiz.md"), "utf8"))
.toBe("PERSON_61");
expect(project.prepareManualMappingEntry(updated.mapping, [],
{ original: "Weiterer Begriff", type: "PERSON" }).placeholder).toBe("PERSON_62");
});
it("verhindert eine neue projektweite Zuordnung für eine früher anders belegte ID", () => {
expect(() => project.prepareManualMappingEntry({}, [
{ PERSON_61: { original: "Alex Beispiel", type: "PERSON" } },
], { placeholder: "PERSON_61", original: "Mara Muster", type: "PERSON" }))
.toThrow("andere Bedeutung");
});
it("übernimmt API-Trefferpositionen auch nach einem Emoji korrekt", () => {
const text = "😀 Max";
const spans = project.toUtf16Offsets(text, [{ id: "max", start: 2, end: 5, placeholder: "PERSON_01" }]);