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:
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user