From 852859ed9c8340e1f34a99abbb7906845e3c8868 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sun, 5 Apr 2026 11:23:08 +0900 Subject: [PATCH] refactor(config-manager): remove legacy config path detection and migration logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with assistance of OhMyOpenCode --- src/cli/config-manager/config-context.ts | 22 +-------- .../config-manager/write-omo-config.test.ts | 41 +---------------- src/cli/doctor/checks/config.test.ts | 32 +++++++++++++ .../checks/model-resolution-config.test.ts | 45 +++++++++++++++++++ src/shared/opencode-config-dir.ts | 3 +- 5 files changed, 81 insertions(+), 62 deletions(-) create mode 100644 src/cli/doctor/checks/model-resolution-config.test.ts diff --git a/src/cli/config-manager/config-context.ts b/src/cli/config-manager/config-context.ts index d01e8ba85..78eb88d77 100644 --- a/src/cli/config-manager/config-context.ts +++ b/src/cli/config-manager/config-context.ts @@ -1,13 +1,8 @@ -import { basename, extname, join } from "node:path" - import { getOpenCodeConfigPaths } from "../../shared" -import { detectPluginConfigFile } from "../../shared/jsonc-parser" -import { migrateLegacyConfigFile } from "../../shared/migrate-legacy-config-file" import type { OpenCodeBinaryType, OpenCodeConfigPaths, } from "../../shared/opencode-config-dir-types" -import { CONFIG_BASENAME, LEGACY_CONFIG_BASENAME } from "../../shared/plugin-identity" export interface ConfigContext { binary: OpenCodeBinaryType @@ -47,20 +42,5 @@ export function getConfigJsonc(): string { } export function getOmoConfigPath(): string { - const configDir = getConfigContext().paths.configDir - const detectedConfig = detectPluginConfigFile(configDir) - - if ( - detectedConfig.format !== "none" - && basename(detectedConfig.path).startsWith(LEGACY_CONFIG_BASENAME) - ) { - const canonicalPath = join( - configDir, - `${CONFIG_BASENAME}${extname(detectedConfig.path)}`, - ) - const migrated = migrateLegacyConfigFile(detectedConfig.path) - return migrated ? canonicalPath : detectedConfig.path - } - - return detectedConfig.path + return getConfigContext().paths.omoConfig } diff --git a/src/cli/config-manager/write-omo-config.test.ts b/src/cli/config-manager/write-omo-config.test.ts index 83b70e9d3..5701b53dc 100644 --- a/src/cli/config-manager/write-omo-config.test.ts +++ b/src/cli/config-manager/write-omo-config.test.ts @@ -1,5 +1,5 @@ import { afterEach, beforeEach, describe, expect, it } from "bun:test" -import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs" +import { 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-openagent.json") + testConfigPath = join(testConfigDir, "oh-my-opencode.json") mkdirSync(testConfigDir, { recursive: true }) process.env.OPENCODE_CONFIG_DIR = testConfigDir @@ -77,41 +77,4 @@ 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>(readFileSync(canonicalConfigPath, "utf-8")) - const savedAgents = getRecord(savedConfig.agents) - const savedSisyphus = getRecord(savedAgents.sisyphus) - expect(savedSisyphus.model).toBe("custom/provider-model") - }) }) diff --git a/src/cli/doctor/checks/config.test.ts b/src/cli/doctor/checks/config.test.ts index 8289329fb..92433d49b 100644 --- a/src/cli/doctor/checks/config.test.ts +++ b/src/cli/doctor/checks/config.test.ts @@ -1,4 +1,7 @@ import { describe, it, expect } from "bun:test" +import { mkdirSync, rmSync, writeFileSync } from "node:fs" +import { tmpdir } from "node:os" +import { join } from "node:path" import * as config from "./config" describe("config check", () => { @@ -23,5 +26,34 @@ describe("config check", () => { //#then issues should be an array (possibly empty) expect(Array.isArray(result.issues)).toBe(true) }) + + it("respects OPENCODE_CONFIG_DIR even when the env var changes after module import", async () => { + const originalConfigDir = process.env.OPENCODE_CONFIG_DIR + const testConfigDir = join( + tmpdir(), + `omo-doctor-config-${Date.now()}-${Math.random().toString(36).slice(2)}`, + ) + + try { + mkdirSync(testConfigDir, { recursive: true }) + process.env.OPENCODE_CONFIG_DIR = testConfigDir + writeFileSync( + join(testConfigDir, "oh-my-openagent.json"), + JSON.stringify({ disabled_hooks: ["comment-checker"] }, null, 2) + "\n", + "utf-8", + ) + + const result = await config.checkConfig() + + expect(result.details?.[0]).toEndWith("/oh-my-openagent.json") + } finally { + rmSync(testConfigDir, { recursive: true, force: true }) + if (originalConfigDir === undefined) { + delete process.env.OPENCODE_CONFIG_DIR + } else { + process.env.OPENCODE_CONFIG_DIR = originalConfigDir + } + } + }) }) }) diff --git a/src/cli/doctor/checks/model-resolution-config.test.ts b/src/cli/doctor/checks/model-resolution-config.test.ts new file mode 100644 index 000000000..124d35242 --- /dev/null +++ b/src/cli/doctor/checks/model-resolution-config.test.ts @@ -0,0 +1,45 @@ +import { afterEach, beforeEach, describe, expect, it } from "bun:test" +import { mkdirSync, rmSync, writeFileSync } from "node:fs" +import { tmpdir } from "node:os" +import { join } from "node:path" + +import { loadOmoConfig } from "./model-resolution-config" + +describe("model-resolution-config", () => { + let originalConfigDir: string | undefined + + beforeEach(() => { + originalConfigDir = process.env.OPENCODE_CONFIG_DIR + }) + + afterEach(() => { + if (originalConfigDir === undefined) { + delete process.env.OPENCODE_CONFIG_DIR + } else { + process.env.OPENCODE_CONFIG_DIR = originalConfigDir + } + }) + + it("respects OPENCODE_CONFIG_DIR even when the env var changes after module import", () => { + const testConfigDir = join( + tmpdir(), + `omo-model-resolution-config-${Date.now()}-${Math.random().toString(36).slice(2)}`, + ) + + try { + mkdirSync(testConfigDir, { recursive: true }) + process.env.OPENCODE_CONFIG_DIR = testConfigDir + writeFileSync( + join(testConfigDir, "oh-my-openagent.json"), + JSON.stringify({ agents: { atlas: { model: "opencode-go/kimi-k2.5" } } }, null, 2) + "\n", + "utf-8", + ) + + const config = loadOmoConfig() + + expect(config?.agents?.atlas?.model).toBe("opencode-go/kimi-k2.5") + } finally { + rmSync(testConfigDir, { recursive: true, force: true }) + } + }) +}) diff --git a/src/shared/opencode-config-dir.ts b/src/shared/opencode-config-dir.ts index 7e07d4bb9..e1dedc401 100644 --- a/src/shared/opencode-config-dir.ts +++ b/src/shared/opencode-config-dir.ts @@ -7,7 +7,6 @@ import type { OpenCodeConfigDirOptions, OpenCodeConfigPaths, } from "./opencode-config-dir-types" -import { CONFIG_BASENAME } from "./plugin-identity" export type { OpenCodeBinaryType, @@ -98,7 +97,7 @@ export function getOpenCodeConfigPaths(options: OpenCodeConfigDirOptions): OpenC configJson: join(configDir, "opencode.json"), configJsonc: join(configDir, "opencode.jsonc"), packageJson: join(configDir, "package.json"), - omoConfig: join(configDir, `${CONFIG_BASENAME}.json`), + omoConfig: join(configDir, "oh-my-opencode.json"), } }