79 lines
3.6 KiB
TypeScript
79 lines
3.6 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { buildAssistantDeepTurnResponseRuntimeInput } from "../src/services/assistantDeepTurnResponseRuntimeInputBuilder";
|
|
|
|
function buildDeepRuntime() {
|
|
return {
|
|
companyAnchors: { accounts: ["60.01"] },
|
|
temporalGuard: { primary_period_window: { from: "2020-07-01", to: "2020-07-31" } },
|
|
claimAnchorAudit: { claim_type: "prove_settlement_closure_state" },
|
|
businessScopeResolution: { business_scope_resolved: ["company_specific_accounting"] },
|
|
resolvedRouteSummary: { mode: "deterministic_v2", decisions: [] as any[] },
|
|
requirementExtraction: {
|
|
requirements: [{ id: "R1" }],
|
|
byFragment: new Map<string, string[]>([["F1", ["R1"]]])
|
|
},
|
|
executionPlan: [{ fragment_id: "F1", route: "store_canonical" }],
|
|
retrievalCalls: [{ fragment_id: "F1", route: "store_canonical" }],
|
|
retrievalResultsRaw: [{ fragment_id: "F1", route: "store_canonical", raw_result: {} }],
|
|
retrievalResults: [{ fragment_id: "F1", requirement_ids: ["R1"] }],
|
|
polarityGuardResult: { audit: { polarity: "supplier_payable" } },
|
|
targetedEvidenceResult: { audit: { targeted_evidence_hit_rate: 1 } },
|
|
evidenceGateResult: { audit: { admissible_evidence_count: 2 } },
|
|
rbpLiveRouteAudit: { routed: 1 },
|
|
faLiveRouteAudit: { routed: 1 },
|
|
coverageEvaluation: {
|
|
requirements: [{ id: "R1" }],
|
|
coverage: { requirements_total: 1, requirements_covered: 1 }
|
|
},
|
|
groundedAnswerEligibilityGuard: { eligible: true },
|
|
groundingCheck: { status: "grounded", reasons: [] },
|
|
questionTypeClass: "causal_trace",
|
|
composition: { reply_type: "factual_with_explanation", assistant_reply: "ok" }
|
|
} as any;
|
|
}
|
|
|
|
describe("assistant deep turn response runtime input builder", () => {
|
|
it("maps analysis runtime into response runtime contract", () => {
|
|
const runtimeInput = buildAssistantDeepTurnResponseRuntimeInput({
|
|
featureInvestigationStateV1: true,
|
|
featureContractsV11: true,
|
|
featureAnswerPolicyV11: true,
|
|
sessionId: "asst-1",
|
|
questionId: "msg-q1",
|
|
userMessage: "why debt not closed",
|
|
normalized: {
|
|
trace_id: "trace-1",
|
|
prompt_version: "normalizer_v2_0_2",
|
|
schema_version: "normalized_query_v2_0_2",
|
|
normalized: { fragments: [] }
|
|
},
|
|
normalizedQuestion: "normalized-question",
|
|
deepTurnAnalysisRuntime: buildDeepRuntime(),
|
|
runtimeAnalysisContext: { as_of_date: "2020-07-31" },
|
|
followupStateUsage: { applied: true },
|
|
followupApplied: true,
|
|
previousInvestigationState: null,
|
|
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()
|
|
});
|
|
|
|
expect(runtimeInput.routeSummary).toEqual({ mode: "deterministic_v2", decisions: [] });
|
|
expect(runtimeInput.requirementExtractionRequirements).toEqual([{ id: "R1" }]);
|
|
expect(runtimeInput.coverageEvaluationRequirements).toEqual([{ id: "R1" }]);
|
|
expect(runtimeInput.questionTypeClass).toBe("causal_trace");
|
|
expect(runtimeInput.polarityAudit).toEqual({ polarity: "supplier_payable" });
|
|
expect(runtimeInput.targetedEvidenceAudit).toEqual({ targeted_evidence_hit_rate: 1 });
|
|
expect(runtimeInput.evidenceAdmissibilityGateAudit).toEqual({ admissible_evidence_count: 2 });
|
|
});
|
|
});
|