Skip to content

Commit 7d743af

Browse files
committed
feat: add readonly tuple type for AGENT_NAMES constant
Signed-off-by: leocavalcante <leo@cavalcante.dev>
1 parent d3ecd0c commit 7d743af

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/paths.d.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ export declare const OPENCODE_VERSION: string
3131
/**
3232
* List of expected agent names (without .md extension).
3333
* This is the single source of truth for agent filenames.
34+
* Frozen to prevent accidental mutation.
3435
*/
35-
export declare const AGENT_NAMES: string[]
36+
export declare const AGENT_NAMES: readonly ["opencoder", "opencoder-planner", "opencoder-builder"]
3637

3738
/** Minimum character count for valid agent files */
3839
export declare const MIN_CONTENT_LENGTH: number

tests/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe("index.ts exports", () => {
3939
const files = readdirSync(agentsDir)
4040
const mdFiles = files.filter((f) => f.endsWith(".md"))
4141
const agentNamesFromFiles = mdFiles.map((f) => f.replace(/\.md$/, "")).sort()
42-
const agentNamesFromExport = [...agents].sort()
42+
const agentNamesFromExport = ([...agents] as string[]).sort()
4343

4444
expect(agentNamesFromExport).toEqual(agentNamesFromFiles)
4545
})

tests/paths.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,23 +397,23 @@ describe("paths.mjs exports", () => {
397397
it("should prevent push to AGENT_NAMES", () => {
398398
const originalLength = AGENT_NAMES.length
399399
expect(() => {
400-
;(AGENT_NAMES as string[]).push("new-agent")
400+
;(AGENT_NAMES as unknown as string[]).push("new-agent")
401401
}).toThrow()
402402
expect(AGENT_NAMES.length).toBe(originalLength)
403403
})
404404

405405
it("should prevent modification of AGENT_NAMES elements", () => {
406406
const originalFirst = AGENT_NAMES[0]
407407
expect(() => {
408-
;(AGENT_NAMES as string[])[0] = "modified"
408+
;(AGENT_NAMES as unknown as string[])[0] = "modified"
409409
}).toThrow()
410410
expect(AGENT_NAMES[0]).toBe(originalFirst)
411411
})
412412

413413
it("should prevent pop from AGENT_NAMES", () => {
414414
const originalLength = AGENT_NAMES.length
415415
expect(() => {
416-
;(AGENT_NAMES as string[]).pop()
416+
;(AGENT_NAMES as unknown as string[]).pop()
417417
}).toThrow()
418418
expect(AGENT_NAMES.length).toBe(originalLength)
419419
})

0 commit comments

Comments
 (0)