Skip to content

Commit c334f8d

Browse files
committed
refactor: extract EXPECTED_AGENTS constant and add consistency test
Signed-off-by: leocavalcante <[email protected]>
1 parent 05e77fa commit c334f8d

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

src/paths.d.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ export {
1010
parseVersion,
1111
} from "./semver.mjs"
1212

13+
/**
14+
* List of expected agent names (without .md extension).
15+
* This is the single source of truth for agent filenames.
16+
*/
17+
export declare const AGENT_NAMES: string[]
18+
1319
/** Minimum character count for valid agent files */
1420
export declare const MIN_CONTENT_LENGTH: number
1521

src/paths.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ export {
1616
parseVersion,
1717
} from "./semver.mjs"
1818

19+
/**
20+
* List of expected agent names (without .md extension).
21+
* This is the single source of truth for agent filenames.
22+
*/
23+
export const AGENT_NAMES = ["opencoder", "opencoder-planner", "opencoder-builder"]
24+
1925
/** Minimum character count for valid agent files */
2026
export const MIN_CONTENT_LENGTH = 100
2127

tests/agents.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { afterEach, beforeEach, describe, expect, it } from "bun:test"
22
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"
33
import { tmpdir } from "node:os"
44
import { join } from "node:path"
5+
import { agents } from "../src/metadata"
6+
import { AGENT_NAMES } from "../src/paths.mjs"
57

68
describe("postinstall.mjs", () => {
79
const testDir = join(tmpdir(), `opencoder-test-${Date.now()}`)
@@ -58,6 +60,32 @@ describe("agent files existence", () => {
5860
})
5961
})
6062

63+
describe("agent metadata consistency", () => {
64+
const agentsDir = join(import.meta.dir, "..", "agents")
65+
66+
it("should have AGENT_NAMES match agents export from metadata", () => {
67+
expect(AGENT_NAMES).toEqual(agents)
68+
})
69+
70+
it("should have agents export match actual files in agents/ directory", () => {
71+
const actualFiles = readdirSync(agentsDir)
72+
.filter((f) => f.endsWith(".md"))
73+
.map((f) => f.replace(/\.md$/, ""))
74+
.sort()
75+
const expectedAgents = [...agents].sort()
76+
expect(actualFiles).toEqual(expectedAgents)
77+
})
78+
79+
it("should have AGENT_NAMES match actual files in agents/ directory", () => {
80+
const actualFiles = readdirSync(agentsDir)
81+
.filter((f) => f.endsWith(".md"))
82+
.map((f) => f.replace(/\.md$/, ""))
83+
.sort()
84+
const expectedAgents = [...AGENT_NAMES].sort()
85+
expect(actualFiles).toEqual(expectedAgents)
86+
})
87+
})
88+
6189
describe("agent files YAML frontmatter", () => {
6290
const agentsDir = join(import.meta.dir, "..", "agents")
6391
const agentFiles = ["opencoder.md", "opencoder-planner.md", "opencoder-builder.md"]

0 commit comments

Comments
 (0)