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:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user