88 bootstrapDirectory ,
99 loadAgentsQuery ,
1010 loadCommands ,
11+ loadGlobalConfigQuery ,
1112 loadPathQuery ,
1213 loadProjectsQuery ,
1314 loadProvidersQuery ,
@@ -76,6 +77,7 @@ function directoryState() {
7677
7778describe ( "bootstrapDirectory" , ( ) => {
7879 test ( "uses legacy MCP endpoints while refreshing a v1 directory" , async ( ) => {
80+ const legacyConfigReads : string [ ] = [ ]
7981 const mcpReads : string [ ] = [ ]
8082 const [ store , setStore ] = directoryState ( )
8183
@@ -91,7 +93,12 @@ describe("bootstrapDirectory", () => {
9193 } ,
9294 sdk : {
9395 app : { agents : async ( ) => ( { data : [ { name : "build" , mode : "primary" } ] } ) } ,
94- config : { get : async ( ) => ( { data : { } } ) } ,
96+ config : {
97+ get : async ( ) => {
98+ legacyConfigReads . push ( "directory" )
99+ return { data : { } }
100+ } ,
101+ } ,
95102 session : { status : async ( ) => ( { data : { } } ) } ,
96103 vcs : { get : async ( ) => ( { data : undefined } ) } ,
97104 command : {
@@ -134,8 +141,88 @@ describe("bootstrapDirectory", () => {
134141 await new Promise ( ( resolve ) => setTimeout ( resolve , 80 ) )
135142
136143 expect ( store . status ) . toBe ( "complete" )
144+ expect ( legacyConfigReads ) . toEqual ( [ "directory" ] )
137145 expect ( mcpReads . sort ( ) ) . toEqual ( [ "command" , "resource" , "status" ] )
138146 } )
147+
148+ test ( "skips legacy config while refreshing a v2 directory" , async ( ) => {
149+ const [ store , setStore ] = directoryState ( )
150+
151+ await bootstrapDirectory ( {
152+ directory : "/project" ,
153+ scope : ServerScope . local ,
154+ mcp : false ,
155+ global : {
156+ config : { } satisfies Config ,
157+ path : { state : "" , config : "" , worktree : "/project" , directory : "/project" , home : "/home" } ,
158+ project : [ { id : "project" , worktree : "/project" } as Project ] ,
159+ provider,
160+ } ,
161+ sdk : {
162+ config : {
163+ get : async ( ) => {
164+ throw new Error ( "legacy directory config should not be called" )
165+ } ,
166+ } ,
167+ } as unknown as OpencodeClient ,
168+ api,
169+ store,
170+ setStore,
171+ vcsCache : { setStore ( ) { } } as unknown as VcsCache ,
172+ loadSessions ( ) { } ,
173+ translate : ( key ) => key ,
174+ queryClient : new QueryClient ( ) ,
175+ protocol : Promise . resolve ( "v2" ) ,
176+ } )
177+
178+ expect ( store . status ) . toBe ( "partial" )
179+
180+ await new Promise ( ( resolve ) => setTimeout ( resolve , 80 ) )
181+
182+ expect ( store . status ) . toBe ( "complete" )
183+ } )
184+ } )
185+
186+ describe ( "config queries" , ( ) => {
187+ test ( "skips legacy global config for v2 servers" , async ( ) => {
188+ const sdk = {
189+ global : {
190+ config : {
191+ get : async ( ) => {
192+ throw new Error ( "legacy global config should not be called" )
193+ } ,
194+ } ,
195+ } ,
196+ } as unknown as OpencodeClient
197+
198+ const result = await new QueryClient ( ) . fetchQuery (
199+ loadGlobalConfigQuery ( ServerScope . local , sdk , Promise . resolve ( "v2" ) ) ,
200+ )
201+
202+ expect ( result ) . toEqual ( { } )
203+ } )
204+
205+ test ( "loads legacy global config for v1 servers" , async ( ) => {
206+ const calls : string [ ] = [ ]
207+ const config = { shell : "zsh" } satisfies Config
208+ const sdk = {
209+ global : {
210+ config : {
211+ get : async ( ) => {
212+ calls . push ( "global" )
213+ return { data : config }
214+ } ,
215+ } ,
216+ } ,
217+ } as unknown as OpencodeClient
218+
219+ const result = await new QueryClient ( ) . fetchQuery (
220+ loadGlobalConfigQuery ( ServerScope . local , sdk , Promise . resolve ( "v1" ) ) ,
221+ )
222+
223+ expect ( result ) . toEqual ( config )
224+ expect ( calls ) . toEqual ( [ "global" ] )
225+ } )
139226} )
140227
141228describe ( "query keys" , ( ) => {
0 commit comments