NODEDC_1C/llm_normalizer/backend/tests/addressInventoryAgingFollow...

116 lines
5.7 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 { runAddressDecomposeStage } from "../src/services/address_runtime/decomposeStage";
import { composeFactualReply } from "../src/services/address_runtime/composeStage";
describe("inventory aging follow-up", () => {
it("clears organization alias item on root old-stock questions with LLM organization semantics", () => {
const result = runAddressDecomposeStage(
'Есть ли у ООО "Альтернатива Плюс" остатки товара, которые закупались очень давно',
null,
{
scope_target_kind: "organization",
scope_target_text: 'ООО "Альтернатива Плюс"',
date_scope_kind: "implicit_current",
self_scope_detected: false,
selected_object_scope_detected: false
}
);
expect(result).not.toBeNull();
expect(result?.intent.intent).toBe("inventory_aging_by_purchase_date");
expect(result?.filters.extracted_filters.organization).toBe('ООО "Альтернатива Плюс"');
expect(result?.filters.extracted_filters.item).toBeUndefined();
expect(result?.baseReasons).toContain("item_cleared_as_organization_scope_alias_for_stock_aging");
});
it("does not mistake an explicit organization name for an inventory item in old-stock questions", () => {
const result = runAddressDecomposeStage('Есть ли у ООО "Альтернатива Плюс" остатки товара, которые закупались очень давно', {
previous_intent: "inventory_aging_by_purchase_date",
previous_filters: {
organization: 'ООО "Альтернатива Плюс"',
as_of_date: "2026-05-25"
},
previous_anchor_type: "organization",
previous_anchor_value: 'ООО "Альтернатива Плюс"'
});
expect(result).not.toBeNull();
expect(result?.intent.intent).toBe("inventory_aging_by_purchase_date");
expect(result?.filters.extracted_filters.organization).toBe('ООО "Альтернатива Плюс"');
expect(result?.filters.extracted_filters.item).toBeUndefined();
expect(result?.baseReasons).toContain("item_cleared_as_organization_scope_alias_for_stock_aging");
});
it("keeps carried date window for 'на эту дату' aging follow-up", () => {
const result = runAddressDecomposeStage("Какие остатки по товарам на эту дату относятся к старым закупкам", {
previous_intent: "inventory_purchase_provenance_for_item",
previous_filters: {
item: "Четки Пост (84*117)",
as_of_date: "2021-09-30",
period_from: "2021-09-01",
period_to: "2021-09-30",
warehouse: "Основной склад",
organization: "ООО \\Альтернатива Плюс\\"
},
previous_anchor_type: "unknown",
previous_anchor_value: null
});
expect(result).not.toBeNull();
expect(result?.intent.intent).toBe("inventory_aging_by_purchase_date");
expect(result?.filters.extracted_filters.as_of_date).toBe("2021-09-30");
expect(result?.filters.extracted_filters.period_from).toBe("2021-09-01");
expect(result?.filters.extracted_filters.period_to).toBe("2021-09-30");
expect(result?.filters.extracted_filters.sort).toBe("period_asc");
expect(result?.baseReasons).toContain("as_of_date_from_followup_context");
expect(result?.baseReasons).toContain("period_from_followup_context");
});
it("renders aging answer as oldest-first item list instead of raw documents", () => {
const reply = composeFactualReply(
"inventory_aging_by_purchase_date",
[
{
period: "2019-02-06T00:00:00Z",
registrator: "Поступление товаров и услуг 00000000004 от 06.02.2019 0:00:00",
account_dt: "41.01",
account_kt: "60.01",
amount: 833.33,
analytics: ["Четки Пост (84*117)", "Основной склад", "Торговый дом \\Союз\\"],
item: "Четки Пост (84*117)",
warehouse: "Основной склад",
organization: "ООО \\Альтернатива Плюс\\"
},
{
period: "2020-11-20T12:00:00Z",
registrator: "Поступление товаров и услуг 00000000030 от 20.11.2020 12:00:00",
account_dt: "41.01",
account_kt: "60.01",
amount: 7250,
analytics: ["Зеркало для инвалидов поворотное травмобезопасное", "Основной склад", "ВИЗАНТИЯ"],
item: "Зеркало для инвалидов поворотное травмобезопасное",
warehouse: "Основной склад",
organization: "ООО \\Альтернатива Плюс\\"
}
],
{
asOfDate: "2021-09-30",
useRubCurrency: true
}
);
expect(reply.responseType).toBe("FACTUAL_SUMMARY");
expect(reply.text).toContain("К самым старым закупкам");
expect(reply.text).toContain("Дата среза: 30.09.2021");
expect(reply.text).toContain("Позиции от самых старых закупок:");
expect(reply.text).toContain("Ограничения:");
expect(reply.text).not.toContain("Блок 1");
expect(reply.text).not.toContain("exact-контур");
expect(reply.text.indexOf("1. Четки Пост (84*117)")).toBeGreaterThan(-1);
expect(reply.text.indexOf("2. Зеркало для инвалидов поворотное травмобезопасное")).toBeGreaterThan(
reply.text.indexOf("1. Четки Пост (84*117)")
);
});
});