|
| 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 | +}) |
0 commit comments