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.
64 lines
2.7 KiB
TypeScript
64 lines
2.7 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import proposeTaskAction from "../../.opencode/tools/propose_task_action.js";
|
|
|
|
import {
|
|
agentTriggerContextSchema,
|
|
buildAgentTriggerPrompt,
|
|
} from "../../src/routes/agentTrigger.js";
|
|
|
|
const trigger = {
|
|
schema_version: "agent-trigger@1",
|
|
kind: "event",
|
|
trigger_id: "peripheral.work_order.created:project-1:50000000-0000-4000-8000-000000000001:1",
|
|
occurred_at: "2026-09-22T10:00:00+08:00",
|
|
source: "peripheral_sample",
|
|
subject_type: "work_order",
|
|
subject_id: "50000000-0000-4000-8000-000000000001",
|
|
workflow: "water_quality_complaint",
|
|
payload: {
|
|
title: "居民反映自来水有异味",
|
|
summary: "演示小区多户居民反映晨间用水有异味。",
|
|
location: "演示小区",
|
|
priority: "high",
|
|
scenario_code: "WQ-SECONDARY-SUPPLY-001",
|
|
origin: "synthetic",
|
|
},
|
|
} as const;
|
|
|
|
describe("agent event trigger", () => {
|
|
it("accepts the water-quality work-order contract and builds a bounded prompt", () => {
|
|
const parsed = agentTriggerContextSchema.parse(trigger);
|
|
const prompt = buildAgentTriggerPrompt(parsed);
|
|
|
|
expect(prompt).toContain("水质监测点");
|
|
expect(prompt).toContain("二次供水");
|
|
expect(prompt).toContain("合成演练数据");
|
|
expect(prompt).toContain("动态规划本次调查");
|
|
expect(prompt).not.toContain("请按‘上游数据质量正常");
|
|
expect(prompt).toContain(trigger.trigger_id);
|
|
});
|
|
|
|
it("keeps event entry and action-tool instructions consistent with report-driven completion", () => {
|
|
const prompt = buildAgentTriggerPrompt(agentTriggerContextSchema.parse(trigger));
|
|
expect(prompt).toContain("mcp_tjwater_get_task_context");
|
|
expect(prompt).toContain("final/insufficient_data");
|
|
expect(prompt).toContain("正常结束本轮");
|
|
expect(prompt).toContain("权限拒绝和接口错误不能证明数据缺失");
|
|
expect(prompt).toContain("interim/concluded");
|
|
expect(prompt).not.toContain("开始调查前调用 publish_execution_plan");
|
|
expect(prompt).not.toContain("人工工作保持 waiting");
|
|
expect(proposeTaskAction.description).toContain("interim concluded report");
|
|
expect(proposeTaskAction.description).toContain("No execution plan is required");
|
|
expect(proposeTaskAction.description).toContain("node_id is an optional display reference");
|
|
expect(proposeTaskAction.description).not.toContain("published current plan");
|
|
expect(proposeTaskAction.description).not.toContain("republish the plan");
|
|
});
|
|
|
|
it("rejects a different scenario instead of routing arbitrary work orders", () => {
|
|
expect(agentTriggerContextSchema.safeParse({
|
|
...trigger,
|
|
payload: { ...trigger.payload, scenario_code: "UNKNOWN" },
|
|
}).success).toBe(false);
|
|
});
|
|
});
|