fix(migration): return true when canonical config write succeeds regardless of archive status (#3133)
Previously returned archivedLegacyConfig which was false when archive rename failed, even though the canonical file was successfully written. Archive failure is secondary cleanup and should not be reported as migration failure. 🤖 Generated with OhMyOpenCode assistance https://github.com/code-yeongyu/oh-my-opencode
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "bun:test"
|
||||
import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test"
|
||||
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
@@ -87,4 +87,26 @@ describe("migrateLegacyConfigFile", () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("#given canonical write succeeds but archive fails", () => {
|
||||
describe("#when migrating the config file", () => {
|
||||
it("#then returns true", () => {
|
||||
const legacyPath = join(testDir, "oh-my-opencode.jsonc")
|
||||
const backupPath = `${legacyPath}.bak`
|
||||
const canonicalPath = join(testDir, "oh-my-openagent.jsonc")
|
||||
writeFileSync(legacyPath, '{ "agents": {} }')
|
||||
|
||||
// given: create backup path as directory (blocks rename, causing archive to return false)
|
||||
mkdirSync(backupPath)
|
||||
|
||||
// when: migrate the config file
|
||||
const result = migrateLegacyConfigFile(legacyPath)
|
||||
|
||||
// then: migration should return true (canonical write succeeded, archive is optional)
|
||||
expect(result).toBe(true)
|
||||
// then: canonical file should exist
|
||||
expect(existsSync(canonicalPath)).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -58,7 +58,7 @@ export function migrateLegacyConfigFile(legacyPath: string): boolean {
|
||||
to: canonicalPath,
|
||||
archivedLegacyConfig,
|
||||
})
|
||||
return archivedLegacyConfig
|
||||
return true
|
||||
} catch (error) {
|
||||
log("[migrateLegacyConfigFile] Failed to migrate legacy config file", { legacyPath, error })
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user