forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent-instance-manager.test.ts
More file actions
54 lines (48 loc) · 1.95 KB
/
Copy pathagent-instance-manager.test.ts
File metadata and controls
54 lines (48 loc) · 1.95 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
import { describe, it, expect } from "vitest";
import { AgentInstanceManager } from "../../src/agents/agent-instance-manager.js";
describe("AgentInstanceManager getOrCreate identity semantics (Issue #113)", () => {
it("returns the same instance reference for identical agentId", () => {
const manager = new AgentInstanceManager();
const first = manager.getOrCreate("agent-1");
const second = manager.getOrCreate("agent-1");
expect(first).toBe(second);
});
it("preserves original createdAt on subsequent calls", () => {
const manager = new AgentInstanceManager();
const first = manager.getOrCreate("agent-persist");
const second = manager.getOrCreate("agent-persist");
expect(second.createdAt).toBe(first.createdAt);
});
it("creates distinct instances for different agentIds", () => {
const manager = new AgentInstanceManager();
const a = manager.getOrCreate("alpha");
const b = manager.getOrCreate("beta");
expect(a).not.toBe(b);
expect(a.agentId).toBe("alpha");
expect(b.agentId).toBe("beta");
});
it("populates agentId and ISO createdAt on creation", () => {
const manager = new AgentInstanceManager();
const instance = manager.getOrCreate("new-agent");
expect(instance.agentId).toBe("new-agent");
expect(instance.createdAt).toMatch(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
);
});
it("lists all created instances without duplicates", () => {
const manager = new AgentInstanceManager();
manager.getOrCreate("x");
manager.getOrCreate("y");
manager.getOrCreate("x"); // duplicate call
const list = manager.list();
expect(list).toHaveLength(2);
const ids = list.map((i) => i.agentId).sort();
expect(ids).toEqual(["x", "y"]);
});
it("rejects empty agentId with INVALID_TASK error", () => {
const manager = new AgentInstanceManager();
expect(() => manager.getOrCreate("")).toThrow(
/agentId must be a non-empty string/
);
});
});