NODEDC_1C/llm_normalizer/backend/tests/assistantAddressLaneAttempt...

89 lines
3.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it, vi } from "vitest";
import { runAssistantAddressLaneAttemptRuntime } from "../src/services/assistantAddressLaneAttemptRuntimeAdapter";
describe("assistant address lane attempt runtime adapter", () => {
it("uses scoped followup context when available", async () => {
const runAddressQueryTryHandle = vi.fn(async () => ({
response_type: "READY"
}));
const result = await runAssistantAddressLaneAttemptRuntime({
messageUsed: "msg",
carryMeta: {
followupContext: {
previous_intent: "docs_by_counterparty"
}
},
analysisDateHint: "2020-07-31",
activeOrganization: "ООО Тест",
knownOrganizations: ["ООО Тест", "ООО Лютик"],
mergeFollowupContextWithOrganizationScope: () => ({
previous_intent: "docs_by_counterparty",
active_organization: "ООО Тест"
}),
runAddressQueryTryHandle
});
expect(runAddressQueryTryHandle).toHaveBeenCalledWith("msg", {
followupContext: {
previous_intent: "docs_by_counterparty",
active_organization: "ООО Тест"
},
analysisDateHint: "2020-07-31",
activeOrganization: "ООО Тест",
knownOrganizations: ["ООО Тест", "ООО Лютик"]
});
expect(result).toEqual({
response_type: "READY"
});
});
it("falls back to plain attempt when scoped followup context is empty", async () => {
const runAddressQueryTryHandle = vi.fn(async () => null);
await runAssistantAddressLaneAttemptRuntime({
messageUsed: "msg",
carryMeta: null,
analysisDateHint: null,
activeOrganization: null,
knownOrganizations: [],
mergeFollowupContextWithOrganizationScope: () => null,
runAddressQueryTryHandle
});
expect(runAddressQueryTryHandle).toHaveBeenCalledWith("msg", {
analysisDateHint: null
});
});
it("forwards llm semantic hints into query options", async () => {
const runAddressQueryTryHandle = vi.fn(async () => ({
response_type: "READY"
}));
await runAssistantAddressLaneAttemptRuntime({
messageUsed: "что на складе конторы альтернатива",
carryMeta: null,
analysisDateHint: null,
llmSemanticHints: {
scope_target_kind: "organization",
scope_target_text: "Альтернатива",
date_scope_kind: "implicit_current",
self_scope_detected: false,
selected_object_scope_detected: false
},
activeOrganization: null,
knownOrganizations: ["ООО Альтернатива Плюс"],
mergeFollowupContextWithOrganizationScope: () => null,
runAddressQueryTryHandle
});
expect(runAddressQueryTryHandle).toHaveBeenCalledWith("что на складе конторы альтернатива", {
analysisDateHint: null,
knownOrganizations: ["ООО Альтернатива Плюс"],
llmSemanticHints: expect.objectContaining({
scope_target_kind: "organization",
scope_target_text: "Альтернатива"
})
});
});
});