|
|
@@ -6,7 +6,7 @@ import type { State } from "./types"
|
|
|
import type { QueryOptionsApi } from "../server-sync"
|
|
|
|
|
|
let createChildStoreManager: typeof import("./child-store").createChildStoreManager
|
|
|
-const queryGroups: Array<() => { queries: Array<{ enabled?: boolean }> }> = []
|
|
|
+const querySingles: Array<() => { queryKey?: unknown[]; enabled?: boolean }> = []
|
|
|
|
|
|
const child = () => createStore({} as State)
|
|
|
const provider = { all: new Map(), connected: [], default: {} } satisfies NormalizedProviderListResponse
|
|
|
@@ -49,14 +49,19 @@ beforeAll(async () => {
|
|
|
persisted: (_target: string, store: unknown[]) => [store[0], store[1], null, () => true],
|
|
|
}))
|
|
|
mock.module("@tanstack/solid-query", () => ({
|
|
|
- useQueries: (options: () => { queries: Array<{ enabled?: boolean }> }) => {
|
|
|
- queryGroups.push(options)
|
|
|
- return [
|
|
|
- { isLoading: true, data: undefined },
|
|
|
- { isLoading: false, data: {} },
|
|
|
- { isLoading: false, data: [] },
|
|
|
- { isLoading: false, data: provider },
|
|
|
- ]
|
|
|
+ useQuery: (options: () => { queryKey?: unknown[]; enabled?: boolean }) => {
|
|
|
+ querySingles.push(options)
|
|
|
+ return {
|
|
|
+ get isLoading() {
|
|
|
+ return options().queryKey?.[1] === "path"
|
|
|
+ },
|
|
|
+ get data() {
|
|
|
+ if (options().queryKey?.[1] === "mcp") return options().enabled ? { demo: { status: "disabled" } } : undefined
|
|
|
+ if (options().queryKey?.[1] === "lsp") return []
|
|
|
+ if (options().queryKey?.[1] === "providers") return provider
|
|
|
+ return undefined
|
|
|
+ },
|
|
|
+ }
|
|
|
},
|
|
|
}))
|
|
|
|
|
|
@@ -159,7 +164,7 @@ describe("createChildStoreManager", () => {
|
|
|
|
|
|
test("enables MCP only when requested for the directory", () => {
|
|
|
let manager: ReturnType<typeof createChildStoreManager> | undefined
|
|
|
- const offset = queryGroups.length
|
|
|
+ const offset = querySingles.length
|
|
|
const mcpLoads: string[] = []
|
|
|
|
|
|
const dispose = createOwner((owner) => {
|
|
|
@@ -180,18 +185,20 @@ describe("createChildStoreManager", () => {
|
|
|
|
|
|
try {
|
|
|
if (!manager) throw new Error("manager required")
|
|
|
- const [, setStore] = manager.child("/project", { bootstrap: false })
|
|
|
- const queries = queryGroups[offset]
|
|
|
- if (!queries) throw new Error("queries required")
|
|
|
- expect(queries().queries[1]?.enabled).toBe(false)
|
|
|
+ const [store, setStore] = manager.child("/project", { bootstrap: false })
|
|
|
+ expect(querySingles.length - offset).toBe(4)
|
|
|
+ const query = querySingles[offset + 1]
|
|
|
+ if (!query) throw new Error("query required")
|
|
|
+ expect(query().enabled).toBe(false)
|
|
|
|
|
|
setStore("status", "complete")
|
|
|
manager.child("/project", { bootstrap: false, mcp: true })
|
|
|
- expect(queries().queries[1]?.enabled).toBe(true)
|
|
|
+ expect(query().enabled).toBe(true)
|
|
|
+ expect(store.mcp).toEqual({ demo: { status: "disabled" } })
|
|
|
expect(mcpLoads).toEqual(["/project"])
|
|
|
|
|
|
manager.disableMcp("/project")
|
|
|
- expect(queries().queries[1]?.enabled).toBe(false)
|
|
|
+ expect(query().enabled).toBe(false)
|
|
|
expect(manager.mcp("/project")).toBe(false)
|
|
|
} finally {
|
|
|
dispose()
|