forked from r.muellner/velum-raycast
feat: improve Velum hit review and session creation
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { expect, it } from "bun:test";
|
||||
import {
|
||||
canonicalPerson, filenameScanText, groupReviewHits, makeTextBatches, mappingForSelection, mergePeople, reconcileDocumentHitIds,
|
||||
spansBySegment, withoutPlaceholderHits, withoutWhitelistedHits, withoutWhitelistedRules,
|
||||
canonicalPerson, filenameScanText, groupReviewHits, literalReviewContext, makeTextBatches, mappingForSelection,
|
||||
mergePeople, reconcileDocumentHitIds, spansBySegment, textHitContexts, withoutPlaceholderHits, withoutWhitelistedHits,
|
||||
withoutWhitelistedRules,
|
||||
} from "../src/lib/project-review";
|
||||
|
||||
it("liest Unterstriche in Namen als Leerzeichen und bewahrt bekannte Codebegriffe", () => {
|
||||
@@ -45,6 +46,20 @@ it("zeigt gleiche Zuordnungen einmal mit der Anzahl ihrer Vorkommen", () => {
|
||||
expect(groups.find((group) => group.placeholder === "PERSON_01")?.hits.map((hit) => hit.id)).toEqual(["a", "b"]);
|
||||
});
|
||||
|
||||
it("ordnet E-Mail-Vorkommen nach Unicode-Position zu und markiert jeweils genau den ausgewählten Treffer", () => {
|
||||
const [signature, sender, recipient] = textHitContexts("😀 Von: Max\nAn: Mia\nDanke, Max", [
|
||||
{ start: 26, end: 29 }, { start: 7, end: 10 }, { start: 15, end: 18 },
|
||||
]);
|
||||
expect(signature).toContain("**Zeile 3**");
|
||||
expect(signature).toContain("Danke, ⟦Max⟧");
|
||||
expect(sender).toContain("**Zeile 1**");
|
||||
expect(sender).toContain("😀 Von: ⟦Max⟧");
|
||||
expect(recipient).toContain("**Zeile 2**");
|
||||
expect(recipient).toContain("An: ⟦Mia⟧");
|
||||
const source = ["**Von:** <max@example.com>", "```", ""].join("\n");
|
||||
expect(literalReviewContext(source)).toBe(["````", source, "````"].join("\n"));
|
||||
});
|
||||
|
||||
it("ordnet bestätigte Dokumenttreffer nach einem 409 nur bei identischem Vorkommen neu zu", () => {
|
||||
const hit = { id: "alt", source: "Absatz 1", start: 4, end: 7, type: "PERSON",
|
||||
original: "Max", context: "Herr Max antwortet" };
|
||||
|
||||
@@ -91,12 +91,14 @@ it("merkt abgelehnte Sitzungstreffer und schlägt sie im nächsten Lauf nicht er
|
||||
spans: [{ start: 0, end: 11, type: "PERSON", score: 0.8,
|
||||
placeholder: "PERSON_01", original: "Fachbegriff" }],
|
||||
});
|
||||
const prepared = await prepareTextInContext({ sessionId: "__new_session__" },
|
||||
const prepared = await prepareTextInContext({ sessionId: "__new_session__", newSessionName: " Kundenmail " },
|
||||
"Fachbegriff", ["PERSON"], request);
|
||||
expect(await sessions.listSessions()).toHaveLength(0);
|
||||
const { result, session } = await commitPreparedText(prepared, new Set());
|
||||
expect(result.pseudonymized_text).toBe("Fachbegriff");
|
||||
expect(session.name).toBe("Kundenmail");
|
||||
expect(session.mapping).toEqual({});
|
||||
expect(await sessions.getActiveSessionId()).toBe(session.id);
|
||||
expect((await sessions.getSession(session.id))?.excludedTerms).toEqual([
|
||||
{ type: "PERSON", original: "Fachbegriff" },
|
||||
]);
|
||||
@@ -104,6 +106,59 @@ it("merkt abgelehnte Sitzungstreffer und schlägt sie im nächsten Lauf nicht er
|
||||
expect(next.raw.spans).toEqual([]);
|
||||
});
|
||||
|
||||
it.each(["session", "project"])("fasst geprüfte Namensvarianten zusammen und speichert sie für Folgeläufe (%s)", async (context) => {
|
||||
let values = { sessionId: "__new_session__", newProjectPath: [] as string[] };
|
||||
if (context === "project") {
|
||||
const root = await fs.mkdtemp(join(tmpdir(), "velum-text-merge-"));
|
||||
roots.push(root);
|
||||
const folder = join(root, "Projekt");
|
||||
await fs.mkdir(folder);
|
||||
values = { sessionId: "__new_project__", newProjectPath: [folder] };
|
||||
}
|
||||
const source = "😀 Max Muster\nMax und Mia";
|
||||
const prepared = await prepareTextInContext(values, source, ["PERSON"], async () => ({
|
||||
pseudonymized_text: "😀 PERSON_01\nPERSON_02 und PERSON_03",
|
||||
selected_entity_types: ["PERSON"], entity_count: 3,
|
||||
mapping: {
|
||||
PERSON_01: { type: "PERSON", original: "Max Muster" },
|
||||
PERSON_02: { type: "PERSON", original: "Max" },
|
||||
PERSON_03: { type: "PERSON", original: "Mia" },
|
||||
},
|
||||
spans: [
|
||||
{ start: 2, end: 12, type: "PERSON", score: 1, placeholder: "PERSON_01", original: "Max Muster" },
|
||||
{ start: 13, end: 16, type: "PERSON", score: 1, placeholder: "PERSON_02", original: "Max" },
|
||||
{ start: 21, end: 24, type: "PERSON", score: 1, placeholder: "PERSON_03", original: "Mia" },
|
||||
],
|
||||
}));
|
||||
await expect(commitPreparedText(prepared, new Set([0, 1]), true, { PERSON_02: "PERSON_03" }))
|
||||
.rejects.toThrow("ausgewählte Personen");
|
||||
const { result, session } = await commitPreparedText(prepared, new Set([0, 1]), true, { PERSON_02: "PERSON_01" });
|
||||
expect(result.pseudonymized_text).toBe("😀 <PERSON_01>\n<PERSON_01> und Mia");
|
||||
expect(result.entity_count).toBe(1);
|
||||
expect(result.spans.map((span) => span.placeholder)).toEqual(["PERSON_01", "PERSON_01"]);
|
||||
expect(result.mapping["<PERSON_02>"]).toEqual({ type: "PERSON", original: "Max", merged_into: "<PERSON_01>" });
|
||||
expect(result.mapping["<PERSON_03>"]).toBeUndefined();
|
||||
expect(session.mapping["<PERSON_02>"].original).toBe("Max Muster");
|
||||
|
||||
const followup = await prepareTextInContext({ sessionId: session.id }, "Max und Maximilian", ["PERSON"],
|
||||
async (_text, mapping) => {
|
||||
expect(mapping.PERSON_02.merged_into).toBe("PERSON_01");
|
||||
expect(mapping["<PERSON_02>"]).toBeUndefined();
|
||||
return {
|
||||
pseudonymized_text: "PERSON_01 und PERSON_03", selected_entity_types: ["PERSON"], entity_count: 2,
|
||||
mapping: { ...mapping, PERSON_03: { type: "PERSON", original: "Maximilian" } },
|
||||
spans: [
|
||||
{ start: 0, end: 3, type: "PERSON", score: 1, placeholder: "PERSON_01", original: "Max" },
|
||||
{ start: 8, end: 18, type: "PERSON", score: 1, placeholder: "PERSON_03", original: "Maximilian" },
|
||||
],
|
||||
};
|
||||
});
|
||||
const updated = await commitPreparedText(followup, new Set([0, 1]), false, { PERSON_01: "PERSON_03" });
|
||||
expect(updated.result.pseudonymized_text).toBe("PERSON_03 und PERSON_03");
|
||||
expect(updated.result.mapping.PERSON_02.merged_into).toBe("PERSON_03");
|
||||
expect(updated.session.mapping.PERSON_02.original).toBe("Maximilian");
|
||||
});
|
||||
|
||||
it("entfernt eine False-Positive-Gruppe aus der Sitzung und merkt alle Varianten", async () => {
|
||||
const session = await sessions.createSession("Test");
|
||||
await sessions.updateSessionMapping(session.id, {
|
||||
|
||||
Reference in New Issue
Block a user