Skip to content

Commit 2a39073

Browse files
committed
feat: freeze AGENT_NAMES array and add immutability tests
Signed-off-by: leocavalcante <leo@cavalcante.dev>
1 parent 016ad01 commit 2a39073

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/paths.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ export {
1919
/**
2020
* List of expected agent names (without .md extension).
2121
* This is the single source of truth for agent filenames.
22+
* Frozen to prevent accidental mutation.
2223
*/
23-
export const AGENT_NAMES = ["opencoder", "opencoder-planner", "opencoder-builder"]
24+
export const AGENT_NAMES = Object.freeze(["opencoder", "opencoder-planner", "opencoder-builder"])
2425

2526
/** Minimum character count for valid agent files */
2627
export const MIN_CONTENT_LENGTH = 100

tests/paths.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, expect, it } from "bun:test"
22
import { homedir } from "node:os"
33
import { join } from "node:path"
44
import {
5+
AGENT_NAMES,
56
AGENTS_TARGET_DIR,
67
checkVersionCompatibility,
78
createLogger,
@@ -381,6 +382,41 @@ describe("paths.mjs exports", () => {
381382
})
382383

383384
describe("constants", () => {
385+
it("should export AGENT_NAMES as an array", () => {
386+
expect(Array.isArray(AGENT_NAMES)).toBe(true)
387+
expect(AGENT_NAMES).toContain("opencoder")
388+
expect(AGENT_NAMES).toContain("opencoder-planner")
389+
expect(AGENT_NAMES).toContain("opencoder-builder")
390+
})
391+
392+
it("should have AGENT_NAMES frozen (immutable)", () => {
393+
expect(Object.isFrozen(AGENT_NAMES)).toBe(true)
394+
})
395+
396+
it("should prevent push to AGENT_NAMES", () => {
397+
const originalLength = AGENT_NAMES.length
398+
expect(() => {
399+
;(AGENT_NAMES as string[]).push("new-agent")
400+
}).toThrow()
401+
expect(AGENT_NAMES.length).toBe(originalLength)
402+
})
403+
404+
it("should prevent modification of AGENT_NAMES elements", () => {
405+
const originalFirst = AGENT_NAMES[0]
406+
expect(() => {
407+
;(AGENT_NAMES as string[])[0] = "modified"
408+
}).toThrow()
409+
expect(AGENT_NAMES[0]).toBe(originalFirst)
410+
})
411+
412+
it("should prevent pop from AGENT_NAMES", () => {
413+
const originalLength = AGENT_NAMES.length
414+
expect(() => {
415+
;(AGENT_NAMES as string[]).pop()
416+
}).toThrow()
417+
expect(AGENT_NAMES.length).toBe(originalLength)
418+
})
419+
384420
it("should export MIN_CONTENT_LENGTH as a number", () => {
385421
expect(typeof MIN_CONTENT_LENGTH).toBe("number")
386422
expect(MIN_CONTENT_LENGTH).toBe(100)

0 commit comments

Comments
 (0)