Skip to content

Commit 70d2f45

Browse files
committed
test: pin the opencode v2 plugin module shape
CONTRIBUTING.md requires tests for behavior changes; the v2 port (0.2.0) changed the module surface to a default export. Assert the default export carries an id and the server plugin function, and that the plugin exposes the meta auth hook, so a regression back to the v1 named-export shape fails in CI instead of as a startup WARN in opencode.
1 parent e337192 commit 70d2f45

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎tests/plugin.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// The opencode v2 plugin contract: opencode loads plugins ONLY from the
2+
// module's default export, which must carry an `id` and the `server` plugin
3+
// function (opencode 1.18.29+ accepts the same shape). A regression back to
4+
// the v1 named-export shape fails at every opencode startup with
5+
// PluginModule.LoadError — only visible as a WARN in the log — so pin the
6+
// exported shape here.
7+
import { test } from "node:test"
8+
import assert from "node:assert/strict"
9+
10+
import plugin from "../dist/index.js"
11+
12+
test("default export satisfies the opencode v2 PluginModule shape", () => {
13+
assert.equal(typeof plugin, "object")
14+
assert.ok(plugin && !Array.isArray(plugin))
15+
assert.equal(typeof plugin.id, "string")
16+
assert.ok(plugin.id.length > 0)
17+
assert.equal(typeof plugin.server, "function")
18+
})
19+
20+
test("server plugin returns the auth hook for provider meta", async () => {
21+
const hooks = await plugin.server()
22+
assert.ok(hooks.auth)
23+
assert.equal(hooks.auth.provider, "meta")
24+
assert.equal(typeof hooks.auth.loader, "function")
25+
assert.ok(Array.isArray(hooks.auth.methods))
26+
assert.equal(hooks.auth.methods.length, 1)
27+
assert.equal(hooks.auth.methods[0].type, "oauth")
28+
assert.equal(typeof hooks.auth.methods[0].authorize, "function")
29+
})

0 commit comments

Comments
 (0)