Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/opencode/src/plugin/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ export function readV1Plugin(
if (tui !== undefined && typeof tui !== "function") {
throw new TypeError(`Plugin ${spec} has invalid tui export`)
}
if (mode === "detect" && kind === "server" && server === undefined) return
if (mode === "detect" && kind === "tui" && tui === undefined) return
if (server !== undefined && tui !== undefined) {
throw new TypeError(`Plugin ${spec} must default export either server() or tui(), not both`)
}
Expand Down
20 changes: 19 additions & 1 deletion packages/opencode/test/plugin/shared.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test"
import { parsePluginSpecifier } from "../../src/plugin/shared"
import { parsePluginSpecifier, readV1Plugin } from "../../src/plugin/shared"

describe("parsePluginSpecifier", () => {
test("parses standard npm package without version", () => {
Expand Down Expand Up @@ -86,3 +86,21 @@ describe("parsePluginSpecifier", () => {
})
})
})

describe("readV1Plugin", () => {
test("skips plugins without the requested entrypoint in detect mode", () => {
const tuiOnly = { id: "demo.tui", tui: async () => {} }
const serverOnly = { id: "demo.server", server: async () => {} }

expect(readV1Plugin({ default: tuiOnly }, "demo-tui", "server", "detect")).toBeUndefined()
expect(readV1Plugin({ default: serverOnly }, "demo-server", "tui", "detect")).toBeUndefined()
})

test("still rejects missing entrypoints in strict mode", () => {
const tuiOnly = { id: "demo.tui", tui: async () => {} }

expect(() => readV1Plugin({ default: tuiOnly }, "demo-tui", "server")).toThrow(
"Plugin demo-tui must default export an object with server()",
)
})
})
Loading