import { describe, expect, it } from "vitest"; import { buildAssistantDeepTurnPackagingInput, type AssistantDeepTurnInputBuilderArgs } from "../src/services/assistantDeepTurnInputBuilder"; function baseArgs(): AssistantDeepTurnInputBuilderArgs { return { sessionId: "asst-1", messageId: "msg-1", userMessage: "проверь 60.01", normalized: { trace_id: "trace-1", prompt_version: "normalizer_v2_0_2", schema_version: "normalized_query_v2_0_2", normalized: { schema_version: "normalized_query_v2_0_2", user_message_raw: "проверь 60.01", message_in_scope: true, scope_confidence: "high", contains_multiple_tasks: false, fragments: [], discarded_fragments: [], global_notes: { needs_clarification: false, clarification_reason: null } } }, normalizedQuestion: "проверь 60.01", routeSummary: null, droppedIntentSegments: [], analysisContextForContract: null, executionPlan: [], requirementExtractionRequirements: [], coverageEvaluationRequirements: [], coverageReport: { requirements_total: 0, requirements_covered: 0, requirements_uncovered: [], requirements_partially_covered: [], clarification_needed_for: [], out_of_scope_requirements: [] }, groundingCheck: { status: "no_grounded_answer", route_subject_match: false, missing_requirements: [], reasons: [], why_included_summary: [], selection_reason_summary: [] }, retrievalCalls: [], retrievalResultsRaw: [], retrievalResults: [], routesForDebug: [], resolvedExecutionState: {}, questionTypeClass: "factual_lookup", companyAnchors: {}, runtimeAnalysisContext: { active: false, as_of_date: null, period_from: null, period_to: null, source: null, snapshot_mode: "auto" }, businessScopeResolution: {}, temporalGuard: {}, polarityAudit: {}, claimAnchorAudit: {}, targetedEvidenceAudit: null, evidenceAdmissibilityGateAudit: null, rbpLiveRouteAudit: null, faLiveRouteAudit: null, groundedAnswerEligibilityGuard: {}, followupStateUsage: undefined, composition: { reply_type: "factual", fallback_type: "none" }, safeAssistantReplyBase: "ok", featureContractsV11: true, featureAnswerPolicyV11: true, investigationStateSnapshot: null, addressRuntimeMetaForDeep: null }; } describe("assistant deep turn input builder", () => { it("applies stable defaults for optional composition and followup fields", () => { const built = buildAssistantDeepTurnPackagingInput(baseArgs()); expect(built.followupStateUsage).toBeNull(); expect(built.composition.answer_structure_v11).toBeNull(); expect(built.composition.problem_centric_answer_applied).toBe(false); expect(built.composition.problem_units_used_count).toBe(0); expect(built.composition.problem_answer_mode).toBe("stage1_policy_v11"); expect(built.composition.problem_unit_ids_used).toEqual([]); }); it("preserves explicit composition fields and normalizes unit ids array", () => { const args = baseArgs(); args.followupStateUsage = { applied: true }; args.composition.answer_structure_v11 = { schema_version: "answer_structure_v1_1", answer_summary: "sum", direct_answer: "direct", mechanism_block: { status: "grounded", mechanism_notes: [], limitation_reason_codes: [] }, evidence_block: { evidence_ids: [], source_refs: [], mechanism_notes: [], coverage_note: "ok" }, uncertainty_block: { open_uncertainties: [], limitations: [] }, next_step_block: { recommended_actions: [], clarification_questions: [] } } as any; args.composition.problem_centric_answer_applied = true; args.composition.problem_units_used_count = 3; args.composition.problem_answer_mode = "stage3_lifecycle_aware_v1"; args.composition.problem_unit_ids_used = ["pu-1", "pu-2"]; const built = buildAssistantDeepTurnPackagingInput(args); expect(built.followupStateUsage).toEqual({ applied: true }); expect(built.composition.answer_structure_v11?.schema_version).toBe("answer_structure_v1_1"); expect(built.composition.problem_centric_answer_applied).toBe(true); expect(built.composition.problem_units_used_count).toBe(3); expect(built.composition.problem_answer_mode).toBe("stage3_lifecycle_aware_v1"); expect(built.composition.problem_unit_ids_used).toEqual(["pu-1", "pu-2"]); }); });