feat(agent): add controlled task execution
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
|
||||
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).toContain(trigger.trigger_id);
|
||||
});
|
||||
|
||||
it("rejects a different scenario instead of routing arbitrary work orders", () => {
|
||||
expect(agentTriggerContextSchema.safeParse({
|
||||
...trigger,
|
||||
payload: { ...trigger.payload, scenario_code: "UNKNOWN" },
|
||||
}).success).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user