82 lines
3.0 KiB
TypeScript
82 lines
3.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
buildConversationExportForCopy,
|
|
sanitizeConversationExportText,
|
|
type ConversationExportItem
|
|
} from "../../frontend/src/utils/conversationExport";
|
|
|
|
function buildConversation(): ConversationExportItem[] {
|
|
return [
|
|
{
|
|
message_id: "m-user-1",
|
|
role: "user",
|
|
text: "Почему не закрывается РБП за июль?",
|
|
reply_type: null,
|
|
created_at: "2026-03-28T18:00:00.000Z",
|
|
trace_id: null,
|
|
debug: null
|
|
},
|
|
{
|
|
message_id: "m-asst-1",
|
|
role: "assistant",
|
|
text: [
|
|
"Коротко: есть признаки неполного списания РБП.",
|
|
"",
|
|
"### debug_payload_json",
|
|
"```json",
|
|
"{\"route_summary\":\"hybrid_store_plus_live\",\"domain_scope\":[\"deferred_expense\"]}",
|
|
"```"
|
|
].join("\n"),
|
|
reply_type: "partial_coverage",
|
|
created_at: "2026-03-28T18:00:05.000Z",
|
|
trace_id: "tr-1",
|
|
debug: {
|
|
route_summary: "hybrid_store_plus_live",
|
|
coverage_report: { requirements_covered: 0 }
|
|
}
|
|
}
|
|
];
|
|
}
|
|
|
|
describe("conversation export regression", () => {
|
|
it("default export excludes debug payload sections and keeps user-facing text", () => {
|
|
const exportText = buildConversationExportForCopy("sess-1", buildConversation(), "default");
|
|
|
|
expect(exportText).toContain("export_mode: default");
|
|
expect(exportText).toContain("Коротко: есть признаки неполного списания РБП.");
|
|
expect(exportText).not.toContain("### debug_payload_json");
|
|
expect(exportText).not.toContain("### technical_debug_payload_json");
|
|
expect(exportText).not.toContain("coverage_report");
|
|
expect(exportText).not.toContain("domain_scope");
|
|
expect(exportText).not.toContain("route_summary");
|
|
});
|
|
|
|
it("technical export includes debug payload in dedicated section only", () => {
|
|
const exportText = buildConversationExportForCopy("sess-1", buildConversation(), "technical");
|
|
|
|
expect(exportText).toContain("export_mode: technical");
|
|
expect(exportText).toContain("### technical_debug_payload_json");
|
|
expect(exportText).toContain("\"route_summary\": \"hybrid_store_plus_live\"");
|
|
expect(exportText).not.toContain("### debug_payload_json");
|
|
});
|
|
|
|
it("sanitizeConversationExportText removes technical tails", () => {
|
|
const source = [
|
|
"Ответ для пользователя.",
|
|
"domain_scope: [vat_flow]",
|
|
"coverage_report: {...}",
|
|
"### technical_breakdown_json",
|
|
"```json",
|
|
"{\"internal\":\"yes\"}",
|
|
"```"
|
|
].join("\n");
|
|
|
|
const sanitized = sanitizeConversationExportText(source);
|
|
expect(sanitized).toContain("Ответ для пользователя.");
|
|
expect(sanitized).not.toContain("domain_scope");
|
|
expect(sanitized).not.toContain("coverage_report");
|
|
expect(sanitized).not.toContain("technical_breakdown_json");
|
|
expect(sanitized).not.toContain("internal");
|
|
});
|
|
});
|