forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent-emission-order.test.ts
More file actions
87 lines (72 loc) · 2.47 KB
/
Copy pathevent-emission-order.test.ts
File metadata and controls
87 lines (72 loc) · 2.47 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
import { describe, expect, it } from "vitest";
import { AgentRuntime, RuntimeEventBus } from "../src/index.js";
describe("Event emission order (Issue #128)", () => {
it("emits runtime.task.received before runtime.task.completed on success", async () => {
const eventBus = new RuntimeEventBus();
const events: string[] = [];
eventBus.on("runtime.task.received", (e) => events.push(e.name));
eventBus.on("runtime.task.completed", (e) => events.push(e.name));
eventBus.on("runtime.task.failed", (e) => events.push(e.name));
const runtime = new AgentRuntime({
runtimeId: "order-success",
eventBus
});
runtime.registerTool({
name: "ok",
description: "Always succeeds",
execute() {
return { ok: true };
}
});
await runtime.start();
await runtime.executeTask({
taskId: "t-ok",
agentId: "a1",
toolName: "ok",
input: "go",
payload: {}
});
const receivedIdx = events.indexOf("runtime.task.received");
const completedIdx = events.indexOf("runtime.task.completed");
const failedIdx = events.indexOf("runtime.task.failed");
expect(receivedIdx).toBeGreaterThanOrEqual(0);
expect(completedIdx).toBeGreaterThan(receivedIdx);
expect(failedIdx).toBe(-1);
});
it("emits runtime.task.received before runtime.task.failed on error", async () => {
const eventBus = new RuntimeEventBus();
const events: string[] = [];
eventBus.on("runtime.task.received", (e) => events.push(e.name));
eventBus.on("runtime.task.completed", (e) => events.push(e.name));
eventBus.on("runtime.task.failed", (e) => events.push(e.name));
const runtime = new AgentRuntime({
runtimeId: "order-fail",
eventBus
});
runtime.registerTool({
name: "boom",
description: "Always throws",
execute() {
throw new Error("intentional failure for ordering test");
}
});
await runtime.start();
try {
await runtime.executeTask({
taskId: "t-fail",
agentId: "a2",
toolName: "boom",
input: "fail",
payload: {}
});
} catch {
// expected
}
const receivedIdx = events.indexOf("runtime.task.received");
const failedIdx = events.indexOf("runtime.task.failed");
const completedIdx = events.indexOf("runtime.task.completed");
expect(receivedIdx).toBeGreaterThanOrEqual(0);
expect(failedIdx).toBeGreaterThan(receivedIdx);
expect(completedIdx).toBe(-1);
});
});