forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime-internal-error.test.ts
More file actions
64 lines (53 loc) · 1.72 KB
/
Copy pathruntime-internal-error.test.ts
File metadata and controls
64 lines (53 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
58
59
60
61
62
63
64
import { describe, it, expect, vi } from "vitest";
import { RuntimeEventBus } from "../runtime-events.js";
describe("RuntimeEventBus runtime.internal.error", () => {
it("emits runtime.internal.error when a listener throws", () => {
const bus = new RuntimeEventBus();
const errorSpy = vi.fn();
bus.on("runtime.started", () => {
throw new Error("listener boom");
});
bus.on("runtime.internal.error", errorSpy);
bus.emit({
name: "runtime.started",
payload: { runtimeId: "r1", occurredAt: "2026-08-25T00:00:00Z" }
});
expect(errorSpy).toHaveBeenCalledTimes(1);
expect(errorSpy.mock.calls[0]![0]!.payload.eventName).toBe(
"runtime.started"
);
expect(errorSpy.mock.calls[0]![0]!.payload.errorMessage).toBe(
"listener boom"
);
});
it("does not propagate errors from error listeners", () => {
const bus = new RuntimeEventBus();
bus.on("runtime.started", () => {
throw new Error("original");
});
bus.on("runtime.internal.error", () => {
throw new Error("error-handler boom");
});
expect(() => {
bus.emit({
name: "runtime.started",
payload: { runtimeId: "r1", occurredAt: "2026-08-25T00:00:00Z" }
});
}).not.toThrow();
});
it("stringifies non-Error throws in errorMessage", () => {
const bus = new RuntimeEventBus();
const errorSpy = vi.fn();
bus.on("runtime.started", () => {
throw "string error";
});
bus.on("runtime.internal.error", errorSpy);
bus.emit({
name: "runtime.started",
payload: { runtimeId: "r1", occurredAt: "2026-08-25T00:00:00Z" }
});
expect(errorSpy.mock.calls[0]![0]!.payload.errorMessage).toBe(
"string error"
);
});
});