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:
39
src/cli/config-manager/bun-install.test.ts
Normal file
39
src/cli/config-manager/bun-install.test.ts
Normal file
@@ -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",
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -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`,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user