forked from Lilly-Protocol/lily-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent-id-stability-reset.test.ts
More file actions
59 lines (47 loc) · 1.72 KB
/
Copy pathagent-id-stability-reset.test.ts
File metadata and controls
59 lines (47 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
import { describe, it, expect, beforeEach } from "vitest";
import request from "supertest";
import { createApp } from "../src/app";
import { agentsService } from "../src/modules/agents/agents.service";
describe("Agent id stability after service reset (issue #129)", () => {
const app = createApp();
beforeEach(() => {
agentsService.reset?.();
});
const createAgent = async (name: string) => {
const res = await request(app)
.post("/api/v1/agents")
.send({
name,
description: "Testing agent id stability after reset",
capabilities: ["test"],
});
expect(res.status).toBe(201);
return res.body.data.agent;
};
it("should produce deterministic ids after each reset cycle", async () => {
const agent1 = await createAgent("First Agent");
expect(agent1.id).toBe("agentlily_2");
const agent2 = await createAgent("Second Agent");
expect(agent2.id).toBe("agentlily_3");
agentsService.reset?.();
const agent3 = await createAgent("After Reset Agent");
expect(agent3.id).toBe("agentlily_2");
});
it("should restart id sequence from seed length + 1 after reset", async () => {
await createAgent("Cycle 1 Agent A");
await createAgent("Cycle 1 Agent B");
await createAgent("Cycle 1 Agent C");
agentsService.reset?.();
const afterReset = await createAgent("Cycle 2 First");
expect(afterReset.id).toBe("agentlily_2");
});
it("should maintain sequential ids within a single cycle", async () => {
const agents = [];
for (let i = 0; i < 5; i++) {
agents.push(await createAgent(`Sequential Agent ${i}`));
}
for (let i = 0; i < agents.length; i++) {
expect(agents[i].id).toBe(`agentlily_${i + 2}`);
}
});
});