forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdouble-start-error.test.ts
More file actions
44 lines (38 loc) · 1.3 KB
/
Copy pathdouble-start-error.test.ts
File metadata and controls
44 lines (38 loc) · 1.3 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
import { describe, it, expect } from "vitest";
import { AgentRuntime } from "../../src/runtime/agent-runtime.js";
import { RuntimeError } from "../../src/errors/runtime-errors.js";
describe("AgentRuntime double-start rejection", () => {
it("throws RUNTIME_ALREADY_STARTED on second start call", async () => {
const runtime = new AgentRuntime({ runtimeId: "double-start-test" });
await runtime.start();
try {
await runtime.start();
expect.fail("should have thrown");
} catch (e) {
const err = e as RuntimeError;
expect(err.code).toBe("RUNTIME_ALREADY_STARTED");
expect(err.message).toContain("already been started");
}
});
it("does not emit runtime.started event twice", async () => {
const { RuntimeEventBus } =
await import("../../src/events/runtime-events.js");
const eventBus = new RuntimeEventBus();
const startedEvents: string[] = [];
eventBus.on("runtime.started", (e) =>
startedEvents.push(e.payload.runtimeId)
);
const runtime = new AgentRuntime({
runtimeId: "double-start-events",
eventBus
});
await runtime.start();
try {
await runtime.start();
} catch {
// expected
}
expect(startedEvents).toHaveLength(1);
expect(startedEvents[0]).toBe("double-start-events");
});
});