@@ -43,6 +43,7 @@ describe('lib/project-base', () => {
4343 this . testStudioManager = {
4444 initializeRoutes : ( ) => { } ,
4545 status : 'INITIALIZED' ,
46+ destroy : ( ) => Promise . resolve ( ) ,
4647 }
4748
4849 sinon . stub ( studio , 'getAndInitializeStudioManager' ) . resolves ( this . testStudioManager )
@@ -736,18 +737,20 @@ This option will not have an effect in Some-other-name. Tests that rely on web s
736737 it ( 'passes onStudioInit callback with AI enabled and a protocol manager' , async function ( ) {
737738 const mockSetupProtocol = sinon . stub ( )
738739 const mockBeforeSpec = sinon . stub ( )
739- const mockAccessStudioLLM = sinon . stub ( ) . resolves ( true )
740- const mockSetProtocolDb = sinon . stub ( )
740+ const mockAccessStudioAI = sinon . stub ( ) . resolves ( true )
741+ const mockSetProtocolDbPath = sinon . stub ( )
742+ const mockInitializeStudioAI = sinon . stub ( ) . resolves ( )
741743
742744 this . project . spec = { }
743745 this . project . ctx . coreData . studio = {
744- canAccessStudioAI : mockAccessStudioLLM ,
746+ canAccessStudioAI : mockAccessStudioAI ,
745747 protocolManager : {
746748 setupProtocol : mockSetupProtocol ,
747749 beforeSpec : mockBeforeSpec ,
748- db : { test : 'db' } ,
750+ dbPath : 'test-db-path' ,
749751 } ,
750- setProtocolDb : mockSetProtocolDb ,
752+ setProtocolDbPath : mockSetProtocolDbPath ,
753+ initializeStudioAI : mockInitializeStudioAI ,
751754 }
752755
753756 sinon . stub ( browsers , 'connectProtocolToBrowser' ) . resolves ( )
@@ -783,7 +786,7 @@ This option will not have an effect in Some-other-name. Tests that rely on web s
783786
784787 expect ( mockSetupProtocol ) . to . be . calledOnce
785788 expect ( mockBeforeSpec ) . to . be . calledOnce
786- expect ( mockAccessStudioLLM ) . to . be . calledWith ( {
789+ expect ( mockAccessStudioAI ) . to . be . calledWith ( {
787790 family : 'chromium' ,
788791 name : 'chrome' ,
789792 channel : 'stable' ,
@@ -796,17 +799,66 @@ This option will not have an effect in Some-other-name. Tests that rely on web s
796799 } )
797800
798801 expect ( this . project [ '_protocolManager' ] ) . to . eq ( this . project . ctx . coreData . studio . protocolManager )
799- expect ( mockSetProtocolDb ) . to . be . calledWith ( { test : 'db' } )
802+ expect ( mockInitializeStudioAI ) . to . be . calledWith ( {
803+ protocolDbPath : 'test-db-path' ,
804+ } )
805+ } )
806+
807+ it ( 'handles case where protocol manager db path is not set' , async function ( ) {
808+ const mockSetupProtocol = sinon . stub ( )
809+ const mockBeforeSpec = sinon . stub ( )
810+ const mockAccessStudioAI = sinon . stub ( ) . resolves ( true )
811+ const mockSetProtocolDbPath = sinon . stub ( )
812+ const mockInitializeStudioAI = sinon . stub ( ) . resolves ( )
813+
814+ this . project . spec = { }
815+ this . project . ctx . coreData . studio = {
816+ canAccessStudioAI : mockAccessStudioAI ,
817+ protocolManager : {
818+ setupProtocol : mockSetupProtocol ,
819+ beforeSpec : mockBeforeSpec ,
820+ dbPath : null ,
821+ } ,
822+ setProtocolDbPath : mockSetProtocolDbPath ,
823+ initializeStudioAI : mockInitializeStudioAI ,
824+ }
825+
826+ sinon . stub ( browsers , 'connectProtocolToBrowser' ) . resolves ( )
827+
828+ this . project . browser = {
829+ name : 'chrome' ,
830+ family : 'chromium' ,
831+ channel : 'stable' ,
832+ }
833+
834+ this . project . options . browsers = [ {
835+ name : 'chrome' ,
836+ family : 'chromium' ,
837+ channel : 'stable' ,
838+ } ]
839+
840+ let studioInitPromise
841+
842+ this . project . server . startWebsockets . callsFake ( async ( automation , config , callbacks ) => {
843+ studioInitPromise = callbacks . onStudioInit ( )
844+ } )
845+
846+ this . project . startWebsockets ( { } , { } )
847+
848+ const { canAccessStudioAI } = await studioInitPromise
849+
850+ expect ( canAccessStudioAI ) . to . be . false
851+ expect ( this . project [ '_protocolManager' ] ) . to . be . undefined
800852 } )
801853
802854 it ( 'passes onStudioInit callback with AI enabled but no protocol manager' , async function ( ) {
803855 const mockSetupProtocol = sinon . stub ( )
804856 const mockBeforeSpec = sinon . stub ( )
805- const mockAccessStudioLLM = sinon . stub ( ) . resolves ( true )
857+ const mockAccessStudioAI = sinon . stub ( ) . resolves ( true )
806858
807859 this . project . spec = { }
808860 this . project . ctx . coreData . studio = {
809- canAccessStudioAI : mockAccessStudioLLM ,
861+ canAccessStudioAI : mockAccessStudioAI ,
810862 }
811863
812864 this . project . browser = {
@@ -836,20 +888,20 @@ This option will not have an effect in Some-other-name. Tests that rely on web s
836888
837889 expect ( mockSetupProtocol ) . not . to . be . called
838890 expect ( mockBeforeSpec ) . not . to . be . called
839- expect ( mockAccessStudioLLM ) . not . to . be . called
891+ expect ( mockAccessStudioAI ) . not . to . be . called
840892
841893 expect ( browsers . connectProtocolToBrowser ) . not . to . be . called
842894 expect ( this . project [ '_protocolManager' ] ) . to . be . undefined
843895 } )
844896
845- it ( 'passes onStudioInit callback with llm disabled' , async function ( ) {
897+ it ( 'passes onStudioInit callback with AI disabled' , async function ( ) {
846898 const mockSetupProtocol = sinon . stub ( )
847899 const mockBeforeSpec = sinon . stub ( )
848- const mockAccessStudioLLM = sinon . stub ( ) . resolves ( false )
900+ const mockAccessStudioAI = sinon . stub ( ) . resolves ( false )
849901
850902 this . project . spec = { }
851903 this . project . ctx . coreData . studio = {
852- canAccessStudioAI : mockAccessStudioLLM ,
904+ canAccessStudioAI : mockAccessStudioAI ,
853905 protocolManager : {
854906 setupProtocol : mockSetupProtocol ,
855907 beforeSpec : mockBeforeSpec ,
@@ -887,9 +939,11 @@ This option will not have an effect in Some-other-name. Tests that rely on web s
887939
888940 it ( 'passes onStudioDestroy callback' , async function ( ) {
889941 const mockClose = sinon . stub ( )
942+ const mockDestroy = sinon . stub ( ) . resolves ( )
890943
891944 this . project . ctx . coreData . studio = {
892945 protocolManager : { } ,
946+ destroy : mockDestroy ,
893947 }
894948
895949 sinon . stub ( browsers , 'closeProtocolConnection' ) . resolves ( )
@@ -928,7 +982,7 @@ This option will not have an effect in Some-other-name. Tests that rely on web s
928982 } )
929983
930984 expect ( mockClose ) . to . be . calledOnce
931-
985+ expect ( mockDestroy ) . to . be . calledOnce
932986 expect ( this . project [ '_protocolManager' ] ) . to . be . undefined
933987 } )
934988 } )
0 commit comments