Skip to content

Commit 65c8450

Browse files
committed
test(preemptive-compaction): add unit tests for smart compaction hook
- Add tests for compaction-logger utility (path verification) - Add comprehensive tests for preemptive-compaction hook: - Disabled state behavior - Model filtering (Claude only) - Threshold checking - Cooldown mechanism - Multi-phase flow (DCP + truncation + summarize) - Custom threshold and model limit callbacks - onBeforeSummarize callback
1 parent 3ee71e4 commit 65c8450

File tree

2 files changed

+551
-0
lines changed

2 files changed

+551
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { describe, it, expect, mock, beforeEach } from "bun:test"
2+
import { getCompactionLogPath } from "./compaction-logger"
3+
4+
// Since we can't easily mock node:fs for appendFileSync in bun:test,
5+
// we'll test the pure functions and verify the log path structure
6+
7+
describe("compaction-logger", () => {
8+
describe("getCompactionLogPath", () => {
9+
it("#then should return a path ending with compaction.log", () => {
10+
const logPath = getCompactionLogPath()
11+
expect(logPath).toContain("compaction.log")
12+
})
13+
14+
it("#then should be in opencode storage directory", () => {
15+
const logPath = getCompactionLogPath()
16+
expect(logPath).toContain("opencode")
17+
})
18+
})
19+
20+
// Note: logCompaction and clearCompactionLog are thin wrappers around fs operations
21+
// with silent error handling. Testing them requires file system access or complex
22+
// module mocking. The key behaviors are:
23+
// 1. Formats log entries correctly (covered by integration)
24+
// 2. Never throws errors (error handling is silent)
25+
// 3. Uses correct log file path (verified above)
26+
27+
// The formatting logic is verified through integration testing and manual inspection
28+
// of the log output format documented in the implementation.
29+
})

0 commit comments

Comments
 (0)