Files
claude-engineering-plugin/tests/codex-agents.test.ts
Trevin Chow accbd2adcf
Some checks failed
CI / pr-title (push) Has been cancelled
CI / test (push) Has been cancelled
Release PR / release-pr (push) Has been cancelled
Release PR / publish-cli (push) Has been cancelled
refactor(todos): remove internal file-based todo system (#635)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 18:16:13 -07:00

65 lines
2.3 KiB
TypeScript

import { describe, expect, test } from "bun:test"
import { promises as fs } from "fs"
import path from "path"
import os from "os"
import {
CODEX_AGENTS_BLOCK_END,
CODEX_AGENTS_BLOCK_START,
ensureCodexAgentsFile,
} from "../src/utils/codex-agents"
async function readFile(filePath: string): Promise<string> {
return fs.readFile(filePath, "utf8")
}
describe("ensureCodexAgentsFile", () => {
test("creates AGENTS.md with managed block when missing", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "codex-agents-"))
await ensureCodexAgentsFile(tempRoot)
const agentsPath = path.join(tempRoot, "AGENTS.md")
const content = await readFile(agentsPath)
expect(content).toContain(CODEX_AGENTS_BLOCK_START)
expect(content).toContain("Tool mapping")
expect(content).toContain("TaskCreate/TaskUpdate/TaskList/TaskGet/TaskStop/TaskOutput")
expect(content).toContain("use update_plan")
expect(content).toContain(CODEX_AGENTS_BLOCK_END)
})
test("appends block without touching existing content", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "codex-agents-existing-"))
const agentsPath = path.join(tempRoot, "AGENTS.md")
await fs.writeFile(agentsPath, "# My Rules\n\nKeep this.")
await ensureCodexAgentsFile(tempRoot)
const content = await readFile(agentsPath)
expect(content).toContain("# My Rules")
expect(content).toContain("Keep this.")
expect(content).toContain(CODEX_AGENTS_BLOCK_START)
expect(content).toContain(CODEX_AGENTS_BLOCK_END)
})
test("replaces only the managed block when present", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "codex-agents-update-"))
const agentsPath = path.join(tempRoot, "AGENTS.md")
const seed = [
"Intro text",
CODEX_AGENTS_BLOCK_START,
"old content",
CODEX_AGENTS_BLOCK_END,
"Footer text",
].join("\n")
await fs.writeFile(agentsPath, seed)
await ensureCodexAgentsFile(tempRoot)
const content = await readFile(agentsPath)
expect(content).toContain("Intro text")
expect(content).toContain("Footer text")
expect(content).not.toContain("old content")
expect(content).toContain(CODEX_AGENTS_BLOCK_START)
expect(content).toContain(CODEX_AGENTS_BLOCK_END)
})
})