127 lines
4.3 KiB
TypeScript
127 lines
4.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { buildAssistantDeepTurnComposition } from "../src/services/assistantDeepTurnCompositionRuntimeAdapter";
|
|
|
|
describe("assistant deep turn composition runtime adapter", () => {
|
|
it("uses followup domain hint and company-anchor period signal", () => {
|
|
let capturedInput: Record<string, unknown> | null = null;
|
|
const output = buildAssistantDeepTurnComposition({
|
|
userMessage: "проверь хвосты по 60.01",
|
|
routeSummary: null,
|
|
retrievalResults: [],
|
|
requirements: [],
|
|
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: []
|
|
},
|
|
followupUsage: { applied: true },
|
|
investigationState: {
|
|
schema_version: "investigation_state_v1",
|
|
session_id: "asst-1",
|
|
status: "active",
|
|
turn_index: 1,
|
|
updated_at: "2026-04-10T10:00:00.000Z",
|
|
question_id: "msg-1",
|
|
question_scope_id: null,
|
|
scope_origin: null,
|
|
focus: {
|
|
domain: "settlements_60_62",
|
|
period: null,
|
|
primary_accounts: [],
|
|
active_query_subject: null
|
|
},
|
|
narrowing_status: "unknown",
|
|
evidence_refs: [],
|
|
open_uncertainties: [],
|
|
last_answer_mode: null,
|
|
followup_context: null,
|
|
query_mode_hint: "direct_answer"
|
|
} as any,
|
|
companyAnchors: {
|
|
periods: ["2020-07"],
|
|
dates: []
|
|
},
|
|
normalizedPayload: { schema_version: "normalized_query_v2_0_2" } as any,
|
|
featureAnswerPolicyV11: true,
|
|
featureProblemCentricAnswerV1: true,
|
|
featureLifecycleAnswerV1: true,
|
|
hasExplicitPeriodAnchor: () => false,
|
|
resolveQuestionTypeFn: () => "factual_lookup",
|
|
composeAssistantAnswerFn: ((input: Record<string, unknown>) => {
|
|
capturedInput = input;
|
|
return {
|
|
assistant_reply: "ok",
|
|
fallback_type: "none",
|
|
reply_type: "factual"
|
|
};
|
|
}) as any
|
|
});
|
|
|
|
expect(output.focusDomainHint).toBe("settlements_60_62");
|
|
expect(output.questionTypeClass).toBe("factual_lookup");
|
|
expect(output.hasPeriodInCompanyAnchors).toBe(true);
|
|
expect(output.normalizationPeriodExplicit).toBe(true);
|
|
expect(output.composition.reply_type).toBe("factual");
|
|
expect(capturedInput?.focusDomainHint).toBe("settlements_60_62");
|
|
expect(capturedInput?.normalizationPeriodExplicit).toBe(true);
|
|
});
|
|
|
|
it("falls back to explicit period from normalized payload when anchors are absent", () => {
|
|
const output = buildAssistantDeepTurnComposition({
|
|
userMessage: "проверь закрытие",
|
|
routeSummary: null,
|
|
retrievalResults: [],
|
|
requirements: [],
|
|
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: []
|
|
},
|
|
followupUsage: { applied: false },
|
|
investigationState: null,
|
|
companyAnchors: {
|
|
periods: [],
|
|
dates: []
|
|
},
|
|
normalizedPayload: { schema_version: "normalized_query_v2_0_2" } as any,
|
|
featureAnswerPolicyV11: true,
|
|
featureProblemCentricAnswerV1: true,
|
|
featureLifecycleAnswerV1: true,
|
|
hasExplicitPeriodAnchor: () => true,
|
|
resolveQuestionTypeFn: () => "verification",
|
|
composeAssistantAnswerFn: (() => ({
|
|
assistant_reply: "ok",
|
|
fallback_type: "none",
|
|
reply_type: "factual"
|
|
})) as any
|
|
});
|
|
|
|
expect(output.focusDomainHint).toBeNull();
|
|
expect(output.questionTypeClass).toBe("verification");
|
|
expect(output.hasPeriodInCompanyAnchors).toBe(false);
|
|
expect(output.normalizationPeriodExplicit).toBe(true);
|
|
});
|
|
});
|