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
145 lines (125 loc) · 4.65 KB
/
Copy pathcodex-agents.test.ts
File metadata and controls
145 lines (125 loc) · 4.65 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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,
removeCodexAgentsToolMapBlock,
stripCodexAgentsToolMap,
} from "../src/utils/codex-agents"
async function readFile(filePath: string): Promise<string> {
return fs.readFile(filePath, "utf8")
}
async function exists(filePath: string): Promise<boolean> {
try {
await fs.access(filePath)
return true
} catch {
return false
}
}
describe("removeCodexAgentsToolMapBlock", () => {
test("returns content unchanged when sentinels are absent", () => {
const input = "# My Rules\n\nKeep this.\n"
expect(removeCodexAgentsToolMapBlock(input)).toBe(input)
})
test("strips only the managed sentinel block", () => {
const input = [
"Intro text",
"",
CODEX_AGENTS_BLOCK_START,
"old managed content",
CODEX_AGENTS_BLOCK_END,
"",
"Footer text",
"",
].join("\n")
const result = removeCodexAgentsToolMapBlock(input)
expect(result).toContain("Intro text")
expect(result).toContain("Footer text")
expect(result).not.toContain(CODEX_AGENTS_BLOCK_START)
expect(result).not.toContain(CODEX_AGENTS_BLOCK_END)
expect(result).not.toContain("old managed content")
})
test("strips a later ordered pair after a stray earlier END", () => {
const input = [
"keep this",
CODEX_AGENTS_BLOCK_END,
"user-owned notes",
CODEX_AGENTS_BLOCK_START,
"legacy map",
CODEX_AGENTS_BLOCK_END,
"",
].join("\n")
const result = removeCodexAgentsToolMapBlock(input)
expect(result).toContain("keep this")
expect(result).toContain("user-owned notes")
expect(result).toContain(CODEX_AGENTS_BLOCK_END)
expect(result).not.toContain(CODEX_AGENTS_BLOCK_START)
expect(result).not.toContain("legacy map")
expect(result.indexOf(CODEX_AGENTS_BLOCK_END)).toBe(
input.indexOf(CODEX_AGENTS_BLOCK_END),
)
})
test("leaves inline documentation of both sentinels unchanged", () => {
const input = [
"keep this",
`The retired map used \`${CODEX_AGENTS_BLOCK_START}\` … \`${CODEX_AGENTS_BLOCK_END}\` inline.`,
"",
].join("\n")
expect(removeCodexAgentsToolMapBlock(input)).toBe(input)
})
test("leaves END-then-BEGIN without a later END unchanged", () => {
const input = [
"keep this",
CODEX_AGENTS_BLOCK_END,
"user-owned notes",
CODEX_AGENTS_BLOCK_START,
"",
].join("\n")
expect(removeCodexAgentsToolMapBlock(input)).toBe(input)
})
test("returns empty string when the file is only the managed block", () => {
const input = [CODEX_AGENTS_BLOCK_START, "only this", CODEX_AGENTS_BLOCK_END].join("\n")
expect(removeCodexAgentsToolMapBlock(input)).toBe("")
})
})
describe("stripCodexAgentsToolMap", () => {
test("no-ops when AGENTS.md is missing", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "codex-agents-missing-"))
await stripCodexAgentsToolMap(tempRoot)
expect(await exists(path.join(tempRoot, "AGENTS.md"))).toBe(false)
})
test("preserves user content and removes the managed block", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "codex-agents-strip-"))
const agentsPath = path.join(tempRoot, "AGENTS.md")
await fs.writeFile(
agentsPath,
["# My Rules", "", "Keep this.", "", CODEX_AGENTS_BLOCK_START, "legacy map", CODEX_AGENTS_BLOCK_END, ""].join("\n"),
)
await stripCodexAgentsToolMap(tempRoot)
const content = await readFile(agentsPath)
expect(content).toContain("# My Rules")
expect(content).toContain("Keep this.")
expect(content).not.toContain(CODEX_AGENTS_BLOCK_START)
expect(content).not.toContain("legacy map")
})
test("deletes AGENTS.md when it only contained the managed block", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "codex-agents-delete-"))
const agentsPath = path.join(tempRoot, "AGENTS.md")
await fs.writeFile(
agentsPath,
[CODEX_AGENTS_BLOCK_START, "legacy map", CODEX_AGENTS_BLOCK_END, ""].join("\n"),
)
await stripCodexAgentsToolMap(tempRoot)
expect(await exists(agentsPath)).toBe(false)
})
test("leaves AGENTS.md alone when the managed block is already gone", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "codex-agents-clean-"))
const agentsPath = path.join(tempRoot, "AGENTS.md")
await fs.writeFile(agentsPath, "# My Rules\n\nKeep this.\n")
await stripCodexAgentsToolMap(tempRoot)
expect(await readFile(agentsPath)).toBe("# My Rules\n\nKeep this.\n")
})
})