АРЧ АП11 - Архитектура после регресса: Архитектура: централизовать anchor и temporal carryover в continuity policy и протянуть их в transition hot path

This commit is contained in:
2026-04-18 21:08:01 +03:00
parent d29fbba214
commit cf17404925
10 changed files with 348 additions and 204 deletions
@@ -1,6 +1,8 @@
import { describe, expect, it } from "vitest";
import {
readAddressDebugTemporalScope,
resolveAddressDebugContextFacts,
resolveAddressDebugAnchorContext,
resolveAssistantOrganizationAuthority
} from "../src/services/assistantContinuityPolicy";
@@ -75,4 +77,27 @@ describe("assistantContinuityPolicy organization authority", () => {
scopedDate: "31.03.2020"
});
});
it("resolves carryover temporal scope and inferred anchor from debug filters when explicit anchor fields are absent", () => {
const debug = {
extracted_filters: {
item: "Рабочая станция",
period_from: "2020-03-01"
},
address_root_frame_context: {
as_of_date: "2020-03-31",
period_to: "2020-03-31"
}
};
expect(readAddressDebugTemporalScope(debug)).toEqual({
asOfDate: "2020-03-31",
periodFrom: "2020-03-01",
periodTo: "2020-03-31"
});
expect(resolveAddressDebugAnchorContext(debug)).toEqual({
anchorType: "item",
anchorValue: "Рабочая станция"
});
});
});
@@ -304,6 +304,41 @@ describe("assistantTransitionPolicy", () => {
expect(carryover?.followupContext?.target_intent).toBe("inventory_on_hand_as_of_date");
});
it("hydrates carryover anchor from shared debug helpers when explicit anchor fields are absent", () => {
const policy = buildPolicy({
findLastAddressAssistantItem: () => ({
text: "Подтвержденный складской срез собран.",
debug: {
detected_intent: "inventory_on_hand_as_of_date",
extracted_filters: {
item: "Рабочая станция",
period_from: "2020-03-01"
},
address_root_frame_context: {
as_of_date: "2020-03-31",
period_to: "2020-03-31"
},
anchor_type: null,
anchor_value_resolved: null
}
}),
hasAddressFollowupContextSignal: () => true,
hasReferentialPointer: () => true,
findRecentInventoryRootFrame: () => null,
findRecentAddressFilterValue: () => null,
resolveAddressIntent: () => ({ intent: "unknown" })
});
const carryover = policy.resolveAddressFollowupCarryoverContext("по этой позиции", [], null, null, null);
expect(carryover?.followupContext?.previous_anchor_type).toBe("item");
expect(carryover?.followupContext?.previous_anchor_value).toBe("Рабочая станция");
expect(carryover?.followupContext?.previous_filters).toMatchObject({
item: "Рабочая станция",
period_from: "2020-03-01"
});
});
it("bridges selected-item purchase provenance into a VAT period follow-up", () => {
const item = "Рабочая станция универсального специалиста";
const policy = buildPolicy({