@@ -9,6 +9,7 @@ import { ChildProcessAttachEventHandler } from '../../../../client/debugger/exte
9
9
import { ChildProcessAttachService } from '../../../../client/debugger/extension/hooks/childProcessAttachService' ;
10
10
import { DebuggerEvents } from '../../../../client/debugger/extension/hooks/constants' ;
11
11
import { AttachRequestArguments } from '../../../../client/debugger/types' ;
12
+ import { DebuggerTypeName } from '../../../../client/debugger/constants' ;
12
13
13
14
suite ( 'Debug - Child Process' , ( ) => {
14
15
test ( 'Do not attach if the event is undefined' , async ( ) => {
@@ -21,23 +22,31 @@ suite('Debug - Child Process', () => {
21
22
const attachService = mock ( ChildProcessAttachService ) ;
22
23
const handler = new ChildProcessAttachEventHandler ( instance ( attachService ) ) ;
23
24
const body : any = { } ;
24
- const session : any = { } ;
25
+ const session : any = { configuration : { type : DebuggerTypeName } } ;
26
+ await handler . handleCustomEvent ( { event : 'abc' , body, session } ) ;
27
+ verify ( attachService . attach ( body , session ) ) . never ( ) ;
28
+ } ) ;
29
+ test ( 'Do not attach to child process if debugger type is different' , async ( ) => {
30
+ const attachService = mock ( ChildProcessAttachService ) ;
31
+ const handler = new ChildProcessAttachEventHandler ( instance ( attachService ) ) ;
32
+ const body : any = { } ;
33
+ const session : any = { configuration : { type : 'other-type' } } ;
25
34
await handler . handleCustomEvent ( { event : 'abc' , body, session } ) ;
26
35
verify ( attachService . attach ( body , session ) ) . never ( ) ;
27
36
} ) ;
28
37
test ( 'Do not attach to child process if ptvsd_attach event is invalid' , async ( ) => {
29
38
const attachService = mock ( ChildProcessAttachService ) ;
30
39
const handler = new ChildProcessAttachEventHandler ( instance ( attachService ) ) ;
31
40
const body : any = { } ;
32
- const session : any = { } ;
41
+ const session : any = { configuration : { type : DebuggerTypeName } } ;
33
42
await handler . handleCustomEvent ( { event : DebuggerEvents . PtvsdAttachToSubprocess , body, session } ) ;
34
43
verify ( attachService . attach ( body , session ) ) . never ( ) ;
35
44
} ) ;
36
45
test ( 'Do not attach to child process if debugpy_attach event is invalid' , async ( ) => {
37
46
const attachService = mock ( ChildProcessAttachService ) ;
38
47
const handler = new ChildProcessAttachEventHandler ( instance ( attachService ) ) ;
39
48
const body : any = { } ;
40
- const session : any = { } ;
49
+ const session : any = { configuration : { type : DebuggerTypeName } } ;
41
50
await handler . handleCustomEvent ( { event : DebuggerEvents . DebugpyAttachToSubprocess , body, session } ) ;
42
51
verify ( attachService . attach ( body , session ) ) . never ( ) ;
43
52
} ) ;
@@ -51,9 +60,11 @@ suite('Debug - Child Process', () => {
51
60
port : 1234 ,
52
61
subProcessId : 2 ,
53
62
} ;
54
- const session : any = { } ;
63
+ const session : any = {
64
+ configuration : { type : DebuggerTypeName } ,
65
+ } ;
55
66
when ( attachService . attach ( body , session ) ) . thenThrow ( new Error ( 'Kaboom' ) ) ;
56
- await handler . handleCustomEvent ( { event : DebuggerEvents . DebugpyAttachToSubprocess , body, session : { } as any } ) ;
67
+ await handler . handleCustomEvent ( { event : DebuggerEvents . DebugpyAttachToSubprocess , body, session } ) ;
57
68
verify ( attachService . attach ( body , anything ( ) ) ) . once ( ) ;
58
69
const [ , secondArg ] = capture ( attachService . attach ) . last ( ) ;
59
70
expect ( secondArg ) . to . deep . equal ( session ) ;
0 commit comments