test: remove remaining legacy warning mock leaks

This commit is contained in:
YeonGyu-Kim
2026-04-04 19:52:25 +09:00
parent a4db240d47
commit 29a830dd89
4 changed files with 86 additions and 59 deletions
@@ -2,6 +2,7 @@
import { afterAll, afterEach, beforeEach, describe, expect, it, mock, spyOn } from "bun:test"
import type { LegacyPluginCheckResult } from "./legacy-plugin-warning"
import { logLegacyPluginStartupWarning } from "./log-legacy-plugin-startup-warning"
function createLegacyPluginCheckResult(
overrides: Partial<LegacyPluginCheckResult> = {},
@@ -25,22 +26,8 @@ afterAll(() => {
})
async function importFreshStartupWarningModule(): Promise<typeof import("./log-legacy-plugin-startup-warning")> {
mock.module("./legacy-plugin-warning", () => ({
checkForLegacyPluginEntry: mockCheckForLegacyPluginEntry,
}))
mock.module("./logger", () => ({
log: mockLog,
}))
mock.module("./migrate-legacy-plugin-entry", () => ({
migrateLegacyPluginEntry: mockMigrateLegacyPluginEntry,
}))
const module = await import(`./log-legacy-plugin-startup-warning?test=${Date.now()}-${Math.random()}`)
mock.restore()
consoleWarnSpy = spyOn(console, "warn").mockImplementation(() => {})
return module
return { logLegacyPluginStartupWarning }
}
describe("logLegacyPluginStartupWarning", () => {
@@ -69,7 +56,11 @@ describe("logLegacyPluginStartupWarning", () => {
const { logLegacyPluginStartupWarning } = await importFreshStartupWarningModule()
//#when
logLegacyPluginStartupWarning()
logLegacyPluginStartupWarning({
checkForLegacyPluginEntry: mockCheckForLegacyPluginEntry,
log: mockLog,
migrateLegacyPluginEntry: mockMigrateLegacyPluginEntry,
})
//#then
expect(mockLog).toHaveBeenCalledTimes(1)
@@ -93,7 +84,11 @@ describe("logLegacyPluginStartupWarning", () => {
const { logLegacyPluginStartupWarning } = await importFreshStartupWarningModule()
//#when
logLegacyPluginStartupWarning()
logLegacyPluginStartupWarning({
checkForLegacyPluginEntry: mockCheckForLegacyPluginEntry,
log: mockLog,
migrateLegacyPluginEntry: mockMigrateLegacyPluginEntry,
})
//#then
expect(consoleWarnSpy).toHaveBeenCalled()
@@ -112,7 +107,11 @@ describe("logLegacyPluginStartupWarning", () => {
const { logLegacyPluginStartupWarning } = await importFreshStartupWarningModule()
//#when
logLegacyPluginStartupWarning()
logLegacyPluginStartupWarning({
checkForLegacyPluginEntry: mockCheckForLegacyPluginEntry,
log: mockLog,
migrateLegacyPluginEntry: mockMigrateLegacyPluginEntry,
})
//#then
expect(mockMigrateLegacyPluginEntry).toHaveBeenCalledWith("/tmp/opencode.json")
@@ -125,7 +124,11 @@ describe("logLegacyPluginStartupWarning", () => {
const { logLegacyPluginStartupWarning } = await importFreshStartupWarningModule()
//#when
logLegacyPluginStartupWarning()
logLegacyPluginStartupWarning({
checkForLegacyPluginEntry: mockCheckForLegacyPluginEntry,
log: mockLog,
migrateLegacyPluginEntry: mockMigrateLegacyPluginEntry,
})
//#then
expect(mockLog).not.toHaveBeenCalled()
@@ -145,7 +148,11 @@ describe("logLegacyPluginStartupWarning", () => {
const { logLegacyPluginStartupWarning } = await importFreshStartupWarningModule()
//#when
logLegacyPluginStartupWarning()
logLegacyPluginStartupWarning({
checkForLegacyPluginEntry: mockCheckForLegacyPluginEntry,
log: mockLog,
migrateLegacyPluginEntry: mockMigrateLegacyPluginEntry,
})
//#then
const calls = consoleWarnSpy.mock.calls.map((call: string[]) => call[0] ?? "")
@@ -4,15 +4,25 @@ import { migrateLegacyPluginEntry } from "./migrate-legacy-plugin-entry"
import { toCanonicalEntry } from "./plugin-entry-migrator"
import { LEGACY_PLUGIN_NAME, PLUGIN_NAME } from "./plugin-identity"
export function logLegacyPluginStartupWarning(): void {
const result = checkForLegacyPluginEntry()
type LogLegacyPluginStartupWarningDeps = {
checkForLegacyPluginEntry?: typeof checkForLegacyPluginEntry
log?: typeof log
migrateLegacyPluginEntry?: typeof migrateLegacyPluginEntry
}
export function logLegacyPluginStartupWarning(deps: LogLegacyPluginStartupWarningDeps = {}): void {
const checkForLegacyPluginEntryFn = deps.checkForLegacyPluginEntry ?? checkForLegacyPluginEntry
const logFn = deps.log ?? log
const migrateLegacyPluginEntryFn = deps.migrateLegacyPluginEntry ?? migrateLegacyPluginEntry
const result = checkForLegacyPluginEntryFn()
if (!result.hasLegacyEntry) {
return
}
const suggestedEntries = result.legacyEntries.map(toCanonicalEntry)
log("[OhMyOpenCodePlugin] Legacy plugin entry detected in OpenCode config", {
logFn("[OhMyOpenCodePlugin] Legacy plugin entry detected in OpenCode config", {
legacyEntries: result.legacyEntries,
suggestedEntries,
hasCanonicalEntry: result.hasCanonicalEntry,
@@ -24,7 +34,7 @@ export function logLegacyPluginStartupWarning(): void {
+ ` Attempting auto-migration...`,
)
const migrated = migrateLegacyPluginEntry(result.configPath!)
const migrated = migrateLegacyPluginEntryFn(result.configPath!)
if (migrated) {
console.warn(`[oh-my-openagent] Auto-migrated opencode.json: ${result.legacyEntries.join(", ")} -> ${suggestedEntries.join(", ")}`)
} else {