NODEDC_1C/llm_normalizer/backend/tests/replyPackaging.test.ts

52 lines
1.7 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from "vitest";
import {
finalizeComposeReplyResult,
inferAddressReplyType,
joinComposeReplyLines
} from "../src/services/address_runtime/replyPackaging";
describe("replyPackaging", () => {
it("joins reply lines without changing their order", () => {
expect(joinComposeReplyLines(["Первая строка", "Вторая строка"])).toBe("Первая строка\nВторая строка");
});
it("applies numeric emphasis line-by-line only when requested", () => {
const result = finalizeComposeReplyResult(
{
responseType: "FACTUAL_SUMMARY",
text: "Сумма 1500\nОстаток 22",
semantics: { result_mode: "aggregate" }
},
{
emphasizeNumbers: true,
emphasizeNumericTokens: (line) => line.replace(/\d+/g, (match) => `**${match}**`)
}
);
expect(result.text).toBe("Сумма **1500**\nОстаток **22**");
expect(result.semantics).toEqual({ result_mode: "aggregate" });
});
it("keeps reply text unchanged when emphasis is disabled", () => {
const result = finalizeComposeReplyResult(
{
responseType: "FACTUAL_SUMMARY",
text: "Сумма 1500"
},
{
emphasizeNumbers: false,
emphasizeNumericTokens: () => "не должно примениться"
}
);
expect(result.text).toBe("Сумма 1500");
});
it("maps factual response types away from partial coverage", () => {
expect(inferAddressReplyType("FACTUAL_LIST")).toBe("factual");
expect(inferAddressReplyType("FACTUAL_SUMMARY")).toBe("factual");
expect(inferAddressReplyType("SOFT_REFUSAL")).toBe("partial_coverage");
});
});