@@ -6,7 +6,7 @@ import type { State } from "./types"
66import type { QueryOptionsApi } from "../server-sync"
77
88let createChildStoreManager : typeof import ( "./child-store" ) . createChildStoreManager
9- const queryGroups : Array < ( ) => { queries : Array < { enabled ?: boolean } > } > = [ ]
9+ const querySingles : Array < ( ) => { queryKey ?: unknown [ ] ; enabled ?: boolean } > = [ ]
1010
1111const child = ( ) => createStore ( { } as State )
1212const 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 ( )
0 commit comments