Files
oh-my-opencode/src/hooks/legacy-plugin-toast/auto-migrate.test.ts
T
YeonGyu-Kim d2c576c510 fix: resolve 25 pre-publish blockers
- postinstall.mjs: fix alias package detection
- migrate-legacy-plugin-entry: dedupe + regression tests
- task_system: default consistency across runtime paths
- task() contract: consistent tool behavior
- runtime model selection, tool cap, stale-task cancellation
- recovery sanitization, context-limit gating
- Ralph semantic DONE hardening, Atlas fallback persistence
- native-skill description/content, skill path traversal guard
- publish workflow: platform awaited via reusable workflow job
- release: version edits reapplied before commit/tag
- JSONC plugin migration: top-level plugin key safety
- cold-cache: user fallback models skip disconnected providers
- docs/version/release framing updates

Verified: bun test (4599 pass), tsc --noEmit clean, bun run build clean
2026-03-28 15:24:18 +09:00

139 lines
4.7 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it } from "bun:test"
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"
import { tmpdir } from "node:os"
import { join } from "node:path"
async function importFreshAutoMigrateModule(): Promise<typeof import("./auto-migrate")> {
return import(`./auto-migrate?test=${Date.now()}-${Math.random()}`)
}
describe("autoMigrateLegacyPluginEntry", () => {
let testConfigDir = ""
beforeEach(() => {
testConfigDir = join(tmpdir(), `omo-legacy-migrate-${Date.now()}-${Math.random().toString(36).slice(2)}`)
mkdirSync(testConfigDir, { recursive: true })
})
afterEach(() => {
rmSync(testConfigDir, { recursive: true, force: true })
})
describe("#given opencode.json has a bare legacy plugin entry", () => {
it("#then replaces oh-my-opencode with oh-my-openagent", async () => {
// given
writeFileSync(
join(testConfigDir, "opencode.json"),
JSON.stringify({ plugin: ["oh-my-opencode"] }, null, 2) + "\n",
)
const { autoMigrateLegacyPluginEntry } = await importFreshAutoMigrateModule()
// when
const result = autoMigrateLegacyPluginEntry(testConfigDir)
// then
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"])
})
})
describe("#given opencode.json has a version-pinned legacy entry", () => {
it("#then preserves the version suffix", async () => {
// given
writeFileSync(
join(testConfigDir, "opencode.json"),
JSON.stringify({ plugin: ["oh-my-opencode@3.10.0"] }, null, 2) + "\n",
)
const { autoMigrateLegacyPluginEntry } = await importFreshAutoMigrateModule()
// when
const result = autoMigrateLegacyPluginEntry(testConfigDir)
// then
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"])
})
})
describe("#given both canonical and legacy entries exist", () => {
it("#then removes legacy entry and keeps canonical", async () => {
// given
writeFileSync(
join(testConfigDir, "opencode.json"),
JSON.stringify({ plugin: ["oh-my-openagent", "oh-my-opencode"] }, null, 2) + "\n",
)
const { autoMigrateLegacyPluginEntry } = await importFreshAutoMigrateModule()
// when
const result = autoMigrateLegacyPluginEntry(testConfigDir)
// then
expect(result.migrated).toBe(true)
const saved = JSON.parse(readFileSync(join(testConfigDir, "opencode.json"), "utf-8"))
expect(saved.plugin).toEqual(["oh-my-openagent"])
})
})
describe("#given no config file exists", () => {
it("#then returns migrated false", async () => {
// given - empty dir
const { autoMigrateLegacyPluginEntry } = await importFreshAutoMigrateModule()
// when
const result = autoMigrateLegacyPluginEntry(testConfigDir)
// then
expect(result.migrated).toBe(false)
expect(result.from).toBeNull()
})
})
describe("#given opencode.jsonc has comments and a legacy entry", () => {
it("#then preserves comments and replaces entry", async () => {
// given
writeFileSync(
join(testConfigDir, "opencode.jsonc"),
'{\n // my config\n "plugin": ["oh-my-opencode"]\n}\n',
)
const { autoMigrateLegacyPluginEntry } = await importFreshAutoMigrateModule()
// when
const result = autoMigrateLegacyPluginEntry(testConfigDir)
// 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")
})
})
describe("#given only canonical entry exists", () => {
it("#then returns migrated false and leaves file untouched", async () => {
// given
const original = JSON.stringify({ plugin: ["oh-my-openagent"] }, null, 2) + "\n"
writeFileSync(join(testConfigDir, "opencode.json"), original)
const { autoMigrateLegacyPluginEntry } = await importFreshAutoMigrateModule()
// when
const result = autoMigrateLegacyPluginEntry(testConfigDir)
// then
expect(result.migrated).toBe(false)
const content = readFileSync(join(testConfigDir, "opencode.json"), "utf-8")
expect(content).toBe(original)
})
})
})