fix(config): handle tuple-format plugin entries in opencode.json (fixes #3122)

OpenCode supports plugin entries as [string, object] tuples for passing
options, but loadOpencodePlugins assumed all entries were strings.
When a tuple entry hit matchesKnownPlugin, it called .toLowerCase()
on an array, crashing the plugin on startup.

Extract the string name from tuple entries and skip non-string values.
Add regression test covering the tuple plugin format.
This commit is contained in:
YeonGyu-Kim
2026-04-04 16:44:29 +09:00
parent e40d3fb37a
commit 733b54865f
3 changed files with 33 additions and 3 deletions
@@ -102,6 +102,32 @@ describe("external-plugin-detector", () => {
expect(result.pluginName).toContain("opencode-notifier")
})
test("should safely handle tuple-format plugin entries without crashing (fixes #3122)", () => {
// given - opencode.json with array/tuple plugin entries
const opencodeDir = path.join(tempDir, ".opencode")
fs.mkdirSync(opencodeDir, { recursive: true })
fs.writeFileSync(
path.join(opencodeDir, "opencode.json"),
JSON.stringify({
plugin: [
"oh-my-opencode",
["advanced-tuple-plugin", { debug: true }],
"opencode-notifier"
]
})
)
// when
const result = detectExternalNotificationPlugin(tempDir)
// then - should detect opencode-notifier without crashing on the tuple entry
expect(result.detected).toBe(true)
expect(result.pluginName).toBe("opencode-notifier")
expect(result.allPlugins).toContain("oh-my-opencode")
expect(result.allPlugins).toContain("advanced-tuple-plugin")
expect(result.allPlugins).not.toContain(["advanced-tuple-plugin", { debug: true }])
})
test("should handle JSONC format with comments", () => {
// given - opencode.jsonc with comments
const opencodeDir = path.join(tempDir, ".opencode")