Files
next-tjwater-agent/tests/routes/agentTrigger.test.ts
T
jiang 6336157ff4
Generic Container CI/CD / test-build-publish (push) Successful in 1m6s
Agent CI/CD / build-test-publish-and-deploy (push) Successful in 1m7s
feat: upgrade investigation and presentation runtime
2026-10-30 17:30:19 +08:00

78 lines
3.5 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: "system_data",
},
} 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).not.toContain("上游三个模拟水质监测点的数据质量均为 valid");
expect(prompt).toContain("外围业务系统的系统数据");
expect(prompt).not.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("业务 Skill");
expect(prompt).toContain("后台调查指令的停止条件");
expect(prompt).toContain("权限拒绝和接口错误不能证明数据缺失");
expect(prompt).not.toContain("提议成功后再保存 final");
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).toContain("continue executable necessary analysis");
expect(proposeTaskAction.description).not.toContain("After success, publish a final report");
expect(proposeTaskAction.description).not.toContain("published current plan");
expect(proposeTaskAction.description).not.toContain("republish the plan");
});
it("accepts business intake without a demo scenario", () => {
const parsed = agentTriggerContextSchema.parse({
...trigger, payload: { ...trigger.payload, origin: "system_data", scenario_code: null },
});
const prompt = buildAgentTriggerPrompt(parsed);
expect(prompt).toContain("外围业务系统的系统数据");
expect(prompt).not.toContain("合成演练");
expect(prompt).not.toContain("且相邻片区没有同类投诉");
expect(prompt).toContain("mcp_tjwater_get_task_context");
});
it("rejects any non-system work-order provenance", () => {
expect(agentTriggerContextSchema.safeParse({
...trigger,
payload: { ...trigger.payload, origin: "synthetic" },
}).success).toBe(false);
});
});