import { describe, expect, it, vi } from "vitest"; import { runAssistantAddressLaneResponseRuntime } from "../src/services/assistantAddressLaneResponseRuntimeAdapter"; describe("assistant address lane response runtime adapter", () => { it("builds debug payload and finalizes address turn", () => { const finalizeAddressTurn = vi.fn(() => ({ response: { ok: true } })); const runtime = runAssistantAddressLaneResponseRuntime({ sessionId: "asst-1", userMessage: "raw", effectiveAddressUserMessage: "canon", addressLane: { handled: true, reply_text: "answer", reply_type: "factual", debug: { extracted_filters: { organization: "ООО Ромашка" } } }, carryoverMeta: { followupContext: { previous_intent: "list_documents" } }, llmPreDecomposeMeta: { attempted: true }, knownOrganizations: ["ООО Ромашка", "ООО Лютик"], activeOrganization: "ООО Ромашка", sanitizeOutgoingAssistantText: (text) => String(text ?? "").trim(), buildAddressDebugPayload: (addressDebug) => ({ ...(addressDebug as Record) }), buildAddressFollowupOffer: () => ({ suggestion: "continue_previous" }), mergeKnownOrganizations: (items) => Array.from(new Set(items)), toNonEmptyString: (value) => (typeof value === "string" && value.trim() ? value.trim() : null), appendItem: () => {}, getSession: () => ({ session_id: "asst-1", updated_at: "", items: [], investigation_state: null } as any), persistSession: () => {}, cloneConversation: (items) => items, logEvent: () => {}, messageIdFactory: () => "msg-1", finalizeAddressTurn }); expect(finalizeAddressTurn).toHaveBeenCalledWith( expect.objectContaining({ assistantReply: "answer", replyType: "factual", llmPreDecomposeMeta: { attempted: true } }) ); expect(runtime.response).toEqual({ ok: true }); expect(runtime.debug).toEqual( expect.objectContaining({ assistant_known_organizations: ["ООО Ромашка", "ООО Лютик"], assistant_active_organization: "ООО Ромашка", address_followup_offer: { suggestion: "continue_previous" } }) ); }); it("keeps debug minimal when optional enrichment is absent", () => { const runtime = runAssistantAddressLaneResponseRuntime({ sessionId: "asst-2", userMessage: "raw", effectiveAddressUserMessage: "raw", addressLane: { handled: true, reply_text: "answer", reply_type: "partial_coverage", debug: {} }, knownOrganizations: [], activeOrganization: null, sanitizeOutgoingAssistantText: (text) => String(text ?? ""), buildAddressDebugPayload: () => ({}), buildAddressFollowupOffer: () => null, mergeKnownOrganizations: (items) => items, toNonEmptyString: () => null, appendItem: () => {}, getSession: () => ({ session_id: "asst-2", updated_at: "", items: [], investigation_state: null } as any), persistSession: () => {}, cloneConversation: (items) => items, logEvent: () => {}, messageIdFactory: () => "msg-2", finalizeAddressTurn: () => ({ response: { ok: true } }) }); expect(runtime.debug).toEqual({}); expect(runtime.response).toEqual({ ok: true }); }); });