test(config): add regression coverage for legacy migration bugs

Lock the current legacy config and plugin migration failures in place before the fixes land so the three regressions stay covered.

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

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-04-04 01:32:17 +09:00
parent 53eeac3f31
commit d60ca63ed4
4 changed files with 115 additions and 17 deletions
@@ -1,7 +1,14 @@
import { afterEach, beforeEach, describe, expect, it } from "bun:test"
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"
import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test"
import { mkdirSync, rmSync, writeFileSync } from "node:fs"
import { tmpdir } from "node:os"
import { join } from "node:path"
const mockMigrateLegacyPluginEntry = mock(() => true)
mock.module("./plugin-entry-migrator", () => ({
migrateLegacyPluginEntry: mockMigrateLegacyPluginEntry,
}))
async function importFreshAutoMigrateModule(): Promise<typeof import("./auto-migrate")> {
return import(`./auto-migrate?test=${Date.now()}-${Math.random()}`)
}
@@ -12,6 +19,8 @@ describe("autoMigrateLegacyPluginEntry", () => {
beforeEach(() => {
testConfigDir = join(tmpdir(), `omo-legacy-migrate-${Date.now()}-${Math.random().toString(36).slice(2)}`)
mkdirSync(testConfigDir, { recursive: true })
mockMigrateLegacyPluginEntry.mockReset()
mockMigrateLegacyPluginEntry.mockReturnValue(true)
})
afterEach(() => {
@@ -35,8 +44,7 @@ describe("autoMigrateLegacyPluginEntry", () => {
expect(result.migrated).toBe(true)
expect(result.from).toBe("oh-my-opencode")
expect(result.to).toBe("oh-my-openagent")
const saved = JSON.parse(readFileSync(join(testConfigDir, "opencode.json"), "utf-8"))
expect(saved.plugin).toEqual(["oh-my-openagent"])
expect(mockMigrateLegacyPluginEntry).toHaveBeenCalledWith(join(testConfigDir, "opencode.json"))
})
})
@@ -57,8 +65,7 @@ describe("autoMigrateLegacyPluginEntry", () => {
expect(result.migrated).toBe(true)
expect(result.from).toBe("oh-my-opencode@3.10.0")
expect(result.to).toBe("oh-my-openagent@3.10.0")
const saved = JSON.parse(readFileSync(join(testConfigDir, "opencode.json"), "utf-8"))
expect(saved.plugin).toEqual(["oh-my-openagent@3.10.0"])
expect(mockMigrateLegacyPluginEntry).toHaveBeenCalledWith(join(testConfigDir, "opencode.json"))
})
})
@@ -77,8 +84,8 @@ describe("autoMigrateLegacyPluginEntry", () => {
// then
expect(result.migrated).toBe(true)
const saved = JSON.parse(readFileSync(join(testConfigDir, "opencode.json"), "utf-8"))
expect(saved.plugin).toEqual(["oh-my-openagent"])
expect(result.to).toBe("oh-my-openagent")
expect(mockMigrateLegacyPluginEntry).toHaveBeenCalledWith(join(testConfigDir, "opencode.json"))
})
})
@@ -93,6 +100,7 @@ describe("autoMigrateLegacyPluginEntry", () => {
// then
expect(result.migrated).toBe(false)
expect(result.from).toBeNull()
expect(mockMigrateLegacyPluginEntry).not.toHaveBeenCalled()
})
})
@@ -111,10 +119,35 @@ describe("autoMigrateLegacyPluginEntry", () => {
// then
expect(result.migrated).toBe(true)
const content = readFileSync(join(testConfigDir, "opencode.jsonc"), "utf-8")
expect(content).toContain("// my config")
expect(content).toContain("oh-my-openagent")
expect(content).not.toContain("oh-my-opencode")
expect(result.to).toBe("oh-my-openagent")
expect(mockMigrateLegacyPluginEntry).toHaveBeenCalledWith(join(testConfigDir, "opencode.jsonc"))
})
})
describe("#given opencode.jsonc has a nested plugin key before the root plugin array", () => {
it("#then migrates only the root plugin entry", async () => {
// given
writeFileSync(
join(testConfigDir, "opencode.jsonc"),
`{
"nested": {
"plugin": ["oh-my-opencode"]
},
"plugin": ["oh-my-opencode@latest"]
}
`,
)
const { autoMigrateLegacyPluginEntry } = await importFreshAutoMigrateModule()
// when
const result = autoMigrateLegacyPluginEntry(testConfigDir)
// then
expect(result.migrated).toBe(true)
expect(result.from).toBe("oh-my-opencode@latest")
expect(result.to).toBe("oh-my-openagent@latest")
expect(mockMigrateLegacyPluginEntry).toHaveBeenCalledWith(join(testConfigDir, "opencode.jsonc"))
})
})
@@ -131,8 +164,7 @@ describe("autoMigrateLegacyPluginEntry", () => {
// then
expect(result.migrated).toBe(false)
const content = readFileSync(join(testConfigDir, "opencode.json"), "utf-8")
expect(content).toBe(original)
expect(mockMigrateLegacyPluginEntry).not.toHaveBeenCalled()
})
})
})