fix: resolve #3124 #3125 #3127 session tools, cache priming, and compaction loop

- #3124: Session tools now merge SDK and file-backed sessions for SQLite backend
- #3125: Cache priming fixed for OpenCode >=1.3.14 empty workspace
- #3127: Activity-based progress detection prevents infinite compaction on Kimi/Minimax

All 29 new tests pass, 4885 total tests passing.
This commit is contained in:
YeonGyu-Kim
2026-04-05 09:30:19 +09:00
parent aeb9c97c30
commit 130f4ac080
22 changed files with 538 additions and 114 deletions
@@ -3,15 +3,16 @@ import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test"
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
import { join } from "node:path"
import { createBackgroundUpdateCheckRunner } from "../auto-update-checker/hook/background-update-check"
import type { PluginEntryInfo } from "../auto-update-checker/checker"
import type { SyncResult } from "../auto-update-checker/checker/sync-package-json"
import { PACKAGE_NAME } from "../auto-update-checker/constants"
type ToastMessageGetter = (isUpdate: boolean, version?: string) => string
let importCounter = 0
function createPluginEntry(overrides?: Partial<PluginEntryInfo>): PluginEntryInfo {
return {
entry: "oh-my-openagent@3.4.0",
entry: `${PACKAGE_NAME}@3.4.0`,
isPinned: false,
pinnedVersion: null,
configPath: "/test/opencode.json",
@@ -21,6 +22,7 @@ function createPluginEntry(overrides?: Partial<PluginEntryInfo>): PluginEntryInf
const TEST_DIR = join(import.meta.dir, "__test-workspace-resolution__")
const TEST_CACHE_DIR = join(TEST_DIR, "cache")
const TEST_CACHE_WORKSPACE_DIR = join(TEST_CACHE_DIR, "packages")
const TEST_CONFIG_DIR = join(TEST_DIR, "config")
const mockFindPluginEntry = mock((_directory: string): PluginEntryInfo | null => createPluginEntry())
@@ -38,7 +40,9 @@ const mockSyncCachePackageJsonToIntent = mock((_pluginInfo: PluginEntryInfo): Sy
const mockRunBunInstallWithDetails = mock(async (_opts?: { outputMode?: string; workspaceDir?: string }) => ({ success: true }))
const mockLog = mock(() => {})
function createRunner() {
async function createRunner() {
const { createBackgroundUpdateCheckRunner } = await import(`../auto-update-checker/hook/background-update-check?test=${importCounter++}`)
return createBackgroundUpdateCheckRunner({
existsSync,
join,
@@ -69,6 +73,7 @@ describe("workspace resolution", () => {
isUpdate ? `Update to ${version}` : "Up to date"
beforeEach(() => {
importCounter += 1
if (existsSync(TEST_DIR)) {
rmSync(TEST_DIR, { recursive: true, force: true })
}
@@ -101,12 +106,12 @@ describe("workspace resolution", () => {
it("#given config-dir install exists but cache-dir does not #when updating #then it installs to config-dir", async () => {
// #given
const runBackgroundUpdateCheck = createRunner()
mkdirSync(join(TEST_CONFIG_DIR, "node_modules", "oh-my-openagent"), { recursive: true })
writeFileSync(join(TEST_CONFIG_DIR, "package.json"), JSON.stringify({ dependencies: { "oh-my-openagent": "3.4.0" } }, null, 2))
const runBackgroundUpdateCheck = await createRunner()
mkdirSync(join(TEST_CONFIG_DIR, "node_modules", PACKAGE_NAME), { recursive: true })
writeFileSync(join(TEST_CONFIG_DIR, "package.json"), JSON.stringify({ dependencies: { [PACKAGE_NAME]: "3.4.0" } }, null, 2))
writeFileSync(
join(TEST_CONFIG_DIR, "node_modules", "oh-my-openagent", "package.json"),
JSON.stringify({ name: "oh-my-openagent", version: "3.4.0" }, null, 2),
join(TEST_CONFIG_DIR, "node_modules", PACKAGE_NAME, "package.json"),
JSON.stringify({ name: PACKAGE_NAME, version: "3.4.0" }, null, 2),
)
// #when
@@ -118,18 +123,18 @@ describe("workspace resolution", () => {
it("#given both config-dir and cache-dir installs exist #when updating #then it prefers config-dir", async () => {
// #given
const runBackgroundUpdateCheck = createRunner()
mkdirSync(join(TEST_CONFIG_DIR, "node_modules", "oh-my-openagent"), { recursive: true })
writeFileSync(join(TEST_CONFIG_DIR, "package.json"), JSON.stringify({ dependencies: { "oh-my-openagent": "3.4.0" } }, null, 2))
const runBackgroundUpdateCheck = await createRunner()
mkdirSync(join(TEST_CONFIG_DIR, "node_modules", PACKAGE_NAME), { recursive: true })
writeFileSync(join(TEST_CONFIG_DIR, "package.json"), JSON.stringify({ dependencies: { [PACKAGE_NAME]: "3.4.0" } }, null, 2))
writeFileSync(
join(TEST_CONFIG_DIR, "node_modules", "oh-my-openagent", "package.json"),
JSON.stringify({ name: "oh-my-openagent", version: "3.4.0" }, null, 2),
join(TEST_CONFIG_DIR, "node_modules", PACKAGE_NAME, "package.json"),
JSON.stringify({ name: PACKAGE_NAME, version: "3.4.0" }, null, 2),
)
mkdirSync(join(TEST_CACHE_DIR, "node_modules", "oh-my-openagent"), { recursive: true })
writeFileSync(join(TEST_CACHE_DIR, "package.json"), JSON.stringify({ dependencies: { "oh-my-openagent": "3.4.0" } }, null, 2))
mkdirSync(join(TEST_CACHE_DIR, "node_modules", PACKAGE_NAME), { recursive: true })
writeFileSync(join(TEST_CACHE_DIR, "package.json"), JSON.stringify({ dependencies: { [PACKAGE_NAME]: "3.4.0" } }, null, 2))
writeFileSync(
join(TEST_CACHE_DIR, "node_modules", "oh-my-openagent", "package.json"),
JSON.stringify({ name: "oh-my-openagent", version: "3.4.0" }, null, 2),
join(TEST_CACHE_DIR, "node_modules", PACKAGE_NAME, "package.json"),
JSON.stringify({ name: PACKAGE_NAME, version: "3.4.0" }, null, 2),
)
// #when
@@ -141,18 +146,49 @@ describe("workspace resolution", () => {
it("#given only cache-dir install exists #when updating #then it falls back to cache-dir", async () => {
// #given
const runBackgroundUpdateCheck = createRunner()
mkdirSync(join(TEST_CACHE_DIR, "node_modules", "oh-my-openagent"), { recursive: true })
writeFileSync(join(TEST_CACHE_DIR, "package.json"), JSON.stringify({ dependencies: { "oh-my-openagent": "3.4.0" } }, null, 2))
const runBackgroundUpdateCheck = await createRunner()
mkdirSync(join(TEST_CACHE_WORKSPACE_DIR, "node_modules", PACKAGE_NAME), { recursive: true })
writeFileSync(join(TEST_CACHE_WORKSPACE_DIR, "package.json"), JSON.stringify({ dependencies: { [PACKAGE_NAME]: "3.4.0" } }, null, 2))
writeFileSync(
join(TEST_CACHE_DIR, "node_modules", "oh-my-openagent", "package.json"),
JSON.stringify({ name: "oh-my-openagent", version: "3.4.0" }, null, 2),
join(TEST_CACHE_WORKSPACE_DIR, "node_modules", PACKAGE_NAME, "package.json"),
JSON.stringify({ name: PACKAGE_NAME, version: "3.4.0" }, null, 2),
)
// #when
await runBackgroundUpdateCheck(mockCtx, true, getToastMessage)
// #then
expect(mockRunBunInstallWithDetails.mock.calls[0]?.[0]?.workspaceDir).toBe(TEST_CACHE_DIR)
expect(mockRunBunInstallWithDetails.mock.calls[0]?.[0]?.workspaceDir).toBe(TEST_CACHE_WORKSPACE_DIR)
})
it("#given cache workspace package.json exists without installed module #when updating #then it installs to cache-dir", async () => {
// #given
const runner = await createRunner()
mkdirSync(TEST_CACHE_WORKSPACE_DIR, { recursive: true })
writeFileSync(join(TEST_CACHE_WORKSPACE_DIR, "package.json"), JSON.stringify({ dependencies: { [PACKAGE_NAME]: "3.4.0" } }, null, 2))
// #when
await runner(mockCtx, true, getToastMessage)
// #then
expect(mockRunBunInstallWithDetails.mock.calls[0]?.[0]?.workspaceDir).toBe(TEST_CACHE_WORKSPACE_DIR)
})
it("#given config-dir install exists #when updating #then it also primes the cache workspace", async () => {
// #given
const runBackgroundUpdateCheck = await createRunner()
mkdirSync(join(TEST_CONFIG_DIR, "node_modules", PACKAGE_NAME), { recursive: true })
writeFileSync(join(TEST_CONFIG_DIR, "package.json"), JSON.stringify({ dependencies: { [PACKAGE_NAME]: "3.4.0" } }, null, 2))
writeFileSync(
join(TEST_CONFIG_DIR, "node_modules", PACKAGE_NAME, "package.json"),
JSON.stringify({ name: PACKAGE_NAME, version: "3.4.0" }, null, 2),
)
// #when
await runBackgroundUpdateCheck(mockCtx, true, getToastMessage)
// #then
expect(mockRunBunInstallWithDetails.mock.calls[0]?.[0]?.workspaceDir).toBe(TEST_CONFIG_DIR)
expect(mockRunBunInstallWithDetails.mock.calls[1]?.[0]?.workspaceDir).toBe(TEST_CACHE_WORKSPACE_DIR)
})
})