Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check config type in the ChildProcessAttachEvents #21272

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -103,6 +103,7 @@ jobs:
- name: Run Pyright
uses: jakebailey/pyright-action@v1
with:
version: 1.1.308
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have done this as a separate PR, so we could just revert it when it is fixed by pyright

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, im going to do that

working-directory: 'pythonFiles'

### Non-smoke tests
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 @@ -77,6 +77,7 @@ jobs:
- name: Run Pyright
uses: jakebailey/pyright-action@v1
with:
version: 1.1.308
working-directory: 'pythonFiles'

### Non-smoke tests
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