import { describe, expect, it } from "bun:test"; import { taskReportSchema } from "../../src/product/investigation-report.js"; const report = { title: "调查报告", current_conclusion: "无法确定原因", conclusion_boundary: "仅有上游数据", evidence_refs: ["query-1"], recommendations: [], pending_items: [], stage: "final", outcome: "insufficient_data", stop_reason: "缺少关键采样", data_gaps: [{ gap_id: "g1", node_id: "read", missing_data: "末梢采样", scope: "投诉时段", impact: "无法判断异常来源", required_data: "该时段采样结果", evidence_refs: ["query-1"], blocking: true }] }; describe("new investigation report writes", () => { it("requires explicit outcome and gap assessment", () => { expect(taskReportSchema.parse(report).outcome).toBe("insufficient_data"); for (const field of ["stage", "outcome", "data_gaps"]) { const incomplete = { ...report }; Reflect.deleteProperty(incomplete, field); expect(() => taskReportSchema.parse(incomplete)).toThrow(); } }); it("accepts an evidence-backed gap without a plan or diagram node", () => { const { node_id: _nodeId, ...gap } = report.data_gaps[0]; expect(taskReportSchema.parse({ ...report, data_gaps: [gap] }).data_gaps[0]?.node_id).toBeUndefined(); }); it("accepts an optional narrative diagram and rejects interactive directives", () => { const diagram = { title: "核查关系", mermaid: 'flowchart TD\nA["查询"] --> B["判断"]', node_refs: [{ node_id: "A", label: "查询", evidence_refs: ["query-1"] }] }; expect(taskReportSchema.parse({ ...report, diagram }).diagram?.node_refs[0]?.action_refs).toEqual([]); for (const mermaid of ['%%{init: {}}%%\nflowchart TD\nA-->B', 'flowchart TD\nclick A callback', 'flowchart TD; A-->B; click A callback', 'sequenceDiagram\nA->>B: 查询']) { expect(() => taskReportSchema.parse({ ...report, diagram: { ...diagram, mermaid } })).toThrow(); } }); it("rejects downstream work or unsupported claims on insufficient-data exit", () => { for (const changes of [{ recommendations: ["派采样工单"] }, { pending_items: ["等待人工"] }, { stop_reason: null }, { data_gaps: [] }, { stage: "interim" }, { outcome: "concluded" }, { data_gaps: [{ ...report.data_gaps[0], evidence_refs: [] }] }, { schema: "unexpected" }]) { expect(() => taskReportSchema.parse({ ...report, ...changes })).toThrow(); } }); });