Skip to content

Commit 84ab06d

Browse files
committed
test: add test suite for plugin exports and agent files
- Add tests for index.ts exports (name, version, description, agents) - Add tests for agent file existence - Add tests for postinstall.mjs file filtering logic - All tests use bun:test framework Signed-off-by: leocavalcante <[email protected]>
1 parent 5b0b802 commit 84ab06d

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

tests/agents.test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { afterEach, beforeEach, describe, expect, it } from "bun:test"
2+
import { existsSync, mkdirSync, readdirSync, rmSync, writeFileSync } from "node:fs"
3+
import { tmpdir } from "node:os"
4+
import { join } from "node:path"
5+
6+
describe("postinstall.mjs", () => {
7+
const testDir = join(tmpdir(), `opencoder-test-${Date.now()}`)
8+
const agentsSourceDir = join(testDir, "agents")
9+
10+
beforeEach(() => {
11+
// Create test directories
12+
mkdirSync(agentsSourceDir, { recursive: true })
13+
// Create mock agent files
14+
writeFileSync(join(agentsSourceDir, "test-agent.md"), "# Test Agent")
15+
writeFileSync(join(agentsSourceDir, "another-agent.md"), "# Another Agent")
16+
})
17+
18+
afterEach(() => {
19+
// Clean up test directories
20+
if (existsSync(testDir)) {
21+
rmSync(testDir, { recursive: true, force: true })
22+
}
23+
})
24+
25+
it("should identify .md files in source directory", () => {
26+
const files = readdirSync(agentsSourceDir).filter((f) => f.endsWith(".md"))
27+
expect(files).toContain("test-agent.md")
28+
expect(files).toContain("another-agent.md")
29+
expect(files).toHaveLength(2)
30+
})
31+
32+
it("should not include non-.md files", () => {
33+
writeFileSync(join(agentsSourceDir, "readme.txt"), "Not an agent")
34+
const files = readdirSync(agentsSourceDir).filter((f) => f.endsWith(".md"))
35+
expect(files).not.toContain("readme.txt")
36+
expect(files).toHaveLength(2)
37+
})
38+
})
39+
40+
describe("agent files existence", () => {
41+
const agentsDir = join(import.meta.dir, "..", "agents")
42+
43+
it("should have opencoder.md agent file", () => {
44+
expect(existsSync(join(agentsDir, "opencoder.md"))).toBe(true)
45+
})
46+
47+
it("should have opencoder-planner.md agent file", () => {
48+
expect(existsSync(join(agentsDir, "opencoder-planner.md"))).toBe(true)
49+
})
50+
51+
it("should have opencoder-builder.md agent file", () => {
52+
expect(existsSync(join(agentsDir, "opencoder-builder.md"))).toBe(true)
53+
})
54+
55+
it("should have exactly 3 agent files", () => {
56+
const files = readdirSync(agentsDir).filter((f) => f.endsWith(".md"))
57+
expect(files).toHaveLength(3)
58+
})
59+
})

tests/index.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { describe, expect, it } from "bun:test"
2+
import pkg from "../package.json"
3+
import { agents, description, name, version } from "../src/index.ts"
4+
5+
describe("index.ts exports", () => {
6+
it("should export the plugin name from package.json", () => {
7+
expect(name).toBe("opencode-plugin-opencoder")
8+
expect(name).toBe(pkg.name)
9+
})
10+
11+
it("should export the version from package.json", () => {
12+
expect(version).toMatch(/^\d+\.\d+\.\d+/)
13+
expect(version).toBe(pkg.version)
14+
})
15+
16+
it("should export a description from package.json", () => {
17+
expect(description).toContain("autonomous")
18+
expect(description).toBe(pkg.description)
19+
})
20+
21+
it("should export the list of agents", () => {
22+
expect(agents).toEqual(["opencoder", "opencoder-planner", "opencoder-builder"])
23+
})
24+
25+
it("should have 3 agents", () => {
26+
expect(agents).toHaveLength(3)
27+
})
28+
})

0 commit comments

Comments
 (0)