Procházet zdrojové kódy

core: add compaction config tests to verify auto and prune settings work correctly

Dax Raad před 1 měsícem
rodič
revize
2cdc88d295
1 změnil soubory, kde provedl 94 přidání a 0 odebrání
  1. 94 0
      packages/opencode/test/config/config.test.ts

+ 94 - 0
packages/opencode/test/config/config.test.ts

@@ -533,3 +533,97 @@ test("deduplicates duplicate plugins from global and local configs", async () =>
     },
   })
 })
+
+test("compaction config defaults to true when not specified", async () => {
+  await using tmp = await tmpdir({
+    init: async (dir) => {
+      await Bun.write(
+        path.join(dir, "opencode.json"),
+        JSON.stringify({
+          $schema: "https://opencode.ai/config.json",
+        }),
+      )
+    },
+  })
+  await Instance.provide({
+    directory: tmp.path,
+    fn: async () => {
+      const config = await Config.get()
+      // When not specified, compaction should be undefined (defaults handled in usage)
+      expect(config.compaction).toBeUndefined()
+    },
+  })
+})
+
+test("compaction config can disable auto compaction", async () => {
+  await using tmp = await tmpdir({
+    init: async (dir) => {
+      await Bun.write(
+        path.join(dir, "opencode.json"),
+        JSON.stringify({
+          $schema: "https://opencode.ai/config.json",
+          compaction: {
+            auto: false,
+          },
+        }),
+      )
+    },
+  })
+  await Instance.provide({
+    directory: tmp.path,
+    fn: async () => {
+      const config = await Config.get()
+      expect(config.compaction?.auto).toBe(false)
+      expect(config.compaction?.prune).toBeUndefined()
+    },
+  })
+})
+
+test("compaction config can disable prune", async () => {
+  await using tmp = await tmpdir({
+    init: async (dir) => {
+      await Bun.write(
+        path.join(dir, "opencode.json"),
+        JSON.stringify({
+          $schema: "https://opencode.ai/config.json",
+          compaction: {
+            prune: false,
+          },
+        }),
+      )
+    },
+  })
+  await Instance.provide({
+    directory: tmp.path,
+    fn: async () => {
+      const config = await Config.get()
+      expect(config.compaction?.prune).toBe(false)
+      expect(config.compaction?.auto).toBeUndefined()
+    },
+  })
+})
+
+test("compaction config can disable both auto and prune", async () => {
+  await using tmp = await tmpdir({
+    init: async (dir) => {
+      await Bun.write(
+        path.join(dir, "opencode.json"),
+        JSON.stringify({
+          $schema: "https://opencode.ai/config.json",
+          compaction: {
+            auto: false,
+            prune: false,
+          },
+        }),
+      )
+    },
+  })
+  await Instance.provide({
+    directory: tmp.path,
+    fn: async () => {
+      const config = await Config.get()
+      expect(config.compaction?.auto).toBe(false)
+      expect(config.compaction?.prune).toBe(false)
+    },
+  })
+})