Skip to content

Commit

Permalink
Merge pull request #6958 from meeseeksmachine/auto-backport-of-pr-694…
Browse files Browse the repository at this point in the history
…9-on-1.0.x

Backport PR #6949 on branch 1.0.x (Fix comm_info_request content to conform to spec in a backwards-compatible way)
  • Loading branch information
blink1073 committed Aug 9, 2019
2 parents 33618ba + fa29c78 commit 1435cab
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
27 changes: 25 additions & 2 deletions packages/services/src/kernel/messages.ts
Expand Up @@ -110,6 +110,18 @@ export namespace KernelMessage {
): T;

export function createMessage<T extends Message>(options: IOptions<T>): T {
// Backwards compatibility workaround for services 4.0 defining the wrong
// comm_info_request content. This should be removed with the deprecated
// `target` content option in services 5.0. See
// https://github.com/jupyterlab/jupyterlab/issues/6947
if (options.msgType === 'comm_info_request') {
const content = options.content as ICommInfoRequestMsg['content'];
if (content.target_name === undefined) {
content.target_name = content.target;
}
delete content.target;
}

return {
buffers: options.buffers || [],
channel: options.channel,
Expand Down Expand Up @@ -987,10 +999,22 @@ export namespace KernelMessage {
*
* **See also:** [[ICommInfoReplyMsg]], [[IKernel.commInfo]]
*/

export interface ICommInfoRequestMsg
extends IShellMessage<'comm_info_request'> {
content: {
/**
* The comm target name to filter returned comms
*/
target_name?: string;

/**
* Filter for returned comms
*
* @deprecated - this is a non-standard field. Use target_name instead
*
* #### Notes
* See https://github.com/jupyterlab/jupyterlab/issues/6947
*/
target?: string;
};
}
Expand All @@ -1002,7 +1026,6 @@ export namespace KernelMessage {
*
* **See also:** [[ICommInfoRequest]], [[IKernel.commInfo]]
*/

export interface ICommInfoReply extends IReplyOkContent {
/**
* Mapping of comm ids to target names.
Expand Down
29 changes: 29 additions & 0 deletions tests/test-services/src/kernel/messages.spec.ts
Expand Up @@ -168,4 +168,33 @@ describe('kernel/messages', () => {
expect(KernelMessage.isInputRequestMsg(msg2)).to.equal(false);
});
});

describe('KernelMessage.createMessage()', () => {
// Tests deprecated option workaround. Should be deleted in services 5.0.
// See https://github.com/jupyterlab/jupyterlab/pull/6949
it('contains a backwards-compatibility workaround for services 4.0 for a deprecated comm_info_request content', () => {
let commRequest = KernelMessage.createMessage({
msgType: 'comm_info_request',
channel: 'shell',
session: 'baz',
content: {
target: 'example'
}
});
expect(commRequest.content.target_name).to.equal('example');
expect(commRequest.content.target).to.be.undefined;

commRequest = KernelMessage.createMessage({
msgType: 'comm_info_request',
channel: 'shell',
session: 'baz',
content: {
target_name: 'real_target',
target: 'example'
}
});
expect(commRequest.content.target_name).to.equal('real_target');
expect(commRequest.content.target).to.be.undefined;
});
});
});

0 comments on commit 1435cab

Please sign in to comment.