@@ -189,4 +189,50 @@ suite('Debug - Attach to Child Process', () => {
189189 expect ( thirdArg ) . to . deep . equal ( { parentSession : session , lifecycleManagedByParent : true } ) ;
190190 sinon . assert . notCalled ( showErrorMessageStub ) ;
191191 } ) ;
192+ test ( 'Child process debug config should not inherit purpose from parent session' , async ( ) => {
193+ // When the parent session is a test debug session (purpose: ['debug-test']),
194+ // the child process config inherits 'purpose' via debugpy's notify_of_subprocess.
195+ // We must strip 'purpose' from the child config so that VS Code's test adapter
196+ // does not treat child process session termination as test run completion,
197+ // which would cause premature disconnection of the parent debug session.
198+ // Regression test for: https://github.com/microsoft/vscode-python-debugger/issues/981
199+ const data : AttachRequestArguments = {
200+ request : 'attach' ,
201+ type : debuggerTypeName ,
202+ name : 'Attach' ,
203+ port : 1234 ,
204+ subProcessId : 2 ,
205+ purpose : [ 'debug-test' ] ,
206+ } ;
207+
208+ const session : any = { } ;
209+ getWorkspaceFoldersStub . returns ( undefined ) ;
210+ startDebuggingStub . resolves ( true ) ;
211+
212+ await attachService . attach ( data , session ) ;
213+
214+ sinon . assert . calledOnce ( startDebuggingStub ) ;
215+ const [ , secondArg ] = startDebuggingStub . args [ 0 ] ;
216+ expect ( secondArg ) . to . not . have . property ( 'purpose' ) ;
217+ sinon . assert . notCalled ( showErrorMessageStub ) ;
218+ } ) ;
219+ test ( 'Attaching to child process does not mutate the original data object' , async ( ) => {
220+ const data : AttachRequestArguments = {
221+ request : 'attach' ,
222+ type : debuggerTypeName ,
223+ name : 'Attach' ,
224+ port : 1234 ,
225+ subProcessId : 2 ,
226+ purpose : [ 'debug-test' ] ,
227+ } ;
228+
229+ const session : any = { } ;
230+ getWorkspaceFoldersStub . returns ( undefined ) ;
231+ startDebuggingStub . resolves ( true ) ;
232+
233+ await attachService . attach ( data , session ) ;
234+
235+ // The original data object must not be mutated.
236+ expect ( data ) . to . have . property ( 'purpose' ) . deep . equal ( [ 'debug-test' ] ) ;
237+ } ) ;
192238} ) ;
0 commit comments