fix(auto-update-checker): use OpenCode cache paths for updates

Align version lookup, invalidation, and bun install with OpenCode's cache directory so updates target the loaded plugin location. Keep dependency declarations intact during invalidation so auto-update can reinstall instead of converging to uninstall.
This commit is contained in:
acamq
2026-03-07 15:56:21 -07:00
parent fd9642a6ab
commit dfb258ed50
6 changed files with 155 additions and 38 deletions
@@ -0,0 +1,39 @@
import { beforeEach, afterEach, describe, expect, it, mock, spyOn } from "bun:test"
import * as dataPath from "../../shared/data-path"
import * as logger from "../../shared/logger"
import * as spawnHelpers from "../../shared/spawn-with-windows-hide"
import { runBunInstallWithDetails } from "./bun-install"
describe("runBunInstallWithDetails", () => {
let getOpenCodeCacheDirSpy: ReturnType<typeof spyOn>
let logSpy: ReturnType<typeof spyOn>
let spawnWithWindowsHideSpy: ReturnType<typeof spyOn>
beforeEach(() => {
getOpenCodeCacheDirSpy = spyOn(dataPath, "getOpenCodeCacheDir").mockReturnValue("/tmp/opencode-cache")
logSpy = spyOn(logger, "log").mockImplementation(() => {})
spawnWithWindowsHideSpy = spyOn(spawnHelpers, "spawnWithWindowsHide").mockReturnValue({
exited: Promise.resolve(0),
exitCode: 0,
kill: mock(() => {}),
} as ReturnType<typeof spawnHelpers.spawnWithWindowsHide>)
})
afterEach(() => {
getOpenCodeCacheDirSpy.mockRestore()
logSpy.mockRestore()
spawnWithWindowsHideSpy.mockRestore()
})
it("runs bun install in the OpenCode cache directory", async () => {
const result = await runBunInstallWithDetails()
expect(result).toEqual({ success: true })
expect(getOpenCodeCacheDirSpy).toHaveBeenCalledTimes(1)
expect(spawnWithWindowsHideSpy).toHaveBeenCalledWith(["bun", "install"], {
cwd: "/tmp/opencode-cache",
stdout: "inherit",
stderr: "inherit",
})
})
})
+8 -5
View File
@@ -1,4 +1,5 @@
import { getConfigDir } from "./config-context"
import { getOpenCodeCacheDir } from "../../shared/data-path"
import { log } from "../../shared/logger"
import { spawnWithWindowsHide } from "../../shared/spawn-with-windows-hide"
const BUN_INSTALL_TIMEOUT_SECONDS = 60
@@ -16,9 +17,11 @@ export async function runBunInstall(): Promise<boolean> {
}
export async function runBunInstallWithDetails(): Promise<BunInstallResult> {
const cacheDir = getOpenCodeCacheDir()
try {
const proc = spawnWithWindowsHide(["bun", "install"], {
cwd: getConfigDir(),
cwd: cacheDir,
stdout: "inherit",
stderr: "inherit",
})
@@ -34,13 +37,13 @@ export async function runBunInstallWithDetails(): Promise<BunInstallResult> {
if (result === "timeout") {
try {
proc.kill()
} catch {
/* intentionally empty - process may have already exited */
} catch (err) {
log("[cli/install] Failed to kill timed out bun install process:", err)
}
return {
success: false,
timedOut: true,
error: `bun install timed out after ${BUN_INSTALL_TIMEOUT_SECONDS} seconds. Try running manually: cd ${getConfigDir()} && bun i`,
error: `bun install timed out after ${BUN_INSTALL_TIMEOUT_SECONDS} seconds. Try running manually: cd ${cacheDir} && bun i`,
}
}