Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ jobs:
python -m pip install --upgrade -r build/test-requirements.txt

- name: Run Pyright
version: 1.1.308
uses: jakebailey/pyright-action@v1
with:
working-directory: 'pythonFiles'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
python -m pip install --upgrade -r build/test-requirements.txt

- name: Run Pyright
version: 1.1.308
uses: jakebailey/pyright-action@v1
with:
working-directory: 'pythonFiles'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { swallowExceptions } from '../../../common/utils/decorators';
import { AttachRequestArguments } from '../../types';
import { DebuggerEvents } from './constants';
import { IChildProcessAttachService, IDebugSessionEventHandlers } from './types';
import { DebuggerTypeName } from '../../constants';

/**
* This class is responsible for automatically attaching the debugger to any
Expand All @@ -25,7 +26,7 @@ export class ChildProcessAttachEventHandler implements IDebugSessionEventHandler

@swallowExceptions('Handle child process launch')
public async handleCustomEvent(event: DebugSessionCustomEvent): Promise<void> {
if (!event) {
if (!event || event.session.configuration.type !== DebuggerTypeName) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ChildProcessAttachEventHandler } from '../../../../client/debugger/exte
import { ChildProcessAttachService } from '../../../../client/debugger/extension/hooks/childProcessAttachService';
import { DebuggerEvents } from '../../../../client/debugger/extension/hooks/constants';
import { AttachRequestArguments } from '../../../../client/debugger/types';
import { DebuggerTypeName } from '../../../../client/debugger/constants';

suite('Debug - Child Process', () => {
test('Do not attach if the event is undefined', async () => {
Expand All @@ -21,23 +22,31 @@ suite('Debug - Child Process', () => {
const attachService = mock(ChildProcessAttachService);
const handler = new ChildProcessAttachEventHandler(instance(attachService));
const body: any = {};
const session: any = {};
const session: any = { configuration: { type: DebuggerTypeName } };
await handler.handleCustomEvent({ event: 'abc', body, session });
verify(attachService.attach(body, session)).never();
});
test('Do not attach to child process if debugger type is different', async () => {
const attachService = mock(ChildProcessAttachService);
const handler = new ChildProcessAttachEventHandler(instance(attachService));
const body: any = {};
const session: any = { configuration: { type: 'other-type' } };
await handler.handleCustomEvent({ event: 'abc', body, session });
verify(attachService.attach(body, session)).never();
});
test('Do not attach to child process if ptvsd_attach event is invalid', async () => {
const attachService = mock(ChildProcessAttachService);
const handler = new ChildProcessAttachEventHandler(instance(attachService));
const body: any = {};
const session: any = {};
const session: any = { configuration: { type: DebuggerTypeName } };
await handler.handleCustomEvent({ event: DebuggerEvents.PtvsdAttachToSubprocess, body, session });
verify(attachService.attach(body, session)).never();
});
test('Do not attach to child process if debugpy_attach event is invalid', async () => {
const attachService = mock(ChildProcessAttachService);
const handler = new ChildProcessAttachEventHandler(instance(attachService));
const body: any = {};
const session: any = {};
const session: any = { configuration: { type: DebuggerTypeName } };
await handler.handleCustomEvent({ event: DebuggerEvents.DebugpyAttachToSubprocess, body, session });
verify(attachService.attach(body, session)).never();
});
Expand All @@ -51,9 +60,11 @@ suite('Debug - Child Process', () => {
port: 1234,
subProcessId: 2,
};
const session: any = {};
const session: any = {
configuration: { type: DebuggerTypeName },
};
when(attachService.attach(body, session)).thenThrow(new Error('Kaboom'));
await handler.handleCustomEvent({ event: DebuggerEvents.DebugpyAttachToSubprocess, body, session: {} as any });
await handler.handleCustomEvent({ event: DebuggerEvents.DebugpyAttachToSubprocess, body, session });
verify(attachService.attach(body, anything())).once();
const [, secondArg] = capture(attachService.attach).last();
expect(secondArg).to.deep.equal(session);
Expand Down