Skip to content

Commit 2f8b20c

Browse files
opencodeclaude
andcommitted
fix(app): address Copilot review findings on #36
- mcp-catalog-client.ts / use-mcp-catalog.ts: derive McpCatalogEntry/ McpLiveStatus from the client's own return shape (McpListResult/ McpStatusResult) instead of importing @opencode-ai/client-next types a second time in the hook -- keeps the alias's surface bounded to the one file its own header claims. - use-mcp-catalog.ts: create the client once per effect run (directory/ server change) instead of once per call -- mcp.list and every status poll now share the same connection instead of each allocating its own. - mcp.tsx: statusLabel(entry) was computed twice (once for Show's `when`, once for the rendered text) -- reactive divergence risk across updates. Switched to Show's render-function form, matching errorText's existing pattern, so it's computed once. - settings-mcp-catalog.spec.ts: the "disabled" assertion checked the whole row's text once, which wouldn't fail if a regression collapsed the static Tag and the live status label into one element. Split into two independent assertions; confirmed the stronger version actually catches that regression (temporarily removed the Tag, watched it fail, restored). Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JJQrqYMv43CrdbjpTT7884
1 parent e2697c2 commit 2f8b20c

4 files changed

Lines changed: 23 additions & 11 deletions

File tree

‎packages/app/e2e/user-story/settings-mcp-catalog.spec.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,13 @@ test("MCP tab shows live status per server, distinct from the static catalog", a
103103
await expect(sentryRow).toContainText("connection refused")
104104

105105
// The catalog's own static status ("disabled") is a Tag, and the live status agrees here --
106-
// but they are two different fields, asserted separately so a future change can't silently
107-
// collapse "the user disabled it" into "the live status happens to also say disabled".
106+
// but they are two different fields. Asserted against each element independently (Copilot
107+
// review, PR #36: a single toContainText("disabled") on the whole row would still pass if a
108+
// regression collapsed the two into one element) so a future change can't silently collapse
109+
// "the user disabled it" into "the live status happens to also say disabled".
108110
const parkedRow = list.locator(".settings-v2-mcp-row", { hasText: "parked" })
109-
await expect(parkedRow).toContainText("disabled")
111+
await expect(parkedRow.locator(".settings-v2-mcp-main")).toContainText("disabled")
112+
await expect(parkedRow.locator(".settings-v2-mcp-status-label")).toHaveText("disabled")
110113

111114
await expect(dialog.locator('[data-component="mcp-runtime-unavailable"]')).toHaveCount(0)
112115
})

‎packages/app/src/components/settings-v2/mcp.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const SettingsMcpV2: Component<{ directory: Accessor<string | undefined>
112112
</Show>
113113
</div>
114114
<Show when={statusLabel(entry)}>
115-
<span class="settings-v2-mcp-status-label">{statusLabel(entry)}</span>
115+
{(label) => <span class="settings-v2-mcp-status-label">{label()}</span>}
116116
</Show>
117117
<Show when={errorText(entry)}>
118118
{(text) => <span class="settings-v2-mcp-error truncate">{text()}</span>}

‎packages/app/src/hooks/use-mcp-catalog.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { type Accessor, createEffect, onCleanup } from "solid-js"
22
import { createStore, reconcile } from "solid-js/store"
33
import { useServerSDK } from "@/context/server-sdk"
44
import { createMcpCatalogClient, isServiceUnavailableError } from "@/utils/mcp-catalog-client"
5-
import type { McpListOutput, McpStatusOutput } from "@opencode-ai/client-next"
5+
import type { McpListResult, McpStatusResult } from "@/utils/mcp-catalog-client"
66

7-
export type McpCatalogEntry = McpListOutput["data"][number]
8-
export type McpLiveStatus = McpStatusOutput["data"][string]
7+
export type McpCatalogEntry = McpListResult["data"][number]
8+
export type McpLiveStatus = McpStatusResult["data"][string]
99

1010
/**
1111
* `status` is a three-state discriminated union, not a boolean loading flag: a caller must be
@@ -23,7 +23,6 @@ const statusPollMs = 10_000
2323

2424
export function useMcpCatalog(directory: Accessor<string | undefined>) {
2525
const sdk = useServerSDK()
26-
const client = () => createMcpCatalogClient(sdk().server)
2726

2827
const [catalog, setCatalog] = createStore<{ entries: McpCatalogEntry[]; loading: boolean; error?: string }>({
2928
entries: [],
@@ -33,12 +32,16 @@ export function useMcpCatalog(directory: Accessor<string | undefined>) {
3332

3433
createEffect(() => {
3534
const dir = directory()
35+
// Created once per effect run (directory/server change), not once per call -- list and every
36+
// status poll share the same server connection instead of each allocating its own client
37+
// (Copilot review, PR #36).
38+
const client = createMcpCatalogClient(sdk().server)
3639
let dead = false
3740
setCatalog("loading", true)
3841
setStatus("state", { tag: "loading" })
3942

40-
void client()
41-
.mcp.list(dir ? { location: { directory: dir } } : undefined)
43+
void client.mcp
44+
.list(dir ? { location: { directory: dir } } : undefined)
4245
.then((result) => {
4346
if (dead) return
4447
setCatalog({ entries: [...result.data], loading: false, error: undefined })
@@ -50,7 +53,7 @@ export function useMcpCatalog(directory: Accessor<string | undefined>) {
5053

5154
const refreshStatus = async () => {
5255
try {
53-
const result = await client().mcp.status(dir ? { location: { directory: dir } } : undefined)
56+
const result = await client.mcp.status(dir ? { location: { directory: dir } } : undefined)
5457
if (dead) return
5558
setStatus("state", reconcile({ tag: "ready", status: result.data }))
5659
} catch (cause) {

‎packages/app/src/utils/mcp-catalog-client.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,10 @@ export const createMcpCatalogClient = (conn: ServerConnection.Any) => {
6565
}
6666

6767
export type McpCatalogClient = ReturnType<typeof createMcpCatalogClient>
68+
// Derived from the client's OWN return shape rather than re-exporting the client-next wire types
69+
// directly -- callers (use-mcp-catalog.ts) get the types they need without importing
70+
// `@opencode-ai/client-next` a second time, keeping the alias's surface bounded to this one file
71+
// (Copilot review, PR #36).
72+
export type McpListResult = Awaited<ReturnType<McpCatalogClient["mcp"]["list"]>>
73+
export type McpStatusResult = Awaited<ReturnType<McpCatalogClient["mcp"]["status"]>>
6874
export { isServiceUnavailableError }

0 commit comments

Comments
 (0)