@@ -204,4 +204,56 @@ describe('attach remote', function () {
204204 // we are testing is whether afterEach() can still disconnect after
205205 // having killed the gdbserver.
206206 } ) ;
207+
208+ it ( 'executes preConnectCommands before target connection and initCommands' , async function ( ) {
209+ // Capture all stdout output
210+ const stdOutput : string [ ] = [ ] ;
211+ dc . on ( 'output' , ( event ) => {
212+ if ( event . body . category === 'stdout' ) {
213+ stdOutput . push ( event . body . output ) ;
214+ }
215+ } ) ;
216+
217+ // Use shell echo with string concatenation to avoid the marker strings
218+ // appearing literally in the command definition
219+ const preMarker = 'PRE_CMD_EXEC' ;
220+ const initMarker = 'INIT_CMD_EXEC' ;
221+
222+ const attachArgs = fillDefaults ( this . test , {
223+ program : program ,
224+ openGdbConsole : false ,
225+ preConnectCommands : [
226+ `shell echo ${ preMarker . substring ( 0 , 7 ) } ${ preMarker . substring ( 7 ) } ` ,
227+ ] ,
228+ initCommands : [
229+ `shell echo ${ initMarker . substring ( 0 , 8 ) } ${ initMarker . substring ( 8 ) } ` ,
230+ ] ,
231+ target : {
232+ type : 'remote' ,
233+ parameters : [ `localhost:${ port } ` ] ,
234+ } as TargetAttachArguments ,
235+ } as TargetAttachRequestArguments ) ;
236+
237+ await Promise . all ( [
238+ dc
239+ . waitForEvent ( 'initialized' )
240+ . then ( ( ) => dc . configurationDoneRequest ( ) ) ,
241+ dc . initializeRequest ( ) . then ( ( ) => dc . attachRequest ( attachArgs ) ) ,
242+ ] ) ;
243+
244+ // Verify both commands produced output
245+ const allOutput = stdOutput . join ( '' ) ;
246+ expect ( allOutput ) . to . include ( preMarker ) ;
247+ expect ( allOutput ) . to . include ( initMarker ) ;
248+
249+ // Verify order: preConnectCommands should appear before initCommands in the output
250+ const preConnectPos = allOutput . indexOf ( preMarker ) ;
251+ const initPos = allOutput . indexOf ( initMarker ) ;
252+ expect ( preConnectPos ) . to . be . greaterThan ( - 1 ) ;
253+ expect ( initPos ) . to . be . greaterThan ( - 1 ) ;
254+ expect ( preConnectPos ) . to . be . lessThan (
255+ initPos ,
256+ 'preConnectCommands should execute before initCommands'
257+ ) ;
258+ } ) ;
207259} ) ;
0 commit comments