@@ -538,29 +538,30 @@ describe('StackCloneCommand', () => {
538538 }
539539 } ) ;
540540
541- it . skip ( 'should exit when not authenticated and no management token aliases' , async ( ) => {
541+ it ( 'should exit when not authenticated and no management token aliases' , async ( ) => {
542542 const parseStub = sandbox . stub ( command , 'parse' as any ) . resolves ( {
543543 flags : mockFlags ,
544544 } ) ;
545- const exitStub = sandbox . stub ( command , 'exit' as any ) . callsFake ( ( ( ) => {
546- throw new Error ( 'exit called' ) ;
547- } ) as ( ) => never ) ;
545+ const configHandlerGetStub = sandbox . stub ( cliUtilities . configHandler , 'get' ) . returns ( undefined ) ;
546+ const configHandlerSetStub = sandbox . stub ( cliUtilities . configHandler , 'set' ) ;
547+ const logStub = { error : sandbox . stub ( ) , warn : sandbox . stub ( ) , debug : sandbox . stub ( ) , info : sandbox . stub ( ) } ;
548+ sandbox . stub ( cliUtilities , 'log' ) . value ( logStub ) ;
549+ // exit(1) throws inside run()'s own try/catch which swallows it — stub cleanUp to
550+ // prevent real filesystem ops and assert on exitStub directly after run() settles.
551+ const cleanUpStub = sandbox . stub ( command , 'cleanUp' ) . resolves ( ) ;
552+ const exitStub = sandbox . stub ( command , 'exit' as any ) ;
548553
549- // Only test if not authenticated
550- if ( ! cliUtilities . isAuthenticated ( ) ) {
551- try {
552- await command . run ( ) ;
553- expect . fail ( 'Should have exited' ) ;
554- } catch ( error : any ) {
555- expect ( error . message ) . to . equal ( 'exit called' ) ;
556- }
554+ await command . run ( ) ;
557555
558- expect ( parseStub . calledOnce ) . to . be . true ;
559- expect ( exitStub . calledOnce ) . to . be . true ;
560- }
556+ expect ( parseStub . calledOnce ) . to . be . true ;
557+ expect ( exitStub . calledOnce ) . to . be . true ;
558+ expect ( logStub . error . called ) . to . be . true ;
559+ expect ( logStub . error . firstCall . args [ 0 ] ) . to . include ( 'Please login' ) ;
560+ // progressSupportedModule must NOT be set when auth fails
561+ expect ( configHandlerSetStub . calledWith ( 'log.progressSupportedModule' , 'clone' ) ) . to . be . false ;
561562 } ) ;
562563
563- it . skip ( 'should exit when management token aliases provided but not authenticated and branches provided' , async ( ) => {
564+ it ( 'should exit when management token aliases provided but not authenticated and branches provided' , async ( ) => {
564565 const parseStub = sandbox . stub ( command , 'parse' as any ) . resolves ( {
565566 flags : {
566567 ...mockFlags ,
@@ -569,22 +570,21 @@ describe('StackCloneCommand', () => {
569570 'source-branch' : 'main' ,
570571 } ,
571572 } ) ;
572- const exitStub = sandbox . stub ( command , 'exit' as any ) . callsFake ( ( ( ) => {
573- throw new Error ( 'exit called' ) ;
574- } ) as ( ) => never ) ;
573+ const configHandlerGetStub = sandbox . stub ( cliUtilities . configHandler , 'get' ) . returns ( undefined ) ;
574+ const configHandlerSetStub = sandbox . stub ( cliUtilities . configHandler , 'set' ) ;
575+ const logStub = { error : sandbox . stub ( ) , warn : sandbox . stub ( ) , debug : sandbox . stub ( ) , info : sandbox . stub ( ) } ;
576+ sandbox . stub ( cliUtilities , 'log' ) . value ( logStub ) ;
577+ const cleanUpStub = sandbox . stub ( command , 'cleanUp' ) . resolves ( ) ;
578+ const exitStub = sandbox . stub ( command , 'exit' as any ) ;
575579
576- // Only test if not authenticated
577- if ( ! cliUtilities . isAuthenticated ( ) ) {
578- try {
579- await command . run ( ) ;
580- expect . fail ( 'Should have exited' ) ;
581- } catch ( error : any ) {
582- expect ( error . message ) . to . equal ( 'exit called' ) ;
583- }
580+ await command . run ( ) ;
584581
585- expect ( parseStub . calledOnce ) . to . be . true ;
586- expect ( exitStub . calledOnce ) . to . be . true ;
587- }
582+ expect ( parseStub . calledOnce ) . to . be . true ;
583+ expect ( exitStub . calledOnce ) . to . be . true ;
584+ expect ( logStub . error . called ) . to . be . true ;
585+ expect ( logStub . error . firstCall . args [ 0 ] ) . to . include ( 'Log in' ) ;
586+ // progressSupportedModule must NOT be set when auth fails
587+ expect ( configHandlerSetStub . calledWith ( 'log.progressSupportedModule' , 'clone' ) ) . to . be . false ;
588588 } ) ;
589589
590590 it ( 'should handle run error and cleanup' , async ( ) => {
@@ -794,6 +794,7 @@ describe('StackCloneCommand', () => {
794794 'destination-management-token-alias' : 'dest-alias' ,
795795 } ,
796796 } ) ;
797+ const configHandlerSetStub = sandbox . stub ( cliUtilities . configHandler , 'set' ) ;
797798 const configHandlerStub = sandbox . stub ( cliUtilities . configHandler , 'get' ) ;
798799 // Stub authorisationType to 'OAUTH' to make isAuthenticated() return true
799800 configHandlerStub . callsFake ( ( key : string ) => {
@@ -835,6 +836,8 @@ describe('StackCloneCommand', () => {
835836 expect ( cloneHandlerExecuteStub . calledOnce ) . to . be . true ;
836837 // Verify all config flags were set
837838 expect ( logStub . debug . called ) . to . be . true ;
839+ // progressSupportedModule must be set inside handleClone (after auth passes)
840+ expect ( configHandlerSetStub . calledWith ( 'log.progressSupportedModule' , 'clone' ) ) . to . be . true ;
838841 } ) ;
839842
840843 it ( 'should handle CloneHandler.execute error (covers line 263)' , async ( ) => {
0 commit comments