fix(auto-update-checker): suppress background bun install output

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-03-08 02:16:03 +09:00
parent c74d653fdf
commit 1973ef1cdf
2 changed files with 49 additions and 34 deletions
@@ -24,8 +24,14 @@ const mockFindPluginEntry = mock((_directory: string): PluginEntry | null => cre
const mockGetCachedVersion = mock((): string | null => "3.4.0") const mockGetCachedVersion = mock((): string | null => "3.4.0")
const mockGetLatestVersion = mock(async (): Promise<string | null> => "3.5.0") const mockGetLatestVersion = mock(async (): Promise<string | null> => "3.5.0")
const mockExtractChannel = mock(() => "latest") const mockExtractChannel = mock(() => "latest")
const mockInvalidatePackage = mock(() => {}) const operationOrder: string[] = []
const mockRunBunInstall = mock(async () => true) const mockSyncCachePackageJsonToIntent = mock((_pluginEntry: PluginEntry) => {
operationOrder.push("sync")
})
const mockInvalidatePackage = mock((_packageName: string) => {
operationOrder.push("invalidate")
})
const mockRunBunInstallWithDetails = mock(async () => ({ success: true }))
const mockShowUpdateAvailableToast = mock( const mockShowUpdateAvailableToast = mock(
async (_ctx: PluginInput, _latestVersion: string, _getToastMessage: ToastMessageGetter): Promise<void> => {} async (_ctx: PluginInput, _latestVersion: string, _getToastMessage: ToastMessageGetter): Promise<void> => {}
) )
@@ -38,10 +44,11 @@ mock.module("../checker", () => ({
getCachedVersion: mockGetCachedVersion, getCachedVersion: mockGetCachedVersion,
getLatestVersion: mockGetLatestVersion, getLatestVersion: mockGetLatestVersion,
revertPinnedVersion: mock(() => false), revertPinnedVersion: mock(() => false),
syncCachePackageJsonToIntent: mockSyncCachePackageJsonToIntent,
})) }))
mock.module("../version-channel", () => ({ extractChannel: mockExtractChannel })) mock.module("../version-channel", () => ({ extractChannel: mockExtractChannel }))
mock.module("../cache", () => ({ invalidatePackage: mockInvalidatePackage })) mock.module("../cache", () => ({ invalidatePackage: mockInvalidatePackage }))
mock.module("../../../cli/config-manager", () => ({ runBunInstall: mockRunBunInstall })) mock.module("../../../cli/config-manager", () => ({ runBunInstallWithDetails: mockRunBunInstallWithDetails }))
mock.module("./update-toasts", () => ({ mock.module("./update-toasts", () => ({
showUpdateAvailableToast: mockShowUpdateAvailableToast, showUpdateAvailableToast: mockShowUpdateAvailableToast,
showAutoUpdatedToast: mockShowAutoUpdatedToast, showAutoUpdatedToast: mockShowAutoUpdatedToast,
@@ -51,36 +58,44 @@ mock.module("../../../shared/logger", () => ({ log: () => {} }))
const modulePath = "./background-update-check?test" const modulePath = "./background-update-check?test"
const { runBackgroundUpdateCheck } = await import(modulePath) const { runBackgroundUpdateCheck } = await import(modulePath)
async function runCheck(autoUpdate = true): Promise<void> { const mockContext = { directory: "/test" } as PluginInput
const mockContext = { directory: "/test" } as PluginInput const getToastMessage: ToastMessageGetter = (isUpdate, version) =>
const getToastMessage: ToastMessageGetter = (isUpdate, version) => isUpdate ? `Update to ${version}` : "Up to date"
isUpdate ? `Update to ${version}` : "Up to date"
async function runCheck(autoUpdate = true): Promise<void> {
await runBackgroundUpdateCheck(mockContext, autoUpdate, getToastMessage) await runBackgroundUpdateCheck(mockContext, autoUpdate, getToastMessage)
} }
function expectNoUpdateEffects(): void { function expectNoUpdateEffects(): void {
expect(mockShowUpdateAvailableToast).not.toHaveBeenCalled() expect(mockShowUpdateAvailableToast).not.toHaveBeenCalled()
expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled() expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled()
expect(mockRunBunInstall).not.toHaveBeenCalled() expect(mockRunBunInstallWithDetails).not.toHaveBeenCalled()
expect(mockSyncCachePackageJsonToIntent).not.toHaveBeenCalled()
expect(mockInvalidatePackage).not.toHaveBeenCalled()
} }
describe("runBackgroundUpdateCheck", () => { describe("runBackgroundUpdateCheck", () => {
let pluginEntry: PluginEntry
beforeEach(() => { beforeEach(() => {
mockFindPluginEntry.mockReset() mockFindPluginEntry.mockReset()
mockGetCachedVersion.mockReset() mockGetCachedVersion.mockReset()
mockGetLatestVersion.mockReset() mockGetLatestVersion.mockReset()
mockExtractChannel.mockReset() mockExtractChannel.mockReset()
mockSyncCachePackageJsonToIntent.mockReset()
mockInvalidatePackage.mockReset() mockInvalidatePackage.mockReset()
mockRunBunInstall.mockReset() mockRunBunInstallWithDetails.mockReset()
mockShowUpdateAvailableToast.mockReset() mockShowUpdateAvailableToast.mockReset()
mockShowAutoUpdatedToast.mockReset() mockShowAutoUpdatedToast.mockReset()
mockFindPluginEntry.mockReturnValue(createPluginEntry()) operationOrder.length = 0
pluginEntry = createPluginEntry()
mockFindPluginEntry.mockReturnValue(pluginEntry)
mockGetCachedVersion.mockReturnValue("3.4.0") mockGetCachedVersion.mockReturnValue("3.4.0")
mockGetLatestVersion.mockResolvedValue("3.5.0") mockGetLatestVersion.mockResolvedValue("3.5.0")
mockExtractChannel.mockReturnValue("latest") mockExtractChannel.mockReturnValue("latest")
mockRunBunInstall.mockResolvedValue(true) mockRunBunInstallWithDetails.mockResolvedValue({ success: true })
}) })
describe("#given no-op scenarios", () => { describe("#given no-op scenarios", () => {
@@ -129,13 +144,10 @@ describe("runBackgroundUpdateCheck", () => {
//#when //#when
await runCheck(autoUpdate) await runCheck(autoUpdate)
//#then //#then
expect(mockShowUpdateAvailableToast).toHaveBeenCalledWith( expect(mockShowUpdateAvailableToast).toHaveBeenCalledWith(mockContext, "3.5.0", getToastMessage)
expect.objectContaining({ directory: "/test" }), expect(mockRunBunInstallWithDetails).not.toHaveBeenCalled()
"3.5.0",
expect.any(Function)
)
expect(mockRunBunInstall).not.toHaveBeenCalled()
expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled() expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled()
expect(operationOrder).toEqual([])
}) })
}) })
@@ -147,7 +159,7 @@ describe("runBackgroundUpdateCheck", () => {
await runCheck() await runCheck()
//#then //#then
expect(mockShowUpdateAvailableToast).toHaveBeenCalledTimes(1) expect(mockShowUpdateAvailableToast).toHaveBeenCalledTimes(1)
expect(mockRunBunInstall).not.toHaveBeenCalled() expect(mockRunBunInstallWithDetails).not.toHaveBeenCalled()
expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled() expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled()
}) })
@@ -177,35 +189,33 @@ describe("runBackgroundUpdateCheck", () => {
describe("#given unpinned with auto-update and install succeeds", () => { describe("#given unpinned with auto-update and install succeeds", () => {
it("invalidates cache, installs, and shows auto-updated toast", async () => { it("invalidates cache, installs, and shows auto-updated toast", async () => {
//#given //#given
mockRunBunInstall.mockResolvedValue(true) mockRunBunInstallWithDetails.mockResolvedValue({ success: true })
//#when //#when
await runCheck() await runCheck()
//#then //#then
expect(mockSyncCachePackageJsonToIntent).toHaveBeenCalledWith(pluginEntry)
expect(mockInvalidatePackage).toHaveBeenCalledTimes(1) expect(mockInvalidatePackage).toHaveBeenCalledTimes(1)
expect(mockRunBunInstall).toHaveBeenCalledTimes(1) expect(mockRunBunInstallWithDetails).toHaveBeenCalledTimes(1)
expect(mockShowAutoUpdatedToast).toHaveBeenCalledWith( expect(mockRunBunInstallWithDetails).toHaveBeenCalledWith({ outputMode: "pipe" })
expect.objectContaining({ directory: "/test" }), expect(mockShowAutoUpdatedToast).toHaveBeenCalledWith(mockContext, "3.4.0", "3.5.0")
"3.4.0",
"3.5.0"
)
expect(mockShowUpdateAvailableToast).not.toHaveBeenCalled() expect(mockShowUpdateAvailableToast).not.toHaveBeenCalled()
expect(operationOrder).toEqual(["sync", "invalidate"])
}) })
}) })
describe("#given unpinned with auto-update and install fails", () => { describe("#given unpinned with auto-update and install fails", () => {
it("falls back to notification-only toast", async () => { it("falls back to notification-only toast", async () => {
//#given //#given
mockRunBunInstall.mockResolvedValue(false) mockRunBunInstallWithDetails.mockResolvedValue({ success: false, error: "install failed" })
//#when //#when
await runCheck() await runCheck()
//#then //#then
expect(mockRunBunInstall).toHaveBeenCalledTimes(1) expect(mockRunBunInstallWithDetails).toHaveBeenCalledTimes(1)
expect(mockShowUpdateAvailableToast).toHaveBeenCalledWith( expect(mockRunBunInstallWithDetails).toHaveBeenCalledWith({ outputMode: "pipe" })
expect.objectContaining({ directory: "/test" }), expect(mockSyncCachePackageJsonToIntent).toHaveBeenCalledWith(pluginEntry)
"3.5.0", expect(mockShowUpdateAvailableToast).toHaveBeenCalledWith(mockContext, "3.5.0", getToastMessage)
expect.any(Function)
)
expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled() expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled()
expect(operationOrder).toEqual(["sync", "invalidate"])
}) })
}) })
}) })
@@ -1,5 +1,5 @@
import type { PluginInput } from "@opencode-ai/plugin" import type { PluginInput } from "@opencode-ai/plugin"
import { runBunInstall } from "../../../cli/config-manager" import { runBunInstallWithDetails } from "../../../cli/config-manager"
import { log } from "../../../shared/logger" import { log } from "../../../shared/logger"
import { invalidatePackage } from "../cache" import { invalidatePackage } from "../cache"
import { PACKAGE_NAME } from "../constants" import { PACKAGE_NAME } from "../constants"
@@ -13,7 +13,12 @@ function getPinnedVersionToastMessage(latestVersion: string): string {
async function runBunInstallSafe(): Promise<boolean> { async function runBunInstallSafe(): Promise<boolean> {
try { try {
return await runBunInstall() const result = await runBunInstallWithDetails({ outputMode: "pipe" })
if (!result.success && result.error) {
log("[auto-update-checker] bun install failed:", result.error)
}
return result.success
} catch (err) { } catch (err) {
const errorMessage = err instanceof Error ? err.message : String(err) const errorMessage = err instanceof Error ? err.message : String(err)
log("[auto-update-checker] bun install error:", errorMessage) log("[auto-update-checker] bun install error:", errorMessage)