feat: add custom terms and consolidate session management

Show exact matches in red and add categorized custom terms to hit review. Move session administration into the translation tables command.
This commit is contained in:
muena
2026-12-02 10:18:43 +01:00
parent b630093075
commit b845062824
27 changed files with 537 additions and 410 deletions

View File

@@ -1,6 +1,6 @@
import { expect, it } from "bun:test";
import {
canonicalPerson, filenameScanText, groupReviewHits, literalReviewContext, makeTextBatches, mappingForSelection,
canonicalPerson, filenameScanText, groupReviewHits, highlightedReviewContext, literalReviewContext, makeTextBatches, mappingForSelection,
mergePeople, reconcileDocumentHitIds, spansBySegment, textHitContexts, withoutPlaceholderHits, withoutWhitelistedHits,
withoutWhitelistedRules,
} from "../src/lib/project-review";
@@ -50,14 +50,26 @@ it("ordnet E-Mail-Vorkommen nach Unicode-Position zu und markiert jeweils genau
const [signature, sender, recipient] = textHitContexts("😀 Von: Max\nAn: Mia\nDanke, Max", [
{ start: 26, end: 29 }, { start: 7, end: 10 }, { start: 15, end: 18 },
]);
const max = String.raw`\(\textcolor{#dc2626}{\text{Max}}\)`;
const mia = String.raw`\(\textcolor{#dc2626}{\text{Mia}}\)`;
expect(signature).toContain("**Zeile 3**");
expect(signature).toContain("Danke, ⟦Max⟧");
expect(signature).toContain(`Danke, ${max}`);
expect(sender).toContain("**Zeile 1**");
expect(sender).toContain("😀 Von: ⟦Max⟧");
expect(sender).toContain(`😀 Von: ${max}`);
expect(recipient).toContain("**Zeile 2**");
expect(recipient).toContain("An: ⟦Mia⟧");
expect(recipient).toContain(`An: ${mia}`);
const source = ["**Von:** <max@example.com>", "```", "![Bild](https://example.com/image.png)"].join("\n");
expect(literalReviewContext(source)).toBe(["````", source, "````"].join("\n"));
expect(highlightedReviewContext("😀 Max, Max", 8, 3)).toBe(`&#128512; Max&#44; ${max}`);
});
it("zeigt Markdown-Sonderzeichen wörtlich und färbt mehrzeilige Treffer an ihrer Fundstelle", () => {
const before = "![Bild](https://example.com/)\n";
const match = String.raw`A\){#}&` + "\nB_20%";
const context = highlightedReviewContext(before + match, before.length, match.length);
expect(context).not.toContain("![");
expect(context).toContain(String.raw`\text{A\textbackslash{})\{\#\}\&}`);
expect(context).toContain(String.raw`\text{B\_20\%}`);
});
it("ordnet bestätigte Dokumenttreffer nach einem 409 nur bei identischem Vorkommen neu zu", () => {

View File

@@ -16,7 +16,7 @@ mock.module("@raycast/api", () => ({
getPreferenceValues: () => ({ velumBaseUrl: "", authentikTokenUrl: "", clientId: "",
serviceAccountUsername: "", serviceAccountPassword: "", maxSessions: "20" }),
}));
const { applyProjectWhitelist, pseudonymizeInContext, prepareTextInContext, commitPreparedText } = await import("../src/text-context");
const { addTextReviewTerm, applyProjectWhitelist, pseudonymizeInContext, prepareTextInContext, commitPreparedText } = await import("../src/text-context");
const project = await import("../src/lib/velum-project");
const sessions = await import("../src/sessions");
const { relocateProject } = await import("../src/lib/project-relocation");
@@ -106,6 +106,49 @@ it("merkt abgelehnte Sitzungstreffer und schlägt sie im nächsten Lauf nicht er
expect(next.raw.spans).toEqual([]);
});
it.each(["session", "project"])("ergänzt eigene Begriffe auch bei abgewählter Kategorie und merkt sie für Folgeläufe (%s)", async (context) => {
const values = { sessionId: "__new_session__", newProjectPath: [] as string[] };
if (context === "project") {
const root = await fs.mkdtemp(join(tmpdir(), "velum-custom-term-"));
roots.push(root);
const folder = join(root, "Projekt");
await fs.mkdir(folder);
roots.push(project.projectDataRoot(folder));
values.sessionId = "__new_project__";
values.newProjectPath = [folder];
}
const text = "Max, 4711, 2025, 4711";
const term = { type: "REFERENZ", value: "4711" };
const request: typeof import("../src/velum").pseudonymize = async (_text, mapping, types, masks) => {
expect(types).toEqual(masks ? ["PERSON", "REFERENZ"] : ["PERSON"]);
if (masks) expect(masks).toEqual({ REFERENZ: ["4711"] });
const spans = [{ start: 0, end: 3, type: "PERSON", score: 1, placeholder: "PERSON_01", original: "Max" }];
if (masks) spans.push(
{ start: 5, end: 9, type: "REFERENZ", score: 1, placeholder: "REFERENZ_01", original: "4711" },
{ start: 11, end: 15, type: "REFERENZ", score: 1, placeholder: "REFERENZ_02", original: "2025" },
{ start: 17, end: 21, type: "REFERENZ", score: 1, placeholder: "REFERENZ_01", original: "4711" },
);
return {
spans, selected_entity_types: types ?? [], entity_count: masks ? 3 : 1,
mapping: { ...mapping, PERSON_01: { type: "PERSON", original: "Max" },
...(masks && { REFERENZ_01: { type: "REFERENZ", original: "4711" },
REFERENZ_02: { type: "REFERENZ", original: "2025" } }) },
pseudonymized_text: masks ? "PERSON_01, REFERENZ_01, REFERENZ_02, REFERENZ_01" : "PERSON_01, 4711, 2025, 4711",
};
};
const initial = await prepareTextInContext(values, text, ["PERSON"], request);
const updated = await addTextReviewTerm(initial, term, new Set(), request);
expect([...updated.selected]).toEqual([1, 2]);
expect(await sessions.listSessions()).toHaveLength(0);
if (context === "project") expect(await project.loadProjectRules(values.newProjectPath[0])).toEqual([]);
const { result, session } = await commitPreparedText(updated.prepared, updated.selected, true);
expect(result.pseudonymized_text).toBe("Max, <REFERENZ_01>, 2025, <REFERENZ_01>");
expect(result.selected_entity_types).toEqual(["PERSON"]);
const followup = await prepareTextInContext({ sessionId: session.id }, text, ["PERSON"], request);
expect(followup.raw.spans.map((span) => span.original)).toEqual(["4711", "4711"]);
expect(followup.customTerms).toEqual([term]);
});
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") {

View File

@@ -22,9 +22,13 @@ describe("Velum-Projektstände", () => {
const support = join(root, "Raycast");
await fs.mkdir(source);
await fs.writeFile(join(source, "Notiz.txt"), "Max Mustermann");
const rules = project.parseProjectRules("PERSON: Max Mustermann\nKundenSuite");
const rules = project.parseProjectRules("PERSON: Max Mustermann\nKundenSuite\nREFERENZ: 4711",
["BEGRIFF", "PERSON", "REFERENZ"]);
await project.saveProjectRules(source, rules, support);
expect(await project.loadProjectRules(source, support)).toEqual(rules);
expect(project.forceMasks(rules)).toEqual({
PERSON: ["Max Mustermann"], BEGRIFF: ["KundenSuite"], REFERENZ: ["4711"],
});
await project.saveProjectWhitelist(source, [
{ type: "PERSON", original: "Falscher Treffer" },
{ type: "PERSON", original: "falscher treffer" },