forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask-validation.test.ts
More file actions
112 lines (92 loc) · 2.76 KB
/
Copy pathtask-validation.test.ts
File metadata and controls
112 lines (92 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { describe, expect, it } from "vitest";
import { AgentRuntime } from "../../src/index.js";
import { RuntimeEventBus } from "../../src/events/runtime-events.js";
describe("AgentRuntime.executeTask task field validation (Issue #263)", () => {
function makeRuntime() {
const eventBus = new RuntimeEventBus();
const events: string[] = [];
eventBus.on("runtime.task.received", () => events.push("received"));
eventBus.on("runtime.task.completed", () => events.push("completed"));
eventBus.on("runtime.task.failed", () => events.push("failed"));
const runtime = new AgentRuntime({
runtimeId: "test-validation",
eventBus
});
runtime.registerTool({
name: "ok",
description: "Always ok",
execute() {
return { ok: true };
}
});
return { runtime, events };
}
it("rejects empty taskId before emitting any events", async () => {
const { runtime, events } = makeRuntime();
await runtime.start();
await expect(
runtime.executeTask({
taskId: "",
agentId: "a1",
toolName: "ok",
input: "go",
payload: {}
})
).rejects.toMatchObject({ code: "INVALID_TASK" });
expect(events).toEqual([]);
});
it("rejects whitespace-only agentId before emitting any events", async () => {
const { runtime, events } = makeRuntime();
await runtime.start();
await expect(
runtime.executeTask({
taskId: "t1",
agentId: " ",
toolName: "ok",
input: "go",
payload: {}
})
).rejects.toMatchObject({ code: "INVALID_TASK" });
expect(events).toEqual([]);
});
it("rejects empty toolName before emitting any events", async () => {
const { runtime, events } = makeRuntime();
await runtime.start();
await expect(
runtime.executeTask({
taskId: "t1",
agentId: "a1",
toolName: "",
input: "go",
payload: {}
})
).rejects.toMatchObject({ code: "INVALID_TASK" });
expect(events).toEqual([]);
});
it("rejects blank input before emitting any events", async () => {
const { runtime, events } = makeRuntime();
await runtime.start();
await expect(
runtime.executeTask({
taskId: "t1",
agentId: "a1",
toolName: "ok",
input: " \n\t ",
payload: {}
})
).rejects.toMatchObject({ code: "INVALID_TASK" });
expect(events).toEqual([]);
});
it("still emits events for valid tasks", async () => {
const { runtime, events } = makeRuntime();
await runtime.start();
await runtime.executeTask({
taskId: "t-valid",
agentId: "a1",
toolName: "ok",
input: "go",
payload: {}
});
expect(events).toEqual(["received", "completed"]);
});
});