diff --git a/src/cli/config-manager/add-plugin-to-opencode-config.ts b/src/cli/config-manager/add-plugin-to-opencode-config.ts index 23c398873..8cb7d0838 100644 --- a/src/cli/config-manager/add-plugin-to-opencode-config.ts +++ b/src/cli/config-manager/add-plugin-to-opencode-config.ts @@ -79,11 +79,7 @@ export async function addPluginToOpenCodeConfig(currentVersion: string): Promise const normalizedPlugins = [...otherPlugins] - if (canonicalEntries.length > 0 || legacyEntries.length > 0) { - normalizedPlugins.push(pluginEntry) - } else { - normalizedPlugins.push(pluginEntry) - } + normalizedPlugins.push(pluginEntry) config.plugin = normalizedPlugins diff --git a/src/cli/config-manager/parse-opencode-config-file.test.ts b/src/cli/config-manager/parse-opencode-config-file.test.ts new file mode 100644 index 000000000..f8351d8c2 --- /dev/null +++ b/src/cli/config-manager/parse-opencode-config-file.test.ts @@ -0,0 +1,49 @@ +import { afterEach, describe, expect, test } from "bun:test" +import { mkdtempSync, rmSync, writeFileSync } from "node:fs" +import { tmpdir } from "node:os" +import { join } from "node:path" + +import { parseOpenCodeConfigFileWithError } from "./parse-opencode-config-file" + +describe("parseOpenCodeConfigFileWithError", () => { + const tempDirectories: string[] = [] + + afterEach(() => { + for (const directory of tempDirectories.splice(0)) { + rmSync(directory, { recursive: true, force: true }) + } + }) + + test("#given a valid object config #when parsing the file #then it returns the parsed config", () => { + // given + const directory = mkdtempSync(join(tmpdir(), "omo-parse-config-")) + tempDirectories.push(directory) + const filePath = join(directory, "opencode.json") + writeFileSync(filePath, '{"plugin": ["oh-my-openagent"]}\n', "utf-8") + + // when + const result = parseOpenCodeConfigFileWithError(filePath) + + // then + expect(result).toEqual({ + config: { plugin: ["oh-my-openagent"] }, + }) + }) + + test("#given a null config payload #when parsing the file #then it returns a null parse error", () => { + // given + const directory = mkdtempSync(join(tmpdir(), "omo-parse-config-")) + tempDirectories.push(directory) + const filePath = join(directory, "opencode.json") + writeFileSync(filePath, "null\n", "utf-8") + + // when + const result = parseOpenCodeConfigFileWithError(filePath) + + // then + expect(result).toEqual({ + config: null, + error: `Config file parsed to null/undefined: ${filePath}. Ensure it contains valid JSON.`, + }) + }) +}) diff --git a/src/cli/config-manager/parse-opencode-config-file.ts b/src/cli/config-manager/parse-opencode-config-file.ts index 3e399d847..ed1f25526 100644 --- a/src/cli/config-manager/parse-opencode-config-file.ts +++ b/src/cli/config-manager/parse-opencode-config-file.ts @@ -30,7 +30,7 @@ export function parseOpenCodeConfigFileWithError(path: string): ParseConfigResul const config = parseJsonc(content) - if (config === null || config === undefined) { + if (config == null) { return { config: null, error: `Config file parsed to null/undefined: ${path}. Ensure it contains valid JSON.` } }