@@ -1445,6 +1445,7 @@ describe('MetadataApiDeploy', () => {
14451445 const connection = await testOrg . getConnection ( ) ;
14461446
14471447 const readFileStub = $$ . SANDBOX . stub ( fs . promises , 'readFile' ) . resolves ( agentContent ) ;
1448+ const refreshAuthStub = $$ . SANDBOX . stub ( Connection . prototype , 'refreshAuth' ) . resolves ( ) ;
14481449
14491450 $$ . SANDBOX . stub ( connection , 'getConnectionOptions' ) . returns ( {
14501451 accessToken : 'test-access-token' ,
@@ -1488,6 +1489,8 @@ describe('MetadataApiDeploy', () => {
14881489 expect ( callCount ) . to . be . at . least ( 2 ) ;
14891490 // Verify URL uses production endpoint when SF_TEST_API is not set
14901491 expect ( compileUrl ) . to . equal ( 'https://api.salesforce.com/einstein/ai-agent/v1.1/authoring/scripts' ) ;
1492+ // Regardless of success or failure, compileAABComponents should refresh auth.
1493+ expect ( refreshAuthStub . calledOnce ) . to . be . true ;
14911494 } ) ;
14921495
14931496 it ( 'should not throw error when compilation succeeds' , async ( ) => {
@@ -1496,6 +1499,7 @@ describe('MetadataApiDeploy', () => {
14961499
14971500 // Stub retrieveMaxApiVersion on prototype before getting connection
14981501 $$ . SANDBOX . stub ( Connection . prototype , 'retrieveMaxApiVersion' ) . resolves ( '60.0' ) ;
1502+ const refreshAuthStub = $$ . SANDBOX . stub ( Connection . prototype , 'refreshAuth' ) . resolves ( ) ;
14991503 const connection = await testOrg . getConnection ( ) ;
15001504
15011505 const readFileStub = $$ . SANDBOX . stub ( fs . promises , 'readFile' ) . resolves ( agentContent ) ;
@@ -1530,6 +1534,8 @@ describe('MetadataApiDeploy', () => {
15301534 expect ( callCount ) . to . be . at . least ( 2 ) ;
15311535 // Verify URL uses production endpoint when SF_TEST_API is not set
15321536 expect ( compileUrl ) . to . equal ( 'https://api.salesforce.com/einstein/ai-agent/v1.1/authoring/scripts' ) ;
1537+ // Regardless of success or failure, compileAABComponents should refresh auth.
1538+ expect ( refreshAuthStub . calledOnce ) . to . be . true ;
15331539 } ) ;
15341540
15351541 it ( 'should not compile when no AABs present in component set' , async ( ) => {
@@ -1669,6 +1675,7 @@ describe('MetadataApiDeploy', () => {
16691675
16701676 // Stub retrieveMaxApiVersion on prototype before getting connection
16711677 $$ . SANDBOX . stub ( Connection . prototype , 'retrieveMaxApiVersion' ) . resolves ( '60.0' ) ;
1678+ const refreshAuthStub = $$ . SANDBOX . stub ( Connection . prototype , 'refreshAuth' ) . resolves ( ) ;
16721679 const connection = await testOrg . getConnection ( ) ;
16731680
16741681 const readFileStub = $$ . SANDBOX . stub ( fs . promises , 'readFile' ) . resolves ( agentContent ) ;
@@ -1705,6 +1712,8 @@ describe('MetadataApiDeploy', () => {
17051712 expect ( ( e as Error ) . name ) . to . equal ( 'ERROR_HTTP_404' ) ;
17061713 expect ( ( e as SfError ) . actions ! . length ) . to . equal ( 2 ) ;
17071714 }
1715+ // Regardless of success or failure, compileAABComponents should refresh auth.
1716+ expect ( refreshAuthStub . calledOnce ) . to . be . true ;
17081717 } ) ;
17091718
17101719 it ( 'should not compile when SF_AAB_COMPILATION=false' , async ( ) => {
0 commit comments