diff --git a/src/hooks/anthropic-context-window-limit-recovery/executor.test.ts b/src/hooks/anthropic-context-window-limit-recovery/executor.test.ts
index c5983e872..4c1ef6330 100644
--- a/src/hooks/anthropic-context-window-limit-recovery/executor.test.ts
+++ b/src/hooks/anthropic-context-window-limit-recovery/executor.test.ts
@@ -1,5 +1,6 @@
///
import { afterEach, beforeEach, describe, expect, mock, spyOn, test } from "bun:test"
+import { OhMyOpenCodeConfigSchema } from "../../config"
import { executeCompact } from "./executor"
import type { AutoCompactState } from "./types"
import * as recoveryStrategy from "./recovery-strategy"
@@ -80,6 +81,7 @@ describe("executeCompact lock management", () => {
let autoCompactState: AutoCompactState
let mockClient: any
let fakeTimeouts: FakeTimeouts
+ let pluginConfig: ReturnType
const sessionID = "test-session-123"
const directory = "/test/dir"
const msg = { providerID: "anthropic", modelID: "claude-opus-4-6" }
@@ -87,7 +89,7 @@ describe("executeCompact lock management", () => {
beforeEach(() => {
// given: Fresh state for each test
autoCompactState = {
- pendingCompact: new Set(),
+ pendingCompact: new Set([sessionID]),
errorDataBySession: new Map(),
retryStateBySession: new Map(),
retryTimerBySession: new Map(),
@@ -108,6 +110,7 @@ describe("executeCompact lock management", () => {
},
}
+ pluginConfig = OhMyOpenCodeConfigSchema.parse({})
fakeTimeouts = createFakeTimeouts()
})
@@ -124,7 +127,14 @@ describe("executeCompact lock management", () => {
})
// when: Execute compaction successfully
- await executeCompact(sessionID, msg, autoCompactState, mockClient, directory)
+ await executeCompact(sessionID, msg, autoCompactState, mockClient, directory, pluginConfig)
+
+ expect(mockClient.session.summarize).toHaveBeenCalledWith(
+ expect.objectContaining({
+ path: { id: sessionID },
+ body: { providerID: "anthropic", modelID: "claude-opus-4-6", auto: true },
+ }),
+ )
// then: Lock should be cleared
expect(autoCompactState.compactionInProgress.has(sessionID)).toBe(false)
@@ -142,7 +152,14 @@ describe("executeCompact lock management", () => {
})
// when: Execute compaction
- await executeCompact(sessionID, msg, autoCompactState, mockClient, directory)
+ await executeCompact(sessionID, msg, autoCompactState, mockClient, directory, pluginConfig)
+
+ expect(mockClient.session.summarize).toHaveBeenCalledWith(
+ expect.objectContaining({
+ path: { id: sessionID },
+ body: { providerID: "anthropic", modelID: "claude-opus-4-6", auto: true },
+ }),
+ )
// then: Lock should still be cleared despite exception
expect(autoCompactState.compactionInProgress.has(sessionID)).toBe(false)
@@ -153,7 +170,7 @@ describe("executeCompact lock management", () => {
autoCompactState.compactionInProgress.add(sessionID)
// when: Try to execute compaction
- await executeCompact(sessionID, msg, autoCompactState, mockClient, directory)
+ await executeCompact(sessionID, msg, autoCompactState, mockClient, directory, pluginConfig)
// then: Toast should be shown with warning message
expect(mockClient.tui.showToast).toHaveBeenCalledWith(
@@ -181,7 +198,7 @@ describe("executeCompact lock management", () => {
})
//#when - Execute compaction (fixEmptyMessages will be called)
- await executeCompact(sessionID, msg, autoCompactState, mockClient, directory)
+ await executeCompact(sessionID, msg, autoCompactState, mockClient, directory, pluginConfig)
//#then - Lock should be cleared
expect(autoCompactState.compactionInProgress.has(sessionID)).toBe(false)
@@ -209,6 +226,7 @@ describe("executeCompact lock management", () => {
autoCompactState,
mockClient,
directory,
+ pluginConfig,
experimental,
)
@@ -222,7 +240,7 @@ describe("executeCompact lock management", () => {
autoCompactState.compactionInProgress.add(sessionID)
// when: Try to execute compaction while lock is held
- await executeCompact(sessionID, msg, autoCompactState, mockClient, directory)
+ await executeCompact(sessionID, msg, autoCompactState, mockClient, directory, pluginConfig)
// then: Toast should be shown
const toastCalls = (mockClient.tui.showToast as any).mock.calls
@@ -243,6 +261,7 @@ describe("executeCompact lock management", () => {
autoCompactState.retryStateBySession.set(sessionID, {
attempt: 5,
lastAttemptTime: Date.now(),
+ firstAttemptTime: Date.now(),
})
autoCompactState.truncateStateBySession.set(sessionID, {
truncateAttempt: 5,
@@ -254,7 +273,7 @@ describe("executeCompact lock management", () => {
})
// when: Execute compaction
- await executeCompact(sessionID, msg, autoCompactState, mockClient, directory)
+ await executeCompact(sessionID, msg, autoCompactState, mockClient, directory, pluginConfig)
// then: Should show failure toast
const toastCalls = (mockClient.tui.showToast as any).mock.calls
@@ -279,7 +298,7 @@ describe("executeCompact lock management", () => {
})
// when: Execute compaction
- await executeCompact(sessionID, msg, autoCompactState, mockClient, directory)
+ await executeCompact(sessionID, msg, autoCompactState, mockClient, directory, pluginConfig)
// then: Lock should be cleared even if toast fails
expect(autoCompactState.compactionInProgress.has(sessionID)).toBe(false)
@@ -297,7 +316,7 @@ describe("executeCompact lock management", () => {
})
// when: Execute compaction
- await executeCompact(sessionID, msg, autoCompactState, mockClient, directory)
+ await executeCompact(sessionID, msg, autoCompactState, mockClient, directory, pluginConfig)
// Wait for setTimeout callback
await fakeTimeouts.advanceBy(600)
@@ -324,7 +343,7 @@ describe("executeCompact lock management", () => {
}))
// when: Execute compaction
- await executeCompact(sessionID, msg, autoCompactState, mockClient, directory)
+ await executeCompact(sessionID, msg, autoCompactState, mockClient, directory, pluginConfig)
// then: Truncation was attempted
expect(truncateSpy).toHaveBeenCalled()
@@ -372,7 +391,7 @@ describe("executeCompact lock management", () => {
})
// when: Execute compaction
- await executeCompact(sessionID, msg, autoCompactState, mockClient, directory)
+ await executeCompact(sessionID, msg, autoCompactState, mockClient, directory, pluginConfig)
// Wait for setTimeout callback
await fakeTimeouts.advanceBy(600)