Архитектура: централизовать inventory root-frame state и root-scoped carryover в continuity policy

This commit is contained in:
2026-04-19 09:25:22 +03:00
parent c9730c986a
commit 46dfef6fb6
9 changed files with 297 additions and 132 deletions
@@ -1,5 +1,7 @@
import { describe, expect, it } from "vitest";
import {
buildRootScopedCarryoverFilters,
hydrateInventoryRootFrameState,
readAddressDebugTemporalScope,
resolveAddressDebugCarryoverFilters,
resolveAddressDebugContextFacts,
@@ -133,4 +135,68 @@ describe("assistantContinuityPolicy organization authority", () => {
period_to: "2021-03-31"
});
});
it("hydrates inventory root-frame state from navigation scope and preserves derived current frame kind", () => {
const state = hydrateInventoryRootFrameState(
{
intent: "inventory_on_hand_as_of_date",
filters: {
warehouse: "Main Warehouse"
},
anchorType: "organization",
anchorValue: "Org Alt",
currentFrameKind: null
},
"inventory_purchase_documents_for_item",
"Org Alt",
{
as_of_date: "2021-03-31",
period_from: "2021-03-01",
period_to: "2021-03-31"
},
undefined,
(intent) => String(intent ?? "") === "inventory_purchase_documents_for_item",
(intent) => String(intent ?? "") === "inventory_on_hand_as_of_date"
);
expect(state.currentFrameKind).toBe("inventory_drilldown");
expect(state.inventoryRootFrame).toMatchObject({
currentFrameKind: "inventory_drilldown",
filters: {
organization: "Org Alt",
warehouse: "Main Warehouse",
as_of_date: "2021-03-31",
period_from: "2021-03-01",
period_to: "2021-03-31"
}
});
});
it("builds root-scoped carryover filters with previous date precedence over inventory root frame", () => {
const filters = buildRootScopedCarryoverFilters(
{
organization: "Org Alt",
as_of_date: "2020-03-31",
period_from: "2020-03-01",
period_to: "2020-03-31"
},
{
filters: {
organization: "Org Alt",
warehouse: "Main Warehouse",
as_of_date: "2021-03-31",
period_from: "2021-03-01",
period_to: "2021-03-31"
}
}
);
expect(filters).toEqual({
organization: "Org Alt",
warehouse: "Main Warehouse",
as_of_date: "2020-03-31",
period_from: "2020-03-01",
period_to: "2020-03-31"
});
});
});
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { createAssistantTransitionPolicy } from "../src/services/assistantTransitionPolicy";
import { buildRootScopedCarryoverFiltersForTests } from "../src/services/assistantService";
import { buildRootScopedCarryoverFilters } from "../src/services/assistantContinuityPolicy";
function toNonEmptyString(value: unknown): string | null {
if (value === null || value === undefined) {
@@ -661,7 +661,7 @@ describe("assistantTransitionPolicy", () => {
});
it("prefers the freshest previous date scope over a stale inventory root frame during same-date pivot", () => {
const filters = buildRootScopedCarryoverFiltersForTests(
const filters = buildRootScopedCarryoverFilters(
{
organization: 'ООО "Альтернатива Плюс"',
as_of_date: "2020-03-31",