Fix mock.module() CI contamination by isolating tests into separate directories
- Moved hook-integration tests → src/hooks/_auc-mocks-hook/ - Moved workspace-resolution tests → src/hooks/_auc-mocks-workspace/ - Moved background-update-check tests → src/hooks/_auc-mocks-bgupdate/ - Moved cache tests → src/hooks/_auc-mocks-cache/ - Moved sync-package-json tests → src/hooks/_auc-sync-mocks/ - Removed hook.test.ts, workspace-resolution.test.ts, background-update-check.test.ts from auto-update-checker - Removed cache.test.ts from auto-update-checker - Each test file with mock.module() now in its own isolated CI batch - Bun's prefix glob matching was picking up _auc-mocks-* when running auto-update-checker - Solution: Separate into dedicated directories prevents cross-contamination CI Results: 3151 pass, 0 fail ✓
This commit is contained in:
+8
-8
@@ -37,24 +37,24 @@ const mockSyncCachePackageJsonToIntent = mock(() => false)
|
|||||||
|
|
||||||
let importCounter = 0
|
let importCounter = 0
|
||||||
|
|
||||||
async function importFreshBackgroundUpdateCheck(): Promise<typeof import("./background-update-check")> {
|
async function importFreshBackgroundUpdateCheck(): Promise<typeof import("../auto-update-checker/hook/background-update-check")> {
|
||||||
mock.module("../checker", () => ({
|
mock.module("../auto-update-checker/checker", () => ({
|
||||||
findPluginEntry: mockFindPluginEntry,
|
findPluginEntry: mockFindPluginEntry,
|
||||||
getCachedVersion: mockGetCachedVersion,
|
getCachedVersion: mockGetCachedVersion,
|
||||||
getLatestVersion: mockGetLatestVersion,
|
getLatestVersion: mockGetLatestVersion,
|
||||||
revertPinnedVersion: mock(() => false),
|
revertPinnedVersion: mock(() => false),
|
||||||
syncCachePackageJsonToIntent: mockSyncCachePackageJsonToIntent,
|
syncCachePackageJsonToIntent: mockSyncCachePackageJsonToIntent,
|
||||||
}))
|
}))
|
||||||
mock.module("../version-channel", () => ({ extractChannel: mockExtractChannel }))
|
mock.module("../auto-update-checker/version-channel", () => ({ extractChannel: mockExtractChannel }))
|
||||||
mock.module("../cache", () => ({ invalidatePackage: mockInvalidatePackage }))
|
mock.module("../auto-update-checker/cache", () => ({ invalidatePackage: mockInvalidatePackage }))
|
||||||
mock.module("../../../cli/config-manager", () => ({ runBunInstallWithDetails: mockRunBunInstallWithDetails }))
|
mock.module("../../cli/config-manager", () => ({ runBunInstallWithDetails: mockRunBunInstallWithDetails }))
|
||||||
mock.module("./update-toasts", () => ({
|
mock.module("../auto-update-checker/hook/update-toasts", () => ({
|
||||||
showUpdateAvailableToast: mockShowUpdateAvailableToast,
|
showUpdateAvailableToast: mockShowUpdateAvailableToast,
|
||||||
showAutoUpdatedToast: mockShowAutoUpdatedToast,
|
showAutoUpdatedToast: mockShowAutoUpdatedToast,
|
||||||
}))
|
}))
|
||||||
mock.module("../../../shared/logger", () => ({ log: () => {} }))
|
mock.module("../../shared/logger", () => ({ log: () => {} }))
|
||||||
|
|
||||||
const backgroundUpdateCheckModule = await import(`./background-update-check?test=${importCounter++}`)
|
const backgroundUpdateCheckModule = await import(`../auto-update-checker/hook/background-update-check?test=${importCounter++}`)
|
||||||
mock.restore()
|
mock.restore()
|
||||||
return backgroundUpdateCheckModule
|
return backgroundUpdateCheckModule
|
||||||
}
|
}
|
||||||
+3
-3
@@ -8,8 +8,8 @@ const TEST_USER_CONFIG_DIR = "/tmp/opencode-config"
|
|||||||
|
|
||||||
let importCounter = 0
|
let importCounter = 0
|
||||||
|
|
||||||
async function importFreshCacheModule(): Promise<typeof import("./cache")> {
|
async function importFreshCacheModule(): Promise<typeof import("../auto-update-checker/cache")> {
|
||||||
mock.module("./constants", () => ({
|
mock.module("../auto-update-checker/constants", () => ({
|
||||||
CACHE_DIR: TEST_OPENCODE_CACHE_DIR,
|
CACHE_DIR: TEST_OPENCODE_CACHE_DIR,
|
||||||
USER_CONFIG_DIR: TEST_USER_CONFIG_DIR,
|
USER_CONFIG_DIR: TEST_USER_CONFIG_DIR,
|
||||||
PACKAGE_NAME: "oh-my-opencode",
|
PACKAGE_NAME: "oh-my-opencode",
|
||||||
@@ -26,7 +26,7 @@ async function importFreshCacheModule(): Promise<typeof import("./cache")> {
|
|||||||
log: () => {},
|
log: () => {},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const cacheModule = await import(`./cache?test=${importCounter++}`)
|
const cacheModule = await import(`../auto-update-checker/cache?test=${importCounter++}`)
|
||||||
mock.restore()
|
mock.restore()
|
||||||
return cacheModule
|
return cacheModule
|
||||||
}
|
}
|
||||||
+10
-10
@@ -10,38 +10,38 @@ const mockRunBackgroundUpdateCheck = mock(async () => {})
|
|||||||
const mockGetCachedVersion = mock(() => "3.6.0")
|
const mockGetCachedVersion = mock(() => "3.6.0")
|
||||||
const mockGetLocalDevVersion = mock<(directory: string) => string | null>(() => null)
|
const mockGetLocalDevVersion = mock<(directory: string) => string | null>(() => null)
|
||||||
|
|
||||||
mock.module("../hook/config-errors-toast", () => ({
|
mock.module("../auto-update-checker/hook/config-errors-toast", () => ({
|
||||||
showConfigErrorsIfAny: mockShowConfigErrorsIfAny,
|
showConfigErrorsIfAny: mockShowConfigErrorsIfAny,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
mock.module("../hook/model-cache-warning", () => ({
|
mock.module("../auto-update-checker/hook/model-cache-warning", () => ({
|
||||||
showModelCacheWarningIfNeeded: mockShowModelCacheWarningIfNeeded,
|
showModelCacheWarningIfNeeded: mockShowModelCacheWarningIfNeeded,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
mock.module("../hook/connected-providers-status", () => ({
|
mock.module("../auto-update-checker/hook/connected-providers-status", () => ({
|
||||||
updateAndShowConnectedProvidersCacheStatus:
|
updateAndShowConnectedProvidersCacheStatus:
|
||||||
mockUpdateAndShowConnectedProvidersCacheStatus,
|
mockUpdateAndShowConnectedProvidersCacheStatus,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
mock.module("../hook/model-capabilities-status", () => ({
|
mock.module("../auto-update-checker/hook/model-capabilities-status", () => ({
|
||||||
refreshModelCapabilitiesOnStartup: mockRefreshModelCapabilitiesOnStartup,
|
refreshModelCapabilitiesOnStartup: mockRefreshModelCapabilitiesOnStartup,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
mock.module("../hook/startup-toasts", () => ({
|
mock.module("../auto-update-checker/hook/startup-toasts", () => ({
|
||||||
showLocalDevToast: mockShowLocalDevToast,
|
showLocalDevToast: mockShowLocalDevToast,
|
||||||
showVersionToast: mockShowVersionToast,
|
showVersionToast: mockShowVersionToast,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
mock.module("../hook/background-update-check", () => ({
|
mock.module("../auto-update-checker/hook/background-update-check", () => ({
|
||||||
runBackgroundUpdateCheck: mockRunBackgroundUpdateCheck,
|
runBackgroundUpdateCheck: mockRunBackgroundUpdateCheck,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
mock.module("../checker", () => ({
|
mock.module("../auto-update-checker/checker", () => ({
|
||||||
getCachedVersion: mockGetCachedVersion,
|
getCachedVersion: mockGetCachedVersion,
|
||||||
getLocalDevVersion: mockGetLocalDevVersion,
|
getLocalDevVersion: mockGetLocalDevVersion,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
mock.module("../../../shared/logger", () => ({
|
mock.module("../../shared/logger", () => ({
|
||||||
log: () => {},
|
log: () => {},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@@ -49,10 +49,10 @@ afterAll(() => {
|
|||||||
mock.restore()
|
mock.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
type HookFactory = typeof import("../hook").createAutoUpdateCheckerHook
|
type HookFactory = typeof import("../auto-update-checker/hook").createAutoUpdateCheckerHook
|
||||||
|
|
||||||
async function importFreshHookFactory(): Promise<HookFactory> {
|
async function importFreshHookFactory(): Promise<HookFactory> {
|
||||||
const hookModule = await import(`../hook?test-${Date.now()}-${Math.random()}`)
|
const hookModule = await import(`../auto-update-checker/hook?test-${Date.now()}-${Math.random()}`)
|
||||||
return hookModule.createAutoUpdateCheckerHook
|
return hookModule.createAutoUpdateCheckerHook
|
||||||
}
|
}
|
||||||
|
|
||||||
+12
-12
@@ -2,7 +2,7 @@ import type { PluginInput } from "@opencode-ai/plugin"
|
|||||||
import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from "bun:test"
|
import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from "bun:test"
|
||||||
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
|
||||||
import { join } from "node:path"
|
import { join } from "node:path"
|
||||||
import * as shared from "../../../shared"
|
import * as shared from "../../shared"
|
||||||
|
|
||||||
type PluginEntry = {
|
type PluginEntry = {
|
||||||
entry: string
|
entry: string
|
||||||
@@ -50,24 +50,24 @@ let importCounter = 0
|
|||||||
let getOpenCodeCacheDirSpy: { mockRestore: () => void } | undefined
|
let getOpenCodeCacheDirSpy: { mockRestore: () => void } | undefined
|
||||||
let getOpenCodeConfigPathsSpy: { mockRestore: () => void } | undefined
|
let getOpenCodeConfigPathsSpy: { mockRestore: () => void } | undefined
|
||||||
|
|
||||||
async function importFreshBackgroundUpdateCheck(): Promise<typeof import("./background-update-check")> {
|
async function importFreshBackgroundUpdateCheck(): Promise<typeof import("../auto-update-checker/hook/background-update-check")> {
|
||||||
mock.module("../checker", () => ({
|
mock.module("../auto-update-checker/checker", () => ({
|
||||||
findPluginEntry: mockFindPluginEntry,
|
findPluginEntry: mockFindPluginEntry,
|
||||||
getCachedVersion: mockGetCachedVersion,
|
getCachedVersion: mockGetCachedVersion,
|
||||||
getLatestVersion: mockGetLatestVersion,
|
getLatestVersion: mockGetLatestVersion,
|
||||||
revertPinnedVersion: mock(() => false),
|
revertPinnedVersion: mock(() => false),
|
||||||
syncCachePackageJsonToIntent: mockSyncCachePackageJsonToIntent,
|
syncCachePackageJsonToIntent: mockSyncCachePackageJsonToIntent,
|
||||||
}))
|
}))
|
||||||
mock.module("../version-channel", () => ({ extractChannel: mockExtractChannel }))
|
mock.module("../auto-update-checker/version-channel", () => ({ extractChannel: mockExtractChannel }))
|
||||||
mock.module("../cache", () => ({ invalidatePackage: mockInvalidatePackage }))
|
mock.module("../auto-update-checker/cache", () => ({ invalidatePackage: mockInvalidatePackage }))
|
||||||
mock.module("../../../cli/config-manager", () => ({
|
mock.module("../../cli/config-manager", () => ({
|
||||||
runBunInstallWithDetails: mockRunBunInstallWithDetails,
|
runBunInstallWithDetails: mockRunBunInstallWithDetails,
|
||||||
}))
|
}))
|
||||||
mock.module("./update-toasts", () => ({
|
mock.module("../auto-update-checker/hook/update-toasts", () => ({
|
||||||
showUpdateAvailableToast: mockShowUpdateAvailableToast,
|
showUpdateAvailableToast: mockShowUpdateAvailableToast,
|
||||||
showAutoUpdatedToast: mockShowAutoUpdatedToast,
|
showAutoUpdatedToast: mockShowAutoUpdatedToast,
|
||||||
}))
|
}))
|
||||||
mock.module("../../../shared/logger", () => ({ log: () => {} }))
|
mock.module("../../shared/logger", () => ({ log: () => {} }))
|
||||||
getOpenCodeCacheDirSpy = spyOn(shared, "getOpenCodeCacheDir").mockReturnValue(TEST_CACHE_DIR)
|
getOpenCodeCacheDirSpy = spyOn(shared, "getOpenCodeCacheDir").mockReturnValue(TEST_CACHE_DIR)
|
||||||
getOpenCodeConfigPathsSpy = spyOn(shared, "getOpenCodeConfigPaths").mockReturnValue({
|
getOpenCodeConfigPathsSpy = spyOn(shared, "getOpenCodeConfigPaths").mockReturnValue({
|
||||||
configDir: TEST_CONFIG_DIR,
|
configDir: TEST_CONFIG_DIR,
|
||||||
@@ -77,7 +77,7 @@ async function importFreshBackgroundUpdateCheck(): Promise<typeof import("./back
|
|||||||
omoConfig: join(TEST_CONFIG_DIR, "oh-my-opencode.json"),
|
omoConfig: join(TEST_CONFIG_DIR, "oh-my-opencode.json"),
|
||||||
})
|
})
|
||||||
|
|
||||||
mock.module("../constants", () => ({
|
mock.module("../auto-update-checker/constants", () => ({
|
||||||
PACKAGE_NAME: "oh-my-opencode",
|
PACKAGE_NAME: "oh-my-opencode",
|
||||||
CACHE_DIR: TEST_CACHE_DIR,
|
CACHE_DIR: TEST_CACHE_DIR,
|
||||||
USER_CONFIG_DIR: TEST_CONFIG_DIR,
|
USER_CONFIG_DIR: TEST_CONFIG_DIR,
|
||||||
@@ -90,14 +90,14 @@ async function importFreshBackgroundUpdateCheck(): Promise<typeof import("./back
|
|||||||
getWindowsAppdataDir: () => null,
|
getWindowsAppdataDir: () => null,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
mock.module("../../../shared/data-path", () => ({
|
mock.module("../../shared/data-path", () => ({
|
||||||
getDataDir: () => join(TEST_DIR, "data"),
|
getDataDir: () => join(TEST_DIR, "data"),
|
||||||
getOpenCodeStorageDir: () => join(TEST_DIR, "data", "opencode", "storage"),
|
getOpenCodeStorageDir: () => join(TEST_DIR, "data", "opencode", "storage"),
|
||||||
getCacheDir: () => TEST_DIR,
|
getCacheDir: () => TEST_DIR,
|
||||||
getOmoOpenCodeCacheDir: () => join(TEST_DIR, "oh-my-opencode"),
|
getOmoOpenCodeCacheDir: () => join(TEST_DIR, "oh-my-opencode"),
|
||||||
getOpenCodeCacheDir: () => TEST_CACHE_DIR,
|
getOpenCodeCacheDir: () => TEST_CACHE_DIR,
|
||||||
}))
|
}))
|
||||||
mock.module("../../../shared/opencode-config-dir", () => ({
|
mock.module("../../shared/opencode-config-dir", () => ({
|
||||||
getOpenCodeConfigDir: () => TEST_CONFIG_DIR,
|
getOpenCodeConfigDir: () => TEST_CONFIG_DIR,
|
||||||
getOpenCodeConfigPaths: () => ({
|
getOpenCodeConfigPaths: () => ({
|
||||||
configDir: TEST_CONFIG_DIR,
|
configDir: TEST_CONFIG_DIR,
|
||||||
@@ -108,7 +108,7 @@ async function importFreshBackgroundUpdateCheck(): Promise<typeof import("./back
|
|||||||
}),
|
}),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const backgroundUpdateCheckModule = await import(`./background-update-check?test=${importCounter++}`)
|
const backgroundUpdateCheckModule = await import(`../auto-update-checker/hook/background-update-check?test=${importCounter++}`)
|
||||||
return backgroundUpdateCheckModule
|
return backgroundUpdateCheckModule
|
||||||
}
|
}
|
||||||
|
|
||||||
+5
-5
@@ -1,14 +1,14 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test"
|
import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test"
|
||||||
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"
|
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"
|
||||||
import { join } from "node:path"
|
import { join } from "node:path"
|
||||||
import type { PluginEntryInfo } from "../plugin-entry"
|
import type { PluginEntryInfo } from "../auto-update-checker/checker/plugin-entry"
|
||||||
|
|
||||||
const TEST_CACHE_DIR = join(import.meta.dir, "__test-sync-cache__")
|
const TEST_CACHE_DIR = join(import.meta.dir, "__test-sync-cache__")
|
||||||
|
|
||||||
let importCounter = 0
|
let importCounter = 0
|
||||||
|
|
||||||
async function importFreshSyncPackageJsonModule(): Promise<typeof import("../sync-package-json")> {
|
async function importFreshSyncPackageJsonModule(): Promise<typeof import("../auto-update-checker/checker/sync-package-json")> {
|
||||||
mock.module("../../constants", () => ({
|
mock.module("../auto-update-checker/constants", () => ({
|
||||||
CACHE_DIR: TEST_CACHE_DIR,
|
CACHE_DIR: TEST_CACHE_DIR,
|
||||||
PACKAGE_NAME: "oh-my-opencode",
|
PACKAGE_NAME: "oh-my-opencode",
|
||||||
NPM_REGISTRY_URL: "https://registry.npmjs.org/-/package/oh-my-opencode/dist-tags",
|
NPM_REGISTRY_URL: "https://registry.npmjs.org/-/package/oh-my-opencode/dist-tags",
|
||||||
@@ -21,11 +21,11 @@ async function importFreshSyncPackageJsonModule(): Promise<typeof import("../syn
|
|||||||
getWindowsAppdataDir: () => null,
|
getWindowsAppdataDir: () => null,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
mock.module("../../../../shared/logger", () => ({
|
mock.module("../../shared/logger", () => ({
|
||||||
log: () => {},
|
log: () => {},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const syncPackageJsonModule = await import(`../sync-package-json?test=${importCounter++}`)
|
const syncPackageJsonModule = await import(`../auto-update-checker/checker/sync-package-json?test=${importCounter++}`)
|
||||||
mock.restore()
|
mock.restore()
|
||||||
return syncPackageJsonModule
|
return syncPackageJsonModule
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user