NODEDC_1C/llm_normalizer/backend/tests/assistantMemoryRecapPolicy....

91 lines
3.3 KiB
TypeScript
Raw 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 } from "vitest";
import {
buildAddressMemoryRecapReply,
createAssistantMemoryRecapPolicy,
resolveAssistantLivingChatMemoryContext
} from "../src/services/assistantMemoryRecapPolicy";
const policy = createAssistantMemoryRecapPolicy({
hasHistoricalCapabilityFollowupSignal: (text: unknown) =>
/историческ|архив|раньше/i.test(String(text ?? "")),
hasConversationMemoryRecallFollowupSignal: (text: unknown) =>
/помнишь|remember/i.test(String(text ?? "")),
isGroundedInventoryContextDebug: (debug: unknown) =>
String((debug as Record<string, unknown> | null)?.detected_intent ?? "") === "inventory_on_hand_as_of_date"
});
describe("assistantMemoryRecapPolicy", () => {
it("detects contextual historical capability follow-up", () => {
const signals = policy.resolveRouteMemorySignals({
rawUserMessage: "а исторические остатки тоже можешь?",
repairedRawUserMessage: "",
effectiveAddressUserMessage: "",
repairedEffectiveAddressUserMessage: "",
dataScopeMetaQuery: false,
capabilityMetaQuery: true,
dataRetrievalSignal: false,
strongDataSignal: false,
aggregateBusinessAnalyticsSignal: false,
lastGroundedAddressDebug: {
detected_intent: "inventory_on_hand_as_of_date"
},
hasPriorAddressDebug: true
});
expect(signals.contextualHistoricalCapabilityFollowupDetected).toBe(true);
expect(signals.contextualMemoryRecapFollowupDetected).toBe(false);
});
it("detects contextual memory recap over prior address debug", () => {
const signals = policy.resolveRouteMemorySignals({
rawUserMessage: "а ты помнишь что мы обсуждали?",
repairedRawUserMessage: "",
effectiveAddressUserMessage: "",
repairedEffectiveAddressUserMessage: "",
dataScopeMetaQuery: false,
capabilityMetaQuery: false,
dataRetrievalSignal: false,
strongDataSignal: false,
aggregateBusinessAnalyticsSignal: false,
lastGroundedAddressDebug: null,
hasPriorAddressDebug: true
});
expect(signals.contextualHistoricalCapabilityFollowupDetected).toBe(false);
expect(signals.contextualMemoryRecapFollowupDetected).toBe(true);
});
it("builds deterministic recap from prior selected object context", () => {
const context = resolveAssistantLivingChatMemoryContext({
modeDecisionReason: "memory_recap_followup_detected",
sessionItems: [
{
role: "assistant",
debug: {
execution_lane: "address_query",
anchor_type: "item",
anchor_value_resolved: "Рабочая станция",
extracted_filters: {
item: "Рабочая станция",
as_of_date: "2022-02-28"
}
}
}
]
});
const reply = buildAddressMemoryRecapReply({
organization: null,
addressDebug: context.lastMemoryAddressDebug,
toNonEmptyString: (value: unknown) => {
const text = String(value ?? "").trim();
return text.length > 0 ? text : null;
}
});
expect(context.contextualMemoryRecapFollowup).toBe(true);
expect(reply).toContain("Рабочая станция");
expect(reply).toContain("28.02.2022");
});
});