180 lines
5.7 KiB
TypeScript
180 lines
5.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { assembleAssistantDeepTurnPackaging } from "../src/services/assistantDeepTurnPackaging";
|
|
|
|
function buildRetrieval() {
|
|
return {
|
|
fragment_id: "F1",
|
|
requirement_ids: ["R1"],
|
|
route: "hybrid_store_plus_live",
|
|
status: "ok",
|
|
result_type: "summary",
|
|
items: [],
|
|
summary: {},
|
|
evidence: [],
|
|
why_included: [],
|
|
selection_reason: [],
|
|
risk_factors: [],
|
|
business_interpretation: [],
|
|
confidence: "medium",
|
|
limitations: [],
|
|
errors: []
|
|
};
|
|
}
|
|
|
|
function baseInput() {
|
|
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: [{ fragment_id: "F1" }],
|
|
discarded_fragments: [],
|
|
global_notes: {
|
|
needs_clarification: false,
|
|
clarification_reason: null
|
|
}
|
|
}
|
|
},
|
|
normalizedQuestion: "проверь хвосты по 60.01",
|
|
routeSummary: {
|
|
mode: "deterministic_v2",
|
|
message_in_scope: true,
|
|
scope_confidence: "high",
|
|
planner: {
|
|
total_fragments: 1,
|
|
in_scope_fragments: 1,
|
|
out_of_scope_fragments: 0,
|
|
discarded_fragments: 0,
|
|
contains_multiple_tasks: false
|
|
},
|
|
decisions: [],
|
|
fallback: {
|
|
type: "none",
|
|
message: null
|
|
}
|
|
},
|
|
droppedIntentSegments: [],
|
|
analysisContextForContract: {
|
|
as_of_date: "2020-07-31",
|
|
period_from: null,
|
|
period_to: null,
|
|
source: "eval_analysis_date",
|
|
snapshot_mode: "auto" as const
|
|
},
|
|
executionPlan: [
|
|
{
|
|
fragment_id: "F1",
|
|
requirement_ids: ["R1"],
|
|
route: "hybrid_store_plus_live",
|
|
should_execute: true,
|
|
no_route_reason: null,
|
|
clarification_reason: null
|
|
}
|
|
],
|
|
requirementExtractionRequirements: [
|
|
{
|
|
requirement_id: "R1",
|
|
source_fragment_id: "F1",
|
|
requirement_text: "проверить хвосты 60.01",
|
|
subject_tokens: ["account_60.01"],
|
|
status: "covered",
|
|
route: "hybrid_store_plus_live"
|
|
}
|
|
],
|
|
coverageEvaluationRequirements: [
|
|
{
|
|
requirement_id: "R1",
|
|
source_fragment_id: "F1",
|
|
requirement_text: "проверить хвосты 60.01",
|
|
subject_tokens: ["account_60.01"],
|
|
status: "covered",
|
|
route: "hybrid_store_plus_live"
|
|
}
|
|
],
|
|
coverageReport: {
|
|
requirements_total: 1,
|
|
requirements_covered: 1,
|
|
requirements_uncovered: [],
|
|
requirements_partially_covered: [],
|
|
clarification_needed_for: [],
|
|
out_of_scope_requirements: []
|
|
},
|
|
groundingCheck: {
|
|
status: "grounded",
|
|
route_subject_match: true,
|
|
missing_requirements: [],
|
|
reasons: [],
|
|
why_included_summary: [],
|
|
selection_reason_summary: []
|
|
},
|
|
retrievalCalls: [{ route: "hybrid_store_plus_live" }],
|
|
retrievalResultsRaw: [buildRetrieval()],
|
|
retrievalResults: [buildRetrieval()],
|
|
routesForDebug: [{ fragment_id: "F1", route: "hybrid_store_plus_live" }],
|
|
resolvedExecutionState: { executable: 1 },
|
|
questionTypeClass: "factual_lookup",
|
|
companyAnchors: { companies: ["demo"] },
|
|
runtimeAnalysisContext: {
|
|
active: true,
|
|
as_of_date: "2020-07-31",
|
|
period_from: null,
|
|
period_to: null,
|
|
source: "eval_analysis_date",
|
|
snapshot_mode: "auto" as const
|
|
},
|
|
businessScopeResolution: {
|
|
business_scope_raw: ["company_specific_accounting"],
|
|
business_scope_resolved: ["company_specific_accounting"],
|
|
company_grounding_applied: true,
|
|
scope_resolution_reason: ["resolved"]
|
|
},
|
|
temporalGuard: { temporal_guard_applied: true },
|
|
polarityAudit: { resolved_account_anchors: ["60.01"] },
|
|
claimAnchorAudit: { settlement_role: "supplier" },
|
|
targetedEvidenceAudit: { targeted_evidence_hit_rate: 1 },
|
|
evidenceAdmissibilityGateAudit: { admissible_evidence_count: 1 },
|
|
rbpLiveRouteAudit: null,
|
|
faLiveRouteAudit: null,
|
|
groundedAnswerEligibilityGuard: { eligible: true },
|
|
followupStateUsage: null,
|
|
composition: {
|
|
reply_type: "factual" as const,
|
|
fallback_type: "none",
|
|
answer_structure_v11: null,
|
|
problem_centric_answer_applied: true,
|
|
problem_units_used_count: 1,
|
|
problem_answer_mode: "stage3_lifecycle_aware_v1",
|
|
problem_unit_ids_used: ["pu-1"]
|
|
},
|
|
safeAssistantReplyBase: "Короткий ответ\n\ndebug_payload_json: {\"x\":1}",
|
|
featureContractsV11: true,
|
|
featureAnswerPolicyV11: true,
|
|
investigationStateSnapshot: { status: "active" },
|
|
addressRuntimeMetaForDeep: null
|
|
};
|
|
}
|
|
|
|
describe("assistant deep turn packaging", () => {
|
|
it("assembles deep artifacts, debug payload and processed log in one call", () => {
|
|
const input = baseInput();
|
|
const output = assembleAssistantDeepTurnPackaging(input as any);
|
|
|
|
expect(output.deepAnswerArtifacts.safeAssistantReply).toBe("Короткий ответ");
|
|
expect(output.contractsBundleV1.outcomeClassV1).toBe("FULLY_ANSWERED");
|
|
expect(output.debug.trace_id).toBe("trace-1");
|
|
expect(output.assistantItem.message_id).toBe("msg-1");
|
|
expect(output.assistantItem.text).toBe("Короткий ответ");
|
|
expect(output.deepAnalysisLogDetails.session_id).toBe("asst-1");
|
|
expect(output.deepAnalysisLogDetails.message_id).toBe("msg-1");
|
|
});
|
|
});
|