143 lines
5.3 KiB
TypeScript
143 lines
5.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { runAssistantDeepTurnGroundingRuntime } from "../src/services/assistantDeepTurnGroundingRuntimeAdapter";
|
|
|
|
describe("assistant deep turn grounding runtime adapter", () => {
|
|
it("runs audits, coverage-grounding pipeline and eligibility overlay in stable order", () => {
|
|
const callOrder: string[] = [];
|
|
const retrievalResults = [{ fragment_id: "F1" }] as any[];
|
|
const coverageEvaluation = {
|
|
requirements: [{ requirement_id: "R1" }],
|
|
coverage: {
|
|
requirements_total: 1,
|
|
requirements_covered: 1,
|
|
requirements_uncovered: [],
|
|
requirements_partially_covered: [],
|
|
clarification_needed_for: [],
|
|
out_of_scope_requirements: []
|
|
}
|
|
} as any;
|
|
const groundingCheckBase = {
|
|
status: "grounded_positive",
|
|
reasons: [],
|
|
route_subject_match: true,
|
|
missing_requirements: [],
|
|
why_included_summary: [],
|
|
selection_reason_summary: []
|
|
} as any;
|
|
|
|
const output = runAssistantDeepTurnGroundingRuntime({
|
|
claimType: "prove_settlement_closure_state",
|
|
retrievalResults,
|
|
rbpPlanAudit: { rbp: true },
|
|
faPlanAudit: { fa: true },
|
|
routeSummary: { mode: "deterministic_v2", decisions: [] } as any,
|
|
normalizedPayload: { schema_version: "normalized_query_v2_0_2" } as any,
|
|
userMessage: "check",
|
|
requirementExtraction: {
|
|
requirements: [{ requirement_id: "R1" }] as any,
|
|
byFragment: new Map([["F1", ["R1"]]])
|
|
} as any,
|
|
extractRequirements: (() => {
|
|
throw new Error("should not be called when requirementExtraction is provided");
|
|
}) as any,
|
|
evaluateCoverage: (() => {
|
|
throw new Error("should not be called directly from adapter");
|
|
}) as any,
|
|
checkGrounding: (() => {
|
|
throw new Error("should not be called directly from adapter");
|
|
}) as any,
|
|
temporalGuard: { temporal_guard_outcome: "passed" } as any,
|
|
polarityAudit: { outcome: "passed" } as any,
|
|
evidenceAudit: { admissible_evidence_count: 2 } as any,
|
|
claimAnchorAudit: { claim_type: "prove_settlement_closure_state" } as any,
|
|
targetedEvidenceHitRate: 0.5,
|
|
businessScopeResolved: ["company_specific_accounting"],
|
|
collectRbpLiveRouteAudit: (input) => {
|
|
callOrder.push("rbp_audit");
|
|
expect(input.planAudit).toEqual({ rbp: true });
|
|
return { rbp_live: 1 };
|
|
},
|
|
collectFaLiveRouteAudit: (input) => {
|
|
callOrder.push("fa_audit");
|
|
expect(input.planAudit).toEqual({ fa: true });
|
|
return { fa_live: 1 };
|
|
},
|
|
runCoverageGroundingPipelineFn: ((input: Record<string, unknown>) => {
|
|
callOrder.push("coverage_pipeline");
|
|
expect(input.retrievalResults).toBe(retrievalResults);
|
|
return {
|
|
requirementExtraction: input.requirementExtraction,
|
|
coverageEvaluation,
|
|
groundingCheckBase
|
|
};
|
|
}) as any,
|
|
applyGroundingEligibilityFn: ((input: Record<string, unknown>) => {
|
|
callOrder.push("eligibility");
|
|
expect(input.groundingCheckBase).toBe(groundingCheckBase);
|
|
return {
|
|
groundedAnswerEligibilityGuard: {
|
|
eligible: true
|
|
},
|
|
groundingCheck: groundingCheckBase
|
|
};
|
|
}) as any
|
|
});
|
|
|
|
expect(callOrder).toEqual(["rbp_audit", "fa_audit", "coverage_pipeline", "eligibility"]);
|
|
expect(output.rbpLiveRouteAudit).toEqual({ rbp_live: 1 });
|
|
expect(output.faLiveRouteAudit).toEqual({ fa_live: 1 });
|
|
expect(output.coverageEvaluation).toBe(coverageEvaluation);
|
|
expect(output.groundedAnswerEligibilityGuard).toEqual({ eligible: true });
|
|
expect(output.groundingCheck).toBe(groundingCheckBase);
|
|
});
|
|
|
|
it("threads default pipeline output through without custom hooks", () => {
|
|
const output = runAssistantDeepTurnGroundingRuntime({
|
|
claimType: "unknown",
|
|
retrievalResults: [],
|
|
rbpPlanAudit: null,
|
|
faPlanAudit: null,
|
|
routeSummary: null,
|
|
normalizedPayload: null as any,
|
|
userMessage: "q",
|
|
requirementExtraction: {
|
|
requirements: [],
|
|
byFragment: new Map()
|
|
} as any,
|
|
extractRequirements: () => ({
|
|
requirements: [],
|
|
byFragment: new Map()
|
|
}) as any,
|
|
evaluateCoverage: () => ({
|
|
requirements: [],
|
|
coverage: {
|
|
requirements_total: 0,
|
|
requirements_covered: 0,
|
|
requirements_uncovered: [],
|
|
requirements_partially_covered: [],
|
|
clarification_needed_for: [],
|
|
out_of_scope_requirements: []
|
|
}
|
|
}),
|
|
checkGrounding: () =>
|
|
({
|
|
status: "no_grounded_answer",
|
|
route_subject_match: false,
|
|
missing_requirements: [],
|
|
reasons: [],
|
|
why_included_summary: [],
|
|
selection_reason_summary: []
|
|
}) as any,
|
|
temporalGuard: { temporal_guard_outcome: "passed", temporal_guard_basis: "none" } as any,
|
|
polarityAudit: { applied: false, outcome: "not_applicable" } as any,
|
|
evidenceAudit: { admissible_evidence_count: 0 } as any,
|
|
claimAnchorAudit: null,
|
|
collectRbpLiveRouteAudit: () => null,
|
|
collectFaLiveRouteAudit: () => null
|
|
});
|
|
|
|
expect(output.coverageEvaluation.requirements).toEqual([]);
|
|
expect(output.groundingCheck.status).toBe("no_grounded_answer");
|
|
});
|
|
});
|