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
+34 -1
View File
@@ -1,18 +1,26 @@
import { describe, expect, test, beforeEach, afterEach } from "bun:test"
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test"
import { detectExternalNotificationPlugin, getNotificationConflictWarning, detectExternalSkillPlugin, getSkillPluginConflictWarning } from "./external-plugin-detector"
import * as fs from "node:fs"
import * as path from "node:path"
import * as os from "node:os"
async function importFreshExternalPluginDetectorModule(): Promise<typeof import("./external-plugin-detector")> {
return import(`./external-plugin-detector?test=${Date.now()}-${Math.random()}`)
}
describe("external-plugin-detector", () => {
let tempDir: string
let tempHomeDir: string
beforeEach(() => {
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "omo-test-"))
tempHomeDir = fs.mkdtempSync(path.join(os.tmpdir(), "omo-home-"))
})
afterEach(() => {
mock.restore()
fs.rmSync(tempDir, { recursive: true, force: true })
fs.rmSync(tempHomeDir, { recursive: true, force: true })
})
describe("detectExternalNotificationPlugin", () => {
@@ -399,6 +407,31 @@ describe("external-plugin-detector", () => {
expect(result.pluginName).toBe("opencode-skills")
})
test("should detect user-level opencode-skills when project config exists without plugins", async () => {
// given
const projectConfigDir = path.join(tempDir, ".opencode")
const userConfigDir = path.join(tempHomeDir, ".config", "opencode")
fs.mkdirSync(projectConfigDir, { recursive: true })
fs.mkdirSync(userConfigDir, { recursive: true })
fs.writeFileSync(path.join(projectConfigDir, "opencode.json"), JSON.stringify({}))
fs.writeFileSync(path.join(userConfigDir, "opencode.json"), JSON.stringify({ plugin: ["opencode-skills"] }))
const nodeOs = await import("node:os")
mock.module("node:os", () => ({
...nodeOs,
homedir: () => tempHomeDir,
}))
const { detectExternalSkillPlugin: detectExternalSkillPluginFresh } = await importFreshExternalPluginDetectorModule()
// when
const result = detectExternalSkillPluginFresh(tempDir)
// then
expect(result.detected).toBe(true)
expect(result.pluginName).toBe("opencode-skills")
expect(result.allPlugins).toEqual(["opencode-skills"])
})
test("should NOT match opencode-skills-extra (suffix variation)", () => {
// given - plugin with similar name but different suffix
const opencodeDir = path.join(tempDir, ".opencode")
@@ -18,15 +18,19 @@ describe("migrateLegacyConfigFile", () => {
describe("#given oh-my-opencode.jsonc exists but oh-my-openagent.jsonc does not", () => {
describe("#when migrating the config file", () => {
it("#then copies to oh-my-openagent.jsonc", () => {
it("#then writes oh-my-openagent.jsonc and renames the legacy file to a backup", () => {
const legacyPath = join(testDir, "oh-my-opencode.jsonc")
const backupPath = join(testDir, "oh-my-opencode.jsonc.bak")
writeFileSync(legacyPath, '{ "agents": {} }')
const result = migrateLegacyConfigFile(legacyPath)
expect(result).toBe(true)
expect(existsSync(join(testDir, "oh-my-openagent.jsonc"))).toBe(true)
expect(existsSync(legacyPath)).toBe(false)
expect(existsSync(backupPath)).toBe(true)
expect(readFileSync(join(testDir, "oh-my-openagent.jsonc"), "utf-8")).toBe('{ "agents": {} }')
expect(readFileSync(backupPath, "utf-8")).toBe('{ "agents": {} }')
})
})
})