Skip to content

Commit 2cdc88d

Browse files
committed
core: add compaction config tests to verify auto and prune settings work correctly
1 parent f8fb08b commit 2cdc88d

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

packages/opencode/test/config/config.test.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,97 @@ test("deduplicates duplicate plugins from global and local configs", async () =>
533533
},
534534
})
535535
})
536+
537+
test("compaction config defaults to true when not specified", async () => {
538+
await using tmp = await tmpdir({
539+
init: async (dir) => {
540+
await Bun.write(
541+
path.join(dir, "opencode.json"),
542+
JSON.stringify({
543+
$schema: "https://opencode.ai/config.json",
544+
}),
545+
)
546+
},
547+
})
548+
await Instance.provide({
549+
directory: tmp.path,
550+
fn: async () => {
551+
const config = await Config.get()
552+
// When not specified, compaction should be undefined (defaults handled in usage)
553+
expect(config.compaction).toBeUndefined()
554+
},
555+
})
556+
})
557+
558+
test("compaction config can disable auto compaction", async () => {
559+
await using tmp = await tmpdir({
560+
init: async (dir) => {
561+
await Bun.write(
562+
path.join(dir, "opencode.json"),
563+
JSON.stringify({
564+
$schema: "https://opencode.ai/config.json",
565+
compaction: {
566+
auto: false,
567+
},
568+
}),
569+
)
570+
},
571+
})
572+
await Instance.provide({
573+
directory: tmp.path,
574+
fn: async () => {
575+
const config = await Config.get()
576+
expect(config.compaction?.auto).toBe(false)
577+
expect(config.compaction?.prune).toBeUndefined()
578+
},
579+
})
580+
})
581+
582+
test("compaction config can disable prune", async () => {
583+
await using tmp = await tmpdir({
584+
init: async (dir) => {
585+
await Bun.write(
586+
path.join(dir, "opencode.json"),
587+
JSON.stringify({
588+
$schema: "https://opencode.ai/config.json",
589+
compaction: {
590+
prune: false,
591+
},
592+
}),
593+
)
594+
},
595+
})
596+
await Instance.provide({
597+
directory: tmp.path,
598+
fn: async () => {
599+
const config = await Config.get()
600+
expect(config.compaction?.prune).toBe(false)
601+
expect(config.compaction?.auto).toBeUndefined()
602+
},
603+
})
604+
})
605+
606+
test("compaction config can disable both auto and prune", async () => {
607+
await using tmp = await tmpdir({
608+
init: async (dir) => {
609+
await Bun.write(
610+
path.join(dir, "opencode.json"),
611+
JSON.stringify({
612+
$schema: "https://opencode.ai/config.json",
613+
compaction: {
614+
auto: false,
615+
prune: false,
616+
},
617+
}),
618+
)
619+
},
620+
})
621+
await Instance.provide({
622+
directory: tmp.path,
623+
fn: async () => {
624+
const config = await Config.get()
625+
expect(config.compaction?.auto).toBe(false)
626+
expect(config.compaction?.prune).toBe(false)
627+
},
628+
})
629+
})

0 commit comments

Comments
 (0)