import { describe, expect, it, vi } from "vitest"; import { buildAssistantAddressLaneAttemptRuntimeInput } from "../src/services/assistantAddressLaneAttemptInputBuilder"; function buildInput(overrides: Record = {}) { const mergeFollowupContextWithOrganizationScope = vi.fn((followupContext: Record | null) => followupContext ); const runAddressQueryTryHandle = vi.fn(async () => ({ response_type: "READY" })); return { messageUsed: "Show overdue docs", carryMeta: { followupContext: { previous_intent: "docs_by_counterparty" } }, analysisDateHint: "2020-08-31", activeOrganization: "Org A", knownOrganizations: ["Org A", "Org B"], mergeFollowupContextWithOrganizationScope, runAddressQueryTryHandle, ...overrides } as any; } describe("assistant address lane attempt input builder", () => { it("builds lane-attempt runtime input with message, carry meta and analysis date", () => { const runtimeInput = buildAssistantAddressLaneAttemptRuntimeInput(buildInput()); expect(runtimeInput.messageUsed).toBe("Show overdue docs"); expect(runtimeInput.analysisDateHint).toBe("2020-08-31"); expect(runtimeInput.activeOrganization).toBe("Org A"); expect(runtimeInput.knownOrganizations).toEqual(["Org A", "Org B"]); expect(runtimeInput.carryMeta).toEqual({ followupContext: { previous_intent: "docs_by_counterparty" } }); }); it("preserves injected callbacks and nullable fields", async () => { const mergeFollowupContextWithOrganizationScope = vi.fn(() => null); const runAddressQueryTryHandle = vi.fn(async () => ({ response_type: "NEEDS_CONTEXT" })); const runtimeInput = buildAssistantAddressLaneAttemptRuntimeInput( buildInput({ carryMeta: null, analysisDateHint: null, activeOrganization: null, knownOrganizations: [], mergeFollowupContextWithOrganizationScope, runAddressQueryTryHandle }) ); await runtimeInput.runAddressQueryTryHandle("message", { analysisDateHint: null }); runtimeInput.mergeFollowupContextWithOrganizationScope(null, null); expect(runAddressQueryTryHandle).toHaveBeenCalledWith("message", { analysisDateHint: null }); expect(mergeFollowupContextWithOrganizationScope).toHaveBeenCalledWith(null, null); expect(runtimeInput.carryMeta).toBeNull(); expect(runtimeInput.analysisDateHint).toBeNull(); }); });