2026-02-06 17:49:26 +09:00
|
|
|
import { describe, expect, test } from "bun:test"
|
|
|
|
|
import { readFileSync } from "node:fs"
|
|
|
|
|
|
|
|
|
|
describe("experimental.session.compacting", () => {
|
|
|
|
|
test("does not hardcode a model and uses output.context", () => {
|
|
|
|
|
//#given
|
2026-05-16 15:43:15 +09:00
|
|
|
const moduleUrl = new URL("./testing/create-plugin-module.ts", import.meta.url)
|
2026-05-11 12:54:32 +09:00
|
|
|
const compactionUrl = new URL("./plugin/session-compacting.ts", import.meta.url)
|
2026-05-16 15:43:15 +09:00
|
|
|
const content = readFileSync(moduleUrl, "utf-8")
|
2026-05-11 12:54:32 +09:00
|
|
|
const compactionContent = readFileSync(compactionUrl, "utf-8")
|
2026-02-06 17:49:26 +09:00
|
|
|
|
|
|
|
|
//#when
|
2026-05-11 12:54:32 +09:00
|
|
|
const hookIndex = content.indexOf("createSessionCompactingHandler")
|
2026-02-06 17:49:26 +09:00
|
|
|
|
|
|
|
|
//#then
|
|
|
|
|
expect(hookIndex).toBeGreaterThanOrEqual(0)
|
2026-05-11 12:54:32 +09:00
|
|
|
expect(`${content}\n${compactionContent}`.includes('modelID: "claude-opus-4-7"')).toBe(false)
|
|
|
|
|
expect(compactionContent.includes("output.context.push")).toBe(true)
|
|
|
|
|
expect(compactionContent.includes("providerID:")).toBe(false)
|
|
|
|
|
expect(compactionContent.includes("modelID:")).toBe(false)
|
2026-02-06 17:49:26 +09:00
|
|
|
})
|
2026-05-10 13:02:00 +09:00
|
|
|
|
|
|
|
|
test("registers autocontinue restores before OpenCode synthetic continue", () => {
|
|
|
|
|
//#given
|
2026-05-16 15:43:15 +09:00
|
|
|
const moduleUrl = new URL("./testing/create-plugin-module.ts", import.meta.url)
|
2026-05-11 12:54:32 +09:00
|
|
|
const compactionUrl = new URL("./plugin/session-compacting.ts", import.meta.url)
|
2026-05-16 15:43:15 +09:00
|
|
|
const content = readFileSync(moduleUrl, "utf-8")
|
2026-05-11 12:54:32 +09:00
|
|
|
const compactionContent = readFileSync(compactionUrl, "utf-8")
|
2026-05-10 13:02:00 +09:00
|
|
|
|
|
|
|
|
//#when
|
2026-05-11 12:54:32 +09:00
|
|
|
const hookIndex = content.indexOf("createCompactionAutocontinueHandler")
|
2026-05-10 13:02:00 +09:00
|
|
|
|
|
|
|
|
//#then
|
|
|
|
|
expect(hookIndex).toBeGreaterThanOrEqual(0)
|
2026-05-11 12:54:32 +09:00
|
|
|
expect(compactionContent.includes("compactionContextInjector?.restore")).toBe(true)
|
|
|
|
|
expect(compactionContent.includes("compactionTodoPreserver?.restore")).toBe(true)
|
2026-05-10 13:02:00 +09:00
|
|
|
})
|
2026-02-06 17:49:26 +09:00
|
|
|
})
|