Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/compress/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function finalizeSession(
entries: NotificationEntry[],
batchTopic: string | undefined,
): Promise<void> {
ctx.state.manualMode = ctx.state.manualMode ? "active" : false
ctx.state.manualMode = ctx.state.manualMode === "active" ? "active" : false
applyPendingCompressionDurations(ctx.state)
await saveSessionState(ctx.state, ctx.logger)

Expand Down
96 changes: 96 additions & 0 deletions tests/finalize-session.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import assert from "node:assert/strict"
import test from "node:test"
import { finalizeSession } from "../lib/compress/pipeline"
import type { PluginConfig } from "../lib/config"
import { Logger } from "../lib/logger"
import {
createSessionState,
loadManualModeSetting,
type WithParts,
} from "../lib/state"

function buildConfig(): PluginConfig {
return {
enabled: true,
debug: false,
pruneNotification: "off",
pruneNotificationType: "chat",
commands: { enabled: true, protectedTools: [] },
manualMode: { enabled: false, automaticStrategies: true },
turnProtection: { enabled: false, turns: 4 },
experimental: { allowSubAgents: false, customPrompts: false },
protectedFilePatterns: [],
compress: {
mode: "message",
permission: "allow",
showCompression: false,
maxContextLimit: 150000,
minContextLimit: 50000,
nudgeFrequency: 5,
iterationNudgeThreshold: 15,
nudgeForce: "soft",
protectedTools: ["task"],
protectTags: false,
protectUserMessages: false,
},
strategies: {
deduplication: { enabled: true, protectedTools: [] },
purgeErrors: { enabled: true, turns: 4, protectedTools: [] },
},
} as PluginConfig
}

function buildToolContext(state: ReturnType<typeof createSessionState>) {
return {
client: { session: { get: async () => ({}) } },
state,
logger: new Logger(false),
config: buildConfig(),
prompts: {
reload() {},
getRuntimePrompts() {
return {} as any
},
},
}
}

test("finalizeSession resets compress-pending to auto mode", async () => {
const sessionId = `finalize-compress-pending-${Date.now()}`
const state = createSessionState()
state.sessionId = sessionId
state.manualMode = "compress-pending"

await finalizeSession(
buildToolContext(state) as any,
{ sessionID: sessionId, metadata: () => {}, ask: async () => {} },
[] as WithParts[],
[],
undefined,
)

assert.equal(state.manualMode, false)

const persisted = await loadManualModeSetting(sessionId, new Logger(false))
assert.equal(persisted, false)
})

test("finalizeSession preserves explicit active manual mode", async () => {
const sessionId = `finalize-active-manual-${Date.now()}`
const state = createSessionState()
state.sessionId = sessionId
state.manualMode = "active"

await finalizeSession(
buildToolContext(state) as any,
{ sessionID: sessionId, metadata: () => {}, ask: async () => {} },
[] as WithParts[],
[],
undefined,
)

assert.equal(state.manualMode, "active")

const persisted = await loadManualModeSetting(sessionId, new Logger(false))
assert.equal(persisted, true)
})