forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent-runtime-stop.test.ts
More file actions
57 lines (49 loc) · 1.72 KB
/
Copy pathagent-runtime-stop.test.ts
File metadata and controls
57 lines (49 loc) · 1.72 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
import { describe, it, expect, vi, beforeEach } from "vitest";
import { AgentRuntime } from "../../src/runtime/agent-runtime.js";
import type { RuntimeOptions } from "../../src/runtime/types.js";
describe("AgentRuntime.stop", () => {
let runtime: AgentRuntime;
let emitSpy: ReturnType<typeof vi.fn>;
beforeEach(() => {
const options: RuntimeOptions = {
runtimeId: "test-runtime-stop",
logger: {
level: "error",
info: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
debug: vi.fn()
}
};
runtime = new AgentRuntime(options);
emitSpy = vi.fn();
// Replace eventBus.emit with spy to capture events
(runtime as any).dependencies.eventBus.emit = emitSpy;
});
it("emits runtime.stopped event when stop is called after start", async () => {
await runtime.start();
await runtime.stop();
const stoppedEvent = emitSpy.mock.calls.find(
(call) => call[0].name === "runtime.stopped"
);
expect(stoppedEvent).toBeDefined();
expect(stoppedEvent![0].payload.runtimeId).toBe("test-runtime-stop");
expect(stoppedEvent![0].payload.occurredAt).toBeDefined();
});
it("does not emit runtime.stopped if runtime was never started", async () => {
await runtime.stop();
const stoppedEvent = emitSpy.mock.calls.find(
(call) => call[0].name === "runtime.stopped"
);
expect(stoppedEvent).toBeUndefined();
});
it("does not emit runtime.stopped twice on consecutive stop calls", async () => {
await runtime.start();
await runtime.stop();
await runtime.stop();
const stoppedEvents = emitSpy.mock.calls.filter(
(call) => call[0].name === "runtime.stopped"
);
expect(stoppedEvents.length).toBe(1);
});
});