forked from laurentenhoor/devclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnames.test.ts
More file actions
74 lines (64 loc) · 2.36 KB
/
names.test.ts
File metadata and controls
74 lines (64 loc) · 2.36 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
65
66
67
68
69
70
71
72
73
74
import { describe, it, expect } from "vitest";
import { nameFromSeed, slotName, NAMES } from "./names.js";
describe("NAMES pool", () => {
it("has enough names to be collision-resistant", () => {
expect(NAMES.length).toBeGreaterThan(1000);
});
});
describe("nameFromSeed", () => {
it("is deterministic — same seed always returns same name", () => {
const a = nameFromSeed("test-seed");
const b = nameFromSeed("test-seed");
expect(a).toBe(b);
});
it("returns different names for different seeds", () => {
const a = nameFromSeed("seed-a");
const b = nameFromSeed("seed-b");
// Could theoretically collide but extremely unlikely with different seeds
expect(a).not.toBe(b);
});
it("returns a name from the NAMES list", () => {
const name = nameFromSeed("any-seed");
expect(NAMES).toContain(name);
});
it("handles empty string seed", () => {
const name = nameFromSeed("");
expect(NAMES).toContain(name);
});
});
describe("slotName", () => {
it("is deterministic for the same slot coordinates", () => {
const a = slotName("myapp", "developer", "medior", 0);
const b = slotName("myapp", "developer", "medior", 0);
expect(a).toBe(b);
});
it("returns different names for different slot indices", () => {
const a = slotName("myapp", "developer", "medior", 0);
const b = slotName("myapp", "developer", "medior", 1);
expect(a).not.toBe(b);
});
it("returns different names for different roles", () => {
const a = slotName("myapp", "developer", "medior", 0);
const b = slotName("myapp", "tester", "medior", 0);
expect(a).not.toBe(b);
});
it("returns different names for different projects", () => {
const a = slotName("project-a", "developer", "medior", 0);
const b = slotName("project-b", "developer", "medior", 0);
expect(a).not.toBe(b);
});
it("produces no collisions for typical slot counts within a project", () => {
const names = new Set<string>();
const roles = ["developer", "tester", "reviewer"];
const levels = ["junior", "medior", "senior"];
for (const role of roles) {
for (const level of levels) {
for (let i = 0; i < 3; i++) {
names.add(`${role}:${level}:${slotName("myapp", role, level, i)}`);
}
}
}
// 3 roles × 3 levels × 3 slots = 27 — all should be unique
expect(names.size).toBe(27);
});
});