forked from EveryInc/compound-engineering-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodex-agents.test.ts
More file actions
62 lines (53 loc) · 2.14 KB
/
Copy pathcodex-agents.test.ts
File metadata and controls
62 lines (53 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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(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)
})
})