From 62c7cdb5cb997bf1da31fc40a9022366e891a01c Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Mon, 5 Aug 2019 11:11:28 -0700 Subject: [PATCH 1/2] Fix comm_info_request content to conform to spec in a backwards-compatible way. This workaround should be removed in services 5.0. Fixes #6947 --- packages/services/src/kernel/messages.ts | 27 ++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/services/src/kernel/messages.ts b/packages/services/src/kernel/messages.ts index 83d401f0be00..8c1bd6561581 100644 --- a/packages/services/src/kernel/messages.ts +++ b/packages/services/src/kernel/messages.ts @@ -143,6 +143,18 @@ export namespace KernelMessage { ): T; export function createMessage(options: IOptions): 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, @@ -1076,10 +1088,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; }; } @@ -1091,7 +1115,6 @@ export namespace KernelMessage { * * **See also:** [[ICommInfoRequest]], [[IKernel.commInfo]] */ - export interface ICommInfoReply extends IReplyOkContent { /** * Mapping of comm ids to target names. From d7525540448d31a6449e7609e2729c1506f8a6a4 Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Mon, 5 Aug 2019 11:41:50 -0700 Subject: [PATCH 2/2] Add test for backwards compatibility workaround --- .../test-services/src/kernel/messages.spec.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test-services/src/kernel/messages.spec.ts b/tests/test-services/src/kernel/messages.spec.ts index 493951d4426a..9224380701f5 100644 --- a/tests/test-services/src/kernel/messages.spec.ts +++ b/tests/test-services/src/kernel/messages.spec.ts @@ -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; + }); + }); });