@@ -59,6 +59,7 @@ suite("DabTool Tests", () => {
5959 tables : SchemaDesigner . Table [ ] ;
6060 dabConfig ?: Dab . DabConfig | null ;
6161 initialized ?: boolean ;
62+ waitForInitialization ?: sinon . SinonStub ;
6263 } ) => {
6364 let currentTables = params . tables ;
6465 let currentDabConfig = params . dabConfig ?? null ;
@@ -67,6 +68,8 @@ suite("DabTool Tests", () => {
6768 const commitSpy = sandbox . spy ( ( config : Dab . DabConfig ) => {
6869 currentDabConfig = config ;
6970 } ) ;
71+ const waitForInitialization =
72+ params . waitForInitialization ?? sandbox . stub ( ) . resolves ( params . initialized ?? true ) ;
7073
7174 const extensionRpc = {
7275 onRequest : sandbox . stub ( ) . callsFake ( ( type : any , handler : any ) => {
@@ -77,6 +80,7 @@ suite("DabTool Tests", () => {
7780 registerSchemaDesignerDabToolHandlers ( {
7881 extensionRpc : extensionRpc as any ,
7982 isInitializedRef,
83+ waitForInitialization,
8084 getCurrentDabConfig : ( ) => currentDabConfig ,
8185 getCurrentSchemaTables : ( ) => currentTables ,
8286 commitDabConfig : commitSpy ,
@@ -92,6 +96,8 @@ suite("DabTool Tests", () => {
9296 } ,
9397 getConfig : ( ) => currentDabConfig ,
9498 commitSpy,
99+ waitForInitialization,
100+ isInitializedRef,
95101 } ;
96102 } ;
97103
@@ -155,19 +161,6 @@ suite("DabTool Tests", () => {
155161 const mockDesigner = sandbox . createStubInstance ( SchemaDesignerWebviewController ) ;
156162 sandbox . stub ( mockDesigner as any , "server" ) . get ( ( ) => sampleServer ) ;
157163 sandbox . stub ( mockDesigner as any , "database" ) . get ( ( ) => sampleDatabase ) ;
158- mockDesigner . getDabToolState . resolves ( {
159- returnState : "full" ,
160- version : "dabcfg_state" ,
161- summary : {
162- entityCount : 2 ,
163- enabledEntityCount : 1 ,
164- apiTypes : [ Dab . ApiType . Rest ] ,
165- } ,
166- config : Dab . createDefaultConfig ( [
167- createTable ( "t1" , "dbo" , "Users" ) ,
168- createTable ( "t2" , "sales" , "Orders" ) ,
169- ] ) ,
170- } ) ;
171164 showDabStub . resolves ( mockDesigner ) ;
172165
173166 const options = {
@@ -180,21 +173,17 @@ suite("DabTool Tests", () => {
180173 const parsed = JSON . parse ( await dabTool . call ( options , mockToken ) ) ;
181174 expect ( parsed . success ) . to . equal ( true ) ;
182175 expect ( parsed . message ) . to . equal ( loc . dabToolShowSuccessMessage ) ;
183- expect ( parsed . version ) . to . equal ( "dabcfg_state" ) ;
184- expect ( parsed . summary ) . to . deep . equal ( {
185- entityCount : 2 ,
186- enabledEntityCount : 1 ,
187- apiTypes : [ Dab . ApiType . Rest ] ,
188- } ) ;
189176 expect ( parsed . recommendedTool ) . to . equal ( "mssql_dab" ) ;
190177 expect ( parsed . recommendedNextCall ) . to . deep . equal ( {
191178 operation : "get_state" ,
192179 } ) ;
193180 expect ( parsed . server ) . to . equal ( sampleServer ) ;
194181 expect ( parsed . database ) . to . equal ( sampleDatabase ) ;
195182 expect ( parsed ) . to . not . have . property ( "config" ) ;
183+ expect ( parsed ) . to . not . have . property ( "version" ) ;
184+ expect ( parsed ) . to . not . have . property ( "summary" ) ;
196185 expect ( showDabStub . calledOnceWith ( sampleConnectionId , sampleDatabase ) ) . to . equal ( true ) ;
197- expect ( mockDesigner . getDabToolState . calledOnce ) . to . equal ( true ) ;
186+ expect ( mockDesigner . getDabToolState . called ) . to . equal ( false ) ;
198187 } ) ;
199188
200189 test ( "returns no_active_designer when there is no active schema designer" , async ( ) => {
@@ -733,7 +722,7 @@ suite("DabTool Tests", () => {
733722 expect ( state ) . to . not . have . property ( "config" ) ;
734723 } ) ;
735724
736- test ( "get_state throws when handlers are not initialized " , async ( ) => {
725+ test ( "get_state throws when initialization does not complete " , async ( ) => {
737726 const harness = createDabHandlerHarness ( {
738727 tables : [ createTable ( "t1" , "dbo" , "Users" ) ] ,
739728 dabConfig : null ,
@@ -748,11 +737,32 @@ suite("DabTool Tests", () => {
748737 }
749738
750739 expect ( caughtError ) . to . be . instanceOf ( Error ) ;
740+ expect ( harness . waitForInitialization . calledOnce ) . to . equal ( true ) ;
751741 expect ( ( caughtError as Error ) . message ) . to . equal (
752742 locConstants . schemaDesigner . schemaDesignerNotInitialized ,
753743 ) ;
754744 } ) ;
755745
746+ test ( "get_state waits for initialization before returning state" , async ( ) => {
747+ let harness : ReturnType < typeof createDabHandlerHarness > ;
748+ const waitForInitialization = sandbox . stub ( ) . callsFake ( async ( ) => {
749+ harness . isInitializedRef . current = true ;
750+ return true ;
751+ } ) ;
752+ harness = createDabHandlerHarness ( {
753+ tables : [ createTable ( "t1" , "dbo" , "Users" ) ] ,
754+ dabConfig : null ,
755+ initialized : false ,
756+ waitForInitialization,
757+ } ) ;
758+
759+ const state = await harness . getState ( ) ;
760+
761+ expect ( waitForInitialization . calledOnce ) . to . equal ( true ) ;
762+ expect ( state . returnState ) . to . equal ( "full" ) ;
763+ expect ( state . summary . entityCount ) . to . equal ( 1 ) ;
764+ } ) ;
765+
756766 test ( "get_state avoids commit when config is already synchronized with schema" , async ( ) => {
757767 const tables = [
758768 createTable ( "t1" , "dbo" , "Users" ) ,
0 commit comments