Skip to content

Commit 4e70eab

Browse files
authored
fix(app): restore deferred MCP status updates (anomalyco#30220)
1 parent 1cae8f8 commit 4e70eab

2 files changed

Lines changed: 28 additions & 25 deletions

File tree

packages/app/src/context/global-sync/child-store.test.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { State } from "./types"
66
import type { QueryOptionsApi } from "../server-sync"
77

88
let createChildStoreManager: typeof import("./child-store").createChildStoreManager
9-
const queryGroups: Array<() => { queries: Array<{ enabled?: boolean }> }> = []
9+
const querySingles: Array<() => { queryKey?: unknown[]; enabled?: boolean }> = []
1010

1111
const child = () => createStore({} as State)
1212
const provider = { all: new Map(), connected: [], default: {} } satisfies NormalizedProviderListResponse
@@ -49,14 +49,19 @@ beforeAll(async () => {
4949
persisted: (_target: string, store: unknown[]) => [store[0], store[1], null, () => true],
5050
}))
5151
mock.module("@tanstack/solid-query", () => ({
52-
useQueries: (options: () => { queries: Array<{ enabled?: boolean }> }) => {
53-
queryGroups.push(options)
54-
return [
55-
{ isLoading: true, data: undefined },
56-
{ isLoading: false, data: {} },
57-
{ isLoading: false, data: [] },
58-
{ isLoading: false, data: provider },
59-
]
52+
useQuery: (options: () => { queryKey?: unknown[]; enabled?: boolean }) => {
53+
querySingles.push(options)
54+
return {
55+
get isLoading() {
56+
return options().queryKey?.[1] === "path"
57+
},
58+
get data() {
59+
if (options().queryKey?.[1] === "mcp") return options().enabled ? { demo: { status: "disabled" } } : undefined
60+
if (options().queryKey?.[1] === "lsp") return []
61+
if (options().queryKey?.[1] === "providers") return provider
62+
return undefined
63+
},
64+
}
6065
},
6166
}))
6267

@@ -159,7 +164,7 @@ describe("createChildStoreManager", () => {
159164

160165
test("enables MCP only when requested for the directory", () => {
161166
let manager: ReturnType<typeof createChildStoreManager> | undefined
162-
const offset = queryGroups.length
167+
const offset = querySingles.length
163168
const mcpLoads: string[] = []
164169

165170
const dispose = createOwner((owner) => {
@@ -180,18 +185,20 @@ describe("createChildStoreManager", () => {
180185

181186
try {
182187
if (!manager) throw new Error("manager required")
183-
const [, setStore] = manager.child("/project", { bootstrap: false })
184-
const queries = queryGroups[offset]
185-
if (!queries) throw new Error("queries required")
186-
expect(queries().queries[1]?.enabled).toBe(false)
188+
const [store, setStore] = manager.child("/project", { bootstrap: false })
189+
expect(querySingles.length - offset).toBe(4)
190+
const query = querySingles[offset + 1]
191+
if (!query) throw new Error("query required")
192+
expect(query().enabled).toBe(false)
187193

188194
setStore("status", "complete")
189195
manager.child("/project", { bootstrap: false, mcp: true })
190-
expect(queries().queries[1]?.enabled).toBe(true)
196+
expect(query().enabled).toBe(true)
197+
expect(store.mcp).toEqual({ demo: { status: "disabled" } })
191198
expect(mcpLoads).toEqual(["/project"])
192199

193200
manager.disableMcp("/project")
194-
expect(queries().queries[1]?.enabled).toBe(false)
201+
expect(query().enabled).toBe(false)
195202
expect(manager.mcp("/project")).toBe(false)
196203
} finally {
197204
dispose()

packages/app/src/context/global-sync/child-store.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
type VcsCache,
1515
} from "./types"
1616
import { canDisposeDirectory, pickDirectoriesToEvict } from "./eviction"
17-
import { useQueries } from "@tanstack/solid-query"
17+
import { useQuery } from "@tanstack/solid-query"
1818
import { QueryOptionsApi } from "../server-sync"
1919
import { directoryKey, type DirectoryKey } from "./utils"
2020
import { NormalizedProviderListResponse } from "@opencode-ai/ui/context"
@@ -180,14 +180,10 @@ export function createChildStoreManager(input: {
180180
const initialIcon = icon[0].value
181181
const [mcpEnabled, setMcpEnabled] = createSignal(false)
182182

183-
const [pathQuery, mcpQuery, lspQuery, providerQuery] = useQueries(() => ({
184-
queries: [
185-
input.queryOptions.path(key),
186-
{ ...input.queryOptions.mcp(key), enabled: mcpEnabled() },
187-
input.queryOptions.lsp(key),
188-
input.queryOptions.providers(key),
189-
],
190-
}))
183+
const pathQuery = useQuery(() => input.queryOptions.path(key))
184+
const mcpQuery = useQuery(() => ({ ...input.queryOptions.mcp(key), enabled: mcpEnabled() }))
185+
const lspQuery = useQuery(() => input.queryOptions.lsp(key))
186+
const providerQuery = useQuery(() => input.queryOptions.providers(key))
191187

192188
const child = createStore<State>({
193189
project: "",

0 commit comments

Comments
 (0)