From 92ba31272d81d390ceb934bc67f292e36801d8d7 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sat, 4 Apr 2026 18:56:29 +0900 Subject: [PATCH] Fix mock isolation in system.test.ts by moving mocks to importFresh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Move mock.module() calls from top-level into importFreshSystemModule() - Restore real modules in afterAll to prevent cross-test contamination - Reset mocks before each test 🤖 GENERATED WITH ASSISTANCE OF OhMyOpenCode --- src/cli/doctor/checks/system.test.ts | 45 ++++++++++++++++------------ 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/cli/doctor/checks/system.test.ts b/src/cli/doctor/checks/system.test.ts index c0a5ef177..5f39289a3 100644 --- a/src/cli/doctor/checks/system.test.ts +++ b/src/cli/doctor/checks/system.test.ts @@ -6,10 +6,6 @@ import type { PluginInfo } from "./system-plugin" type SystemModule = typeof import("./system") -async function importFreshSystemModule(): Promise { - return import(`./system?test=${Date.now()}-${Math.random()}`) -} - const mockFindOpenCodeBinary = mock(async () => ({ path: "/usr/local/bin/opencode" })) const mockGetOpenCodeVersion = mock(async () => "1.0.200") const mockCompareVersions = mock((_leftVersion?: string, _rightVersion?: string) => true) @@ -31,26 +27,37 @@ const mockGetLoadedPluginVersion = mock(() => ({ const mockGetLatestPluginVersion = mock(async (_currentVersion: string | null) => null as string | null) const mockGetSuggestedInstallTag = mock(() => "latest") -mock.module("./system-binary", () => ({ - findOpenCodeBinary: mockFindOpenCodeBinary, - getOpenCodeVersion: mockGetOpenCodeVersion, - compareVersions: mockCompareVersions, -})) - -mock.module("./system-plugin", () => ({ - getPluginInfo: mockGetPluginInfo, -})) - -mock.module("./system-loaded-version", () => ({ - getLoadedPluginVersion: mockGetLoadedPluginVersion, - getLatestPluginVersion: mockGetLatestPluginVersion, - getSuggestedInstallTag: mockGetSuggestedInstallTag, -})) +const realSystemBinary = require("./system-binary") +const realSystemPlugin = require("./system-plugin") +const realSystemLoadedVersion = require("./system-loaded-version") afterAll(() => { + mock.module("./system-binary", () => realSystemBinary) + mock.module("./system-plugin", () => realSystemPlugin) + mock.module("./system-loaded-version", () => realSystemLoadedVersion) mock.restore() }) +async function importFreshSystemModule(): Promise { + mock.module("./system-binary", () => ({ + findOpenCodeBinary: mockFindOpenCodeBinary, + getOpenCodeVersion: mockGetOpenCodeVersion, + compareVersions: mockCompareVersions, + })) + + mock.module("./system-plugin", () => ({ + getPluginInfo: mockGetPluginInfo, + })) + + mock.module("./system-loaded-version", () => ({ + getLoadedPluginVersion: mockGetLoadedPluginVersion, + getLatestPluginVersion: mockGetLatestPluginVersion, + getSuggestedInstallTag: mockGetSuggestedInstallTag, + })) + + return import(`./system?test=${Date.now()}-${Math.random()}`) +} + describe("system check", () => { beforeEach(() => { mockFindOpenCodeBinary.mockReset()