107 lines
4.1 KiB
TypeScript
107 lines
4.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { buildAssistantDeepTurnRuntimeContext } from "../src/services/assistantDeepTurnContextRuntimeAdapter";
|
|
|
|
describe("assistant deep turn context runtime adapter", () => {
|
|
it("assembles context in deterministic order and propagates followup flag", () => {
|
|
const callOrder: string[] = [];
|
|
const companyAnchors = { accounts: ["60.01"] };
|
|
const temporalGuard = {
|
|
effective_primary_period: { from: "2020-07-01", to: "2020-07-31" },
|
|
primary_period_window: { from: "2020-07-01", to: "2020-07-31" }
|
|
};
|
|
const businessScope = { route_summary_resolved: { mode: "deterministic_v2", decisions: [] as any[] } } as any;
|
|
|
|
const output = buildAssistantDeepTurnRuntimeContext({
|
|
userMessage: "почему не закрыт 60.01",
|
|
normalizedPayload: { schema_version: "normalized_query_v2_0_2" } as any,
|
|
routeSummary: { mode: "deterministic_v2", decisions: [] } as any,
|
|
runtimeAnalysisContext: {
|
|
active: true,
|
|
as_of_date: "2020-07-31",
|
|
period_from: null,
|
|
period_to: null,
|
|
source: "analysis_context"
|
|
},
|
|
followupUsage: { applied: true },
|
|
resolveCompanyAnchors: () => {
|
|
callOrder.push("anchors");
|
|
return companyAnchors;
|
|
},
|
|
resolveBusinessScopeAlignment: () => {
|
|
callOrder.push("scope_align");
|
|
return businessScope;
|
|
},
|
|
inferP0DomainFromMessage: () => {
|
|
callOrder.push("infer_domain");
|
|
return "settlements_60_62";
|
|
},
|
|
resolveTemporalGuard: (input) => {
|
|
callOrder.push("temporal");
|
|
expect(input.analysisContext).toEqual({
|
|
as_of_date: "2020-07-31",
|
|
period_from: null,
|
|
period_to: null,
|
|
source: "analysis_context"
|
|
});
|
|
return temporalGuard as any;
|
|
},
|
|
resolveDomainPolarityGuard: (input) => {
|
|
callOrder.push("polarity");
|
|
expect(input.focusDomainHint).toBe("settlements_60_62");
|
|
return { polarity: "supplier_payable" };
|
|
},
|
|
resolveClaimBoundAnchors: (input) => {
|
|
callOrder.push("claim");
|
|
expect(input.primaryPeriod).toEqual(temporalGuard.effective_primary_period);
|
|
return { claim_type: "prove_settlement_closure_state" } as any;
|
|
},
|
|
resolveBusinessScopeFromLiveContext: (input) => {
|
|
callOrder.push("scope_live");
|
|
expect(input.followupApplied).toBe(true);
|
|
return {
|
|
...businessScope,
|
|
live_scope_used: true
|
|
} as any;
|
|
}
|
|
});
|
|
|
|
expect(callOrder).toEqual(["anchors", "scope_align", "infer_domain", "temporal", "polarity", "claim", "scope_live"]);
|
|
expect(output.companyAnchors).toBe(companyAnchors);
|
|
expect(output.focusDomainForGuards).toBe("settlements_60_62");
|
|
expect(output.claimAnchorAudit.claim_type).toBe("prove_settlement_closure_state");
|
|
expect(output.liveTemporalHint).toEqual({
|
|
as_of_date: "2020-07-31",
|
|
period_from: null,
|
|
period_to: null,
|
|
source: "analysis_context"
|
|
});
|
|
});
|
|
|
|
it("drops unknown inferred domain and disables live temporal hint when context is inactive", () => {
|
|
const output = buildAssistantDeepTurnRuntimeContext({
|
|
userMessage: "какой-нибудь вопрос",
|
|
normalizedPayload: null as any,
|
|
routeSummary: null,
|
|
runtimeAnalysisContext: {
|
|
active: false,
|
|
as_of_date: null,
|
|
period_from: null,
|
|
period_to: null,
|
|
source: null
|
|
},
|
|
followupUsage: null,
|
|
resolveCompanyAnchors: () => ({}),
|
|
resolveBusinessScopeAlignment: () => ({ route_summary_resolved: null }),
|
|
inferP0DomainFromMessage: () => "unknown_domain",
|
|
resolveTemporalGuard: () => ({ primary_period_window: null }),
|
|
resolveDomainPolarityGuard: () => ({ polarity: "not_applicable" }),
|
|
resolveClaimBoundAnchors: () => ({ claim_type: "unknown" } as any),
|
|
resolveBusinessScopeFromLiveContext: () => ({ route_summary_resolved: null })
|
|
});
|
|
|
|
expect(output.focusDomainForGuards).toBeNull();
|
|
expect(output.resolvedRouteSummary).toBeNull();
|
|
expect(output.liveTemporalHint).toBeNull();
|
|
});
|
|
});
|