Skip to content

Commit 7375fc6

Browse files
committed
test(app): cover Console extension helpers with unit tests
1 parent 1aefdc0 commit 7375fc6

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { expect, test } from "bun:test"
2+
import type { ConfigEntry, CredentialEntry } from "@opencode/client/promise"
3+
import { consoleAccount, consoleMcpLinks, consoleMcps, consoleSkillLink } from "./console-extensions"
4+
5+
type ServerConfig = NonNullable<
6+
NonNullable<Extract<ConfigEntry, { type: "document" }>["info"]["mcp"]>["servers"]
7+
>[string]
8+
9+
const consoleUrl = "https://opencode.ai/console"
10+
11+
const gateway = (slug: string): ServerConfig => ({
12+
type: "remote",
13+
url: `${consoleUrl}/api/integration-gateway/${slug}/mcp`,
14+
oauth: false,
15+
})
16+
17+
const pinned = (slug: string): ServerConfig => ({ ...gateway(slug), protocol: "2026-07-28" })
18+
19+
const document = (servers: Record<string, ServerConfig>): ConfigEntry => ({
20+
type: "document",
21+
info: { mcp: { servers } },
22+
})
23+
24+
const credential = (metadata: { server?: string; orgID?: string }, active = true): CredentialEntry => ({
25+
id: "cred_console",
26+
integrationID: "opencode",
27+
label: "Acme",
28+
active,
29+
value: { type: "key", key: "fixture-only", metadata },
30+
})
31+
32+
test("console account comes from the active opencode credential, without a trailing slash", () => {
33+
expect(consoleAccount([credential({ server: `${consoleUrl}//`, orgID: "org_1" })])).toEqual({
34+
server: consoleUrl,
35+
orgID: "org_1",
36+
})
37+
expect(consoleAccount([credential({})])).toEqual({ server: consoleUrl, orgID: undefined })
38+
expect(consoleAccount([credential({ orgID: "org_1" }, false)])).toBeUndefined()
39+
expect(consoleAccount([])).toBeUndefined()
40+
})
41+
42+
test("console MCPs recognize only managed gateway entries and sort by name", () => {
43+
const entries = [
44+
document({
45+
slack: gateway("slack"),
46+
github: pinned("github"),
47+
oauth: { type: "remote", url: `${consoleUrl}/api/integration-gateway/oauth/mcp` },
48+
other: { type: "remote", url: "https://example.com/mcp", oauth: false },
49+
local: { type: "local", command: ["x"] },
50+
}),
51+
]
52+
53+
expect(consoleMcps(entries)).toEqual([
54+
{ name: "github", server: consoleUrl, slug: "github", needsConnection: true, overridden: false },
55+
{ name: "slack", server: consoleUrl, slug: "slack", needsConnection: false, overridden: false },
56+
])
57+
})
58+
59+
test("a same-named server in the effective config marks Console's as overridden", () => {
60+
const offered = [document({ slack: gateway("slack"), github: gateway("github") })]
61+
62+
const active = [document({ slack: { type: "remote", url: "https://example.com/mcp" }, github: gateway("github") })]
63+
64+
expect(consoleMcps(offered, active).map((item) => [item.name, item.overridden])).toEqual([
65+
["github", false],
66+
["slack", true],
67+
])
68+
})
69+
70+
test("MCP links open the member's org page, or only Console when the account differs", () => {
71+
const github = consoleMcps([document({ github: gateway("github") })])[0]
72+
73+
expect(consoleMcpLinks(github, { server: consoleUrl, orgID: "org 1" })).toEqual({
74+
manage: `${consoleUrl}/org%201/extensions/mcp/github`,
75+
connect: `${consoleUrl}/org%201/extensions?connect=github`,
76+
})
77+
expect(consoleMcpLinks(github, { server: "https://other.example", orgID: "org_1" })).toEqual({ manage: consoleUrl })
78+
expect(consoleMcpLinks(github, { server: consoleUrl, orgID: undefined })).toEqual({ manage: consoleUrl })
79+
expect(consoleMcpLinks(github, undefined)).toEqual({ manage: consoleUrl })
80+
})
81+
82+
test("skills link to Console only for virtual skills while signed in, except the built-ins", () => {
83+
const account = { server: consoleUrl, orgID: "org_1" }
84+
85+
const deploy = { id: "deploy", path: "skill://deploy/SKILL.md" }
86+
87+
expect(consoleSkillLink(deploy, account)).toBe(`${consoleUrl}/org_1/extensions?kind=skills&search=deploy`)
88+
expect(consoleSkillLink(deploy, { server: consoleUrl, orgID: undefined })).toBe(consoleUrl)
89+
expect(consoleSkillLink(deploy, undefined)).toBeUndefined()
90+
expect(consoleSkillLink({ id: "deploy", path: "/home/me/.skills/deploy/SKILL.md" }, account)).toBeUndefined()
91+
expect(consoleSkillLink({ id: "report", path: "skill://report/SKILL.md" }, account)).toBeUndefined()
92+
})

0 commit comments

Comments
 (0)