fix: use jsonc-parser for safe JSONC migration and add project-local config detection

This commit is contained in:
YeonGyu-Kim
2026-03-31 17:06:46 -07:00
parent 9f2c4500e8
commit 11ee88f28f
7 changed files with 187 additions and 54 deletions
@@ -1,3 +1,5 @@
/// <reference path="../../../bun-test.d.ts" />
import { afterEach, beforeEach, describe, expect, it } from "bun:test"
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"
import { tmpdir } from "node:os"
@@ -118,6 +120,37 @@ describe("autoMigrateLegacyPluginEntry", () => {
})
})
describe("#given opencode.jsonc contains a nested plugin key before the top-level plugin array", () => {
it("#then rewrites only the top-level plugin array", 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)
const content = readFileSync(join(testConfigDir, "opencode.jsonc"), "utf-8")
expect(content).toContain(`"nested": {
"plugin": ["oh-my-opencode"]
}`)
expect(content).toContain(`"plugin": [
"oh-my-openagent@latest"
]`)
})
})
describe("#given only canonical entry exists", () => {
it("#then returns migrated false and leaves file untouched", async () => {
// given