forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime-lifecycle-shutdown.test.ts
More file actions
72 lines (61 loc) · 2.04 KB
/
Copy pathruntime-lifecycle-shutdown.test.ts
File metadata and controls
72 lines (61 loc) · 2.04 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
import { describe, expect, it } from "vitest";
import { AgentRuntime } from "../../src/runtime/agent-runtime.js";
import { RuntimeEventBus } from "../../src/events/runtime-events.js";
describe("AgentRuntime Shutdown Lifecycle & Duration Tracking", () => {
it("emits runtime.stopped upon graceful stop()", async () => {
const eventBus = new RuntimeEventBus();
const emitted: string[] = [];
eventBus.on("runtime.started", (e) => emitted.push(e.name));
eventBus.on("runtime.stopped", (e) => emitted.push(e.name));
const runtime = new AgentRuntime({
runtimeId: "rt-shutdown",
eventBus
});
await runtime.start();
await runtime.stop();
expect(emitted).toEqual(["runtime.started", "runtime.stopped"]);
});
it("rejects executeTask with RUNTIME_NOT_STARTED after shutdown", async () => {
const runtime = new AgentRuntime({ runtimeId: "rt-test" });
runtime.registerTool({
name: "ping",
description: "Ping tool",
execute: () => ({ ok: true })
});
await runtime.start();
await runtime.stop();
await expect(
runtime.executeTask({
taskId: "task-after-stop",
agentId: "agent-1",
toolName: "ping",
input: "ping",
payload: {}
})
).rejects.toMatchObject({
code: "RUNTIME_NOT_STARTED"
});
});
it("populates startedAt, completedAt, and durationMs on TaskExecutionResult", async () => {
const runtime = new AgentRuntime({ runtimeId: "rt-metrics" });
runtime.registerTool({
name: "delay",
description: "Delayed work",
execute: async () => {
await new Promise((r) => setTimeout(r, 20));
return { done: true };
}
});
await runtime.start();
const result = await runtime.executeTask({
taskId: "task-perf",
agentId: "agent-1",
toolName: "delay",
input: "measure timing",
payload: {}
});
expect(result.startedAt).toBeDefined();
expect(result.completedAt).toBeDefined();
expect(result.durationMs).toBeGreaterThanOrEqual(15);
});
});