115 lines
4.4 KiB
TypeScript
115 lines
4.4 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import {
|
|
buildAssistantDeepTurnAnalysisAttemptRuntimeInput,
|
|
buildAssistantDeepTurnNormalizationRuntimeInput,
|
|
buildAssistantDeepTurnResponseAttemptRuntimeInput
|
|
} from "../src/services/assistantDeepTurnAttemptInputBuilder";
|
|
|
|
function buildNormalizationRuntime(overrides: Record<string, unknown> = {}) {
|
|
return {
|
|
followupBinding: {
|
|
normalizedQuestion: "normalized-question",
|
|
mergedContext: {},
|
|
usage: { applied: true }
|
|
},
|
|
normalizePayload: {
|
|
userQuestion: "normalized-question"
|
|
},
|
|
normalized: {
|
|
trace_id: "trace-1",
|
|
prompt_version: "normalizer_v2_0_2",
|
|
schema_version: "normalized_query_v2_0_2",
|
|
normalized: { fragments: [] },
|
|
route_hint_summary: { mode: "deterministic_v2", decisions: [] }
|
|
},
|
|
...overrides
|
|
} as any;
|
|
}
|
|
|
|
describe("assistant deep turn attempt input builder", () => {
|
|
it("builds normalization runtime input from turn fields", () => {
|
|
const normalize = vi.fn(async () => ({}));
|
|
const runtimeInput = buildAssistantDeepTurnNormalizationRuntimeInput({
|
|
userMessage: "why debt not closed",
|
|
payload: { llmProvider: "openai", context: {} } as any,
|
|
featureInvestigationStateV1: true,
|
|
featureStateFollowupBindingV1: true,
|
|
sessionInvestigationState: { session_id: "asst-1" },
|
|
buildFollowupStateBinding: vi.fn(() => ({
|
|
normalizedQuestion: "normalized",
|
|
mergedContext: {},
|
|
usage: null
|
|
})),
|
|
normalize
|
|
});
|
|
|
|
expect(runtimeInput.userMessage).toBe("why debt not closed");
|
|
expect(runtimeInput.normalize).toBe(normalize);
|
|
expect(runtimeInput.featureInvestigationStateV1).toBe(true);
|
|
expect(runtimeInput.featureStateFollowupBindingV1).toBe(true);
|
|
});
|
|
|
|
it("builds analysis and response attempt inputs from normalization runtime", () => {
|
|
const normalizationRuntime = buildNormalizationRuntime();
|
|
const deepTurnAnalysisRuntime = {
|
|
composition: { reply_type: "partial_coverage" }
|
|
} as any;
|
|
|
|
const analysisInput = buildAssistantDeepTurnAnalysisAttemptRuntimeInput({
|
|
userMessage: "why debt not closed",
|
|
runtimeAnalysisContext: { active: true, as_of_date: "2020-07-31", period_from: null, period_to: null, source: "analysis_context" },
|
|
sessionInvestigationState: { session_id: "asst-1" } as any,
|
|
featureAnswerPolicyV11: true,
|
|
featureProblemCentricAnswerV1: true,
|
|
featureLifecycleAnswerV1: true,
|
|
resolveBusinessScopeAlignment: vi.fn(),
|
|
inferP0DomainFromMessage: vi.fn(),
|
|
resolveBusinessScopeFromLiveContext: vi.fn(),
|
|
extractRequirements: vi.fn(),
|
|
toExecutionPlan: vi.fn(),
|
|
enforceRbpLiveRoutePlan: vi.fn(),
|
|
enforceFaLiveRoutePlan: vi.fn(),
|
|
executeRouteRuntime: vi.fn(),
|
|
mapNoRouteReason: vi.fn(),
|
|
buildSkippedResult: vi.fn(),
|
|
evaluateCoverage: vi.fn(),
|
|
checkGrounding: vi.fn(),
|
|
collectRbpLiveRouteAudit: vi.fn(),
|
|
collectFaLiveRouteAudit: vi.fn(),
|
|
hasExplicitPeriodAnchor: vi.fn(),
|
|
normalizationRuntime
|
|
});
|
|
const responseInput = buildAssistantDeepTurnResponseAttemptRuntimeInput({
|
|
featureInvestigationStateV1: true,
|
|
featureContractsV11: true,
|
|
featureAnswerPolicyV11: true,
|
|
sessionId: "asst-1",
|
|
questionId: "msg-q1",
|
|
userMessage: "why debt not closed",
|
|
runtimeAnalysisContext: { as_of_date: "2020-07-31" } as any,
|
|
sessionInvestigationState: { session_id: "asst-1" } as any,
|
|
addressRuntimeMetaForDeep: null,
|
|
extractDroppedIntentSegments: vi.fn(() => []),
|
|
buildDebugRoutes: vi.fn(() => []),
|
|
extractExecutionState: vi.fn(() => []),
|
|
sanitizeReply: vi.fn((value: string) => value),
|
|
persistInvestigationState: vi.fn(),
|
|
messageIdFactory: vi.fn(() => "msg-a1"),
|
|
appendItem: vi.fn(),
|
|
getSession: vi.fn(),
|
|
persistSession: vi.fn(),
|
|
cloneConversation: vi.fn((items: unknown[]) => items),
|
|
logEvent: vi.fn(),
|
|
normalizationRuntime,
|
|
deepTurnAnalysisRuntime
|
|
});
|
|
|
|
expect(analysisInput.normalizedPayload).toEqual({ fragments: [] });
|
|
expect(analysisInput.routeSummary).toEqual({ mode: "deterministic_v2", decisions: [] });
|
|
expect(analysisInput.followupUsage).toEqual({ applied: true });
|
|
expect(responseInput.normalizedQuestion).toBe("normalized-question");
|
|
expect(responseInput.normalized.trace_id).toBe("trace-1");
|
|
expect(responseInput.followupApplied).toBe(true);
|
|
});
|
|
});
|