forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask-timeout.test.ts
More file actions
49 lines (43 loc) · 1.35 KB
/
Copy pathtask-timeout.test.ts
File metadata and controls
49 lines (43 loc) · 1.35 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
import { describe, expect, it } from "vitest";
import { AgentRuntime, RuntimeEventBus } from "../../src/index.js";
describe("AgentRuntime task timeout", () => {
it("fails a hung task, clears in-flight state, and emits runtime.task.failed", async () => {
const eventBus = new RuntimeEventBus();
const failures: Array<{ taskId: string; reason: string }> = [];
eventBus.on("runtime.task.failed", (event) => {
failures.push({
taskId: event.payload.taskId,
reason: event.payload.reason
});
});
const runtime = new AgentRuntime({
runtimeId: "runtime-task-timeout",
eventBus,
maxTaskDurationMs: 10
});
runtime.registerTool({
name: "hang",
description: "Never resolves.",
execute() {
return new Promise<never>(() => {});
}
});
await runtime.start();
await expect(
runtime.executeTask({
taskId: "task-timeout",
agentId: "agent-timeout",
toolName: "hang",
input: "Wait forever",
payload: {}
})
).rejects.toMatchObject({
code: "EXECUTION_FAILED",
details: { timeoutMs: 10 }
});
expect(runtime.getInFlightTaskCount()).toBe(0);
expect(failures).toHaveLength(1);
expect(failures[0]?.taskId).toBe("task-timeout");
expect(failures[0]?.reason).toContain("timed out after 10ms");
});
});