Move project and host queries into native MCP with host-owned OAuth/context, while retaining memory, skills, actions and publication plugins. Add nearby-model queries and explicit chat/task/learning model defaults. Adopt Responses HTTP/SSE and native steer/queue inbox delivery, preserving scoped session ownership, pending input edits and investigation communication. Disable local-provider discovery: Server /health allowed native vLLM to probe /v1/models on port 8000. A native before/after regression prevents recurrence. Validation: 170 focused Bun tests; service/plugin typechecks; native discovery, provider-discovery and input-inbox smoke checks; no paid model inference.
69 lines
4.8 KiB
TypeScript
69 lines
4.8 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import { taskReportSchema, taskProgressSchema } 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();
|
|
}
|
|
});
|
|
it("shares explicit node activity and supply feature targets with progress", () => {
|
|
const diagram = { title: "当前调查", mermaid: "flowchart LR\nQUERY --> HUMAN",
|
|
node_refs: [{ node_id: "QUERY", label: "核对监测", status: "running", evidence_refs: ["query-1"],
|
|
map_targets: [{ source_id: "scada", feature_id: "MP01" }] },
|
|
{ node_id: "HUMAN", label: "现场核验", status: "waiting_human" }] };
|
|
const progress = taskProgressSchema.parse({ summary: "正在核对投诉时段的实际监测记录", diagram });
|
|
expect(progress.diagram?.node_refs[0]).toMatchObject({ status: "running", map_targets: [{ source_id: "scada", feature_id: "MP01" }] });
|
|
expect(taskReportSchema.parse({ ...report, diagram }).diagram).toEqual(progress.diagram);
|
|
expect(taskProgressSchema.parse({ summary: "调整调查方向", diagram: null }).diagram).toBeNull();
|
|
for (const change of [{ status: "waiting" }, { map_targets: [{ source_id: "drainage", feature_id: "X" }] },
|
|
{ map_targets: [{ source_id: "scada", feature_id: "" }] }]) {
|
|
expect(() => taskProgressSchema.parse({ summary: "核对", diagram: {
|
|
...diagram, node_refs: [{ ...diagram.node_refs[0], ...change }],
|
|
} })).toThrow();
|
|
}
|
|
});
|
|
it("preserves parallel branches with independent activity and a pending join", () => {
|
|
const mermaid = 'flowchart TD\nSTART[受理投诉] --> SPLIT{并行核查}\nSPLIT --> TICKETS[工单核查]\nSPLIT --> SCADA[监测核查]\nTICKETS --> JOIN[汇总证据]\nSCADA --> JOIN';
|
|
const diagram = { title: "并行调查", mermaid, node_refs: [
|
|
{ node_id: "TICKETS", label: "工单核查", status: "running" },
|
|
{ node_id: "SCADA", label: "监测核查", status: "running" },
|
|
{ node_id: "JOIN", label: "汇总证据", status: "pending" },
|
|
] };
|
|
const progress = taskProgressSchema.parse({ summary: "两个独立核查正在执行", diagram });
|
|
expect(progress.diagram?.mermaid).toBe(mermaid);
|
|
expect(progress.diagram?.node_refs.map((node) => node.status)).toEqual(["running", "running", "pending"]);
|
|
const updated = taskProgressSchema.parse({ summary: "工单核查已完成,监测核查仍在执行", diagram: {
|
|
...diagram, node_refs: [{ ...diagram.node_refs[0], status: "completed", evidence_refs: ["query-1"] }, ...diagram.node_refs.slice(1)],
|
|
} });
|
|
expect(updated.diagram?.node_refs.map((node) => node.status)).toEqual(["completed", "running", "pending"]);
|
|
});
|
|
});
|