@@ -80,44 +80,50 @@ const { shouldProcessEventForTesthub, checkAndSetAccessibility, findAvailablePor
8080const TestHubHandler = require ( '../testhub/testhubHandler' ) ;
8181const testObservabilityConstants = require ( '../testObservability/helper/constants' ) ;
8282
83- // Helper function to check accessibility auto-enable status via separate API call
84- const checkAccessibilityAutoEnableStatus = async ( bsConfig , buildId ) => {
83+ // Helper function to check accessibility via existing Test Observability session
84+ const checkAccessibilityViaTestHub = async ( bsConfig , buildId ) => {
8585 try {
86- logToServer ( `Aakash CBT checkAccessibilityAutoEnableStatus - Starting API call for buildId: ${ buildId } ` ) ;
86+ // Only proceed if Test Observability is enabled and we have proper authentication
87+ if ( ! process . env . BS_TESTOPS_JWT || ! process . env . BS_TESTOPS_BUILD_HASHED_ID ) {
88+ logToServer ( `Aakash CBT checkAccessibilityViaTestHub - No Test Observability JWT available, skipping accessibility check` ) ;
89+ return null ;
90+ }
91+
92+ logToServer ( `Aakash CBT checkAccessibilityViaTestHub - Starting API call with JWT for build: ${ process . env . BS_TESTOPS_BUILD_HASHED_ID } ` ) ;
8793
8894 const axios = require ( 'axios' ) ;
89- // Use the same Test Observability API endpoint as C# SDK - get build details
90- // This mimics the C# SDK approach where build creation response contains accessibility info
91- const url = `${ testObservabilityConstants . API_URL } /api/v2/builds/${ buildId } ` ;
95+ // Use Test Observability build details endpoint
96+ const url = `${ testObservabilityConstants . API_URL } /api/v2/builds/${ process . env . BS_TESTOPS_BUILD_HASHED_ID } ` ;
9297
9398 const requestOptions = {
9499 url : url ,
95100 method : 'GET' ,
96101 headers : {
97- 'Authorization' : `Basic ${ Buffer . from ( ` ${ bsConfig . auth . username } : ${ bsConfig . auth . access_key } ` ) . toString ( 'base64' ) } ` ,
102+ 'Authorization' : `Bearer ${ process . env . BS_TESTOPS_JWT } ` ,
98103 'Content-Type' : 'application/json' ,
104+ 'X-BSTACK-TESTOPS' : 'true' ,
99105 'User-Agent' : `${ config . userAgentPrefix } /${ pkg . version } `
100106 } ,
101107 timeout : 10000
102108 } ;
103109
104- logToServer ( `Aakash CBT checkAccessibilityAutoEnableStatus - Making request to Test Observability API: ${ url } ` ) ;
110+ logToServer ( `Aakash CBT checkAccessibilityViaTestHub - Making request to Test Observability API with JWT : ${ url } ` ) ;
105111
106112 const response = await axios ( requestOptions ) ;
107113
108- logToServer ( `Aakash CBT checkAccessibilityAutoEnableStatus - Response status: ${ response . status } , data: ${ JSON . stringify ( response . data , null , 2 ) } ` ) ;
114+ logToServer ( `Aakash CBT checkAccessibilityViaTestHub - Response status: ${ response . status } , data: ${ JSON . stringify ( response . data , null , 2 ) } ` ) ;
109115
110116 if ( response . status === 200 && response . data ) {
111117 return response . data ;
112118 }
113119
114- logToServer ( `Aakash CBT checkAccessibilityAutoEnableStatus - Invalid response status: ${ response . status } ` ) ;
120+ logToServer ( `Aakash CBT checkAccessibilityViaTestHub - Invalid response status: ${ response . status } ` ) ;
115121 return null ;
116122
117123 } catch ( error ) {
118124 // Don't fail the build if accessibility status check fails
119- logToServer ( `Aakash CBT checkAccessibilityAutoEnableStatus - Error: ${ error . message } , status: ${ error . response ?. status } , data: ${ JSON . stringify ( error . response ?. data ) } ` ) ;
120- logger . debug ( `Accessibility status check failed: ${ error . message } ` ) ;
125+ logToServer ( `Aakash CBT checkAccessibilityViaTestHub - Error: ${ error . message } , status: ${ error . response ?. status } , data: ${ JSON . stringify ( error . response ?. data ) } ` ) ;
126+ logger . debug ( `Test Observability accessibility check failed: ${ error . message } ` ) ;
121127 return null ;
122128 }
123129} ;
@@ -566,19 +572,20 @@ module.exports = function run(args, rawArgs) {
566572 // Additional API call to check accessibility auto-enable status (like C# SDK)
567573 let statusAutoEnabled = false ;
568574 if ( ! accessibilityAutoEnabled && data . build_id ) {
569- logToServer ( `Aakash CBT Build Creation - Making separate accessibility status API call for build: ${ data . build_id } ` ) ;
575+ logToServer ( `Aakash CBT Build Creation - Making Test Observability accessibility check for build: ${ data . build_id } ` ) ;
570576
571577 try {
572- const statusResponse = await checkAccessibilityAutoEnableStatus ( bsConfig , data . build_id ) ;
578+ // Use JWT-based Test Observability API call instead of Basic Auth
579+ const statusResponse = await checkAccessibilityViaTestHub ( bsConfig , data . build_id ) ;
573580 if ( statusResponse ) {
574581 statusAutoEnabled = processAccessibilityStatusResponse ( bsConfig , statusResponse ) ;
575582 if ( statusAutoEnabled ) {
576- logger . info ( "Accessibility has been auto-enabled based on separate status API call" ) ;
583+ logger . info ( "Accessibility has been auto-enabled based on Test Observability API call" ) ;
577584 }
578585 }
579586 } catch ( error ) {
580- logToServer ( `Aakash CBT Build Creation - Error in accessibility status API call : ${ error . message } ` ) ;
581- logger . debug ( `Accessibility status API call failed: ${ error . message } ` ) ;
587+ logToServer ( `Aakash CBT Build Creation - Error in Test Observability accessibility check : ${ error . message } ` ) ;
588+ logger . debug ( `Test Observability accessibility check failed: ${ error . message } ` ) ;
582589 }
583590 }
584591
0 commit comments