61 lines
2.4 KiB
TypeScript
61 lines
2.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { buildAssistantDeepTurnPrePackagingContext } from "../src/services/assistantDeepTurnPrePackagingContext";
|
|
|
|
describe("assistant deep turn pre-packaging context", () => {
|
|
it("builds all pre-packaging fields with active analysis context", () => {
|
|
const output = buildAssistantDeepTurnPrePackagingContext({
|
|
normalizedPayload: { schema_version: "normalized_query_v2_0_2" } as any,
|
|
routeSummary: null,
|
|
runtimeAnalysisContext: {
|
|
active: true,
|
|
as_of_date: "2020-07-31",
|
|
period_from: null,
|
|
period_to: null,
|
|
source: "eval_analysis_date",
|
|
snapshot_mode: "auto"
|
|
},
|
|
assistantReply: "raw",
|
|
extractDroppedIntentSegments: () => ["segment_1"],
|
|
buildDebugRoutes: () => [{ fragment_id: "F1", route: "hybrid_store_plus_live" }],
|
|
extractExecutionState: () => ({ executable: 1 }),
|
|
sanitizeReply: (value, fallback) => `${value}::${fallback}`
|
|
});
|
|
|
|
expect(output.droppedIntentSegments).toEqual(["segment_1"]);
|
|
expect(output.analysisContextForContract).toEqual({
|
|
as_of_date: "2020-07-31",
|
|
period_from: null,
|
|
period_to: null,
|
|
source: "eval_analysis_date",
|
|
snapshot_mode: "auto"
|
|
});
|
|
expect(output.routesForDebug).toEqual([{ fragment_id: "F1", route: "hybrid_store_plus_live" }]);
|
|
expect(output.resolvedExecutionState).toEqual({ executable: 1 });
|
|
expect(output.safeAssistantReplyBase).toContain("Нужны уточнения для надежного ответа.");
|
|
});
|
|
|
|
it("returns null analysis context when runtime context is inactive", () => {
|
|
const output = buildAssistantDeepTurnPrePackagingContext({
|
|
normalizedPayload: { schema_version: "normalized_query_v2_0_2" } as any,
|
|
routeSummary: null,
|
|
runtimeAnalysisContext: {
|
|
active: false,
|
|
as_of_date: "2020-07-31",
|
|
period_from: "2020-07-01",
|
|
period_to: "2020-07-31",
|
|
source: "eval_analysis_date",
|
|
snapshot_mode: "auto"
|
|
},
|
|
assistantReply: "ok",
|
|
extractDroppedIntentSegments: () => [],
|
|
buildDebugRoutes: () => [],
|
|
extractExecutionState: () => null,
|
|
sanitizeReply: (value) => value
|
|
});
|
|
|
|
expect(output.analysisContextForContract).toBeNull();
|
|
expect(output.routesForDebug).toEqual([]);
|
|
expect(output.safeAssistantReplyBase).toBe("ok");
|
|
});
|
|
});
|