summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAiden Cline <[email protected]>2026-04-13 11:34:38 -0500
committerGitHub <[email protected]>2026-04-13 11:34:38 -0500
commit5bc2d2498d06e50dda17c4daca73df1648ab971b (patch)
tree24be1d67f881c17f8a5ed7ad3a99ccdeeab99b42
parentc22e34853df71b4d31825614bea61e7c9184f0ba (diff)
downloadopencode-5bc2d2498d06e50dda17c4daca73df1648ab971b.tar.gz
opencode-5bc2d2498d06e50dda17c4daca73df1648ab971b.zip
test: ensure project and global instructions are loaded (#22317)
-rw-r--r--packages/opencode/test/session/instruction.test.ts53
1 files changed, 53 insertions, 0 deletions
diff --git a/packages/opencode/test/session/instruction.test.ts b/packages/opencode/test/session/instruction.test.ts
index 4ba3b78e4..c46bbd20b 100644
--- a/packages/opencode/test/session/instruction.test.ts
+++ b/packages/opencode/test/session/instruction.test.ts
@@ -219,6 +219,59 @@ describe("Instruction.resolve", () => {
test.todo("fetches remote instructions from config URLs via HttpClient", () => {})
})
+describe("Instruction.system", () => {
+ test("loads both project and global AGENTS.md when both exist", async () => {
+ const originalConfigDir = process.env["OPENCODE_CONFIG_DIR"]
+ delete process.env["OPENCODE_CONFIG_DIR"]
+
+ await using globalTmp = await tmpdir({
+ init: async (dir) => {
+ await Bun.write(path.join(dir, "AGENTS.md"), "# Global Instructions")
+ },
+ })
+ await using projectTmp = await tmpdir({
+ init: async (dir) => {
+ await Bun.write(path.join(dir, "AGENTS.md"), "# Project Instructions")
+ },
+ })
+
+ const originalGlobalConfig = Global.Path.config
+ ;(Global.Path as { config: string }).config = globalTmp.path
+
+ try {
+ await Instance.provide({
+ directory: projectTmp.path,
+ fn: () =>
+ run(
+ Instruction.Service.use((svc) =>
+ Effect.gen(function* () {
+ const paths = yield* svc.systemPaths()
+ expect(paths.has(path.join(projectTmp.path, "AGENTS.md"))).toBe(true)
+ expect(paths.has(path.join(globalTmp.path, "AGENTS.md"))).toBe(true)
+
+ const rules = yield* svc.system()
+ expect(rules).toHaveLength(2)
+ expect(rules).toContain(
+ `Instructions from: ${path.join(projectTmp.path, "AGENTS.md")}\n# Project Instructions`,
+ )
+ expect(rules).toContain(
+ `Instructions from: ${path.join(globalTmp.path, "AGENTS.md")}\n# Global Instructions`,
+ )
+ }),
+ ),
+ ),
+ })
+ } finally {
+ ;(Global.Path as { config: string }).config = originalGlobalConfig
+ if (originalConfigDir === undefined) {
+ delete process.env["OPENCODE_CONFIG_DIR"]
+ } else {
+ process.env["OPENCODE_CONFIG_DIR"] = originalConfigDir
+ }
+ }
+ })
+})
+
describe("Instruction.systemPaths OPENCODE_CONFIG_DIR", () => {
let originalConfigDir: string | undefined