187 lines
5.9 KiB
TypeScript
187 lines
5.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
||
import { buildAssistantAnswerStructureV11 } from "../src/services/assistantAnswerPackageBuilder";
|
||
|
||
function buildRetrieval(input?: Partial<any>): any {
|
||
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: [],
|
||
...input
|
||
};
|
||
}
|
||
|
||
describe("assistant answer package builder v11", () => {
|
||
it("builds baseline answer structure with unresolved mechanism", () => {
|
||
const structure = buildAssistantAnswerStructureV11({
|
||
assistantReply: "Первая строка\nВторая строка",
|
||
coverageReport: {
|
||
requirements_total: 2,
|
||
requirements_covered: 1,
|
||
requirements_uncovered: ["R2"],
|
||
requirements_partially_covered: [],
|
||
clarification_needed_for: [],
|
||
out_of_scope_requirements: []
|
||
},
|
||
groundingCheck: {
|
||
status: "partial",
|
||
route_subject_match: true,
|
||
missing_requirements: ["R2"],
|
||
reasons: ["limited coverage"],
|
||
why_included_summary: [],
|
||
selection_reason_summary: []
|
||
},
|
||
retrievalResults: [buildRetrieval()]
|
||
});
|
||
|
||
expect(structure.schema_version).toBe("answer_structure_v1_1");
|
||
expect(structure.answer_summary).toBe("Первая строка");
|
||
expect(structure.mechanism_block.status).toBe("unresolved");
|
||
expect(structure.evidence_block.coverage_note).toBe("coverage_partial_or_limited");
|
||
expect(structure.uncertainty_block.open_uncertainties).toEqual(["R2"]);
|
||
});
|
||
|
||
it("adds claim-evidence links when enrichment is explicitly enabled", () => {
|
||
const structure = buildAssistantAnswerStructureV11({
|
||
assistantReply: "Ответ",
|
||
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: []
|
||
},
|
||
retrievalResults: [
|
||
buildRetrieval({
|
||
evidence: [
|
||
{
|
||
evidence_id: "ev-1",
|
||
claim_ref: "requirement:R1",
|
||
source_type: "retrieval_item",
|
||
source_ref: {
|
||
schema_version: "evidence_source_ref_v1",
|
||
namespace: "snapshot_2020",
|
||
entity: "document",
|
||
id: "doc-1",
|
||
period: "2020-07",
|
||
canonical_ref: "evidence_source_ref_v1|snapshot_2020|document|doc-1|2020-07"
|
||
},
|
||
pointer: {
|
||
fragment_id: "F1",
|
||
route: "hybrid_store_plus_live",
|
||
source: {
|
||
namespace: "snapshot_2020",
|
||
entity: "document",
|
||
id: "doc-1",
|
||
period: "2020-07"
|
||
},
|
||
locator: {
|
||
field_path: "amount",
|
||
item_index: 0
|
||
}
|
||
},
|
||
evidence_kind: "mechanism_link",
|
||
mechanism_note: "trace confirmed",
|
||
confidence: "high",
|
||
limitation: null,
|
||
payload: {}
|
||
}
|
||
]
|
||
})
|
||
],
|
||
options: {
|
||
enableEvidenceEnrichment: true
|
||
}
|
||
});
|
||
|
||
expect(Array.isArray(structure.evidence_block.claim_evidence_links)).toBe(true);
|
||
expect(structure.evidence_block.claim_evidence_links?.[0]?.claim_ref).toBe("requirement:R1");
|
||
expect(structure.evidence_block.claim_evidence_links?.[0]?.evidence_ids).toContain("ev-1");
|
||
});
|
||
|
||
it("omits claim-evidence links when enrichment is disabled", () => {
|
||
const structure = buildAssistantAnswerStructureV11({
|
||
assistantReply: "Ответ",
|
||
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: []
|
||
},
|
||
retrievalResults: [
|
||
buildRetrieval({
|
||
evidence: [
|
||
{
|
||
evidence_id: "ev-1",
|
||
claim_ref: "requirement:R1",
|
||
source_type: "retrieval_item",
|
||
source_ref: {
|
||
schema_version: "evidence_source_ref_v1",
|
||
namespace: "snapshot_2020",
|
||
entity: "document",
|
||
id: "doc-1",
|
||
period: "2020-07",
|
||
canonical_ref: "evidence_source_ref_v1|snapshot_2020|document|doc-1|2020-07"
|
||
},
|
||
pointer: {
|
||
fragment_id: "F1",
|
||
route: "hybrid_store_plus_live",
|
||
source: {
|
||
namespace: "snapshot_2020",
|
||
entity: "document",
|
||
id: "doc-1",
|
||
period: "2020-07"
|
||
},
|
||
locator: {
|
||
field_path: "amount",
|
||
item_index: 0
|
||
}
|
||
},
|
||
evidence_kind: "mechanism_link",
|
||
mechanism_note: "trace confirmed",
|
||
confidence: "high",
|
||
limitation: null,
|
||
payload: {}
|
||
}
|
||
]
|
||
})
|
||
],
|
||
options: {
|
||
enableEvidenceEnrichment: false
|
||
}
|
||
});
|
||
|
||
expect(structure.evidence_block.claim_evidence_links).toBeUndefined();
|
||
});
|
||
});
|