Skip to content

Commit 8c9e80e

Browse files
rekram1-nodemrsimpson
authored andcommitted
test: ensure project and global instructions are loaded (anomalyco#22317)
1 parent 4127992 commit 8c9e80e

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

packages/opencode/test/session/instruction.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,59 @@ describe("Instruction.resolve", () => {
219219
test.todo("fetches remote instructions from config URLs via HttpClient", () => {})
220220
})
221221

222+
describe("Instruction.system", () => {
223+
test("loads both project and global AGENTS.md when both exist", async () => {
224+
const originalConfigDir = process.env["OPENCODE_CONFIG_DIR"]
225+
delete process.env["OPENCODE_CONFIG_DIR"]
226+
227+
await using globalTmp = await tmpdir({
228+
init: async (dir) => {
229+
await Bun.write(path.join(dir, "AGENTS.md"), "# Global Instructions")
230+
},
231+
})
232+
await using projectTmp = await tmpdir({
233+
init: async (dir) => {
234+
await Bun.write(path.join(dir, "AGENTS.md"), "# Project Instructions")
235+
},
236+
})
237+
238+
const originalGlobalConfig = Global.Path.config
239+
;(Global.Path as { config: string }).config = globalTmp.path
240+
241+
try {
242+
await Instance.provide({
243+
directory: projectTmp.path,
244+
fn: () =>
245+
run(
246+
Instruction.Service.use((svc) =>
247+
Effect.gen(function* () {
248+
const paths = yield* svc.systemPaths()
249+
expect(paths.has(path.join(projectTmp.path, "AGENTS.md"))).toBe(true)
250+
expect(paths.has(path.join(globalTmp.path, "AGENTS.md"))).toBe(true)
251+
252+
const rules = yield* svc.system()
253+
expect(rules).toHaveLength(2)
254+
expect(rules).toContain(
255+
`Instructions from: ${path.join(projectTmp.path, "AGENTS.md")}\n# Project Instructions`,
256+
)
257+
expect(rules).toContain(
258+
`Instructions from: ${path.join(globalTmp.path, "AGENTS.md")}\n# Global Instructions`,
259+
)
260+
}),
261+
),
262+
),
263+
})
264+
} finally {
265+
;(Global.Path as { config: string }).config = originalGlobalConfig
266+
if (originalConfigDir === undefined) {
267+
delete process.env["OPENCODE_CONFIG_DIR"]
268+
} else {
269+
process.env["OPENCODE_CONFIG_DIR"] = originalConfigDir
270+
}
271+
}
272+
})
273+
})
274+
222275
describe("Instruction.systemPaths OPENCODE_CONFIG_DIR", () => {
223276
let originalConfigDir: string | undefined
224277

0 commit comments

Comments
 (0)