67 lines
2.5 KiB
TypeScript
67 lines
2.5 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { buildAssistantAddressLaneResponseAttemptRuntimeInput } from "../src/services/assistantAddressLaneResponseAttemptInputBuilder";
|
|
|
|
function buildInput(overrides: Record<string, unknown> = {}) {
|
|
return {
|
|
sessionId: "asst-1",
|
|
userMessage: "Show overdue docs",
|
|
effectiveAddressUserMessage: "Show overdue docs for Org A",
|
|
addressLane: {
|
|
handled: true,
|
|
reply_text: "ok",
|
|
reply_type: "factual_with_explanation",
|
|
debug: {}
|
|
},
|
|
knownOrganizations: ["Org A"],
|
|
activeOrganization: "Org A",
|
|
sanitizeOutgoingAssistantText: (value: unknown, fallback = "") =>
|
|
typeof value === "string" && value.trim().length > 0 ? value.trim() : fallback,
|
|
buildAddressDebugPayload: () => ({}),
|
|
buildAddressFollowupOffer: () => null,
|
|
mergeKnownOrganizations: (organizations: string[]) => organizations,
|
|
toNonEmptyString: (value: unknown) =>
|
|
typeof value === "string" && value.trim().length > 0 ? value.trim() : null,
|
|
appendItem: vi.fn(),
|
|
getSession: vi.fn(),
|
|
persistSession: vi.fn(),
|
|
cloneConversation: vi.fn((items: unknown[]) => items),
|
|
logEvent: vi.fn(),
|
|
messageIdFactory: vi.fn(() => "msg-1"),
|
|
...overrides
|
|
} as any;
|
|
}
|
|
|
|
describe("assistant address lane response attempt input builder", () => {
|
|
it("normalizes optional carryover and predecompose meta to null", () => {
|
|
const runtimeInput = buildAssistantAddressLaneResponseAttemptRuntimeInput(
|
|
buildInput({
|
|
carryoverMeta: undefined,
|
|
llmPreDecomposeMeta: undefined
|
|
})
|
|
);
|
|
|
|
expect(runtimeInput.carryoverMeta).toBeNull();
|
|
expect(runtimeInput.llmPreDecomposeMeta).toBeNull();
|
|
expect(runtimeInput.effectiveAddressUserMessage).toBe("Show overdue docs for Org A");
|
|
expect(runtimeInput.knownOrganizations).toEqual(["Org A"]);
|
|
});
|
|
|
|
it("preserves explicit metadata and callback wiring", () => {
|
|
const logEvent = vi.fn();
|
|
const runtimeInput = buildAssistantAddressLaneResponseAttemptRuntimeInput(
|
|
buildInput({
|
|
carryoverMeta: { followupContext: { previous_intent: "docs_by_counterparty" } },
|
|
llmPreDecomposeMeta: { mode: "supported" },
|
|
logEvent
|
|
})
|
|
);
|
|
|
|
expect(runtimeInput.carryoverMeta).toEqual({
|
|
followupContext: { previous_intent: "docs_by_counterparty" }
|
|
});
|
|
expect(runtimeInput.llmPreDecomposeMeta).toEqual({ mode: "supported" });
|
|
runtimeInput.logEvent({ event: "address_done" });
|
|
expect(logEvent).toHaveBeenCalledWith({ event: "address_done" });
|
|
});
|
|
});
|