import { describe, expect, it, vi } from "vitest"; import { runAssistantAddressLaneResponseAttemptRuntime } from "../src/services/assistantAddressLaneResponseAttemptRuntimeAdapter"; function buildInput(overrides: Record = {}) { return { sessionId: "asst-1", userMessage: "где хвост по оплате", effectiveAddressUserMessage: "где хвост по оплате", addressLane: { reply_text: "address reply", reply_type: "factual_with_explanation", debug: { extracted_filters: {} } }, carryoverMeta: null, llmPreDecomposeMeta: null, knownOrganizations: [], activeOrganization: null, sanitizeOutgoingAssistantText: (value: unknown, fallback = "") => { const text = String(value ?? "").trim(); return text || fallback; }, buildAddressDebugPayload: () => ({}), buildAddressFollowupOffer: () => null, mergeKnownOrganizations: (value: string[]) => value, toNonEmptyString: (value: unknown) => (typeof value === "string" && value.trim() ? value.trim() : null), appendItem: () => {}, getSession: () => ({ session_id: "asst-1", updated_at: "", items: [], investigation_state: null }), persistSession: () => {}, cloneConversation: (items: unknown[]) => items, logEvent: () => {}, messageIdFactory: () => "msg-1", ...overrides } as any; } describe("assistant address lane response attempt runtime adapter", () => { it("returns delegated runtime response", () => { const runAddressLaneResponseRuntime = vi.fn(() => ({ response: { ok: true, lane: "address" }, debug: { marker: "v1" } })); const response = runAssistantAddressLaneResponseAttemptRuntime( buildInput({ runAddressLaneResponseRuntime }) ); expect(response).toEqual({ ok: true, lane: "address" }); expect(runAddressLaneResponseRuntime).toHaveBeenCalledWith( expect.objectContaining({ sessionId: "asst-1", userMessage: "где хвост по оплате" }) ); }); it("forwards carryover and llm predecompose metadata", () => { const carryoverMeta = { previousReplyType: "partial_coverage" }; const llmPreDecomposeMeta = { mode: "supported", confidence: "high" }; const runAddressLaneResponseRuntime = vi.fn(() => ({ response: { ok: true }, debug: {} })); runAssistantAddressLaneResponseAttemptRuntime( buildInput({ carryoverMeta, llmPreDecomposeMeta, runAddressLaneResponseRuntime }) ); expect(runAddressLaneResponseRuntime).toHaveBeenCalledWith( expect.objectContaining({ carryoverMeta, llmPreDecomposeMeta }) ); }); });