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:
@@ -25,7 +25,7 @@ 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 mockInvalidatePackage = mock(() => {})
|
||||||
const mockRunBunInstall = mock(async () => true)
|
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> => {}
|
||||||
)
|
)
|
||||||
@@ -41,7 +41,7 @@ mock.module("../checker", () => ({
|
|||||||
}))
|
}))
|
||||||
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,
|
||||||
@@ -62,7 +62,7 @@ describe("runBackgroundUpdateCheck", () => {
|
|||||||
mockGetLatestVersion.mockReset()
|
mockGetLatestVersion.mockReset()
|
||||||
mockExtractChannel.mockReset()
|
mockExtractChannel.mockReset()
|
||||||
mockInvalidatePackage.mockReset()
|
mockInvalidatePackage.mockReset()
|
||||||
mockRunBunInstall.mockReset()
|
mockRunBunInstallWithDetails.mockReset()
|
||||||
mockShowUpdateAvailableToast.mockReset()
|
mockShowUpdateAvailableToast.mockReset()
|
||||||
mockShowAutoUpdatedToast.mockReset()
|
mockShowAutoUpdatedToast.mockReset()
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ describe("runBackgroundUpdateCheck", () => {
|
|||||||
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 plugin entry found", () => {
|
describe("#given no plugin entry found", () => {
|
||||||
@@ -83,7 +83,7 @@ describe("runBackgroundUpdateCheck", () => {
|
|||||||
expect(mockFindPluginEntry).toHaveBeenCalledTimes(1)
|
expect(mockFindPluginEntry).toHaveBeenCalledTimes(1)
|
||||||
expect(mockShowUpdateAvailableToast).not.toHaveBeenCalled()
|
expect(mockShowUpdateAvailableToast).not.toHaveBeenCalled()
|
||||||
expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled()
|
expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled()
|
||||||
expect(mockRunBunInstall).not.toHaveBeenCalled()
|
expect(mockRunBunInstallWithDetails).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ describe("runBackgroundUpdateCheck", () => {
|
|||||||
await runBackgroundUpdateCheck(mockCtx, true, getToastMessage)
|
await runBackgroundUpdateCheck(mockCtx, true, getToastMessage)
|
||||||
//#then
|
//#then
|
||||||
expect(mockGetLatestVersion).toHaveBeenCalledWith("latest")
|
expect(mockGetLatestVersion).toHaveBeenCalledWith("latest")
|
||||||
expect(mockRunBunInstall).not.toHaveBeenCalled()
|
expect(mockRunBunInstallWithDetails).not.toHaveBeenCalled()
|
||||||
expect(mockShowUpdateAvailableToast).not.toHaveBeenCalled()
|
expect(mockShowUpdateAvailableToast).not.toHaveBeenCalled()
|
||||||
expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled()
|
expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
@@ -125,7 +125,7 @@ describe("runBackgroundUpdateCheck", () => {
|
|||||||
await runBackgroundUpdateCheck(mockCtx, true, getToastMessage)
|
await runBackgroundUpdateCheck(mockCtx, true, getToastMessage)
|
||||||
//#then
|
//#then
|
||||||
expect(mockGetLatestVersion).toHaveBeenCalledTimes(1)
|
expect(mockGetLatestVersion).toHaveBeenCalledTimes(1)
|
||||||
expect(mockRunBunInstall).not.toHaveBeenCalled()
|
expect(mockRunBunInstallWithDetails).not.toHaveBeenCalled()
|
||||||
expect(mockShowUpdateAvailableToast).not.toHaveBeenCalled()
|
expect(mockShowUpdateAvailableToast).not.toHaveBeenCalled()
|
||||||
expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled()
|
expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
@@ -139,7 +139,7 @@ describe("runBackgroundUpdateCheck", () => {
|
|||||||
await runBackgroundUpdateCheck(mockCtx, autoUpdate, getToastMessage)
|
await runBackgroundUpdateCheck(mockCtx, autoUpdate, getToastMessage)
|
||||||
//#then
|
//#then
|
||||||
expect(mockShowUpdateAvailableToast).toHaveBeenCalledWith(mockCtx, "3.5.0", getToastMessage)
|
expect(mockShowUpdateAvailableToast).toHaveBeenCalledWith(mockCtx, "3.5.0", getToastMessage)
|
||||||
expect(mockRunBunInstall).not.toHaveBeenCalled()
|
expect(mockRunBunInstallWithDetails).not.toHaveBeenCalled()
|
||||||
expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled()
|
expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -152,7 +152,7 @@ describe("runBackgroundUpdateCheck", () => {
|
|||||||
await runBackgroundUpdateCheck(mockCtx, true, getToastMessage)
|
await runBackgroundUpdateCheck(mockCtx, true, getToastMessage)
|
||||||
//#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()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -182,12 +182,13 @@ 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 runBackgroundUpdateCheck(mockCtx, true, getToastMessage)
|
await runBackgroundUpdateCheck(mockCtx, true, getToastMessage)
|
||||||
//#then
|
//#then
|
||||||
expect(mockInvalidatePackage).toHaveBeenCalledTimes(1)
|
expect(mockInvalidatePackage).toHaveBeenCalledTimes(1)
|
||||||
expect(mockRunBunInstall).toHaveBeenCalledTimes(1)
|
expect(mockRunBunInstallWithDetails).toHaveBeenCalledTimes(1)
|
||||||
|
expect(mockRunBunInstallWithDetails).toHaveBeenCalledWith({ outputMode: "pipe" })
|
||||||
expect(mockShowAutoUpdatedToast).toHaveBeenCalledWith(mockCtx, "3.4.0", "3.5.0")
|
expect(mockShowAutoUpdatedToast).toHaveBeenCalledWith(mockCtx, "3.4.0", "3.5.0")
|
||||||
expect(mockShowUpdateAvailableToast).not.toHaveBeenCalled()
|
expect(mockShowUpdateAvailableToast).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
@@ -196,11 +197,12 @@ describe("runBackgroundUpdateCheck", () => {
|
|||||||
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 runBackgroundUpdateCheck(mockCtx, true, getToastMessage)
|
await runBackgroundUpdateCheck(mockCtx, true, getToastMessage)
|
||||||
//#then
|
//#then
|
||||||
expect(mockRunBunInstall).toHaveBeenCalledTimes(1)
|
expect(mockRunBunInstallWithDetails).toHaveBeenCalledTimes(1)
|
||||||
|
expect(mockRunBunInstallWithDetails).toHaveBeenCalledWith({ outputMode: "pipe" })
|
||||||
expect(mockShowUpdateAvailableToast).toHaveBeenCalledWith(mockCtx, "3.5.0", getToastMessage)
|
expect(mockShowUpdateAvailableToast).toHaveBeenCalledWith(mockCtx, "3.5.0", getToastMessage)
|
||||||
expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled()
|
expect(mockShowAutoUpdatedToast).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user