ГЛОБАЛЬНЫЙ РЕФАКТОРИНГ АРХИТЕКТУРЫ - Рефакторинг этапов 2.44 - Вынос deep-response склейку из assistantService в новый bridge и Переподключение assistantService на этот адаптер
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { runAssistantDeepTurnResponseAttemptRuntime } from "../src/services/assistantDeepTurnResponseAttemptRuntimeAdapter";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
function buildInput(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
featureInvestigationStateV1: true,
|
||||
featureContractsV11: true,
|
||||
featureAnswerPolicyV11: true,
|
||||
sessionId: "asst-1",
|
||||
questionId: "msg-q1",
|
||||
userMessage: "почему долг не закрылся",
|
||||
normalized: {
|
||||
trace_id: "trace-1",
|
||||
prompt_version: "normalizer_v2_0_2",
|
||||
schema_version: "normalized_query_v2_0_2",
|
||||
normalized: { fragments: [] }
|
||||
},
|
||||
normalizedQuestion: "почему долг не закрылся",
|
||||
deepTurnAnalysisRuntime: buildDeepRuntime(),
|
||||
runtimeAnalysisContext: { as_of_date: "2020-07-31" },
|
||||
followupStateUsage: { applied: true },
|
||||
followupApplied: true,
|
||||
previousInvestigationState: null,
|
||||
addressRuntimeMetaForDeep: null,
|
||||
extractDroppedIntentSegments: () => [],
|
||||
buildDebugRoutes: () => [],
|
||||
extractExecutionState: () => [],
|
||||
sanitizeReply: (value: string) => value,
|
||||
persistInvestigationState: () => {},
|
||||
messageIdFactory: () => "msg-a1",
|
||||
appendItem: () => {},
|
||||
getSession: () => ({ session_id: "asst-1", items: [] }),
|
||||
persistSession: () => {},
|
||||
cloneConversation: () => [],
|
||||
logEvent: () => {},
|
||||
...overrides
|
||||
} as any;
|
||||
}
|
||||
|
||||
describe("assistant deep turn response attempt runtime adapter", () => {
|
||||
it("maps deep-analysis runtime output into response runtime input", () => {
|
||||
const runDeepTurnResponseRuntime = vi.fn(() => ({
|
||||
response: {
|
||||
ok: true,
|
||||
session_id: "asst-1",
|
||||
conversation: [],
|
||||
debug: { trace_id: "trace-1" }
|
||||
},
|
||||
debug: { trace_id: "trace-1" }
|
||||
}));
|
||||
|
||||
const runtime = runAssistantDeepTurnResponseAttemptRuntime(
|
||||
buildInput({
|
||||
runDeepTurnResponseRuntime
|
||||
})
|
||||
);
|
||||
|
||||
expect(runDeepTurnResponseRuntime).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
routeSummary: expect.objectContaining({ mode: "deterministic_v2" }),
|
||||
requirementExtractionRequirements: [{ id: "R1" }],
|
||||
coverageEvaluationRequirements: [{ id: "R1" }],
|
||||
questionTypeClass: "causal_trace",
|
||||
polarityAudit: { polarity: "supplier_payable" },
|
||||
targetedEvidenceAudit: { targeted_evidence_hit_rate: 1 },
|
||||
evidenceAdmissibilityGateAudit: { admissible_evidence_count: 2 },
|
||||
composition: expect.objectContaining({ reply_type: "factual_with_explanation" })
|
||||
})
|
||||
);
|
||||
expect(runtime.response).toEqual(
|
||||
expect.objectContaining({
|
||||
ok: true
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("forwards callbacks and state flags", () => {
|
||||
const extractDroppedIntentSegments = vi.fn(() => []);
|
||||
const persistInvestigationState = vi.fn();
|
||||
const runDeepTurnResponseRuntime = vi.fn(() => ({
|
||||
response: {
|
||||
ok: true,
|
||||
session_id: "asst-1",
|
||||
conversation: [],
|
||||
debug: null
|
||||
},
|
||||
debug: {}
|
||||
}));
|
||||
|
||||
runAssistantDeepTurnResponseAttemptRuntime(
|
||||
buildInput({
|
||||
followupApplied: false,
|
||||
extractDroppedIntentSegments,
|
||||
persistInvestigationState,
|
||||
runDeepTurnResponseRuntime
|
||||
})
|
||||
);
|
||||
|
||||
expect(runDeepTurnResponseRuntime).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
followupApplied: false,
|
||||
extractDroppedIntentSegments,
|
||||
persistInvestigationState
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user