Config-manager: migrate legacy OMO config path
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "bun:test"
|
||||
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"
|
||||
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
|
||||
@@ -34,7 +34,7 @@ describe("writeOmoConfig", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
testConfigDir = join(tmpdir(), `omo-write-config-${Date.now()}-${Math.random().toString(36).slice(2)}`)
|
||||
testConfigPath = join(testConfigDir, "oh-my-opencode.json")
|
||||
testConfigPath = join(testConfigDir, "oh-my-openagent.json")
|
||||
|
||||
mkdirSync(testConfigDir, { recursive: true })
|
||||
process.env.OPENCODE_CONFIG_DIR = testConfigDir
|
||||
@@ -77,4 +77,41 @@ describe("writeOmoConfig", () => {
|
||||
expect(savedConfig).toHaveProperty(defaultKey)
|
||||
}
|
||||
})
|
||||
|
||||
it("migrates legacy oh-my-opencode.json to canonical oh-my-openagent.json before merging", () => {
|
||||
// given
|
||||
const legacyConfigPath = join(testConfigDir, "oh-my-opencode.json")
|
||||
const canonicalConfigPath = join(testConfigDir, "oh-my-openagent.json")
|
||||
const legacyBackupPath = `${legacyConfigPath}.bak`
|
||||
writeFileSync(
|
||||
legacyConfigPath,
|
||||
JSON.stringify(
|
||||
{
|
||||
agents: {
|
||||
sisyphus: {
|
||||
model: "custom/provider-model",
|
||||
},
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
) + "\n",
|
||||
"utf-8",
|
||||
)
|
||||
|
||||
// when
|
||||
const result = writeOmoConfig(installConfig)
|
||||
|
||||
// then
|
||||
expect(result.success).toBe(true)
|
||||
expect(result.configPath).toEndWith("oh-my-openagent.json")
|
||||
expect(existsSync(legacyConfigPath)).toBe(false)
|
||||
expect(existsSync(legacyBackupPath)).toBe(true)
|
||||
expect(existsSync(canonicalConfigPath)).toBe(true)
|
||||
|
||||
const savedConfig = parseJsonc<Record<string, unknown>>(readFileSync(canonicalConfigPath, "utf-8"))
|
||||
const savedAgents = getRecord(savedConfig.agents)
|
||||
const savedSisyphus = getRecord(savedAgents.sisyphus)
|
||||
expect(savedSisyphus.model).toBe("custom/provider-model")
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user