diff --git a/DEVELOPER-GUIDE.md b/DEVELOPER-GUIDE.md index fd16b1ba46..c5ec895f0c 100644 --- a/DEVELOPER-GUIDE.md +++ b/DEVELOPER-GUIDE.md @@ -198,3 +198,49 @@ else - If you get an error about access being denied, ensure that all other Notebooks are closed and then restart the kernel again as in step 5 8. Now, use the kernel as you normally would. You should see your local changes being used by the extension. + + +### Setup full suite of tests to run + +Some tests require additional setup or will be skipped. `JupyterKernel` tests for e.g. are setup to have the same test run against a Jupyter server, directly against the Jupyter kernel over ZMQ and with a simulation of the messages. Jupyter server and Jupyter kernel tests require the following setup or will be skipped while the tests with simulation can be run without additional steps. + +### Run tests with a local Jupyter Server + +1. Install [Jupyter server](https://docs.jupyter.org/en/latest/install.html) or [Anaconda](https://www.anaconda.com/products/distribution) +2. [Install R kernel](https://docs.anaconda.com/anaconda/user-guide/tasks/using-r-language/) for R tests by calling the following in Anaconda Prompt (Windows) or the terminal (Mac/Linux) +``` +conda install -c r r-irkernel +``` +3. Start the server locally as mentioned [here](https://docs.jupyter.org/en/latest/running.html). You can use any random string or guid for your_token value. +``` +jupyter notebook --no-browser --NotebookApp.token= --port=8888 +``` +4. Set an environment variable `TEST_DOTNET_JUPYTER_HTTP_CONN` pointing to the server and the token you are using for the Jupyter server as +``` +--url http://localhost:8888 --token +``` +5. The tests will now use the environment variable to connect to your server. + +### Run tests with a Jupyter Kernel over ZMQ + +1. Install [Anaconda](https://www.anaconda.com/products/distribution) +2. [Install R kernel](https://docs.anaconda.com/anaconda/user-guide/tasks/using-r-language/) for R tests by calling the following in Anaconda Prompt (Windows) or the terminal (Mac/Linux) +``` +conda install -c r r-irkernel +``` +3. Start Anaconda Bash prompt and create an environment variable `TEST_DOTNET_JUPYTER_ZMQ_CONN` and set to `true` and reactivate your conda environment +```bash +conda env config vars set TEST_DOTNET_JUPYTER_ZMQ_CONN=true +conda activate base +``` +3. Restart `dotnet-interactive.sln` from the Anaconda Bash prompt. +4. The tests will now use the environment variable to connect to your server. + +### Run tests directly against the language handler scripts + +These tests can be run directly against the language handler scripts. This is useful for when making changes on the scripts sent to the jupyter kernel without needing a full integration. + +1. Python tests can be run directly in the Anaconda Prompt with IPython by calling `src\Microsoft.DotNet.Interactive.Jupyter.Tests\LanguageHandlerTests\run_python_tests.bat` +2. R tests can be run directly in the Anaconda Prompt with RScript by calling `src\Microsoft.DotNet.Interactive.Jupyter.Tests\LanguageHandlerTests\run_r_tests.bat` +3. Both Python and R tests can be run together in the Anaconda Prompt by calling `src\Microsoft.DotNet.Interactive.Jupyter.Tests\LanguageHandlerTests\run_tests.bat` + diff --git a/NOTICE.txt b/NOTICE.txt index ef7928f774..0b6a695181 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -25683,3 +25683,39 @@ For more information, please refer to --------------------------------------------------------- +Some parts of Jupyter messaging protocol handling and Jupyter Kernel creation are inspired from the nteract OSS project. + +nteract +https://github.com/nteract/nteract +BSD-3-Clause license + +Copyright (c) 2016, nteract contributors +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of nteract nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +--------------------------------------------------------- + diff --git a/src/Microsoft.DotNet.Interactive.ApiCompatibility.Tests/ApiCompatibilityTests.jupyter_api_is_not_changed.approved.txt b/src/Microsoft.DotNet.Interactive.ApiCompatibility.Tests/ApiCompatibilityTests.jupyter_api_is_not_changed.approved.txt index c7def4a587..31c4be4d41 100644 --- a/src/Microsoft.DotNet.Interactive.ApiCompatibility.Tests/ApiCompatibilityTests.jupyter_api_is_not_changed.approved.txt +++ b/src/Microsoft.DotNet.Interactive.ApiCompatibility.Tests/ApiCompatibilityTests.jupyter_api_is_not_changed.approved.txt @@ -15,6 +15,12 @@ Microsoft.DotNet.Interactive.Jupyter public System.String SignatureScheme { get; set;} public System.Int32 StdinPort { get; set;} public System.String Transport { get; set;} + public class ConnectJupyterKernelCommand : Microsoft.DotNet.Interactive.Connection.ConnectKernelCommand, System.Collections.Generic.IEnumerable, System.Collections.IEnumerable, System.CommandLine.Completions.ICompletionSource + .ctor() + public System.CommandLine.Option InitScript { get;} + public System.CommandLine.Option KernelSpecName { get;} + public ConnectJupyterKernelCommand AddConnectionOptions(Microsoft.DotNet.Interactive.Jupyter.Connection.IJupyterKernelConnectionOptions connectionOptions) + public System.Threading.Tasks.Task ConnectKernelAsync(Microsoft.DotNet.Interactive.KernelInvocationContext context, System.CommandLine.Invocation.InvocationContext commandLineContext) public static class Constants public class ExecuteRequestHandler : RequestHandlerBase, System.IDisposable .ctor(Microsoft.DotNet.Interactive.Kernel kernel, System.Reactive.Concurrency.IScheduler scheduler = null) @@ -24,7 +30,11 @@ Microsoft.DotNet.Interactive.Jupyter .ctor(ConnectionInformation connectionInformation) public System.Threading.Tasks.Task StartAsync(System.Threading.CancellationToken cancellationToken) public System.Threading.Tasks.Task StopAsync(System.Threading.CancellationToken cancellationToken) - public abstract class IJupyterMessageSender + public abstract class IJupyterKernelSpecModule + public System.IO.DirectoryInfo GetDefaultKernelSpecDirectory() + public System.Threading.Tasks.Task InstallKernel(System.IO.DirectoryInfo sourceDirectory) + public System.Threading.Tasks.Task> ListKernels() + public abstract class IJupyterMessageResponseSender public System.Void Send(Microsoft.DotNet.Interactive.Jupyter.Protocol.PubSubMessage message) public System.Void Send(Microsoft.DotNet.Interactive.Jupyter.Protocol.ReplyMessage message) public System.String Send(Microsoft.DotNet.Interactive.Jupyter.Protocol.InputRequest message) @@ -39,9 +49,24 @@ Microsoft.DotNet.Interactive.Jupyter public class JupyterClientKernelExtension, Microsoft.DotNet.Interactive.IKernelExtension .ctor() public System.Threading.Tasks.Task OnLoadAsync(Microsoft.DotNet.Interactive.Kernel kernel) + public class JupyterHttpKernelConnectionOptions, Microsoft.DotNet.Interactive.Jupyter.Connection.IJupyterKernelConnectionOptions + .ctor() + public System.CommandLine.Option TargetUrl { get;} + public System.CommandLine.Option Token { get;} + public Microsoft.DotNet.Interactive.Jupyter.Connection.IJupyterConnection GetConnection(System.CommandLine.Parsing.ParseResult connectionOptionsParseResult) + public System.Collections.Generic.IReadOnlyCollection GetOptions() + public class JupyterKernelSpecModule, IJupyterKernelSpecModule + .ctor() + public System.IO.DirectoryInfo GetDefaultKernelSpecDirectory() + public System.Threading.Tasks.Task InstallKernel(System.IO.DirectoryInfo sourceDirectory) + public System.Threading.Tasks.Task> ListKernels() + public class JupyterLocalKernelConnectionOptions, Microsoft.DotNet.Interactive.Jupyter.Connection.IJupyterKernelConnectionOptions + .ctor() + public Microsoft.DotNet.Interactive.Jupyter.Connection.IJupyterConnection GetConnection(System.CommandLine.Parsing.ParseResult connectionOptionsParseResult) + public System.Collections.Generic.IReadOnlyCollection GetOptions() public class JupyterRequestContext - .ctor(IJupyterMessageSender jupyterMessageSender, Microsoft.DotNet.Interactive.Jupyter.Messaging.Message request) - public IJupyterMessageSender JupyterMessageSender { get;} + .ctor(IJupyterMessageResponseSender jupyterMessageSender, Microsoft.DotNet.Interactive.Jupyter.Messaging.Message request) + public IJupyterMessageResponseSender JupyterMessageSender { get;} public Microsoft.DotNet.Interactive.Jupyter.Messaging.Message JupyterRequestMessageEnvelope { get;} public System.String Token { get;} public System.Void Complete() @@ -62,6 +87,15 @@ Microsoft.DotNet.Interactive.Jupyter public static class KernelFormattingExtensions public static Microsoft.DotNet.Interactive.CSharp.CSharpKernel UseMathAndLaTeX() public static Microsoft.DotNet.Interactive.FSharp.FSharpKernel UseMathAndLaTeX() + public class KernelSpec + .ctor() + public System.Collections.Generic.IReadOnlyList CommandArguments { get; set;} + public System.String DisplayName { get; set;} + public System.Collections.Generic.IReadOnlyDictionary EnvironmentVariables { get; set;} + public System.String InterruptMode { get; set;} + public System.String Language { get; set;} + public System.Collections.Generic.IReadOnlyDictionary Metadata { get; set;} + public System.String Name { get; set;} public abstract class RequestHandlerBase, System.IDisposable public System.Void Dispose() protected Microsoft.DotNet.Interactive.Kernel get_Kernel() @@ -83,6 +117,18 @@ Microsoft.DotNet.Interactive.Jupyter public static class TopLevelMethods public static System.String input(System.String prompt = ) public static Microsoft.DotNet.Interactive.PasswordString password(System.String prompt = ) +Microsoft.DotNet.Interactive.Jupyter.Connection + public abstract class IJupyterConnection, System.IDisposable + public System.Threading.Tasks.Task CreateKernelConnectionAsync(System.String kernelSpecName) + public System.Threading.Tasks.Task> GetKernelSpecsAsync() + public abstract class IJupyterKernelConnection, System.IDisposable + public Microsoft.DotNet.Interactive.Jupyter.Messaging.IMessageReceiver Receiver { get;} + public Microsoft.DotNet.Interactive.Jupyter.Messaging.IMessageSender Sender { get;} + public System.Uri Uri { get;} + public System.Threading.Tasks.Task StartAsync() + public abstract class IJupyterKernelConnectionOptions + public IJupyterConnection GetConnection(System.CommandLine.Parsing.ParseResult connectionOptionsParseResult) + public System.Collections.Generic.IReadOnlyCollection GetOptions() Microsoft.DotNet.Interactive.Jupyter.Formatting public class LaTeXString public static LaTeXString op_Implicit(System.String source) @@ -103,15 +149,19 @@ Microsoft.DotNet.Interactive.Jupyter.Messaging public System.String Session { get;} public System.String Username { get;} public System.String Version { get;} + public abstract class IMessageReceiver + public System.IObservable Messages { get;} + public abstract class IMessageSender + public System.Threading.Tasks.Task SendAsync(Message message) public static class JsonElementExtensions public static System.Object[] ToArray() public static System.Collections.Generic.IDictionary ToDictionary() public static System.Object ToObject() public static System.Collections.Generic.IReadOnlyDictionary ToReadOnlyDictionary() public class Message - public static Message Create(T content, Header parentHeader = null, System.Collections.Generic.IReadOnlyList> identifiers = null, System.Collections.Generic.IReadOnlyDictionary metaData = null, System.String signature = null, System.String channel = null) + public static Message Create(T content, Header parentHeader = null, System.Collections.Generic.IReadOnlyList> identifiers = null, System.Collections.Generic.IReadOnlyDictionary metaData = null, System.String signature = null, System.String channel = shell) public static Message CreatePubSub(T content, Message request, System.String kernelIdentity = null) - public static Message CreateReply(T content, Message request, System.String channel = null) + public static Message CreateReply(T content, Message request, System.String channel = shell) .ctor(Header header, Microsoft.DotNet.Interactive.Jupyter.Protocol.Message content = null, Header parentHeader = null, System.String signature = null, System.Collections.Generic.IReadOnlyDictionary metaData = null, System.Collections.Generic.IReadOnlyList> identifiers = null, System.Collections.Generic.IReadOnlyList> buffers = null, System.String channel = shell) public System.Collections.Generic.IReadOnlyList> Buffers { get;} public System.String Channel { get;} @@ -125,6 +175,12 @@ Microsoft.DotNet.Interactive.Jupyter.Messaging public static T DeserializeFromJsonString(System.String source) public static Message DeserializeMessage(System.String signature, System.String headerJson, System.String parentHeaderJson, System.String metadataJson, System.String contentJson, System.Collections.Generic.IReadOnlyList> identifiers, System.Text.Json.JsonSerializerOptions options = null) public static System.Boolean IsEmptyJson(System.String source) + public static class MessageFormatter + public static System.Text.Json.JsonSerializerOptions SerializerOptions { get;} + public static class MessageObservableExtensions + public static System.IObservable Content() + public static System.IObservable ResponseOf(Message parentMessage) + public static System.IObservable TakeUntilMessageType(System.String[] messageTypes) public static class MetadataExtensions public static System.Collections.Generic.Dictionary DeserializeMetadataFromJsonString(System.String metadataJson) Microsoft.DotNet.Interactive.Jupyter.Protocol @@ -143,7 +199,7 @@ Microsoft.DotNet.Interactive.Jupyter.Protocol .ctor(System.Collections.Generic.IReadOnlyDictionary comms) public System.Collections.Generic.IReadOnlyDictionary Comms { get;} public class CommInfoRequest : RequestMessage - .ctor(System.String targetName) + .ctor(System.String targetName = null) public System.String TargetName { get;} public class CommMsg : Message .ctor(System.String commId, System.Collections.Generic.IReadOnlyDictionary data = null) @@ -158,16 +214,23 @@ Microsoft.DotNet.Interactive.Jupyter.Protocol .ctor(System.String targetName) public System.String TargetName { get; set;} public class CompleteReply : ReplyMessage - .ctor(System.Int32 cursorStart = 0, System.Int32 cursorEnd = 0, System.Collections.Generic.IReadOnlyList matches = null, System.Collections.Generic.IReadOnlyDictionary metaData = null, System.String status = null) + .ctor(System.Int32 cursorStart = 0, System.Int32 cursorEnd = 0, System.Collections.Generic.IReadOnlyList matches = null, System.Collections.Generic.IReadOnlyDictionary> metaData = null, System.String status = null) public System.Int32 CursorEnd { get;} public System.Int32 CursorStart { get;} public System.Collections.Generic.IReadOnlyList Matches { get;} - public System.Collections.Generic.IReadOnlyDictionary MetaData { get;} + public System.Collections.Generic.IReadOnlyDictionary> MetaData { get;} public System.String Status { get;} public class CompleteRequest : RequestMessage .ctor(System.String code, System.Int32 cursorPosition = 0) public System.String Code { get; set;} public System.Int32 CursorPosition { get; set;} + public class CompletionResultMetadata + .ctor(System.Int32 start = 0, System.Int32 end = 0, System.String text = null, System.String type = null, System.String displayText = null) + public System.String DisplayText { get;} + public System.Int32 End { get;} + public System.Int32 Start { get;} + public System.String Text { get;} + public System.String Type { get;} public class CSharpLanguageInfo : LanguageInfo .ctor(System.String version = 11.0) public class DisplayData : PubSubMessage diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_connect_to_and_setup_kernel.ir.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_connect_to_and_setup_kernel.ir.json new file mode 100644 index 0000000000..cec2db23be --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_connect_to_and_setup_kernel.ir.json @@ -0,0 +1,263 @@ +[ + { + "header": { + "msg_id": "f5b935d4-c843-11ed-9688-891629944ff8", + "username": "dotnet_kernel", + "session": "e573978f-cab9-4392-a85d-a1f03c1d7de3", + "date": "2023-03-21T23:56:12.928329Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "f0d294b7-12fb-4c83-ab58-2cb57847bbb5", + "username": "dotnet_kernel", + "session": "e573978f-cab9-4392-a85d-a1f03c1d7de3", + "date": "2023-03-21T23:56:12.8630296Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f5b95cda-c843-11ed-9688-891629944ff8", + "username": "dotnet_kernel", + "session": "e573978f-cab9-4392-a85d-a1f03c1d7de3", + "date": "2023-03-21T23:56:12.930338Z", + "msg_type": "kernel_info_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "f0d294b7-12fb-4c83-ab58-2cb57847bbb5", + "username": "dotnet_kernel", + "session": "e573978f-cab9-4392-a85d-a1f03c1d7de3", + "date": "2023-03-21T23:56:12.8630296Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.0", + "implementation": "IRkernel", + "implementation_version": "0.8.15", + "language_info": { + "name": "R", + "version": "3.6.1", + "mimetype": "text/x-r-source", + "file_extension": ".r", + "pygments_lexer": "r", + "codemirror_mode": "r" + }, + "banner": "R version 3.6.1 (2019-07-05)", + "status": "ok", + "help_links": [] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f5b9ab54-c843-11ed-9688-891629944ff8", + "username": "dotnet_kernel", + "session": "e573978f-cab9-4392-a85d-a1f03c1d7de3", + "date": "2023-03-21T23:56:12.932337Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "f0d294b7-12fb-4c83-ab58-2cb57847bbb5", + "username": "dotnet_kernel", + "session": "e573978f-cab9-4392-a85d-a1f03c1d7de3", + "date": "2023-03-21T23:56:12.8630296Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f5bc9972-c843-11ed-9688-891629944ff8", + "username": "dotnet_kernel", + "session": "1df29cd2-86d7-4db4-88c1-0d9b31c03918", + "date": "2023-03-21T23:56:12.951541Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "a6da1752-137d-4109-84cf-49ad7dc738e8", + "username": "dotnet_kernel", + "session": "1df29cd2-86d7-4db4-88c1-0d9b31c03918", + "date": "2023-03-21T23:56:12.9318012Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f5bce792-c843-11ed-9688-891629944ff8", + "username": "dotnet_kernel", + "session": "1df29cd2-86d7-4db4-88c1-0d9b31c03918", + "date": "2023-03-21T23:56:12.953542Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "a6da1752-137d-4109-84cf-49ad7dc738e8", + "username": "dotnet_kernel", + "session": "1df29cd2-86d7-4db4-88c1-0d9b31c03918", + "date": "2023-03-21T23:56:12.9318012Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f5cd2b8e-c843-11ed-9688-891629944ff8", + "username": "dotnet_kernel", + "session": "1df29cd2-86d7-4db4-88c1-0d9b31c03918", + "date": "2023-03-21T23:56:13.060141Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "a6da1752-137d-4109-84cf-49ad7dc738e8", + "username": "dotnet_kernel", + "session": "1df29cd2-86d7-4db4-88c1-0d9b31c03918", + "date": "2023-03-21T23:56:12.9318012Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f5cd529e-c843-11ed-9688-891629944ff8", + "username": "dotnet_kernel", + "session": "1df29cd2-86d7-4db4-88c1-0d9b31c03918", + "date": "2023-03-21T23:56:13.061143Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "a6da1752-137d-4109-84cf-49ad7dc738e8", + "username": "dotnet_kernel", + "session": "1df29cd2-86d7-4db4-88c1-0d9b31c03918", + "date": "2023-03-21T23:56:12.9318012Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f5cdeef2-c843-11ed-9688-891629944ff8", + "username": "dotnet_kernel", + "session": "a8364953-7c65-4b09-a16c-0db9ed40cd9c", + "date": "2023-03-21T23:56:13.064141Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "61b38ad4-3044-4c89-8bb6-5b6c837da88d", + "username": "dotnet_kernel", + "session": "a8364953-7c65-4b09-a16c-0db9ed40cd9c", + "date": "2023-03-21T23:56:13.0615647Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f5ce8b1e-c843-11ed-9688-891629944ff8", + "username": "dotnet_kernel", + "session": "a8364953-7c65-4b09-a16c-0db9ed40cd9c", + "date": "2023-03-21T23:56:13.068140Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "61b38ad4-3044-4c89-8bb6-5b6c837da88d", + "username": "dotnet_kernel", + "session": "a8364953-7c65-4b09-a16c-0db9ed40cd9c", + "date": "2023-03-21T23:56:13.0615647Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "92d4d6d7-809d-4b59-b52e-98dece235ea7", + "data": { + "commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f5ceb238-c843-11ed-9688-891629944ff8", + "username": "dotnet_kernel", + "session": "a8364953-7c65-4b09-a16c-0db9ed40cd9c", + "date": "2023-03-21T23:56:13.069140Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "61b38ad4-3044-4c89-8bb6-5b6c837da88d", + "username": "dotnet_kernel", + "session": "a8364953-7c65-4b09-a16c-0db9ed40cd9c", + "date": "2023-03-21T23:56:13.0615647Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_connect_to_and_setup_kernel.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_connect_to_and_setup_kernel.python3.json new file mode 100644 index 0000000000..5ea4d3c073 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_connect_to_and_setup_kernel.python3.json @@ -0,0 +1,301 @@ +[ + { + "header": { + "msg_id": "9319496a-e2427fc070e41474453100ba_16012_10", + "username": "username", + "session": "9319496a-e2427fc070e41474453100ba", + "date": "2023-03-21T23:56:11.881608Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "247a50ea-ca8b-4cae-8582-8710817bb212", + "username": "dotnet_kernel", + "session": "d4e3014e-ab5d-4f0c-8f52-3e76d9ce0478", + "date": "2023-03-21T23:56:11.8620358Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9319496a-e2427fc070e41474453100ba_16012_12", + "username": "username", + "session": "9319496a-e2427fc070e41474453100ba", + "date": "2023-03-21T23:56:11.883620Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "247a50ea-ca8b-4cae-8582-8710817bb212", + "username": "dotnet_kernel", + "session": "d4e3014e-ab5d-4f0c-8f52-3e76d9ce0478", + "date": "2023-03-21T23:56:11.8620358Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9319496a-e2427fc070e41474453100ba_16012_11", + "username": "username", + "session": "9319496a-e2427fc070e41474453100ba", + "date": "2023-03-21T23:56:11.882619Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "247a50ea-ca8b-4cae-8582-8710817bb212", + "username": "dotnet_kernel", + "session": "d4e3014e-ab5d-4f0c-8f52-3e76d9ce0478", + "date": "2023-03-21T23:56:11.8620358Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9319496a-e2427fc070e41474453100ba_16012_13", + "username": "username", + "session": "9319496a-e2427fc070e41474453100ba", + "date": "2023-03-21T23:56:11.889619Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "590a86b2-4bad-4de1-9643-2f9662fd16ab", + "username": "dotnet_kernel", + "session": "b090c260-292e-41b0-85df-470e6ec6d63e", + "date": "2023-03-21T23:56:11.8865904Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9319496a-e2427fc070e41474453100ba_16012_14", + "username": "username", + "session": "9319496a-e2427fc070e41474453100ba", + "date": "2023-03-21T23:56:11.890618Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "590a86b2-4bad-4de1-9643-2f9662fd16ab", + "username": "dotnet_kernel", + "session": "b090c260-292e-41b0-85df-470e6ec6d63e", + "date": "2023-03-21T23:56:11.8865904Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9319496a-e2427fc070e41474453100ba_16012_15", + "username": "username", + "session": "9319496a-e2427fc070e41474453100ba", + "date": "2023-03-21T23:56:11.920141Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "590a86b2-4bad-4de1-9643-2f9662fd16ab", + "username": "dotnet_kernel", + "session": "b090c260-292e-41b0-85df-470e6ec6d63e", + "date": "2023-03-21T23:56:11.8865904Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:56:11.889619Z", + "dependencies_met": true, + "engine": "1d75488d-3123-44c0-aaca-d16796da7cf7", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9319496a-e2427fc070e41474453100ba_16012_16", + "username": "username", + "session": "9319496a-e2427fc070e41474453100ba", + "date": "2023-03-21T23:56:11.920141Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "590a86b2-4bad-4de1-9643-2f9662fd16ab", + "username": "dotnet_kernel", + "session": "b090c260-292e-41b0-85df-470e6ec6d63e", + "date": "2023-03-21T23:56:11.8865904Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9319496a-e2427fc070e41474453100ba_16012_17", + "username": "username", + "session": "9319496a-e2427fc070e41474453100ba", + "date": "2023-03-21T23:56:11.924140Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "ef8a5b02-7333-47b2-a70b-d8d98baeebb9", + "username": "dotnet_kernel", + "session": "47beb32d-c088-4b9d-92f9-b22255ce3b77", + "date": "2023-03-21T23:56:11.9229729Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9319496a-e2427fc070e41474453100ba_16012_18", + "username": "username", + "session": "9319496a-e2427fc070e41474453100ba", + "date": "2023-03-21T23:56:11.925140Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "ef8a5b02-7333-47b2-a70b-d8d98baeebb9", + "username": "dotnet_kernel", + "session": "47beb32d-c088-4b9d-92f9-b22255ce3b77", + "date": "2023-03-21T23:56:11.9229729Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "f9b37eaa-f9f6-41a7-92f3-ad57572328a4", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9319496a-e2427fc070e41474453100ba_16012_19", + "username": "username", + "session": "9319496a-e2427fc070e41474453100ba", + "date": "2023-03-21T23:56:11.926140Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "ef8a5b02-7333-47b2-a70b-d8d98baeebb9", + "username": "dotnet_kernel", + "session": "47beb32d-c088-4b9d-92f9-b22255ce3b77", + "date": "2023-03-21T23:56:11.9229729Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_completions_and_get_value_produced.ir.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_completions_and_get_value_produced.ir.json new file mode 100644 index 0000000000..cd18afbca5 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_completions_and_get_value_produced.ir.json @@ -0,0 +1,411 @@ +[ + { + "header": { + "msg_id": "eb0db236-c843-11ed-a42a-2be4e70d42a0", + "username": "dotnet_kernel", + "session": "7d71926c-c562-45fe-952d-c13247efa964", + "date": "2023-03-21T23:55:55.028079Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "357a4900-18ad-4959-9377-dd1d521cf7fa", + "username": "dotnet_kernel", + "session": "7d71926c-c562-45fe-952d-c13247efa964", + "date": "2023-03-21T23:55:54.9391553Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "eb0dd93c-c843-11ed-a42a-2be4e70d42a0", + "username": "dotnet_kernel", + "session": "7d71926c-c562-45fe-952d-c13247efa964", + "date": "2023-03-21T23:55:55.030078Z", + "msg_type": "kernel_info_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "357a4900-18ad-4959-9377-dd1d521cf7fa", + "username": "dotnet_kernel", + "session": "7d71926c-c562-45fe-952d-c13247efa964", + "date": "2023-03-21T23:55:54.9391553Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.0", + "implementation": "IRkernel", + "implementation_version": "0.8.15", + "language_info": { + "name": "R", + "version": "3.6.1", + "mimetype": "text/x-r-source", + "file_extension": ".r", + "pygments_lexer": "r", + "codemirror_mode": "r" + }, + "banner": "R version 3.6.1 (2019-07-05)", + "status": "ok", + "help_links": [] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "eb0e275c-c843-11ed-a42a-2be4e70d42a0", + "username": "dotnet_kernel", + "session": "7d71926c-c562-45fe-952d-c13247efa964", + "date": "2023-03-21T23:55:55.031075Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "357a4900-18ad-4959-9377-dd1d521cf7fa", + "username": "dotnet_kernel", + "session": "7d71926c-c562-45fe-952d-c13247efa964", + "date": "2023-03-21T23:55:54.9391553Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "eb0eeaa2-c843-11ed-a42a-2be4e70d42a0", + "username": "dotnet_kernel", + "session": "a26d094c-ae7c-4a64-926f-bfbc426b0e94", + "date": "2023-03-21T23:55:55.035078Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "f83f3ba4-0600-4e89-b1ce-8ed2dd7132d6", + "username": "dotnet_kernel", + "session": "a26d094c-ae7c-4a64-926f-bfbc426b0e94", + "date": "2023-03-21T23:55:55.0312257Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "eb0f38b8-c843-11ed-a42a-2be4e70d42a0", + "username": "dotnet_kernel", + "session": "a26d094c-ae7c-4a64-926f-bfbc426b0e94", + "date": "2023-03-21T23:55:55.038086Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "f83f3ba4-0600-4e89-b1ce-8ed2dd7132d6", + "username": "dotnet_kernel", + "session": "a26d094c-ae7c-4a64-926f-bfbc426b0e94", + "date": "2023-03-21T23:55:55.0312257Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "eb1e096a-c843-11ed-a42a-2be4e70d42a0", + "username": "dotnet_kernel", + "session": "a26d094c-ae7c-4a64-926f-bfbc426b0e94", + "date": "2023-03-21T23:55:55.135167Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "f83f3ba4-0600-4e89-b1ce-8ed2dd7132d6", + "username": "dotnet_kernel", + "session": "a26d094c-ae7c-4a64-926f-bfbc426b0e94", + "date": "2023-03-21T23:55:55.0312257Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "eb1e5776-c843-11ed-a42a-2be4e70d42a0", + "username": "dotnet_kernel", + "session": "a26d094c-ae7c-4a64-926f-bfbc426b0e94", + "date": "2023-03-21T23:55:55.138170Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "f83f3ba4-0600-4e89-b1ce-8ed2dd7132d6", + "username": "dotnet_kernel", + "session": "a26d094c-ae7c-4a64-926f-bfbc426b0e94", + "date": "2023-03-21T23:55:55.0312257Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "eb1f41f4-c843-11ed-a42a-2be4e70d42a0", + "username": "dotnet_kernel", + "session": "68488ce2-0945-4a31-a44d-1b870ab766a6", + "date": "2023-03-21T23:55:55.142167Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2a179890-8dc9-4c0c-9beb-b34611edc213", + "username": "dotnet_kernel", + "session": "68488ce2-0945-4a31-a44d-1b870ab766a6", + "date": "2023-03-21T23:55:55.1387020Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "eb1fde0c-c843-11ed-a42a-2be4e70d42a0", + "username": "dotnet_kernel", + "session": "68488ce2-0945-4a31-a44d-1b870ab766a6", + "date": "2023-03-21T23:55:55.146167Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2a179890-8dc9-4c0c-9beb-b34611edc213", + "username": "dotnet_kernel", + "session": "68488ce2-0945-4a31-a44d-1b870ab766a6", + "date": "2023-03-21T23:55:55.1387020Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "cffec468-4251-4560-b9ca-39609d63e8f0", + "data": { + "commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "eb200526-c843-11ed-a42a-2be4e70d42a0", + "username": "dotnet_kernel", + "session": "68488ce2-0945-4a31-a44d-1b870ab766a6", + "date": "2023-03-21T23:55:55.147169Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2a179890-8dc9-4c0c-9beb-b34611edc213", + "username": "dotnet_kernel", + "session": "68488ce2-0945-4a31-a44d-1b870ab766a6", + "date": "2023-03-21T23:55:55.1387020Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "eb20efd6-c843-11ed-a42a-2be4e70d42a0", + "username": "dotnet_kernel", + "session": "50c30335-817c-4ecd-9b05-58986e3aa6de", + "date": "2023-03-21T23:55:55.153174Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0ab61895-7ca0-4328-ad7a-d7bb7e3b6087", + "username": "dotnet_kernel", + "session": "50c30335-817c-4ecd-9b05-58986e3aa6de", + "date": "2023-03-21T23:55:55.1501004Z", + "msg_type": "complete_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "eb22ffd8-c843-11ed-a42a-2be4e70d42a0", + "username": "dotnet_kernel", + "session": "50c30335-817c-4ecd-9b05-58986e3aa6de", + "date": "2023-03-21T23:55:55.167699Z", + "msg_type": "complete_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0ab61895-7ca0-4328-ad7a-d7bb7e3b6087", + "username": "dotnet_kernel", + "session": "50c30335-817c-4ecd-9b05-58986e3aa6de", + "date": "2023-03-21T23:55:55.1501004Z", + "msg_type": "complete_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "matches": [ + "prcomp", + "precip", + "predict", + "predict.glm", + "predict.lm", + "preplot", + "presidents", + "pressure", + "prettify", + "pretty", + "pretty.default", + "prettyNum", + "princomp", + "print", + "print.AsIs", + "print.by", + "print.condition", + "print.connection", + "print.data.frame", + "print.Date", + "print.default", + "print.difftime", + "print.Dlist", + "print.DLLInfo", + "print.DLLInfoList", + "print.DLLRegisteredRoutines", + "print.eigen", + "print.factor", + "print.function", + "print.hexmode", + "print.libraryIQR", + "print.listof", + "print.NativeRoutineList", + "print.noquote", + "print.numeric_version", + "print.octmode", + "print.packageInfo", + "print.POSIXct", + "print.POSIXlt", + "print.proc_time", + "print.restart", + "print.rle", + "print.simple.list", + "print.srcfile", + "print.srcref", + "print.summary.table", + "print.summary.warnings", + "print.summaryDefault", + "print.table", + "print.vignette", + "print.warnings", + "printCoefmat", + "prmatrix", + "proc.time", + "process.events", + "prod", + "profile", + "prohibitGeneric", + "proj", + "promax", + "prompt", + "promptClass", + "promptData", + "promptImport", + "promptMethods", + "promptPackage", + "prop.table", + "prop.test", + "prop.trend.test", + "prototype", + "provideDimnames" + ], + "cursor_start": 0, + "cursor_end": 2, + "metadata": {}, + "status": "ok" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "eb234e3e-c843-11ed-a42a-2be4e70d42a0", + "username": "dotnet_kernel", + "session": "50c30335-817c-4ecd-9b05-58986e3aa6de", + "date": "2023-03-21T23:55:55.168700Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0ab61895-7ca0-4328-ad7a-d7bb7e3b6087", + "username": "dotnet_kernel", + "session": "50c30335-817c-4ecd-9b05-58986e3aa6de", + "date": "2023-03-21T23:55:55.1501004Z", + "msg_type": "complete_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_completions_and_get_value_produced.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_completions_and_get_value_produced.python3.json new file mode 100644 index 0000000000..48d2b5b541 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_completions_and_get_value_produced.python3.json @@ -0,0 +1,423 @@ +[ + { + "header": { + "msg_id": "181f75f7-b06edae76dc0c257fc728094_10420_10", + "username": "username", + "session": "181f75f7-b06edae76dc0c257fc728094", + "date": "2023-03-21T23:55:53.179913Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "e0570746-53a0-42b9-b011-dbf8ac3e808f", + "username": "dotnet_kernel", + "session": "b17a6f9f-3b72-4fb7-89ce-b818d2ff73d6", + "date": "2023-03-21T23:55:53.1636518Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "181f75f7-b06edae76dc0c257fc728094_10420_12", + "username": "username", + "session": "181f75f7-b06edae76dc0c257fc728094", + "date": "2023-03-21T23:55:53.180917Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "e0570746-53a0-42b9-b011-dbf8ac3e808f", + "username": "dotnet_kernel", + "session": "b17a6f9f-3b72-4fb7-89ce-b818d2ff73d6", + "date": "2023-03-21T23:55:53.1636518Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "181f75f7-b06edae76dc0c257fc728094_10420_11", + "username": "username", + "session": "181f75f7-b06edae76dc0c257fc728094", + "date": "2023-03-21T23:55:53.179913Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "e0570746-53a0-42b9-b011-dbf8ac3e808f", + "username": "dotnet_kernel", + "session": "b17a6f9f-3b72-4fb7-89ce-b818d2ff73d6", + "date": "2023-03-21T23:55:53.1636518Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "181f75f7-b06edae76dc0c257fc728094_10420_13", + "username": "username", + "session": "181f75f7-b06edae76dc0c257fc728094", + "date": "2023-03-21T23:55:53.185911Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c0ca9746-6781-4eb1-8230-3bd805c9a0b5", + "username": "dotnet_kernel", + "session": "f472fa56-6fe4-45e7-84bb-21c697f327ed", + "date": "2023-03-21T23:55:53.1839318Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "181f75f7-b06edae76dc0c257fc728094_10420_14", + "username": "username", + "session": "181f75f7-b06edae76dc0c257fc728094", + "date": "2023-03-21T23:55:53.185911Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c0ca9746-6781-4eb1-8230-3bd805c9a0b5", + "username": "dotnet_kernel", + "session": "f472fa56-6fe4-45e7-84bb-21c697f327ed", + "date": "2023-03-21T23:55:53.1839318Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "181f75f7-b06edae76dc0c257fc728094_10420_16", + "username": "username", + "session": "181f75f7-b06edae76dc0c257fc728094", + "date": "2023-03-21T23:55:53.221429Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c0ca9746-6781-4eb1-8230-3bd805c9a0b5", + "username": "dotnet_kernel", + "session": "f472fa56-6fe4-45e7-84bb-21c697f327ed", + "date": "2023-03-21T23:55:53.1839318Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "181f75f7-b06edae76dc0c257fc728094_10420_15", + "username": "username", + "session": "181f75f7-b06edae76dc0c257fc728094", + "date": "2023-03-21T23:55:53.221429Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c0ca9746-6781-4eb1-8230-3bd805c9a0b5", + "username": "dotnet_kernel", + "session": "f472fa56-6fe4-45e7-84bb-21c697f327ed", + "date": "2023-03-21T23:55:53.1839318Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:55:53.185911Z", + "dependencies_met": true, + "engine": "1715e5ad-923c-4cc3-9fbf-08715312b54c", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "181f75f7-b06edae76dc0c257fc728094_10420_17", + "username": "username", + "session": "181f75f7-b06edae76dc0c257fc728094", + "date": "2023-03-21T23:55:53.225430Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "89a64ed7-d4de-47c2-a697-672d823d8ae5", + "username": "dotnet_kernel", + "session": "8ef247a1-bd07-4cc9-bd7b-46322bb920bc", + "date": "2023-03-21T23:55:53.2242188Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "181f75f7-b06edae76dc0c257fc728094_10420_18", + "username": "username", + "session": "181f75f7-b06edae76dc0c257fc728094", + "date": "2023-03-21T23:55:53.226465Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "89a64ed7-d4de-47c2-a697-672d823d8ae5", + "username": "dotnet_kernel", + "session": "8ef247a1-bd07-4cc9-bd7b-46322bb920bc", + "date": "2023-03-21T23:55:53.2242188Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "1ed16b4f-1f4a-4418-b17f-37fd80c37e0b", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "181f75f7-b06edae76dc0c257fc728094_10420_19", + "username": "username", + "session": "181f75f7-b06edae76dc0c257fc728094", + "date": "2023-03-21T23:55:53.227461Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "89a64ed7-d4de-47c2-a697-672d823d8ae5", + "username": "dotnet_kernel", + "session": "8ef247a1-bd07-4cc9-bd7b-46322bb920bc", + "date": "2023-03-21T23:55:53.2242188Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "181f75f7-b06edae76dc0c257fc728094_10420_20", + "username": "username", + "session": "181f75f7-b06edae76dc0c257fc728094", + "date": "2023-03-21T23:55:53.233459Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "8084ff70-b404-4817-89b1-ebfb015161ca", + "username": "dotnet_kernel", + "session": "937cc4e5-0ea1-4ee6-a938-fe2c0755b930", + "date": "2023-03-21T23:55:53.2324355Z", + "msg_type": "complete_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "181f75f7-b06edae76dc0c257fc728094_10420_22", + "username": "username", + "session": "181f75f7-b06edae76dc0c257fc728094", + "date": "2023-03-21T23:55:53.868426Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "8084ff70-b404-4817-89b1-ebfb015161ca", + "username": "dotnet_kernel", + "session": "937cc4e5-0ea1-4ee6-a938-fe2c0755b930", + "date": "2023-03-21T23:55:53.2324355Z", + "msg_type": "complete_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "181f75f7-b06edae76dc0c257fc728094_10420_21", + "username": "username", + "session": "181f75f7-b06edae76dc0c257fc728094", + "date": "2023-03-21T23:55:53.867429Z", + "msg_type": "complete_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "8084ff70-b404-4817-89b1-ebfb015161ca", + "username": "dotnet_kernel", + "session": "937cc4e5-0ea1-4ee6-a938-fe2c0755b930", + "date": "2023-03-21T23:55:53.2324355Z", + "msg_type": "complete_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "matches": [ + "print", + "property", + "PrintHood/", + "%precision", + "%prun", + "%%prun" + ], + "cursor_start": 0, + "cursor_end": 2, + "metadata": { + "_jupyter_types_experimental": [ + { + "end": 2, + "start": 0, + "type": "function", + "text": "print" + }, + { + "end": 2, + "start": 0, + "type": "", + "text": "property" + }, + { + "end": 2, + "start": 0, + "type": "", + "text": "PrintHood/" + }, + { + "end": 2, + "start": 0, + "type": "", + "text": "%precision" + }, + { + "end": 2, + "start": 0, + "type": "", + "text": "%prun" + }, + { + "end": 2, + "start": 0, + "type": "", + "text": "%%prun" + } + ] + }, + "status": "ok" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_hover_text_and_get_value_produced.ir.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_hover_text_and_get_value_produced.ir.json new file mode 100644 index 0000000000..448faac1be --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_hover_text_and_get_value_produced.ir.json @@ -0,0 +1,342 @@ +[ + { + "header": { + "msg_id": "f12c9f60-c843-11ed-93eb-eb53504a5a3c", + "username": "dotnet_kernel", + "session": "bfc56089-89a3-47d6-bdfe-48d66b7be2a3", + "date": "2023-03-21T23:56:05.296088Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "dd40f229-f8f3-4476-aa59-0221e8ea704a", + "username": "dotnet_kernel", + "session": "bfc56089-89a3-47d6-bdfe-48d66b7be2a3", + "date": "2023-03-21T23:56:05.2228700Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f12cc670-c843-11ed-93eb-eb53504a5a3c", + "username": "dotnet_kernel", + "session": "bfc56089-89a3-47d6-bdfe-48d66b7be2a3", + "date": "2023-03-21T23:56:05.298088Z", + "msg_type": "kernel_info_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "dd40f229-f8f3-4476-aa59-0221e8ea704a", + "username": "dotnet_kernel", + "session": "bfc56089-89a3-47d6-bdfe-48d66b7be2a3", + "date": "2023-03-21T23:56:05.2228700Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.0", + "implementation": "IRkernel", + "implementation_version": "0.8.15", + "language_info": { + "name": "R", + "version": "3.6.1", + "mimetype": "text/x-r-source", + "file_extension": ".r", + "pygments_lexer": "r", + "codemirror_mode": "r" + }, + "banner": "R version 3.6.1 (2019-07-05)", + "status": "ok", + "help_links": [] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f12d1490-c843-11ed-93eb-eb53504a5a3c", + "username": "dotnet_kernel", + "session": "bfc56089-89a3-47d6-bdfe-48d66b7be2a3", + "date": "2023-03-21T23:56:05.299090Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "dd40f229-f8f3-4476-aa59-0221e8ea704a", + "username": "dotnet_kernel", + "session": "bfc56089-89a3-47d6-bdfe-48d66b7be2a3", + "date": "2023-03-21T23:56:05.2228700Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f12dd7e0-c843-11ed-93eb-eb53504a5a3c", + "username": "dotnet_kernel", + "session": "9bc45a57-5f3f-4930-b198-757ea2017d19", + "date": "2023-03-21T23:56:05.304088Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2e9c96cf-8747-49e7-87bb-bcefb693c77b", + "username": "dotnet_kernel", + "session": "9bc45a57-5f3f-4930-b198-757ea2017d19", + "date": "2023-03-21T23:56:05.2998779Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f12e2646-c843-11ed-93eb-eb53504a5a3c", + "username": "dotnet_kernel", + "session": "9bc45a57-5f3f-4930-b198-757ea2017d19", + "date": "2023-03-21T23:56:05.307102Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2e9c96cf-8747-49e7-87bb-bcefb693c77b", + "username": "dotnet_kernel", + "session": "9bc45a57-5f3f-4930-b198-757ea2017d19", + "date": "2023-03-21T23:56:05.2998779Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f13e0890-c843-11ed-93eb-eb53504a5a3c", + "username": "dotnet_kernel", + "session": "9bc45a57-5f3f-4930-b198-757ea2017d19", + "date": "2023-03-21T23:56:05.410191Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2e9c96cf-8747-49e7-87bb-bcefb693c77b", + "username": "dotnet_kernel", + "session": "9bc45a57-5f3f-4930-b198-757ea2017d19", + "date": "2023-03-21T23:56:05.2998779Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f13e2f96-c843-11ed-93eb-eb53504a5a3c", + "username": "dotnet_kernel", + "session": "9bc45a57-5f3f-4930-b198-757ea2017d19", + "date": "2023-03-21T23:56:05.412191Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2e9c96cf-8747-49e7-87bb-bcefb693c77b", + "username": "dotnet_kernel", + "session": "9bc45a57-5f3f-4930-b198-757ea2017d19", + "date": "2023-03-21T23:56:05.2998779Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f13edfe0-c843-11ed-93eb-eb53504a5a3c", + "username": "dotnet_kernel", + "session": "aff26447-f13c-41aa-952f-1ec17a72acae", + "date": "2023-03-21T23:56:05.415703Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "893821b9-d8d3-4565-a39f-268abc299f7b", + "username": "dotnet_kernel", + "session": "aff26447-f13c-41aa-952f-1ec17a72acae", + "date": "2023-03-21T23:56:05.4126453Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f13f7c20-c843-11ed-93eb-eb53504a5a3c", + "username": "dotnet_kernel", + "session": "aff26447-f13c-41aa-952f-1ec17a72acae", + "date": "2023-03-21T23:56:05.420704Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "893821b9-d8d3-4565-a39f-268abc299f7b", + "username": "dotnet_kernel", + "session": "aff26447-f13c-41aa-952f-1ec17a72acae", + "date": "2023-03-21T23:56:05.4126453Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "0be2a9a7-b8fc-460d-8667-4e8ff204cc27", + "data": { + "commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f13fa330-c843-11ed-93eb-eb53504a5a3c", + "username": "dotnet_kernel", + "session": "aff26447-f13c-41aa-952f-1ec17a72acae", + "date": "2023-03-21T23:56:05.421706Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "893821b9-d8d3-4565-a39f-268abc299f7b", + "username": "dotnet_kernel", + "session": "aff26447-f13c-41aa-952f-1ec17a72acae", + "date": "2023-03-21T23:56:05.4126453Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f14066a8-c843-11ed-93eb-eb53504a5a3c", + "username": "dotnet_kernel", + "session": "34f5487d-e255-4fc8-9d24-d9d9d22c2625", + "date": "2023-03-21T23:56:05.426704Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "ba875301-16ad-4d8b-ace2-ab2c513912bd", + "username": "dotnet_kernel", + "session": "34f5487d-e255-4fc8-9d24-d9d9d22c2625", + "date": "2023-03-21T23:56:05.4239063Z", + "msg_type": "inspect_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f15df39e-c843-11ed-93eb-eb53504a5a3c", + "username": "dotnet_kernel", + "session": "34f5487d-e255-4fc8-9d24-d9d9d22c2625", + "date": "2023-03-21T23:56:05.620371Z", + "msg_type": "inspect_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "ba875301-16ad-4d8b-ace2-ab2c513912bd", + "username": "dotnet_kernel", + "session": "34f5487d-e255-4fc8-9d24-d9d9d22c2625", + "date": "2023-03-21T23:56:05.4239063Z", + "msg_type": "inspect_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "status": "ok", + "found": true, + "data": { + "text/plain": "print package:base R Documentation\n\n_\bP_\br_\bi_\bn_\bt _\bV_\ba_\bl_\bu_\be_\bs\n\n_\bD_\be_\bs_\bc_\br_\bi_\bp_\bt_\bi_\bo_\bn:\n\n 'print' prints its argument and returns it _invisibly_ (via\n 'invisible(x)'). It is a generic function which means that new\n printing methods can be easily added for new 'class'es.\n\n_\bU_\bs_\ba_\bg_\be:\n\n print(x, ...)\n \n ## S3 method for class 'factor'\n print(x, quote = FALSE, max.levels = NULL,\n width = getOption(\"width\"), ...)\n \n ## S3 method for class 'table'\n print(x, digits = getOption(\"digits\"), quote = FALSE,\n na.print = \"\", zero.print = \"0\",\n right = is.numeric(x) || is.complex(x),\n justify = \"none\", ...)\n \n ## S3 method for class 'function'\n print(x, useSource = TRUE, ...)\n \n_\bA_\br_\bg_\bu_\bm_\be_\bn_\bt_\bs:\n\n x: an object used to select a method.\n\n ...: further arguments passed to or from other methods.\n\n quote: logical, indicating whether or not strings should be printed\n with surrounding quotes.\n\nmax.levels: integer, indicating how many levels should be printed for a\n factor; if '0', no extra \"Levels\" line will be printed. The\n default, 'NULL', entails choosing 'max.levels' such that the\n levels print on one line of width 'width'.\n\n width: only used when 'max.levels' is NULL, see above.\n\n digits: minimal number of _significant_ digits, see 'print.default'.\n\nna.print: character string (or 'NULL') indicating 'NA' values in\n printed output, see 'print.default'.\n\nzero.print: character specifying how zeros ('0') should be printed; for\n sparse tables, using '\".\"' can produce more readable results,\n similar to printing sparse matrices in 'Matrix'.\n\n right: logical, indicating whether or not strings should be right\n aligned.\n\n justify: character indicating if strings should left- or\n right-justified or left alone, passed to 'format'.\n\nuseSource: logical indicating if internally stored source should be\n used for printing when present, e.g., if 'options(keep.source\n = TRUE)' has been in use.\n\n_\bD_\be_\bt_\ba_\bi_\bl_\bs:\n\n The default method, 'print.default' has its own help page. Use\n 'methods(\"print\")' to get all the methods for the 'print' generic.\n\n 'print.factor' allows some customization and is used for printing\n 'ordered' factors as well.\n\n 'print.table' for printing 'table's allows other customization. As\n of R 3.0.0, it only prints a description in case of a table with\n 0-extents (this can happen if a classifier has no valid data).\n\n See 'noquote' as an example of a class whose main purpose is a\n specific 'print' method.\n\n_\bR_\be_\bf_\be_\br_\be_\bn_\bc_\be_\bs:\n\n Chambers, J. M. and Hastie, T. J. (1992) _Statistical Models in\n S._ Wadsworth & Brooks/Cole.\n\n_\bS_\be_\be _\bA_\bl_\bs_\bo:\n\n The default method 'print.default', and help for the methods\n above; further 'options', 'noquote'.\n\n For more customizable (but cumbersome) printing, see 'cat',\n 'format' or also 'write'. For a simple prototypical print method,\n see '.print.via.format' in package 'tools'.\n\n_\bE_\bx_\ba_\bm_\bp_\bl_\be_\bs:\n\n require(stats)\n \n ts(1:20) #-- print is the \"Default function\" --> print.ts(.) is called\n for(i in 1:3) print(1:i)\n \n ## Printing of factors\n attenu$station ## 117 levels -> 'max.levels' depending on width\n \n ## ordered factors: levels \"l1 < l2 < ..\"\n esoph$agegp[1:12]\n esoph$alcgp[1:12]\n \n ## Printing of sparse (contingency) tables\n set.seed(521)\n t1 <- round(abs(rt(200, df = 1.8)))\n t2 <- round(abs(rt(200, df = 1.4)))\n table(t1, t2) # simple\n print(table(t1, t2), zero.print = \".\") # nicer to read\n \n ## same for non-integer \"table\":\n T <- table(t2,t1)\n T <- T * (1+round(rlnorm(length(T)))/4)\n print(T, zero.print = \".\") # quite nicer,\n print.table(T[,2:8] * 1e9, digits=3, zero.print = \".\")\n ## still slightly inferior to Matrix::Matrix(T) for larger T\n \n ## Corner cases with empty extents:\n table(1, NA) # < table of extent 1 x 0 >\n ", + "text/html": "\n
print {base}R Documentation
\n\n

Print Values

\n\n

Description

\n\n

print prints its argument and returns it invisibly (via\ninvisible(x)). It is a generic function which means that\nnew printing methods can be easily added for new classes.\n

\n\n\n

Usage

\n\n
\nprint(x, ...)\n\n## S3 method for class 'factor'\nprint(x, quote = FALSE, max.levels = NULL,\n      width = getOption(\"width\"), ...)\n\n## S3 method for class 'table'\nprint(x, digits = getOption(\"digits\"), quote = FALSE,\n      na.print = \"\", zero.print = \"0\",\n      right = is.numeric(x) || is.complex(x),\n      justify = \"none\", ...)\n\n## S3 method for class 'function'\nprint(x, useSource = TRUE, ...)\n
\n\n\n

Arguments

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
x\n

an object used to select a method.

\n
...\n

further arguments passed to or from other methods.

\n
quote\n

logical, indicating whether or not strings should be\nprinted with surrounding quotes.

\n
max.levels\n

integer, indicating how many levels should be\nprinted for a factor; if 0, no extra "Levels" line will be\nprinted. The default, NULL, entails choosing max.levels\nsuch that the levels print on one line of width width.

\n
width\n

only used when max.levels is NULL, see above.

\n
digits\n

minimal number of significant digits, see\nprint.default.

\n
na.print\n

character string (or NULL) indicating\nNA values in printed output, see\nprint.default.

\n
zero.print\n

character specifying how zeros (0) should be\nprinted; for sparse tables, using \".\" can produce more\nreadable results, similar to printing sparse matrices in Matrix.

\n
right\n

logical, indicating whether or not strings should be\nright aligned.

\n
justify\n

character indicating if strings should left- or\nright-justified or left alone, passed to format.

\n
useSource\n

logical indicating if internally stored source\nshould be used for printing when present, e.g., if\noptions(keep.source = TRUE) has been in use.

\n
\n\n\n

Details

\n\n

The default method, print.default has its own help page.\nUse methods(\"print\") to get all the methods for the\nprint generic.\n

\n

print.factor allows some customization and is used for printing\nordered factors as well.\n

\n

print.table for printing tables allows other\ncustomization. As of R 3.0.0, it only prints a description in case of a table\nwith 0-extents (this can happen if a classifier has no valid data).\n

\n

See noquote as an example of a class whose main\npurpose is a specific print method.\n

\n\n\n

References

\n\n

Chambers, J. M. and Hastie, T. J. (1992)\nStatistical Models in S.\nWadsworth & Brooks/Cole.\n

\n\n\n

See Also

\n\n

The default method print.default, and help for the\nmethods above; further options, noquote.\n

\n

For more customizable (but cumbersome) printing, see\ncat, format or also write.\nFor a simple prototypical print method, see\n.print.via.format in package tools.\n

\n\n\n

Examples

\n\n
\nrequire(stats)\n\nts(1:20)  #-- print is the \"Default function\" --> print.ts(.) is called\nfor(i in 1:3) print(1:i)\n\n## Printing of factors\nattenu$station ## 117 levels -> 'max.levels' depending on width\n\n## ordered factors: levels  \"l1 < l2 < ..\"\nesoph$agegp[1:12]\nesoph$alcgp[1:12]\n\n## Printing of sparse (contingency) tables\nset.seed(521)\nt1 <- round(abs(rt(200, df = 1.8)))\nt2 <- round(abs(rt(200, df = 1.4)))\ntable(t1, t2) # simple\nprint(table(t1, t2), zero.print = \".\") # nicer to read\n\n## same for non-integer \"table\":\nT <- table(t2,t1)\nT <- T * (1+round(rlnorm(length(T)))/4)\nprint(T, zero.print = \".\") # quite nicer,\nprint.table(T[,2:8] * 1e9, digits=3, zero.print = \".\")\n## still slightly inferior to  Matrix::Matrix(T)  for larger T\n\n## Corner cases with empty extents:\ntable(1, NA) # < table of extent 1 x 0 >\n
\n\n
[Package base version 3.6.1 ]
", + "text/latex": "\\inputencoding{utf8}\n\\HeaderA{print}{Print Values}{print}\n\\methaliasA{print.Dlist}{print}{print.Dlist}\n\\methaliasA{print.factor}{print}{print.factor}\n\\methaliasA{print.function}{print}{print.function}\n\\methaliasA{print.listof}{print}{print.listof}\n\\methaliasA{print.simple.list}{print}{print.simple.list}\n\\methaliasA{print.table}{print}{print.table}\n\\keyword{print}{print}\n%\n\\begin{Description}\\relax\n\\code{print} prints its argument and returns it \\emph{invisibly} (via\n\\code{\\LinkA{invisible}{invisible}(x)}). It is a generic function which means that\nnew printing methods can be easily added for new \\code{\\LinkA{class}{class}}es.\n\\end{Description}\n%\n\\begin{Usage}\n\\begin{verbatim}\n\nprint(x, ...)\n\n## S3 method for class 'factor'\nprint(x, quote = FALSE, max.levels = NULL,\n width = getOption(\"width\"), ...)\n\n## S3 method for class 'table'\nprint(x, digits = getOption(\"digits\"), quote = FALSE,\n na.print = \"\", zero.print = \"0\",\n right = is.numeric(x) || is.complex(x),\n justify = \"none\", ...)\n\n## S3 method for class 'function'\nprint(x, useSource = TRUE, ...)\n\\end{verbatim}\n\\end{Usage}\n%\n\\begin{Arguments}\n\\begin{ldescription}\n\\item[\\code{x}] an object used to select a method.\n\\item[\\code{...}] further arguments passed to or from other methods.\n\\item[\\code{quote}] logical, indicating whether or not strings should be\nprinted with surrounding quotes.\n\\item[\\code{max.levels}] integer, indicating how many levels should be\nprinted for a factor; if \\code{0}, no extra \"Levels\" line will be\nprinted. The default, \\code{NULL}, entails choosing \\code{max.levels}\nsuch that the levels print on one line of width \\code{width}.\n\\item[\\code{width}] only used when \\code{max.levels} is NULL, see above.\n\\item[\\code{digits}] minimal number of \\emph{significant} digits, see\n\\code{\\LinkA{print.default}{print.default}}.\n\\item[\\code{na.print}] character string (or \\code{NULL}) indicating\n\\code{\\LinkA{NA}{NA}} values in printed output, see\n\\code{\\LinkA{print.default}{print.default}}.\n\\item[\\code{zero.print}] character specifying how zeros (\\code{0}) should be\nprinted; for sparse tables, using \\code{\".\"} can produce more\nreadable results, similar to printing sparse matrices in \\Rhref{https://CRAN.R-project.org/package=Matrix}{\\pkg{Matrix}}.\n\\item[\\code{right}] logical, indicating whether or not strings should be\nright aligned.\n\\item[\\code{justify}] character indicating if strings should left- or\nright-justified or left alone, passed to \\code{\\LinkA{format}{format}}.\n\\item[\\code{useSource}] logical indicating if internally stored source\nshould be used for printing when present, e.g., if\n\\code{\\LinkA{options}{options}(keep.source = TRUE)} has been in use.\n\\end{ldescription}\n\\end{Arguments}\n%\n\\begin{Details}\\relax\nThe default method, \\code{\\LinkA{print.default}{print.default}} has its own help page.\nUse \\code{\\LinkA{methods}{methods}(\"print\")} to get all the methods for the\n\\code{print} generic.\n\n\\code{print.factor} allows some customization and is used for printing\n\\code{\\LinkA{ordered}{ordered}} factors as well.\n\n\\code{print.table} for printing \\code{\\LinkA{table}{table}}s allows other\ncustomization. As of R 3.0.0, it only prints a description in case of a table\nwith 0-extents (this can happen if a classifier has no valid data).\n\nSee \\code{\\LinkA{noquote}{noquote}} as an example of a class whose main\npurpose is a specific \\code{print} method.\n\\end{Details}\n%\n\\begin{References}\\relax\nChambers, J. M. and Hastie, T. J. (1992)\n\\emph{Statistical Models in S.}\nWadsworth \\& Brooks/Cole.\n\\end{References}\n%\n\\begin{SeeAlso}\\relax\nThe default method \\code{\\LinkA{print.default}{print.default}}, and help for the\nmethods above; further \\code{\\LinkA{options}{options}}, \\code{\\LinkA{noquote}{noquote}}.\n\nFor more customizable (but cumbersome) printing, see\n\\code{\\LinkA{cat}{cat}}, \\code{\\LinkA{format}{format}} or also \\code{\\LinkA{write}{write}}.\nFor a simple prototypical print method, see\n\\code{\\LinkA{.print.via.format}{.print.via.format}} in package \\pkg{tools}.\n\\end{SeeAlso}\n%\n\\begin{Examples}\n\\begin{ExampleCode}\nrequire(stats)\n\nts(1:20) #-- print is the \"Default function\" --> print.ts(.) is called\nfor(i in 1:3) print(1:i)\n\n## Printing of factors\nattenu$station ## 117 levels -> 'max.levels' depending on width\n\n## ordered factors: levels \"l1 < l2 < ..\"\nesoph$agegp[1:12]\nesoph$alcgp[1:12]\n\n## Printing of sparse (contingency) tables\nset.seed(521)\nt1 <- round(abs(rt(200, df = 1.8)))\nt2 <- round(abs(rt(200, df = 1.4)))\ntable(t1, t2) # simple\nprint(table(t1, t2), zero.print = \".\") # nicer to read\n\n## same for non-integer \"table\":\nT <- table(t2,t1)\nT <- T * (1+round(rlnorm(length(T)))/4)\nprint(T, zero.print = \".\") # quite nicer,\nprint.table(T[,2:8] * 1e9, digits=3, zero.print = \".\")\n## still slightly inferior to Matrix::Matrix(T) for larger T\n\n## Corner cases with empty extents:\ntable(1, NA) # < table of extent 1 x 0 >\n\\end{ExampleCode}\n\\end{Examples}" + }, + "metadata": {} + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f15e41be-c843-11ed-93eb-eb53504a5a3c", + "username": "dotnet_kernel", + "session": "34f5487d-e255-4fc8-9d24-d9d9d22c2625", + "date": "2023-03-21T23:56:05.621372Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "ba875301-16ad-4d8b-ace2-ab2c513912bd", + "username": "dotnet_kernel", + "session": "34f5487d-e255-4fc8-9d24-d9d9d22c2625", + "date": "2023-03-21T23:56:05.4239063Z", + "msg_type": "inspect_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_hover_text_and_get_value_produced.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_hover_text_and_get_value_produced.python3.json new file mode 100644 index 0000000000..0fb34c3612 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_hover_text_and_get_value_produced.python3.json @@ -0,0 +1,378 @@ +[ + { + "header": { + "msg_id": "234f0560-67ce339e282ed3604f68082f_15408_10", + "username": "username", + "session": "234f0560-67ce339e282ed3604f68082f", + "date": "2023-03-21T23:56:04.201578Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "3776ad3b-5665-4a83-9f9e-263cb73ab037", + "username": "dotnet_kernel", + "session": "5c41ac22-40f8-45ce-967b-79d2f34fae6c", + "date": "2023-03-21T23:56:04.1668666Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "234f0560-67ce339e282ed3604f68082f_15408_12", + "username": "username", + "session": "234f0560-67ce339e282ed3604f68082f", + "date": "2023-03-21T23:56:04.202577Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "3776ad3b-5665-4a83-9f9e-263cb73ab037", + "username": "dotnet_kernel", + "session": "5c41ac22-40f8-45ce-967b-79d2f34fae6c", + "date": "2023-03-21T23:56:04.1668666Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "234f0560-67ce339e282ed3604f68082f_15408_11", + "username": "username", + "session": "234f0560-67ce339e282ed3604f68082f", + "date": "2023-03-21T23:56:04.201578Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "3776ad3b-5665-4a83-9f9e-263cb73ab037", + "username": "dotnet_kernel", + "session": "5c41ac22-40f8-45ce-967b-79d2f34fae6c", + "date": "2023-03-21T23:56:04.1668666Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "234f0560-67ce339e282ed3604f68082f_15408_13", + "username": "username", + "session": "234f0560-67ce339e282ed3604f68082f", + "date": "2023-03-21T23:56:04.207576Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "888c6bb4-7b86-4a93-be03-aacb09aacf92", + "username": "dotnet_kernel", + "session": "fd84b398-61e5-4c36-8e64-eb36c9d9a580", + "date": "2023-03-21T23:56:04.2055536Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "234f0560-67ce339e282ed3604f68082f_15408_14", + "username": "username", + "session": "234f0560-67ce339e282ed3604f68082f", + "date": "2023-03-21T23:56:04.208577Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "888c6bb4-7b86-4a93-be03-aacb09aacf92", + "username": "dotnet_kernel", + "session": "fd84b398-61e5-4c36-8e64-eb36c9d9a580", + "date": "2023-03-21T23:56:04.2055536Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "234f0560-67ce339e282ed3604f68082f_15408_16", + "username": "username", + "session": "234f0560-67ce339e282ed3604f68082f", + "date": "2023-03-21T23:56:04.239091Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "888c6bb4-7b86-4a93-be03-aacb09aacf92", + "username": "dotnet_kernel", + "session": "fd84b398-61e5-4c36-8e64-eb36c9d9a580", + "date": "2023-03-21T23:56:04.2055536Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "234f0560-67ce339e282ed3604f68082f_15408_15", + "username": "username", + "session": "234f0560-67ce339e282ed3604f68082f", + "date": "2023-03-21T23:56:04.239091Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "888c6bb4-7b86-4a93-be03-aacb09aacf92", + "username": "dotnet_kernel", + "session": "fd84b398-61e5-4c36-8e64-eb36c9d9a580", + "date": "2023-03-21T23:56:04.2055536Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:56:04.207576Z", + "dependencies_met": true, + "engine": "5f779fe9-3996-4501-863e-9f23566d5f1f", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "234f0560-67ce339e282ed3604f68082f_15408_17", + "username": "username", + "session": "234f0560-67ce339e282ed3604f68082f", + "date": "2023-03-21T23:56:04.242107Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "f3470ee1-6f05-414a-b338-6c1adb1d5cdb", + "username": "dotnet_kernel", + "session": "0f442172-4e75-4af0-9425-a3228e4bb6c5", + "date": "2023-03-21T23:56:04.2413697Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "234f0560-67ce339e282ed3604f68082f_15408_18", + "username": "username", + "session": "234f0560-67ce339e282ed3604f68082f", + "date": "2023-03-21T23:56:04.243106Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "f3470ee1-6f05-414a-b338-6c1adb1d5cdb", + "username": "dotnet_kernel", + "session": "0f442172-4e75-4af0-9425-a3228e4bb6c5", + "date": "2023-03-21T23:56:04.2413697Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "84c6c0c8-96fb-43f0-80ef-ed7d098f577b", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "234f0560-67ce339e282ed3604f68082f_15408_19", + "username": "username", + "session": "234f0560-67ce339e282ed3604f68082f", + "date": "2023-03-21T23:56:04.244104Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "f3470ee1-6f05-414a-b338-6c1adb1d5cdb", + "username": "dotnet_kernel", + "session": "0f442172-4e75-4af0-9425-a3228e4bb6c5", + "date": "2023-03-21T23:56:04.2413697Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "234f0560-67ce339e282ed3604f68082f_15408_20", + "username": "username", + "session": "234f0560-67ce339e282ed3604f68082f", + "date": "2023-03-21T23:56:04.250106Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "7cfba6d6-e3dc-48a0-8f30-877b65fa4b61", + "username": "dotnet_kernel", + "session": "449ceadc-56b1-4331-94ac-0d149c4cf9fe", + "date": "2023-03-21T23:56:04.2490788Z", + "msg_type": "inspect_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "234f0560-67ce339e282ed3604f68082f_15408_22", + "username": "username", + "session": "234f0560-67ce339e282ed3604f68082f", + "date": "2023-03-21T23:56:04.252105Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "7cfba6d6-e3dc-48a0-8f30-877b65fa4b61", + "username": "dotnet_kernel", + "session": "449ceadc-56b1-4331-94ac-0d149c4cf9fe", + "date": "2023-03-21T23:56:04.2490788Z", + "msg_type": "inspect_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "234f0560-67ce339e282ed3604f68082f_15408_21", + "username": "username", + "session": "234f0560-67ce339e282ed3604f68082f", + "date": "2023-03-21T23:56:04.251109Z", + "msg_type": "inspect_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "7cfba6d6-e3dc-48a0-8f30-877b65fa4b61", + "username": "dotnet_kernel", + "session": "449ceadc-56b1-4331-94ac-0d149c4cf9fe", + "date": "2023-03-21T23:56:04.2490788Z", + "msg_type": "inspect_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "status": "ok", + "found": true, + "data": { + "text/plain": "\u001B[1;31mDocstring:\u001B[0m\nprint(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n\nPrints the values to a stream, or to sys.stdout by default.\nOptional keyword arguments:\nfile: a file-like object (stream); defaults to the current sys.stdout.\nsep: string inserted between values, default a space.\nend: string appended after the last value, default a newline.\nflush: whether to forcibly flush the stream.\n\u001B[1;31mType:\u001B[0m builtin_function_or_method\n" + }, + "metadata": {} + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_signature_help_and_get_value_produced.ir.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_signature_help_and_get_value_produced.ir.json new file mode 100644 index 0000000000..6683336f81 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_signature_help_and_get_value_produced.ir.json @@ -0,0 +1,342 @@ +[ + { + "header": { + "msg_id": "e81aba24-c843-11ed-93dd-dd93b86c8355", + "username": "dotnet_kernel", + "session": "a6fdba27-0634-481d-84a4-6f61e56640df", + "date": "2023-03-21T23:55:50.108355Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "17d5ad0e-194a-44dc-a9a9-51762378e482", + "username": "dotnet_kernel", + "session": "a6fdba27-0634-481d-84a4-6f61e56640df", + "date": "2023-03-21T23:55:50.0490835Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "e81f287a-c843-11ed-93dd-dd93b86c8355", + "username": "dotnet_kernel", + "session": "a6fdba27-0634-481d-84a4-6f61e56640df", + "date": "2023-03-21T23:55:50.110355Z", + "msg_type": "kernel_info_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "17d5ad0e-194a-44dc-a9a9-51762378e482", + "username": "dotnet_kernel", + "session": "a6fdba27-0634-481d-84a4-6f61e56640df", + "date": "2023-03-21T23:55:50.0490835Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.0", + "implementation": "IRkernel", + "implementation_version": "0.8.15", + "language_info": { + "name": "R", + "version": "3.6.1", + "mimetype": "text/x-r-source", + "file_extension": ".r", + "pygments_lexer": "r", + "codemirror_mode": "r" + }, + "banner": "R version 3.6.1 (2019-07-05)", + "status": "ok", + "help_links": [] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "e81f9dbe-c843-11ed-93dd-dd93b86c8355", + "username": "dotnet_kernel", + "session": "a6fdba27-0634-481d-84a4-6f61e56640df", + "date": "2023-03-21T23:55:50.111356Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "17d5ad0e-194a-44dc-a9a9-51762378e482", + "username": "dotnet_kernel", + "session": "a6fdba27-0634-481d-84a4-6f61e56640df", + "date": "2023-03-21T23:55:50.0490835Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "e82012ee-c843-11ed-93dd-dd93b86c8355", + "username": "dotnet_kernel", + "session": "1e19f29a-56f3-49b9-be28-99155c09cd9d", + "date": "2023-03-21T23:55:50.114356Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2e0daf41-cdaa-480f-8641-acae30a64880", + "username": "dotnet_kernel", + "session": "1e19f29a-56f3-49b9-be28-99155c09cd9d", + "date": "2023-03-21T23:55:50.1116609Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "e820610e-c843-11ed-93dd-dd93b86c8355", + "username": "dotnet_kernel", + "session": "1e19f29a-56f3-49b9-be28-99155c09cd9d", + "date": "2023-03-21T23:55:50.117364Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2e0daf41-cdaa-480f-8641-acae30a64880", + "username": "dotnet_kernel", + "session": "1e19f29a-56f3-49b9-be28-99155c09cd9d", + "date": "2023-03-21T23:55:50.1116609Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "e831c99e-c843-11ed-93dd-dd93b86c8355", + "username": "dotnet_kernel", + "session": "1e19f29a-56f3-49b9-be28-99155c09cd9d", + "date": "2023-03-21T23:55:50.230441Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2e0daf41-cdaa-480f-8641-acae30a64880", + "username": "dotnet_kernel", + "session": "1e19f29a-56f3-49b9-be28-99155c09cd9d", + "date": "2023-03-21T23:55:50.1116609Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "e831f09a-c843-11ed-93dd-dd93b86c8355", + "username": "dotnet_kernel", + "session": "1e19f29a-56f3-49b9-be28-99155c09cd9d", + "date": "2023-03-21T23:55:50.232446Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2e0daf41-cdaa-480f-8641-acae30a64880", + "username": "dotnet_kernel", + "session": "1e19f29a-56f3-49b9-be28-99155c09cd9d", + "date": "2023-03-21T23:55:50.1116609Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "e8328d02-c843-11ed-93dd-dd93b86c8355", + "username": "dotnet_kernel", + "session": "901d8703-7d66-4f73-b453-c0313a2177ef", + "date": "2023-03-21T23:55:50.235442Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "9bb2cf47-4243-4674-b2dd-da53df2451a3", + "username": "dotnet_kernel", + "session": "901d8703-7d66-4f73-b453-c0313a2177ef", + "date": "2023-03-21T23:55:50.2329081Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "e833291a-c843-11ed-93dd-dd93b86c8355", + "username": "dotnet_kernel", + "session": "901d8703-7d66-4f73-b453-c0313a2177ef", + "date": "2023-03-21T23:55:50.239441Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "9bb2cf47-4243-4674-b2dd-da53df2451a3", + "username": "dotnet_kernel", + "session": "901d8703-7d66-4f73-b453-c0313a2177ef", + "date": "2023-03-21T23:55:50.2329081Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "fc8a2845-dbf6-4629-b427-abf6f8ca7b93", + "data": { + "commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "e833502a-c843-11ed-93dd-dd93b86c8355", + "username": "dotnet_kernel", + "session": "901d8703-7d66-4f73-b453-c0313a2177ef", + "date": "2023-03-21T23:55:50.240446Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "9bb2cf47-4243-4674-b2dd-da53df2451a3", + "username": "dotnet_kernel", + "session": "901d8703-7d66-4f73-b453-c0313a2177ef", + "date": "2023-03-21T23:55:50.2329081Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "e83413e8-c843-11ed-93dd-dd93b86c8355", + "username": "dotnet_kernel", + "session": "6b23083a-bb76-4a5a-960e-293676d5ffe3", + "date": "2023-03-21T23:55:50.245451Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "91de1d9a-eec2-4865-89e1-efdba88663b4", + "username": "dotnet_kernel", + "session": "6b23083a-bb76-4a5a-960e-293676d5ffe3", + "date": "2023-03-21T23:55:50.2436932Z", + "msg_type": "inspect_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "e861d210-c843-11ed-93dd-dd93b86c8355", + "username": "dotnet_kernel", + "session": "6b23083a-bb76-4a5a-960e-293676d5ffe3", + "date": "2023-03-21T23:55:50.546233Z", + "msg_type": "inspect_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "91de1d9a-eec2-4865-89e1-efdba88663b4", + "username": "dotnet_kernel", + "session": "6b23083a-bb76-4a5a-960e-293676d5ffe3", + "date": "2023-03-21T23:55:50.2436932Z", + "msg_type": "inspect_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "status": "ok", + "found": true, + "data": { + "text/plain": "print package:base R Documentation\n\n_\bP_\br_\bi_\bn_\bt _\bV_\ba_\bl_\bu_\be_\bs\n\n_\bD_\be_\bs_\bc_\br_\bi_\bp_\bt_\bi_\bo_\bn:\n\n 'print' prints its argument and returns it _invisibly_ (via\n 'invisible(x)'). It is a generic function which means that new\n printing methods can be easily added for new 'class'es.\n\n_\bU_\bs_\ba_\bg_\be:\n\n print(x, ...)\n \n ## S3 method for class 'factor'\n print(x, quote = FALSE, max.levels = NULL,\n width = getOption(\"width\"), ...)\n \n ## S3 method for class 'table'\n print(x, digits = getOption(\"digits\"), quote = FALSE,\n na.print = \"\", zero.print = \"0\",\n right = is.numeric(x) || is.complex(x),\n justify = \"none\", ...)\n \n ## S3 method for class 'function'\n print(x, useSource = TRUE, ...)\n \n_\bA_\br_\bg_\bu_\bm_\be_\bn_\bt_\bs:\n\n x: an object used to select a method.\n\n ...: further arguments passed to or from other methods.\n\n quote: logical, indicating whether or not strings should be printed\n with surrounding quotes.\n\nmax.levels: integer, indicating how many levels should be printed for a\n factor; if '0', no extra \"Levels\" line will be printed. The\n default, 'NULL', entails choosing 'max.levels' such that the\n levels print on one line of width 'width'.\n\n width: only used when 'max.levels' is NULL, see above.\n\n digits: minimal number of _significant_ digits, see 'print.default'.\n\nna.print: character string (or 'NULL') indicating 'NA' values in\n printed output, see 'print.default'.\n\nzero.print: character specifying how zeros ('0') should be printed; for\n sparse tables, using '\".\"' can produce more readable results,\n similar to printing sparse matrices in 'Matrix'.\n\n right: logical, indicating whether or not strings should be right\n aligned.\n\n justify: character indicating if strings should left- or\n right-justified or left alone, passed to 'format'.\n\nuseSource: logical indicating if internally stored source should be\n used for printing when present, e.g., if 'options(keep.source\n = TRUE)' has been in use.\n\n_\bD_\be_\bt_\ba_\bi_\bl_\bs:\n\n The default method, 'print.default' has its own help page. Use\n 'methods(\"print\")' to get all the methods for the 'print' generic.\n\n 'print.factor' allows some customization and is used for printing\n 'ordered' factors as well.\n\n 'print.table' for printing 'table's allows other customization. As\n of R 3.0.0, it only prints a description in case of a table with\n 0-extents (this can happen if a classifier has no valid data).\n\n See 'noquote' as an example of a class whose main purpose is a\n specific 'print' method.\n\n_\bR_\be_\bf_\be_\br_\be_\bn_\bc_\be_\bs:\n\n Chambers, J. M. and Hastie, T. J. (1992) _Statistical Models in\n S._ Wadsworth & Brooks/Cole.\n\n_\bS_\be_\be _\bA_\bl_\bs_\bo:\n\n The default method 'print.default', and help for the methods\n above; further 'options', 'noquote'.\n\n For more customizable (but cumbersome) printing, see 'cat',\n 'format' or also 'write'. For a simple prototypical print method,\n see '.print.via.format' in package 'tools'.\n\n_\bE_\bx_\ba_\bm_\bp_\bl_\be_\bs:\n\n require(stats)\n \n ts(1:20) #-- print is the \"Default function\" --> print.ts(.) is called\n for(i in 1:3) print(1:i)\n \n ## Printing of factors\n attenu$station ## 117 levels -> 'max.levels' depending on width\n \n ## ordered factors: levels \"l1 < l2 < ..\"\n esoph$agegp[1:12]\n esoph$alcgp[1:12]\n \n ## Printing of sparse (contingency) tables\n set.seed(521)\n t1 <- round(abs(rt(200, df = 1.8)))\n t2 <- round(abs(rt(200, df = 1.4)))\n table(t1, t2) # simple\n print(table(t1, t2), zero.print = \".\") # nicer to read\n \n ## same for non-integer \"table\":\n T <- table(t2,t1)\n T <- T * (1+round(rlnorm(length(T)))/4)\n print(T, zero.print = \".\") # quite nicer,\n print.table(T[,2:8] * 1e9, digits=3, zero.print = \".\")\n ## still slightly inferior to Matrix::Matrix(T) for larger T\n \n ## Corner cases with empty extents:\n table(1, NA) # < table of extent 1 x 0 >\n ", + "text/html": "\n
print {base}R Documentation
\n\n

Print Values

\n\n

Description

\n\n

print prints its argument and returns it invisibly (via\ninvisible(x)). It is a generic function which means that\nnew printing methods can be easily added for new classes.\n

\n\n\n

Usage

\n\n
\nprint(x, ...)\n\n## S3 method for class 'factor'\nprint(x, quote = FALSE, max.levels = NULL,\n      width = getOption(\"width\"), ...)\n\n## S3 method for class 'table'\nprint(x, digits = getOption(\"digits\"), quote = FALSE,\n      na.print = \"\", zero.print = \"0\",\n      right = is.numeric(x) || is.complex(x),\n      justify = \"none\", ...)\n\n## S3 method for class 'function'\nprint(x, useSource = TRUE, ...)\n
\n\n\n

Arguments

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
x\n

an object used to select a method.

\n
...\n

further arguments passed to or from other methods.

\n
quote\n

logical, indicating whether or not strings should be\nprinted with surrounding quotes.

\n
max.levels\n

integer, indicating how many levels should be\nprinted for a factor; if 0, no extra "Levels" line will be\nprinted. The default, NULL, entails choosing max.levels\nsuch that the levels print on one line of width width.

\n
width\n

only used when max.levels is NULL, see above.

\n
digits\n

minimal number of significant digits, see\nprint.default.

\n
na.print\n

character string (or NULL) indicating\nNA values in printed output, see\nprint.default.

\n
zero.print\n

character specifying how zeros (0) should be\nprinted; for sparse tables, using \".\" can produce more\nreadable results, similar to printing sparse matrices in Matrix.

\n
right\n

logical, indicating whether or not strings should be\nright aligned.

\n
justify\n

character indicating if strings should left- or\nright-justified or left alone, passed to format.

\n
useSource\n

logical indicating if internally stored source\nshould be used for printing when present, e.g., if\noptions(keep.source = TRUE) has been in use.

\n
\n\n\n

Details

\n\n

The default method, print.default has its own help page.\nUse methods(\"print\") to get all the methods for the\nprint generic.\n

\n

print.factor allows some customization and is used for printing\nordered factors as well.\n

\n

print.table for printing tables allows other\ncustomization. As of R 3.0.0, it only prints a description in case of a table\nwith 0-extents (this can happen if a classifier has no valid data).\n

\n

See noquote as an example of a class whose main\npurpose is a specific print method.\n

\n\n\n

References

\n\n

Chambers, J. M. and Hastie, T. J. (1992)\nStatistical Models in S.\nWadsworth & Brooks/Cole.\n

\n\n\n

See Also

\n\n

The default method print.default, and help for the\nmethods above; further options, noquote.\n

\n

For more customizable (but cumbersome) printing, see\ncat, format or also write.\nFor a simple prototypical print method, see\n.print.via.format in package tools.\n

\n\n\n

Examples

\n\n
\nrequire(stats)\n\nts(1:20)  #-- print is the \"Default function\" --> print.ts(.) is called\nfor(i in 1:3) print(1:i)\n\n## Printing of factors\nattenu$station ## 117 levels -> 'max.levels' depending on width\n\n## ordered factors: levels  \"l1 < l2 < ..\"\nesoph$agegp[1:12]\nesoph$alcgp[1:12]\n\n## Printing of sparse (contingency) tables\nset.seed(521)\nt1 <- round(abs(rt(200, df = 1.8)))\nt2 <- round(abs(rt(200, df = 1.4)))\ntable(t1, t2) # simple\nprint(table(t1, t2), zero.print = \".\") # nicer to read\n\n## same for non-integer \"table\":\nT <- table(t2,t1)\nT <- T * (1+round(rlnorm(length(T)))/4)\nprint(T, zero.print = \".\") # quite nicer,\nprint.table(T[,2:8] * 1e9, digits=3, zero.print = \".\")\n## still slightly inferior to  Matrix::Matrix(T)  for larger T\n\n## Corner cases with empty extents:\ntable(1, NA) # < table of extent 1 x 0 >\n
\n\n
[Package base version 3.6.1 ]
", + "text/latex": "\\inputencoding{utf8}\n\\HeaderA{print}{Print Values}{print}\n\\methaliasA{print.Dlist}{print}{print.Dlist}\n\\methaliasA{print.factor}{print}{print.factor}\n\\methaliasA{print.function}{print}{print.function}\n\\methaliasA{print.listof}{print}{print.listof}\n\\methaliasA{print.simple.list}{print}{print.simple.list}\n\\methaliasA{print.table}{print}{print.table}\n\\keyword{print}{print}\n%\n\\begin{Description}\\relax\n\\code{print} prints its argument and returns it \\emph{invisibly} (via\n\\code{\\LinkA{invisible}{invisible}(x)}). It is a generic function which means that\nnew printing methods can be easily added for new \\code{\\LinkA{class}{class}}es.\n\\end{Description}\n%\n\\begin{Usage}\n\\begin{verbatim}\n\nprint(x, ...)\n\n## S3 method for class 'factor'\nprint(x, quote = FALSE, max.levels = NULL,\n width = getOption(\"width\"), ...)\n\n## S3 method for class 'table'\nprint(x, digits = getOption(\"digits\"), quote = FALSE,\n na.print = \"\", zero.print = \"0\",\n right = is.numeric(x) || is.complex(x),\n justify = \"none\", ...)\n\n## S3 method for class 'function'\nprint(x, useSource = TRUE, ...)\n\\end{verbatim}\n\\end{Usage}\n%\n\\begin{Arguments}\n\\begin{ldescription}\n\\item[\\code{x}] an object used to select a method.\n\\item[\\code{...}] further arguments passed to or from other methods.\n\\item[\\code{quote}] logical, indicating whether or not strings should be\nprinted with surrounding quotes.\n\\item[\\code{max.levels}] integer, indicating how many levels should be\nprinted for a factor; if \\code{0}, no extra \"Levels\" line will be\nprinted. The default, \\code{NULL}, entails choosing \\code{max.levels}\nsuch that the levels print on one line of width \\code{width}.\n\\item[\\code{width}] only used when \\code{max.levels} is NULL, see above.\n\\item[\\code{digits}] minimal number of \\emph{significant} digits, see\n\\code{\\LinkA{print.default}{print.default}}.\n\\item[\\code{na.print}] character string (or \\code{NULL}) indicating\n\\code{\\LinkA{NA}{NA}} values in printed output, see\n\\code{\\LinkA{print.default}{print.default}}.\n\\item[\\code{zero.print}] character specifying how zeros (\\code{0}) should be\nprinted; for sparse tables, using \\code{\".\"} can produce more\nreadable results, similar to printing sparse matrices in \\Rhref{https://CRAN.R-project.org/package=Matrix}{\\pkg{Matrix}}.\n\\item[\\code{right}] logical, indicating whether or not strings should be\nright aligned.\n\\item[\\code{justify}] character indicating if strings should left- or\nright-justified or left alone, passed to \\code{\\LinkA{format}{format}}.\n\\item[\\code{useSource}] logical indicating if internally stored source\nshould be used for printing when present, e.g., if\n\\code{\\LinkA{options}{options}(keep.source = TRUE)} has been in use.\n\\end{ldescription}\n\\end{Arguments}\n%\n\\begin{Details}\\relax\nThe default method, \\code{\\LinkA{print.default}{print.default}} has its own help page.\nUse \\code{\\LinkA{methods}{methods}(\"print\")} to get all the methods for the\n\\code{print} generic.\n\n\\code{print.factor} allows some customization and is used for printing\n\\code{\\LinkA{ordered}{ordered}} factors as well.\n\n\\code{print.table} for printing \\code{\\LinkA{table}{table}}s allows other\ncustomization. As of R 3.0.0, it only prints a description in case of a table\nwith 0-extents (this can happen if a classifier has no valid data).\n\nSee \\code{\\LinkA{noquote}{noquote}} as an example of a class whose main\npurpose is a specific \\code{print} method.\n\\end{Details}\n%\n\\begin{References}\\relax\nChambers, J. M. and Hastie, T. J. (1992)\n\\emph{Statistical Models in S.}\nWadsworth \\& Brooks/Cole.\n\\end{References}\n%\n\\begin{SeeAlso}\\relax\nThe default method \\code{\\LinkA{print.default}{print.default}}, and help for the\nmethods above; further \\code{\\LinkA{options}{options}}, \\code{\\LinkA{noquote}{noquote}}.\n\nFor more customizable (but cumbersome) printing, see\n\\code{\\LinkA{cat}{cat}}, \\code{\\LinkA{format}{format}} or also \\code{\\LinkA{write}{write}}.\nFor a simple prototypical print method, see\n\\code{\\LinkA{.print.via.format}{.print.via.format}} in package \\pkg{tools}.\n\\end{SeeAlso}\n%\n\\begin{Examples}\n\\begin{ExampleCode}\nrequire(stats)\n\nts(1:20) #-- print is the \"Default function\" --> print.ts(.) is called\nfor(i in 1:3) print(1:i)\n\n## Printing of factors\nattenu$station ## 117 levels -> 'max.levels' depending on width\n\n## ordered factors: levels \"l1 < l2 < ..\"\nesoph$agegp[1:12]\nesoph$alcgp[1:12]\n\n## Printing of sparse (contingency) tables\nset.seed(521)\nt1 <- round(abs(rt(200, df = 1.8)))\nt2 <- round(abs(rt(200, df = 1.4)))\ntable(t1, t2) # simple\nprint(table(t1, t2), zero.print = \".\") # nicer to read\n\n## same for non-integer \"table\":\nT <- table(t2,t1)\nT <- T * (1+round(rlnorm(length(T)))/4)\nprint(T, zero.print = \".\") # quite nicer,\nprint.table(T[,2:8] * 1e9, digits=3, zero.print = \".\")\n## still slightly inferior to Matrix::Matrix(T) for larger T\n\n## Corner cases with empty extents:\ntable(1, NA) # < table of extent 1 x 0 >\n\\end{ExampleCode}\n\\end{Examples}" + }, + "metadata": {} + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "e862203a-c843-11ed-93dd-dd93b86c8355", + "username": "dotnet_kernel", + "session": "6b23083a-bb76-4a5a-960e-293676d5ffe3", + "date": "2023-03-21T23:55:50.547234Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "91de1d9a-eec2-4865-89e1-efdba88663b4", + "username": "dotnet_kernel", + "session": "6b23083a-bb76-4a5a-960e-293676d5ffe3", + "date": "2023-03-21T23:55:50.2436932Z", + "msg_type": "inspect_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_signature_help_and_get_value_produced.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_signature_help_and_get_value_produced.python3.json new file mode 100644 index 0000000000..9ee7db8d8a --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_request_signature_help_and_get_value_produced.python3.json @@ -0,0 +1,378 @@ +[ + { + "header": { + "msg_id": "23bdcaed-33f50460e301cde3b1ab00ee_22928_10", + "username": "username", + "session": "23bdcaed-33f50460e301cde3b1ab00ee", + "date": "2023-03-21T23:55:49.052976Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "882bfff6-5e6d-4bfa-b11b-dc22ba7a8401", + "username": "dotnet_kernel", + "session": "9a8465d6-b179-43e2-b4ca-42ebaa0e6960", + "date": "2023-03-21T23:55:49.0346324Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "23bdcaed-33f50460e301cde3b1ab00ee_22928_11", + "username": "username", + "session": "23bdcaed-33f50460e301cde3b1ab00ee", + "date": "2023-03-21T23:55:49.052976Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "882bfff6-5e6d-4bfa-b11b-dc22ba7a8401", + "username": "dotnet_kernel", + "session": "9a8465d6-b179-43e2-b4ca-42ebaa0e6960", + "date": "2023-03-21T23:55:49.0346324Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "23bdcaed-33f50460e301cde3b1ab00ee_22928_12", + "username": "username", + "session": "23bdcaed-33f50460e301cde3b1ab00ee", + "date": "2023-03-21T23:55:49.053977Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "882bfff6-5e6d-4bfa-b11b-dc22ba7a8401", + "username": "dotnet_kernel", + "session": "9a8465d6-b179-43e2-b4ca-42ebaa0e6960", + "date": "2023-03-21T23:55:49.0346324Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "23bdcaed-33f50460e301cde3b1ab00ee_22928_13", + "username": "username", + "session": "23bdcaed-33f50460e301cde3b1ab00ee", + "date": "2023-03-21T23:55:49.059996Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b373895e-09c4-4c3b-b042-0534a3759937", + "username": "dotnet_kernel", + "session": "85aab78e-b39a-43b6-a902-d8645e43f9fb", + "date": "2023-03-21T23:55:49.0576263Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "23bdcaed-33f50460e301cde3b1ab00ee_22928_14", + "username": "username", + "session": "23bdcaed-33f50460e301cde3b1ab00ee", + "date": "2023-03-21T23:55:49.059996Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b373895e-09c4-4c3b-b042-0534a3759937", + "username": "dotnet_kernel", + "session": "85aab78e-b39a-43b6-a902-d8645e43f9fb", + "date": "2023-03-21T23:55:49.0576263Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "23bdcaed-33f50460e301cde3b1ab00ee_22928_15", + "username": "username", + "session": "23bdcaed-33f50460e301cde3b1ab00ee", + "date": "2023-03-21T23:55:49.098507Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b373895e-09c4-4c3b-b042-0534a3759937", + "username": "dotnet_kernel", + "session": "85aab78e-b39a-43b6-a902-d8645e43f9fb", + "date": "2023-03-21T23:55:49.0576263Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:55:49.059996Z", + "dependencies_met": true, + "engine": "0119354e-04e4-460d-a75b-a0d3d7eeb738", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "23bdcaed-33f50460e301cde3b1ab00ee_22928_16", + "username": "username", + "session": "23bdcaed-33f50460e301cde3b1ab00ee", + "date": "2023-03-21T23:55:49.099510Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b373895e-09c4-4c3b-b042-0534a3759937", + "username": "dotnet_kernel", + "session": "85aab78e-b39a-43b6-a902-d8645e43f9fb", + "date": "2023-03-21T23:55:49.0576263Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "23bdcaed-33f50460e301cde3b1ab00ee_22928_17", + "username": "username", + "session": "23bdcaed-33f50460e301cde3b1ab00ee", + "date": "2023-03-21T23:55:49.104028Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "0982ed15-e8be-4244-ba9f-c6092cb53532", + "username": "dotnet_kernel", + "session": "56f2e332-3982-44a8-8bea-805528585d66", + "date": "2023-03-21T23:55:49.1023392Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "23bdcaed-33f50460e301cde3b1ab00ee_22928_18", + "username": "username", + "session": "23bdcaed-33f50460e301cde3b1ab00ee", + "date": "2023-03-21T23:55:49.105024Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "0982ed15-e8be-4244-ba9f-c6092cb53532", + "username": "dotnet_kernel", + "session": "56f2e332-3982-44a8-8bea-805528585d66", + "date": "2023-03-21T23:55:49.1023392Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "b85bb3f4-426c-45d9-8698-8d98b288cd37", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "23bdcaed-33f50460e301cde3b1ab00ee_22928_19", + "username": "username", + "session": "23bdcaed-33f50460e301cde3b1ab00ee", + "date": "2023-03-21T23:55:49.105024Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "0982ed15-e8be-4244-ba9f-c6092cb53532", + "username": "dotnet_kernel", + "session": "56f2e332-3982-44a8-8bea-805528585d66", + "date": "2023-03-21T23:55:49.1023392Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "23bdcaed-33f50460e301cde3b1ab00ee_22928_20", + "username": "username", + "session": "23bdcaed-33f50460e301cde3b1ab00ee", + "date": "2023-03-21T23:55:49.124037Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "ffc311fa-5243-4d48-8071-7dc5a3cca333", + "username": "dotnet_kernel", + "session": "a17551ca-9d06-4b11-899d-39b14646426e", + "date": "2023-03-21T23:55:49.1212881Z", + "msg_type": "inspect_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "23bdcaed-33f50460e301cde3b1ab00ee_22928_22", + "username": "username", + "session": "23bdcaed-33f50460e301cde3b1ab00ee", + "date": "2023-03-21T23:55:49.125036Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "ffc311fa-5243-4d48-8071-7dc5a3cca333", + "username": "dotnet_kernel", + "session": "a17551ca-9d06-4b11-899d-39b14646426e", + "date": "2023-03-21T23:55:49.1212881Z", + "msg_type": "inspect_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "23bdcaed-33f50460e301cde3b1ab00ee_22928_21", + "username": "username", + "session": "23bdcaed-33f50460e301cde3b1ab00ee", + "date": "2023-03-21T23:55:49.124037Z", + "msg_type": "inspect_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "ffc311fa-5243-4d48-8071-7dc5a3cca333", + "username": "dotnet_kernel", + "session": "a17551ca-9d06-4b11-899d-39b14646426e", + "date": "2023-03-21T23:55:49.1212881Z", + "msg_type": "inspect_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "status": "ok", + "found": true, + "data": { + "text/plain": "\u001B[1;31mDocstring:\u001B[0m\nprint(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n\nPrints the values to a stream, or to sys.stdout by default.\nOptional keyword arguments:\nfile: a file-like object (stream); defaults to the current sys.stdout.\nsep: string inserted between values, default a space.\nend: string appended after the last value, default a newline.\nflush: whether to forcibly flush the stream.\n\u001B[1;31mType:\u001B[0m builtin_function_or_method\n" + }, + "metadata": {} + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_display_value_produced.ir.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_display_value_produced.ir.json new file mode 100644 index 0000000000..34f505a8a3 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_display_value_produced.ir.json @@ -0,0 +1,394 @@ +[ + { + "header": { + "msg_id": "f38312e4-c843-11ed-9f99-99df3beff697", + "username": "dotnet_kernel", + "session": "2d3972c0-1efc-4447-9ac3-e1c03d95e089", + "date": "2023-03-21T23:56:09.218096Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "ff69d331-c336-4f9d-a00e-30e6e94d6576", + "username": "dotnet_kernel", + "session": "2d3972c0-1efc-4447-9ac3-e1c03d95e089", + "date": "2023-03-21T23:56:09.1517402Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f38339e0-c843-11ed-9f99-99df3beff697", + "username": "dotnet_kernel", + "session": "2d3972c0-1efc-4447-9ac3-e1c03d95e089", + "date": "2023-03-21T23:56:09.220096Z", + "msg_type": "kernel_info_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "ff69d331-c336-4f9d-a00e-30e6e94d6576", + "username": "dotnet_kernel", + "session": "2d3972c0-1efc-4447-9ac3-e1c03d95e089", + "date": "2023-03-21T23:56:09.1517402Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.0", + "implementation": "IRkernel", + "implementation_version": "0.8.15", + "language_info": { + "name": "R", + "version": "3.6.1", + "mimetype": "text/x-r-source", + "file_extension": ".r", + "pygments_lexer": "r", + "codemirror_mode": "r" + }, + "banner": "R version 3.6.1 (2019-07-05)", + "status": "ok", + "help_links": [] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f3836122-c843-11ed-9f99-99df3beff697", + "username": "dotnet_kernel", + "session": "2d3972c0-1efc-4447-9ac3-e1c03d95e089", + "date": "2023-03-21T23:56:09.220096Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "ff69d331-c336-4f9d-a00e-30e6e94d6576", + "username": "dotnet_kernel", + "session": "2d3972c0-1efc-4447-9ac3-e1c03d95e089", + "date": "2023-03-21T23:56:09.1517402Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f3842454-c843-11ed-9f99-99df3beff697", + "username": "dotnet_kernel", + "session": "855b025d-d745-4125-a025-b069362f047e", + "date": "2023-03-21T23:56:09.226613Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "80abb883-e449-47b9-83c0-09269c580066", + "username": "dotnet_kernel", + "session": "855b025d-d745-4125-a025-b069362f047e", + "date": "2023-03-21T23:56:09.2212205Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f384adac-c843-11ed-9f99-99df3beff697", + "username": "dotnet_kernel", + "session": "855b025d-d745-4125-a025-b069362f047e", + "date": "2023-03-21T23:56:09.229620Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "80abb883-e449-47b9-83c0-09269c580066", + "username": "dotnet_kernel", + "session": "855b025d-d745-4125-a025-b069362f047e", + "date": "2023-03-21T23:56:09.2212205Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f393e1c8-c843-11ed-9f99-99df3beff697", + "username": "dotnet_kernel", + "session": "855b025d-d745-4125-a025-b069362f047e", + "date": "2023-03-21T23:56:09.329258Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "80abb883-e449-47b9-83c0-09269c580066", + "username": "dotnet_kernel", + "session": "855b025d-d745-4125-a025-b069362f047e", + "date": "2023-03-21T23:56:09.2212205Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f3940914-c843-11ed-9f99-99df3beff697", + "username": "dotnet_kernel", + "session": "855b025d-d745-4125-a025-b069362f047e", + "date": "2023-03-21T23:56:09.329258Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "80abb883-e449-47b9-83c0-09269c580066", + "username": "dotnet_kernel", + "session": "855b025d-d745-4125-a025-b069362f047e", + "date": "2023-03-21T23:56:09.2212205Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f394a518-c843-11ed-9f99-99df3beff697", + "username": "dotnet_kernel", + "session": "a35ab6c2-6161-4402-bf25-acc6f021b0d0", + "date": "2023-03-21T23:56:09.333250Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "aab23588-85b5-447e-adf7-1eda046b407b", + "username": "dotnet_kernel", + "session": "a35ab6c2-6161-4402-bf25-acc6f021b0d0", + "date": "2023-03-21T23:56:09.3303013Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f3958ff0-c843-11ed-9f99-99df3beff697", + "username": "dotnet_kernel", + "session": "a35ab6c2-6161-4402-bf25-acc6f021b0d0", + "date": "2023-03-21T23:56:09.340264Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "aab23588-85b5-447e-adf7-1eda046b407b", + "username": "dotnet_kernel", + "session": "a35ab6c2-6161-4402-bf25-acc6f021b0d0", + "date": "2023-03-21T23:56:09.3303013Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "51f9def4-548e-4af7-b9e8-e973fe484c23", + "data": { + "commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f395de10-c843-11ed-9f99-99df3beff697", + "username": "dotnet_kernel", + "session": "a35ab6c2-6161-4402-bf25-acc6f021b0d0", + "date": "2023-03-21T23:56:09.341265Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "aab23588-85b5-447e-adf7-1eda046b407b", + "username": "dotnet_kernel", + "session": "a35ab6c2-6161-4402-bf25-acc6f021b0d0", + "date": "2023-03-21T23:56:09.3303013Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f3967a64-c843-11ed-9f99-99df3beff697", + "username": "dotnet_kernel", + "session": "829c10ca-b8ac-447d-ae6a-ab4476e01930", + "date": "2023-03-21T23:56:09.345265Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "40f861b1-1825-4274-9644-ab5ddfeb65f7", + "username": "dotnet_kernel", + "session": "829c10ca-b8ac-447d-ae6a-ab4476e01930", + "date": "2023-03-21T23:56:09.3426435Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f39a385c-c843-11ed-9f99-99df3beff697", + "username": "dotnet_kernel", + "session": "829c10ca-b8ac-447d-ae6a-ab4476e01930", + "date": "2023-03-21T23:56:09.370793Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "40f861b1-1825-4274-9644-ab5ddfeb65f7", + "username": "dotnet_kernel", + "session": "829c10ca-b8ac-447d-ae6a-ab4476e01930", + "date": "2023-03-21T23:56:09.3426435Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "1+1", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f39c0d1c-c843-11ed-9f99-99df3beff697", + "username": "dotnet_kernel", + "session": "829c10ca-b8ac-447d-ae6a-ab4476e01930", + "date": "2023-03-21T23:56:09.382829Z", + "msg_type": "display_data", + "version": "5.0" + }, + "parent_header": { + "msg_id": "40f861b1-1825-4274-9644-ab5ddfeb65f7", + "username": "dotnet_kernel", + "session": "829c10ca-b8ac-447d-ae6a-ab4476e01930", + "date": "2023-03-21T23:56:09.3426435Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "data": { + "text/html": "2", + "text/markdown": "2", + "text/latex": "2", + "text/plain": "[1] 2" + }, + "metadata": {}, + "transient": {} + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f39cd1f2-c843-11ed-9f99-99df3beff697", + "username": "dotnet_kernel", + "session": "829c10ca-b8ac-447d-ae6a-ab4476e01930", + "date": "2023-03-21T23:56:09.387829Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "40f861b1-1825-4274-9644-ab5ddfeb65f7", + "username": "dotnet_kernel", + "session": "829c10ca-b8ac-447d-ae6a-ab4476e01930", + "date": "2023-03-21T23:56:09.3426435Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f39cf902-c843-11ed-9f99-99df3beff697", + "username": "dotnet_kernel", + "session": "829c10ca-b8ac-447d-ae6a-ab4476e01930", + "date": "2023-03-21T23:56:09.388834Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "40f861b1-1825-4274-9644-ab5ddfeb65f7", + "username": "dotnet_kernel", + "session": "829c10ca-b8ac-447d-ae6a-ab4476e01930", + "date": "2023-03-21T23:56:09.3426435Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_display_value_produced.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_display_value_produced.python3.json new file mode 100644 index 0000000000..37013f3f97 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_display_value_produced.python3.json @@ -0,0 +1,434 @@ +[ + { + "header": { + "msg_id": "96e4356a-7861b296a127b7f3b8ca73a2_24356_10", + "username": "username", + "session": "96e4356a-7861b296a127b7f3b8ca73a2", + "date": "2023-03-21T23:56:08.186783Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "1e605c90-a4eb-4505-ac8a-58700fbe50ba", + "username": "dotnet_kernel", + "session": "24690ce6-b10e-4a25-ab1c-d789c8723d2c", + "date": "2023-03-21T23:56:08.1691407Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "96e4356a-7861b296a127b7f3b8ca73a2_24356_12", + "username": "username", + "session": "96e4356a-7861b296a127b7f3b8ca73a2", + "date": "2023-03-21T23:56:08.187785Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "1e605c90-a4eb-4505-ac8a-58700fbe50ba", + "username": "dotnet_kernel", + "session": "24690ce6-b10e-4a25-ab1c-d789c8723d2c", + "date": "2023-03-21T23:56:08.1691407Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "96e4356a-7861b296a127b7f3b8ca73a2_24356_11", + "username": "username", + "session": "96e4356a-7861b296a127b7f3b8ca73a2", + "date": "2023-03-21T23:56:08.187785Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "1e605c90-a4eb-4505-ac8a-58700fbe50ba", + "username": "dotnet_kernel", + "session": "24690ce6-b10e-4a25-ab1c-d789c8723d2c", + "date": "2023-03-21T23:56:08.1691407Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "96e4356a-7861b296a127b7f3b8ca73a2_24356_13", + "username": "username", + "session": "96e4356a-7861b296a127b7f3b8ca73a2", + "date": "2023-03-21T23:56:08.194295Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "e861f067-6acc-4f28-8957-683b29cb3a96", + "username": "dotnet_kernel", + "session": "54d7bcc9-5872-4f97-b363-2580e23fc98b", + "date": "2023-03-21T23:56:08.1913153Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "96e4356a-7861b296a127b7f3b8ca73a2_24356_14", + "username": "username", + "session": "96e4356a-7861b296a127b7f3b8ca73a2", + "date": "2023-03-21T23:56:08.194295Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "e861f067-6acc-4f28-8957-683b29cb3a96", + "username": "dotnet_kernel", + "session": "54d7bcc9-5872-4f97-b363-2580e23fc98b", + "date": "2023-03-21T23:56:08.1913153Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "96e4356a-7861b296a127b7f3b8ca73a2_24356_15", + "username": "username", + "session": "96e4356a-7861b296a127b7f3b8ca73a2", + "date": "2023-03-21T23:56:08.226347Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "e861f067-6acc-4f28-8957-683b29cb3a96", + "username": "dotnet_kernel", + "session": "54d7bcc9-5872-4f97-b363-2580e23fc98b", + "date": "2023-03-21T23:56:08.1913153Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:56:08.194295Z", + "dependencies_met": true, + "engine": "455fc9ee-474b-430a-8f23-66eb6674c537", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "96e4356a-7861b296a127b7f3b8ca73a2_24356_16", + "username": "username", + "session": "96e4356a-7861b296a127b7f3b8ca73a2", + "date": "2023-03-21T23:56:08.227355Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "e861f067-6acc-4f28-8957-683b29cb3a96", + "username": "dotnet_kernel", + "session": "54d7bcc9-5872-4f97-b363-2580e23fc98b", + "date": "2023-03-21T23:56:08.1913153Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "96e4356a-7861b296a127b7f3b8ca73a2_24356_17", + "username": "username", + "session": "96e4356a-7861b296a127b7f3b8ca73a2", + "date": "2023-03-21T23:56:08.231343Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "30367866-8d42-4a0f-8a87-bd9017c6a589", + "username": "dotnet_kernel", + "session": "ff92848e-800c-4d39-9e0a-e435674f3f00", + "date": "2023-03-21T23:56:08.2294327Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "96e4356a-7861b296a127b7f3b8ca73a2_24356_18", + "username": "username", + "session": "96e4356a-7861b296a127b7f3b8ca73a2", + "date": "2023-03-21T23:56:08.232342Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "30367866-8d42-4a0f-8a87-bd9017c6a589", + "username": "dotnet_kernel", + "session": "ff92848e-800c-4d39-9e0a-e435674f3f00", + "date": "2023-03-21T23:56:08.2294327Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "bb01e044-d2b3-4794-b1cd-a424f38b2175", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "96e4356a-7861b296a127b7f3b8ca73a2_24356_19", + "username": "username", + "session": "96e4356a-7861b296a127b7f3b8ca73a2", + "date": "2023-03-21T23:56:08.233342Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "30367866-8d42-4a0f-8a87-bd9017c6a589", + "username": "dotnet_kernel", + "session": "ff92848e-800c-4d39-9e0a-e435674f3f00", + "date": "2023-03-21T23:56:08.2294327Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "96e4356a-7861b296a127b7f3b8ca73a2_24356_20", + "username": "username", + "session": "96e4356a-7861b296a127b7f3b8ca73a2", + "date": "2023-03-21T23:56:08.237343Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "8c38caac-2332-49ea-96d4-d3bb6f2db7c6", + "username": "dotnet_kernel", + "session": "a4236672-308a-487a-bed3-c7c02b29f419", + "date": "2023-03-21T23:56:08.2362650Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "96e4356a-7861b296a127b7f3b8ca73a2_24356_21", + "username": "username", + "session": "96e4356a-7861b296a127b7f3b8ca73a2", + "date": "2023-03-21T23:56:08.237343Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "8c38caac-2332-49ea-96d4-d3bb6f2db7c6", + "username": "dotnet_kernel", + "session": "a4236672-308a-487a-bed3-c7c02b29f419", + "date": "2023-03-21T23:56:08.2362650Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "from IPython.display import display; display(2)", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "96e4356a-7861b296a127b7f3b8ca73a2_24356_22", + "username": "username", + "session": "96e4356a-7861b296a127b7f3b8ca73a2", + "date": "2023-03-21T23:56:08.243347Z", + "msg_type": "display_data", + "version": "5.3" + }, + "parent_header": { + "msg_id": "8c38caac-2332-49ea-96d4-d3bb6f2db7c6", + "username": "dotnet_kernel", + "session": "a4236672-308a-487a-bed3-c7c02b29f419", + "date": "2023-03-21T23:56:08.2362650Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "data": { + "text/plain": "2" + }, + "metadata": {}, + "transient": {} + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "96e4356a-7861b296a127b7f3b8ca73a2_24356_23", + "username": "username", + "session": "96e4356a-7861b296a127b7f3b8ca73a2", + "date": "2023-03-21T23:56:08.257864Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "8c38caac-2332-49ea-96d4-d3bb6f2db7c6", + "username": "dotnet_kernel", + "session": "a4236672-308a-487a-bed3-c7c02b29f419", + "date": "2023-03-21T23:56:08.2362650Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:56:08.237343Z", + "dependencies_met": true, + "engine": "455fc9ee-474b-430a-8f23-66eb6674c537", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "96e4356a-7861b296a127b7f3b8ca73a2_24356_24", + "username": "username", + "session": "96e4356a-7861b296a127b7f3b8ca73a2", + "date": "2023-03-21T23:56:08.257864Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "8c38caac-2332-49ea-96d4-d3bb6f2db7c6", + "username": "dotnet_kernel", + "session": "a4236672-308a-487a-bed3-c7c02b29f419", + "date": "2023-03-21T23:56:08.2362650Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_error_produced.ir.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_error_produced.ir.json new file mode 100644 index 0000000000..e686f38598 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_error_produced.ir.json @@ -0,0 +1,340 @@ +[ + { + "header": { + "msg_id": "ed6e585a-c843-11ed-b107-07b1ce00c50b", + "username": "dotnet_kernel", + "session": "e6f54ea9-9fa6-4429-819d-ffe918e7fd1d", + "date": "2023-03-21T23:55:59.016920Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0cfa15b8-4e9b-4957-a15b-c43691aebe96", + "username": "dotnet_kernel", + "session": "e6f54ea9-9fa6-4429-819d-ffe918e7fd1d", + "date": "2023-03-21T23:55:58.9286548Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "ed6e7f60-c843-11ed-b107-07b1ce00c50b", + "username": "dotnet_kernel", + "session": "e6f54ea9-9fa6-4429-819d-ffe918e7fd1d", + "date": "2023-03-21T23:55:59.018922Z", + "msg_type": "kernel_info_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0cfa15b8-4e9b-4957-a15b-c43691aebe96", + "username": "dotnet_kernel", + "session": "e6f54ea9-9fa6-4429-819d-ffe918e7fd1d", + "date": "2023-03-21T23:55:58.9286548Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.0", + "implementation": "IRkernel", + "implementation_version": "0.8.15", + "language_info": { + "name": "R", + "version": "3.6.1", + "mimetype": "text/x-r-source", + "file_extension": ".r", + "pygments_lexer": "r", + "codemirror_mode": "r" + }, + "banner": "R version 3.6.1 (2019-07-05)", + "status": "ok", + "help_links": [] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "ed6ecd8a-c843-11ed-b107-07b1ce00c50b", + "username": "dotnet_kernel", + "session": "e6f54ea9-9fa6-4429-819d-ffe918e7fd1d", + "date": "2023-03-21T23:55:59.020925Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0cfa15b8-4e9b-4957-a15b-c43691aebe96", + "username": "dotnet_kernel", + "session": "e6f54ea9-9fa6-4429-819d-ffe918e7fd1d", + "date": "2023-03-21T23:55:58.9286548Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "ed7300f8-c843-11ed-b107-07b1ce00c50b", + "username": "dotnet_kernel", + "session": "ed2470d3-1b86-4021-94ca-e647f4db1942", + "date": "2023-03-21T23:55:59.047455Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d03033c4-ff6c-4e38-8af4-bcde443659ed", + "username": "dotnet_kernel", + "session": "ed2470d3-1b86-4021-94ca-e647f4db1942", + "date": "2023-03-21T23:55:59.0202387Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "ed737646-c843-11ed-b107-07b1ce00c50b", + "username": "dotnet_kernel", + "session": "ed2470d3-1b86-4021-94ca-e647f4db1942", + "date": "2023-03-21T23:55:59.050454Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d03033c4-ff6c-4e38-8af4-bcde443659ed", + "username": "dotnet_kernel", + "session": "ed2470d3-1b86-4021-94ca-e647f4db1942", + "date": "2023-03-21T23:55:59.0202387Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "ed83cdc0-c843-11ed-b107-07b1ce00c50b", + "username": "dotnet_kernel", + "session": "ed2470d3-1b86-4021-94ca-e647f4db1942", + "date": "2023-03-21T23:55:59.157550Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d03033c4-ff6c-4e38-8af4-bcde443659ed", + "username": "dotnet_kernel", + "session": "ed2470d3-1b86-4021-94ca-e647f4db1942", + "date": "2023-03-21T23:55:59.0202387Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "ed841bcc-c843-11ed-b107-07b1ce00c50b", + "username": "dotnet_kernel", + "session": "ed2470d3-1b86-4021-94ca-e647f4db1942", + "date": "2023-03-21T23:55:59.158554Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d03033c4-ff6c-4e38-8af4-bcde443659ed", + "username": "dotnet_kernel", + "session": "ed2470d3-1b86-4021-94ca-e647f4db1942", + "date": "2023-03-21T23:55:59.0202387Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "ed8490fc-c843-11ed-b107-07b1ce00c50b", + "username": "dotnet_kernel", + "session": "b4218d76-ef43-4b56-8753-de4b6d95c4e1", + "date": "2023-03-21T23:55:59.161550Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "51e338d6-323b-4153-a69c-367fb3f6847c", + "username": "dotnet_kernel", + "session": "b4218d76-ef43-4b56-8753-de4b6d95c4e1", + "date": "2023-03-21T23:55:59.1595872Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "ed85415a-c843-11ed-b107-07b1ce00c50b", + "username": "dotnet_kernel", + "session": "b4218d76-ef43-4b56-8753-de4b6d95c4e1", + "date": "2023-03-21T23:55:59.166064Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "51e338d6-323b-4153-a69c-367fb3f6847c", + "username": "dotnet_kernel", + "session": "b4218d76-ef43-4b56-8753-de4b6d95c4e1", + "date": "2023-03-21T23:55:59.1595872Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "ca33d239-eab3-4024-9ed6-f708f9d2f8c3", + "data": { + "commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "ed856860-c843-11ed-b107-07b1ce00c50b", + "username": "dotnet_kernel", + "session": "b4218d76-ef43-4b56-8753-de4b6d95c4e1", + "date": "2023-03-21T23:55:59.167068Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "51e338d6-323b-4153-a69c-367fb3f6847c", + "username": "dotnet_kernel", + "session": "b4218d76-ef43-4b56-8753-de4b6d95c4e1", + "date": "2023-03-21T23:55:59.1595872Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "ed8604dc-c843-11ed-b107-07b1ce00c50b", + "username": "dotnet_kernel", + "session": "3fd49037-ec99-48fa-ad18-450c57ffb60f", + "date": "2023-03-21T23:55:59.172066Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d616d5fb-03ce-4294-aae4-81d733903088", + "username": "dotnet_kernel", + "session": "3fd49037-ec99-48fa-ad18-450c57ffb60f", + "date": "2023-03-21T23:55:59.1691430Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "ed896032-c843-11ed-b107-07b1ce00c50b", + "username": "dotnet_kernel", + "session": "3fd49037-ec99-48fa-ad18-450c57ffb60f", + "date": "2023-03-21T23:55:59.194072Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d616d5fb-03ce-4294-aae4-81d733903088", + "username": "dotnet_kernel", + "session": "3fd49037-ec99-48fa-ad18-450c57ffb60f", + "date": "2023-03-21T23:55:59.1691430Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "prin()", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "ed8bd330-c843-11ed-b107-07b1ce00c50b", + "username": "dotnet_kernel", + "session": "3fd49037-ec99-48fa-ad18-450c57ffb60f", + "date": "2023-03-21T23:55:59.210115Z", + "msg_type": "error", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d616d5fb-03ce-4294-aae4-81d733903088", + "username": "dotnet_kernel", + "session": "3fd49037-ec99-48fa-ad18-450c57ffb60f", + "date": "2023-03-21T23:55:59.1691430Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "ename": "ERROR", + "evalue": "Error in prin(): could not find function \"prin\"\n", + "traceback": [ + "Error in prin(): could not find function \"prin\"\nTraceback:\n" + ] + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_error_produced.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_error_produced.python3.json new file mode 100644 index 0000000000..8f91230283 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_error_produced.python3.json @@ -0,0 +1,413 @@ +[ + { + "header": { + "msg_id": "d780f076-bde8936061cac605b2b1a76a_23312_10", + "username": "username", + "session": "d780f076-bde8936061cac605b2b1a76a", + "date": "2023-03-21T23:55:57.743547Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "faeeac25-0b1e-4b0e-a760-74e1a1641225", + "username": "dotnet_kernel", + "session": "1ba60cb7-f140-426e-a524-5a6c2bf77464", + "date": "2023-03-21T23:55:57.7282086Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "d780f076-bde8936061cac605b2b1a76a_23312_12", + "username": "username", + "session": "d780f076-bde8936061cac605b2b1a76a", + "date": "2023-03-21T23:55:57.744548Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "faeeac25-0b1e-4b0e-a760-74e1a1641225", + "username": "dotnet_kernel", + "session": "1ba60cb7-f140-426e-a524-5a6c2bf77464", + "date": "2023-03-21T23:55:57.7282086Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "d780f076-bde8936061cac605b2b1a76a_23312_11", + "username": "username", + "session": "d780f076-bde8936061cac605b2b1a76a", + "date": "2023-03-21T23:55:57.743547Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "faeeac25-0b1e-4b0e-a760-74e1a1641225", + "username": "dotnet_kernel", + "session": "1ba60cb7-f140-426e-a524-5a6c2bf77464", + "date": "2023-03-21T23:55:57.7282086Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "d780f076-bde8936061cac605b2b1a76a_23312_13", + "username": "username", + "session": "d780f076-bde8936061cac605b2b1a76a", + "date": "2023-03-21T23:55:57.749548Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "00656736-4804-4c76-9b19-d5fb1d922e00", + "username": "dotnet_kernel", + "session": "c1f25d26-e97d-4b03-af48-00803f37b499", + "date": "2023-03-21T23:55:57.7476706Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "d780f076-bde8936061cac605b2b1a76a_23312_14", + "username": "username", + "session": "d780f076-bde8936061cac605b2b1a76a", + "date": "2023-03-21T23:55:57.749548Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "00656736-4804-4c76-9b19-d5fb1d922e00", + "username": "dotnet_kernel", + "session": "c1f25d26-e97d-4b03-af48-00803f37b499", + "date": "2023-03-21T23:55:57.7476706Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "d780f076-bde8936061cac605b2b1a76a_23312_15", + "username": "username", + "session": "d780f076-bde8936061cac605b2b1a76a", + "date": "2023-03-21T23:55:57.785232Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "00656736-4804-4c76-9b19-d5fb1d922e00", + "username": "dotnet_kernel", + "session": "c1f25d26-e97d-4b03-af48-00803f37b499", + "date": "2023-03-21T23:55:57.7476706Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:55:57.749548Z", + "dependencies_met": true, + "engine": "38ec5901-d330-40e1-96b6-bc021496b6a4", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "d780f076-bde8936061cac605b2b1a76a_23312_16", + "username": "username", + "session": "d780f076-bde8936061cac605b2b1a76a", + "date": "2023-03-21T23:55:57.785232Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "00656736-4804-4c76-9b19-d5fb1d922e00", + "username": "dotnet_kernel", + "session": "c1f25d26-e97d-4b03-af48-00803f37b499", + "date": "2023-03-21T23:55:57.7476706Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "d780f076-bde8936061cac605b2b1a76a_23312_17", + "username": "username", + "session": "d780f076-bde8936061cac605b2b1a76a", + "date": "2023-03-21T23:55:57.788789Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b670e2fe-d1a9-40ce-be40-00510381661e", + "username": "dotnet_kernel", + "session": "6deba714-b985-47b3-8cd6-b93149e50711", + "date": "2023-03-21T23:55:57.7877257Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "d780f076-bde8936061cac605b2b1a76a_23312_18", + "username": "username", + "session": "d780f076-bde8936061cac605b2b1a76a", + "date": "2023-03-21T23:55:57.789785Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b670e2fe-d1a9-40ce-be40-00510381661e", + "username": "dotnet_kernel", + "session": "6deba714-b985-47b3-8cd6-b93149e50711", + "date": "2023-03-21T23:55:57.7877257Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "96661f15-aeb8-412f-9413-483907d6d10d", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "d780f076-bde8936061cac605b2b1a76a_23312_19", + "username": "username", + "session": "d780f076-bde8936061cac605b2b1a76a", + "date": "2023-03-21T23:55:57.790786Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b670e2fe-d1a9-40ce-be40-00510381661e", + "username": "dotnet_kernel", + "session": "6deba714-b985-47b3-8cd6-b93149e50711", + "date": "2023-03-21T23:55:57.7877257Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "d780f076-bde8936061cac605b2b1a76a_23312_20", + "username": "username", + "session": "d780f076-bde8936061cac605b2b1a76a", + "date": "2023-03-21T23:55:57.793787Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "82d25567-0222-4bc0-9635-d8dfc397d4dc", + "username": "dotnet_kernel", + "session": "bcd96446-3aec-4065-bb56-5195f3c6a2f9", + "date": "2023-03-21T23:55:57.7934717Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "d780f076-bde8936061cac605b2b1a76a_23312_21", + "username": "username", + "session": "d780f076-bde8936061cac605b2b1a76a", + "date": "2023-03-21T23:55:57.794786Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "82d25567-0222-4bc0-9635-d8dfc397d4dc", + "username": "dotnet_kernel", + "session": "bcd96446-3aec-4065-bb56-5195f3c6a2f9", + "date": "2023-03-21T23:55:57.7934717Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "prin()", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "d780f076-bde8936061cac605b2b1a76a_23312_22", + "username": "username", + "session": "d780f076-bde8936061cac605b2b1a76a", + "date": "2023-03-21T23:55:57.982434Z", + "msg_type": "error", + "version": "5.3" + }, + "parent_header": { + "msg_id": "82d25567-0222-4bc0-9635-d8dfc397d4dc", + "username": "dotnet_kernel", + "session": "bcd96446-3aec-4065-bb56-5195f3c6a2f9", + "date": "2023-03-21T23:55:57.7934717Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "ename": "NameError", + "evalue": "name 'prin' is not defined", + "traceback": [ + "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m", + "\u001B[1;31mNameError\u001B[0m Traceback (most recent call last)", + "\u001B[1;32m~\\AppData\\Local\\Temp\\ipykernel_23312\\2634956037.py\u001B[0m in \u001B[0;36m\u001B[1;34m\u001B[0m\n\u001B[1;32m----> 1\u001B[1;33m \u001B[0mprin\u001B[0m\u001B[1;33m(\u001B[0m\u001B[1;33m)\u001B[0m\u001B[1;33m\u001B[0m\u001B[1;33m\u001B[0m\u001B[0m\n\u001B[0m", + "\u001B[1;31mNameError\u001B[0m: name 'prin' is not defined" + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "d780f076-bde8936061cac605b2b1a76a_23312_23", + "username": "username", + "session": "d780f076-bde8936061cac605b2b1a76a", + "date": "2023-03-21T23:55:57.989438Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "82d25567-0222-4bc0-9635-d8dfc397d4dc", + "username": "dotnet_kernel", + "session": "bcd96446-3aec-4065-bb56-5195f3c6a2f9", + "date": "2023-03-21T23:55:57.7934717Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:55:57.793787Z", + "dependencies_met": true, + "engine": "38ec5901-d330-40e1-96b6-bc021496b6a4", + "status": "error" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_return_value_produced.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_return_value_produced.python3.json new file mode 100644 index 0000000000..e5524fe4c9 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_return_value_produced.python3.json @@ -0,0 +1,435 @@ +[ + { + "header": { + "msg_id": "3bbc4330-87d1e4976e119a645c5bd7d6_13932_10", + "username": "username", + "session": "3bbc4330-87d1e4976e119a645c5bd7d6", + "date": "2023-03-21T23:55:46.404544Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "8dde8f49-e2f9-4e7c-8e03-e255873e58ab", + "username": "dotnet_kernel", + "session": "43a63453-8cc5-41d2-a2de-036f6c0b65aa", + "date": "2023-03-21T23:55:46.3900306Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "3bbc4330-87d1e4976e119a645c5bd7d6_13932_11", + "username": "username", + "session": "3bbc4330-87d1e4976e119a645c5bd7d6", + "date": "2023-03-21T23:55:46.404544Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "8dde8f49-e2f9-4e7c-8e03-e255873e58ab", + "username": "dotnet_kernel", + "session": "43a63453-8cc5-41d2-a2de-036f6c0b65aa", + "date": "2023-03-21T23:55:46.3900306Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "3bbc4330-87d1e4976e119a645c5bd7d6_13932_12", + "username": "username", + "session": "3bbc4330-87d1e4976e119a645c5bd7d6", + "date": "2023-03-21T23:55:46.405542Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "8dde8f49-e2f9-4e7c-8e03-e255873e58ab", + "username": "dotnet_kernel", + "session": "43a63453-8cc5-41d2-a2de-036f6c0b65aa", + "date": "2023-03-21T23:55:46.3900306Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "3bbc4330-87d1e4976e119a645c5bd7d6_13932_13", + "username": "username", + "session": "3bbc4330-87d1e4976e119a645c5bd7d6", + "date": "2023-03-21T23:55:46.432061Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "af158aa0-a199-4562-a543-6ab933b87d42", + "username": "dotnet_kernel", + "session": "ab8a13f8-eef4-4f7c-8831-73a39a165f60", + "date": "2023-03-21T23:55:46.4237375Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "3bbc4330-87d1e4976e119a645c5bd7d6_13932_14", + "username": "username", + "session": "3bbc4330-87d1e4976e119a645c5bd7d6", + "date": "2023-03-21T23:55:46.432061Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "af158aa0-a199-4562-a543-6ab933b87d42", + "username": "dotnet_kernel", + "session": "ab8a13f8-eef4-4f7c-8831-73a39a165f60", + "date": "2023-03-21T23:55:46.4237375Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "3bbc4330-87d1e4976e119a645c5bd7d6_13932_16", + "username": "username", + "session": "3bbc4330-87d1e4976e119a645c5bd7d6", + "date": "2023-03-21T23:55:46.471586Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "af158aa0-a199-4562-a543-6ab933b87d42", + "username": "dotnet_kernel", + "session": "ab8a13f8-eef4-4f7c-8831-73a39a165f60", + "date": "2023-03-21T23:55:46.4237375Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "3bbc4330-87d1e4976e119a645c5bd7d6_13932_15", + "username": "username", + "session": "3bbc4330-87d1e4976e119a645c5bd7d6", + "date": "2023-03-21T23:55:46.471586Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "af158aa0-a199-4562-a543-6ab933b87d42", + "username": "dotnet_kernel", + "session": "ab8a13f8-eef4-4f7c-8831-73a39a165f60", + "date": "2023-03-21T23:55:46.4237375Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:55:46.432061Z", + "dependencies_met": true, + "engine": "efcee1d4-e56e-4f46-94ed-48b36e34cfb1", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "3bbc4330-87d1e4976e119a645c5bd7d6_13932_17", + "username": "username", + "session": "3bbc4330-87d1e4976e119a645c5bd7d6", + "date": "2023-03-21T23:55:46.483743Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "abdefe3b-3046-441d-be1d-796bc3d88072", + "username": "dotnet_kernel", + "session": "8d44dcc1-72c6-45f4-ab0f-a6b539478e8f", + "date": "2023-03-21T23:55:46.4816895Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "3bbc4330-87d1e4976e119a645c5bd7d6_13932_18", + "username": "username", + "session": "3bbc4330-87d1e4976e119a645c5bd7d6", + "date": "2023-03-21T23:55:46.483743Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "abdefe3b-3046-441d-be1d-796bc3d88072", + "username": "dotnet_kernel", + "session": "8d44dcc1-72c6-45f4-ab0f-a6b539478e8f", + "date": "2023-03-21T23:55:46.4816895Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "ef58b1c4-848d-4d0c-a352-b95f81e0306f", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "3bbc4330-87d1e4976e119a645c5bd7d6_13932_19", + "username": "username", + "session": "3bbc4330-87d1e4976e119a645c5bd7d6", + "date": "2023-03-21T23:55:46.484738Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "abdefe3b-3046-441d-be1d-796bc3d88072", + "username": "dotnet_kernel", + "session": "8d44dcc1-72c6-45f4-ab0f-a6b539478e8f", + "date": "2023-03-21T23:55:46.4816895Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "3bbc4330-87d1e4976e119a645c5bd7d6_13932_20", + "username": "username", + "session": "3bbc4330-87d1e4976e119a645c5bd7d6", + "date": "2023-03-21T23:55:46.533980Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9c8d6ce7-afe0-404e-b159-2845e9298b9f", + "username": "dotnet_kernel", + "session": "32ac5828-ce8c-48e5-9309-0e274701ee74", + "date": "2023-03-21T23:55:46.5322213Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "3bbc4330-87d1e4976e119a645c5bd7d6_13932_21", + "username": "username", + "session": "3bbc4330-87d1e4976e119a645c5bd7d6", + "date": "2023-03-21T23:55:46.533980Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9c8d6ce7-afe0-404e-b159-2845e9298b9f", + "username": "dotnet_kernel", + "session": "32ac5828-ce8c-48e5-9309-0e274701ee74", + "date": "2023-03-21T23:55:46.5322213Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "1+1", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "3bbc4330-87d1e4976e119a645c5bd7d6_13932_22", + "username": "username", + "session": "3bbc4330-87d1e4976e119a645c5bd7d6", + "date": "2023-03-21T23:55:46.534980Z", + "msg_type": "execute_result", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9c8d6ce7-afe0-404e-b159-2845e9298b9f", + "username": "dotnet_kernel", + "session": "32ac5828-ce8c-48e5-9309-0e274701ee74", + "date": "2023-03-21T23:55:46.5322213Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "data": { + "text/plain": "2" + }, + "metadata": {}, + "transient": {}, + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "3bbc4330-87d1e4976e119a645c5bd7d6_13932_23", + "username": "username", + "session": "3bbc4330-87d1e4976e119a645c5bd7d6", + "date": "2023-03-21T23:55:46.550012Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9c8d6ce7-afe0-404e-b159-2845e9298b9f", + "username": "dotnet_kernel", + "session": "32ac5828-ce8c-48e5-9309-0e274701ee74", + "date": "2023-03-21T23:55:46.5322213Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:55:46.533980Z", + "dependencies_met": true, + "engine": "efcee1d4-e56e-4f46-94ed-48b36e34cfb1", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "3bbc4330-87d1e4976e119a645c5bd7d6_13932_24", + "username": "username", + "session": "3bbc4330-87d1e4976e119a645c5bd7d6", + "date": "2023-03-21T23:55:46.550012Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9c8d6ce7-afe0-404e-b159-2845e9298b9f", + "username": "dotnet_kernel", + "session": "32ac5828-ce8c-48e5-9309-0e274701ee74", + "date": "2023-03-21T23:55:46.5322213Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_stderr_produced.ir.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_stderr_produced.ir.json new file mode 100644 index 0000000000..c4e84dcdca --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_stderr_produced.ir.json @@ -0,0 +1,388 @@ +[ + { + "header": { + "msg_id": "fa283a84-c843-11ed-a23a-3b22b2c7d856", + "username": "dotnet_kernel", + "session": "0c27624c-ca2d-43c1-a341-b7b1213e6fb2", + "date": "2023-03-21T23:56:20.366785Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "b21808d7-8927-4fb9-8586-bf9bdbf714b4", + "username": "dotnet_kernel", + "session": "0c27624c-ca2d-43c1-a341-b7b1213e6fb2", + "date": "2023-03-21T23:56:20.2981275Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "fa28618a-c843-11ed-a23a-3b22b2c7d856", + "username": "dotnet_kernel", + "session": "0c27624c-ca2d-43c1-a341-b7b1213e6fb2", + "date": "2023-03-21T23:56:20.368799Z", + "msg_type": "kernel_info_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "b21808d7-8927-4fb9-8586-bf9bdbf714b4", + "username": "dotnet_kernel", + "session": "0c27624c-ca2d-43c1-a341-b7b1213e6fb2", + "date": "2023-03-21T23:56:20.2981275Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.0", + "implementation": "IRkernel", + "implementation_version": "0.8.15", + "language_info": { + "name": "R", + "version": "3.6.1", + "mimetype": "text/x-r-source", + "file_extension": ".r", + "pygments_lexer": "r", + "codemirror_mode": "r" + }, + "banner": "R version 3.6.1 (2019-07-05)", + "status": "ok", + "help_links": [] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "fa28b036-c843-11ed-a23a-3b22b2c7d856", + "username": "dotnet_kernel", + "session": "0c27624c-ca2d-43c1-a341-b7b1213e6fb2", + "date": "2023-03-21T23:56:20.369802Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "b21808d7-8927-4fb9-8586-bf9bdbf714b4", + "username": "dotnet_kernel", + "session": "0c27624c-ca2d-43c1-a341-b7b1213e6fb2", + "date": "2023-03-21T23:56:20.2981275Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "fa29739a-c843-11ed-a23a-3b22b2c7d856", + "username": "dotnet_kernel", + "session": "9a23279e-0bfe-45a6-9074-9206e57058d9", + "date": "2023-03-21T23:56:20.374800Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1e50c73d-560a-4a4a-a4b2-ba74c8af370c", + "username": "dotnet_kernel", + "session": "9a23279e-0bfe-45a6-9074-9206e57058d9", + "date": "2023-03-21T23:56:20.3701907Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "fa29c1a6-c843-11ed-a23a-3b22b2c7d856", + "username": "dotnet_kernel", + "session": "9a23279e-0bfe-45a6-9074-9206e57058d9", + "date": "2023-03-21T23:56:20.377799Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1e50c73d-560a-4a4a-a4b2-ba74c8af370c", + "username": "dotnet_kernel", + "session": "9a23279e-0bfe-45a6-9074-9206e57058d9", + "date": "2023-03-21T23:56:20.3701907Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "fa392f10-c843-11ed-a23a-3b22b2c7d856", + "username": "dotnet_kernel", + "session": "9a23279e-0bfe-45a6-9074-9206e57058d9", + "date": "2023-03-21T23:56:20.478903Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1e50c73d-560a-4a4a-a4b2-ba74c8af370c", + "username": "dotnet_kernel", + "session": "9a23279e-0bfe-45a6-9074-9206e57058d9", + "date": "2023-03-21T23:56:20.3701907Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "fa397d26-c843-11ed-a23a-3b22b2c7d856", + "username": "dotnet_kernel", + "session": "9a23279e-0bfe-45a6-9074-9206e57058d9", + "date": "2023-03-21T23:56:20.479903Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1e50c73d-560a-4a4a-a4b2-ba74c8af370c", + "username": "dotnet_kernel", + "session": "9a23279e-0bfe-45a6-9074-9206e57058d9", + "date": "2023-03-21T23:56:20.3701907Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "fa39f256-c843-11ed-a23a-3b22b2c7d856", + "username": "dotnet_kernel", + "session": "761f1f2f-f109-44d1-9e82-a701f01b7c04", + "date": "2023-03-21T23:56:20.482904Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0eb8f353-775a-423d-a602-0416901d1a69", + "username": "dotnet_kernel", + "session": "761f1f2f-f109-44d1-9e82-a701f01b7c04", + "date": "2023-03-21T23:56:20.4807046Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "fa3adcb6-c843-11ed-a23a-3b22b2c7d856", + "username": "dotnet_kernel", + "session": "761f1f2f-f109-44d1-9e82-a701f01b7c04", + "date": "2023-03-21T23:56:20.488902Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0eb8f353-775a-423d-a602-0416901d1a69", + "username": "dotnet_kernel", + "session": "761f1f2f-f109-44d1-9e82-a701f01b7c04", + "date": "2023-03-21T23:56:20.4807046Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "db110f3a-920f-41e9-a4af-97daa277e2fb", + "data": { + "commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "fa3b03bc-c843-11ed-a23a-3b22b2c7d856", + "username": "dotnet_kernel", + "session": "761f1f2f-f109-44d1-9e82-a701f01b7c04", + "date": "2023-03-21T23:56:20.489903Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0eb8f353-775a-423d-a602-0416901d1a69", + "username": "dotnet_kernel", + "session": "761f1f2f-f109-44d1-9e82-a701f01b7c04", + "date": "2023-03-21T23:56:20.4807046Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "fa3ba042-c843-11ed-a23a-3b22b2c7d856", + "username": "dotnet_kernel", + "session": "1474f706-526b-4c22-b98e-4f6046743ea0", + "date": "2023-03-21T23:56:20.494919Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "5aa41866-ad3b-455e-8490-e801b322cf21", + "username": "dotnet_kernel", + "session": "1474f706-526b-4c22-b98e-4f6046743ea0", + "date": "2023-03-21T23:56:20.4919120Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "fa3efd64-c843-11ed-a23a-3b22b2c7d856", + "username": "dotnet_kernel", + "session": "1474f706-526b-4c22-b98e-4f6046743ea0", + "date": "2023-03-21T23:56:20.516954Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "5aa41866-ad3b-455e-8490-e801b322cf21", + "username": "dotnet_kernel", + "session": "1474f706-526b-4c22-b98e-4f6046743ea0", + "date": "2023-03-21T23:56:20.4919120Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "message('stderr')", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "fa40ab46-c843-11ed-a23a-3b22b2c7d856", + "username": "dotnet_kernel", + "session": "1474f706-526b-4c22-b98e-4f6046743ea0", + "date": "2023-03-21T23:56:20.526959Z", + "msg_type": "stream", + "version": "5.0" + }, + "parent_header": { + "msg_id": "5aa41866-ad3b-455e-8490-e801b322cf21", + "username": "dotnet_kernel", + "session": "1474f706-526b-4c22-b98e-4f6046743ea0", + "date": "2023-03-21T23:56:20.4919120Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "name": "stderr", + "text": "stderr\n" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "fa416e8c-c843-11ed-a23a-3b22b2c7d856", + "username": "dotnet_kernel", + "session": "1474f706-526b-4c22-b98e-4f6046743ea0", + "date": "2023-03-21T23:56:20.531959Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "5aa41866-ad3b-455e-8490-e801b322cf21", + "username": "dotnet_kernel", + "session": "1474f706-526b-4c22-b98e-4f6046743ea0", + "date": "2023-03-21T23:56:20.4919120Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "fa4195a6-c843-11ed-a23a-3b22b2c7d856", + "username": "dotnet_kernel", + "session": "1474f706-526b-4c22-b98e-4f6046743ea0", + "date": "2023-03-21T23:56:20.532960Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "5aa41866-ad3b-455e-8490-e801b322cf21", + "username": "dotnet_kernel", + "session": "1474f706-526b-4c22-b98e-4f6046743ea0", + "date": "2023-03-21T23:56:20.4919120Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_stderr_produced.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_stderr_produced.python3.json new file mode 100644 index 0000000000..4ac7ced55a --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_stderr_produced.python3.json @@ -0,0 +1,431 @@ +[ + { + "header": { + "msg_id": "58b498de-c16ba38c4ff81c58976eccbd_17128_10", + "username": "username", + "session": "58b498de-c16ba38c4ff81c58976eccbd", + "date": "2023-03-21T23:56:19.293203Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9dfe4913-69db-42d1-944c-c55612eeba4c", + "username": "dotnet_kernel", + "session": "65d40b26-e3ef-4fd7-8a9f-6e9b79357020", + "date": "2023-03-21T23:56:19.2754247Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "58b498de-c16ba38c4ff81c58976eccbd_17128_12", + "username": "username", + "session": "58b498de-c16ba38c4ff81c58976eccbd", + "date": "2023-03-21T23:56:19.294208Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9dfe4913-69db-42d1-944c-c55612eeba4c", + "username": "dotnet_kernel", + "session": "65d40b26-e3ef-4fd7-8a9f-6e9b79357020", + "date": "2023-03-21T23:56:19.2754247Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "58b498de-c16ba38c4ff81c58976eccbd_17128_11", + "username": "username", + "session": "58b498de-c16ba38c4ff81c58976eccbd", + "date": "2023-03-21T23:56:19.293203Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9dfe4913-69db-42d1-944c-c55612eeba4c", + "username": "dotnet_kernel", + "session": "65d40b26-e3ef-4fd7-8a9f-6e9b79357020", + "date": "2023-03-21T23:56:19.2754247Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "58b498de-c16ba38c4ff81c58976eccbd_17128_13", + "username": "username", + "session": "58b498de-c16ba38c4ff81c58976eccbd", + "date": "2023-03-21T23:56:19.323746Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "86b82f3c-2510-4004-bbda-d3dd144e0657", + "username": "dotnet_kernel", + "session": "57a045de-8626-41a3-a85d-798dc80d0bc0", + "date": "2023-03-21T23:56:19.2971513Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "58b498de-c16ba38c4ff81c58976eccbd_17128_14", + "username": "username", + "session": "58b498de-c16ba38c4ff81c58976eccbd", + "date": "2023-03-21T23:56:19.323746Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "86b82f3c-2510-4004-bbda-d3dd144e0657", + "username": "dotnet_kernel", + "session": "57a045de-8626-41a3-a85d-798dc80d0bc0", + "date": "2023-03-21T23:56:19.2971513Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "58b498de-c16ba38c4ff81c58976eccbd_17128_15", + "username": "username", + "session": "58b498de-c16ba38c4ff81c58976eccbd", + "date": "2023-03-21T23:56:19.364280Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "86b82f3c-2510-4004-bbda-d3dd144e0657", + "username": "dotnet_kernel", + "session": "57a045de-8626-41a3-a85d-798dc80d0bc0", + "date": "2023-03-21T23:56:19.2971513Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:56:19.323746Z", + "dependencies_met": true, + "engine": "7c968b3d-cacf-4529-9906-e682a1b4e3ac", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "58b498de-c16ba38c4ff81c58976eccbd_17128_16", + "username": "username", + "session": "58b498de-c16ba38c4ff81c58976eccbd", + "date": "2023-03-21T23:56:19.364280Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "86b82f3c-2510-4004-bbda-d3dd144e0657", + "username": "dotnet_kernel", + "session": "57a045de-8626-41a3-a85d-798dc80d0bc0", + "date": "2023-03-21T23:56:19.2971513Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "58b498de-c16ba38c4ff81c58976eccbd_17128_17", + "username": "username", + "session": "58b498de-c16ba38c4ff81c58976eccbd", + "date": "2023-03-21T23:56:19.368289Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "cae29aeb-09ff-45b5-ba00-048f61c97abf", + "username": "dotnet_kernel", + "session": "1d221bc4-ff7d-47f5-8e2a-ee1ba7e892c8", + "date": "2023-03-21T23:56:19.3666666Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "58b498de-c16ba38c4ff81c58976eccbd_17128_18", + "username": "username", + "session": "58b498de-c16ba38c4ff81c58976eccbd", + "date": "2023-03-21T23:56:19.368289Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "cae29aeb-09ff-45b5-ba00-048f61c97abf", + "username": "dotnet_kernel", + "session": "1d221bc4-ff7d-47f5-8e2a-ee1ba7e892c8", + "date": "2023-03-21T23:56:19.3666666Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "37a778f8-1f9b-4c04-87d8-55a2749257d9", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "58b498de-c16ba38c4ff81c58976eccbd_17128_19", + "username": "username", + "session": "58b498de-c16ba38c4ff81c58976eccbd", + "date": "2023-03-21T23:56:19.369291Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "cae29aeb-09ff-45b5-ba00-048f61c97abf", + "username": "dotnet_kernel", + "session": "1d221bc4-ff7d-47f5-8e2a-ee1ba7e892c8", + "date": "2023-03-21T23:56:19.3666666Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "58b498de-c16ba38c4ff81c58976eccbd_17128_20", + "username": "username", + "session": "58b498de-c16ba38c4ff81c58976eccbd", + "date": "2023-03-21T23:56:19.373291Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c932b104-d475-4ad3-9b29-8efe8bfd4e7c", + "username": "dotnet_kernel", + "session": "3185b853-ea07-4069-a643-b8263429b719", + "date": "2023-03-21T23:56:19.3725419Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "58b498de-c16ba38c4ff81c58976eccbd_17128_21", + "username": "username", + "session": "58b498de-c16ba38c4ff81c58976eccbd", + "date": "2023-03-21T23:56:19.373291Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c932b104-d475-4ad3-9b29-8efe8bfd4e7c", + "username": "dotnet_kernel", + "session": "3185b853-ea07-4069-a643-b8263429b719", + "date": "2023-03-21T23:56:19.3725419Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "import sys\n\nprint('stderr', file=sys.stderr)", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "58b498de-c16ba38c4ff81c58976eccbd_17128_22", + "username": "username", + "session": "58b498de-c16ba38c4ff81c58976eccbd", + "date": "2023-03-21T23:56:19.375290Z", + "msg_type": "stream", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c932b104-d475-4ad3-9b29-8efe8bfd4e7c", + "username": "dotnet_kernel", + "session": "3185b853-ea07-4069-a643-b8263429b719", + "date": "2023-03-21T23:56:19.3725419Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "name": "stderr", + "text": "stderr\n" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "58b498de-c16ba38c4ff81c58976eccbd_17128_23", + "username": "username", + "session": "58b498de-c16ba38c4ff81c58976eccbd", + "date": "2023-03-21T23:56:19.380288Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c932b104-d475-4ad3-9b29-8efe8bfd4e7c", + "username": "dotnet_kernel", + "session": "3185b853-ea07-4069-a643-b8263429b719", + "date": "2023-03-21T23:56:19.3725419Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:56:19.373291Z", + "dependencies_met": true, + "engine": "7c968b3d-cacf-4529-9906-e682a1b4e3ac", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "58b498de-c16ba38c4ff81c58976eccbd_17128_24", + "username": "username", + "session": "58b498de-c16ba38c4ff81c58976eccbd", + "date": "2023-03-21T23:56:19.380288Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c932b104-d475-4ad3-9b29-8efe8bfd4e7c", + "username": "dotnet_kernel", + "session": "3185b853-ea07-4069-a643-b8263429b719", + "date": "2023-03-21T23:56:19.3725419Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_stream_stdout_produced.ir.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_stream_stdout_produced.ir.json new file mode 100644 index 0000000000..a19343ecd4 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_stream_stdout_produced.ir.json @@ -0,0 +1,413 @@ +[ + { + "header": { + "msg_id": "f7e079f8-c843-11ed-811a-1b41b6b5c48a", + "username": "dotnet_kernel", + "session": "b18b9d01-e501-44e1-aa4f-d29e96efd042", + "date": "2023-03-21T23:56:16.569619Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e5f44b04-148f-497b-a65d-b3c67479123f", + "username": "dotnet_kernel", + "session": "b18b9d01-e501-44e1-aa4f-d29e96efd042", + "date": "2023-03-21T23:56:16.5067642Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f7e4fabe-c843-11ed-811a-1b41b6b5c48a", + "username": "dotnet_kernel", + "session": "b18b9d01-e501-44e1-aa4f-d29e96efd042", + "date": "2023-03-21T23:56:16.572629Z", + "msg_type": "kernel_info_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e5f44b04-148f-497b-a65d-b3c67479123f", + "username": "dotnet_kernel", + "session": "b18b9d01-e501-44e1-aa4f-d29e96efd042", + "date": "2023-03-21T23:56:16.5067642Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.0", + "implementation": "IRkernel", + "implementation_version": "0.8.15", + "language_info": { + "name": "R", + "version": "3.6.1", + "mimetype": "text/x-r-source", + "file_extension": ".r", + "pygments_lexer": "r", + "codemirror_mode": "r" + }, + "banner": "R version 3.6.1 (2019-07-05)", + "status": "ok", + "help_links": [] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f7e54942-c843-11ed-811a-1b41b6b5c48a", + "username": "dotnet_kernel", + "session": "b18b9d01-e501-44e1-aa4f-d29e96efd042", + "date": "2023-03-21T23:56:16.573630Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e5f44b04-148f-497b-a65d-b3c67479123f", + "username": "dotnet_kernel", + "session": "b18b9d01-e501-44e1-aa4f-d29e96efd042", + "date": "2023-03-21T23:56:16.5067642Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f7e63398-c843-11ed-811a-1b41b6b5c48a", + "username": "dotnet_kernel", + "session": "2951d145-76d1-49c6-a6b1-d3c78e36854a", + "date": "2023-03-21T23:56:16.580629Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3eec7e33-55e8-4509-9e30-a4b2c499eba6", + "username": "dotnet_kernel", + "session": "2951d145-76d1-49c6-a6b1-d3c78e36854a", + "date": "2023-03-21T23:56:16.5741183Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f7e6cfd8-c843-11ed-811a-1b41b6b5c48a", + "username": "dotnet_kernel", + "session": "2951d145-76d1-49c6-a6b1-d3c78e36854a", + "date": "2023-03-21T23:56:16.583629Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3eec7e33-55e8-4509-9e30-a4b2c499eba6", + "username": "dotnet_kernel", + "session": "2951d145-76d1-49c6-a6b1-d3c78e36854a", + "date": "2023-03-21T23:56:16.5741183Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f7f67708-c843-11ed-811a-1b41b6b5c48a", + "username": "dotnet_kernel", + "session": "2951d145-76d1-49c6-a6b1-d3c78e36854a", + "date": "2023-03-21T23:56:16.687214Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3eec7e33-55e8-4509-9e30-a4b2c499eba6", + "username": "dotnet_kernel", + "session": "2951d145-76d1-49c6-a6b1-d3c78e36854a", + "date": "2023-03-21T23:56:16.5741183Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f7f6c51e-c843-11ed-811a-1b41b6b5c48a", + "username": "dotnet_kernel", + "session": "2951d145-76d1-49c6-a6b1-d3c78e36854a", + "date": "2023-03-21T23:56:16.688214Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3eec7e33-55e8-4509-9e30-a4b2c499eba6", + "username": "dotnet_kernel", + "session": "2951d145-76d1-49c6-a6b1-d3c78e36854a", + "date": "2023-03-21T23:56:16.5741183Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f7f78882-c843-11ed-811a-1b41b6b5c48a", + "username": "dotnet_kernel", + "session": "0d45e3db-845b-46c4-b0c1-327fe9863554", + "date": "2023-03-21T23:56:16.692213Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "bc187295-3b5f-4ad5-9d45-e27bd8d202c7", + "username": "dotnet_kernel", + "session": "0d45e3db-845b-46c4-b0c1-327fe9863554", + "date": "2023-03-21T23:56:16.6893978Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f7f81176-c843-11ed-811a-1b41b6b5c48a", + "username": "dotnet_kernel", + "session": "0d45e3db-845b-46c4-b0c1-327fe9863554", + "date": "2023-03-21T23:56:16.695727Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "bc187295-3b5f-4ad5-9d45-e27bd8d202c7", + "username": "dotnet_kernel", + "session": "0d45e3db-845b-46c4-b0c1-327fe9863554", + "date": "2023-03-21T23:56:16.6893978Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "d2a7c228-edae-4450-8b30-c7b497598049", + "data": { + "commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f7f838d6-c843-11ed-811a-1b41b6b5c48a", + "username": "dotnet_kernel", + "session": "0d45e3db-845b-46c4-b0c1-327fe9863554", + "date": "2023-03-21T23:56:16.696728Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "bc187295-3b5f-4ad5-9d45-e27bd8d202c7", + "username": "dotnet_kernel", + "session": "0d45e3db-845b-46c4-b0c1-327fe9863554", + "date": "2023-03-21T23:56:16.6893978Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f7f8d50c-c843-11ed-811a-1b41b6b5c48a", + "username": "dotnet_kernel", + "session": "10e54e7c-a799-4738-a720-91e12b79473b", + "date": "2023-03-21T23:56:16.700729Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d460de1a-72ef-4838-8608-75f655d7ca8f", + "username": "dotnet_kernel", + "session": "10e54e7c-a799-4738-a720-91e12b79473b", + "date": "2023-03-21T23:56:16.6989129Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f7fc09ac-c843-11ed-811a-1b41b6b5c48a", + "username": "dotnet_kernel", + "session": "10e54e7c-a799-4738-a720-91e12b79473b", + "date": "2023-03-21T23:56:16.722735Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d460de1a-72ef-4838-8608-75f655d7ca8f", + "username": "dotnet_kernel", + "session": "10e54e7c-a799-4738-a720-91e12b79473b", + "date": "2023-03-21T23:56:16.6989129Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "for (x in 1:2) {\n\tprint(x);\n\tflush.console()\n}", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f7fe19ea-c843-11ed-811a-1b41b6b5c48a", + "username": "dotnet_kernel", + "session": "10e54e7c-a799-4738-a720-91e12b79473b", + "date": "2023-03-21T23:56:16.735258Z", + "msg_type": "stream", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d460de1a-72ef-4838-8608-75f655d7ca8f", + "username": "dotnet_kernel", + "session": "10e54e7c-a799-4738-a720-91e12b79473b", + "date": "2023-03-21T23:56:16.6989129Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "name": "stdout", + "text": "[1] 1\n" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f7fe4104-c843-11ed-811a-1b41b6b5c48a", + "username": "dotnet_kernel", + "session": "10e54e7c-a799-4738-a720-91e12b79473b", + "date": "2023-03-21T23:56:16.737255Z", + "msg_type": "stream", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d460de1a-72ef-4838-8608-75f655d7ca8f", + "username": "dotnet_kernel", + "session": "10e54e7c-a799-4738-a720-91e12b79473b", + "date": "2023-03-21T23:56:16.6989129Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "name": "stdout", + "text": "[1] 2\n" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f7ff2b46-c843-11ed-811a-1b41b6b5c48a", + "username": "dotnet_kernel", + "session": "10e54e7c-a799-4738-a720-91e12b79473b", + "date": "2023-03-21T23:56:16.742266Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d460de1a-72ef-4838-8608-75f655d7ca8f", + "username": "dotnet_kernel", + "session": "10e54e7c-a799-4738-a720-91e12b79473b", + "date": "2023-03-21T23:56:16.6989129Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "f7ff52c4-c843-11ed-811a-1b41b6b5c48a", + "username": "dotnet_kernel", + "session": "10e54e7c-a799-4738-a720-91e12b79473b", + "date": "2023-03-21T23:56:16.743265Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d460de1a-72ef-4838-8608-75f655d7ca8f", + "username": "dotnet_kernel", + "session": "10e54e7c-a799-4738-a720-91e12b79473b", + "date": "2023-03-21T23:56:16.6989129Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_stream_stdout_produced.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_stream_stdout_produced.python3.json new file mode 100644 index 0000000000..6860ef172f --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_stream_stdout_produced.python3.json @@ -0,0 +1,456 @@ +[ + { + "header": { + "msg_id": "634c3651-b45ea130a5fb24ab9c02765f_11964_10", + "username": "username", + "session": "634c3651-b45ea130a5fb24ab9c02765f", + "date": "2023-03-21T23:56:15.496443Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b2532990-5f9f-4758-8cfb-5044fc928024", + "username": "dotnet_kernel", + "session": "63994505-8537-449b-8a1d-b359711d7bd0", + "date": "2023-03-21T23:56:15.4769044Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "634c3651-b45ea130a5fb24ab9c02765f_11964_12", + "username": "username", + "session": "634c3651-b45ea130a5fb24ab9c02765f", + "date": "2023-03-21T23:56:15.497442Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b2532990-5f9f-4758-8cfb-5044fc928024", + "username": "dotnet_kernel", + "session": "63994505-8537-449b-8a1d-b359711d7bd0", + "date": "2023-03-21T23:56:15.4769044Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "634c3651-b45ea130a5fb24ab9c02765f_11964_11", + "username": "username", + "session": "634c3651-b45ea130a5fb24ab9c02765f", + "date": "2023-03-21T23:56:15.496443Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b2532990-5f9f-4758-8cfb-5044fc928024", + "username": "dotnet_kernel", + "session": "63994505-8537-449b-8a1d-b359711d7bd0", + "date": "2023-03-21T23:56:15.4769044Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "634c3651-b45ea130a5fb24ab9c02765f_11964_13", + "username": "username", + "session": "634c3651-b45ea130a5fb24ab9c02765f", + "date": "2023-03-21T23:56:15.501443Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "848489a5-92ea-49cf-9557-c2b317aa5438", + "username": "dotnet_kernel", + "session": "cf33a31e-c24a-4eaa-8ee0-887d59ef1feb", + "date": "2023-03-21T23:56:15.4998596Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "634c3651-b45ea130a5fb24ab9c02765f_11964_14", + "username": "username", + "session": "634c3651-b45ea130a5fb24ab9c02765f", + "date": "2023-03-21T23:56:15.502442Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "848489a5-92ea-49cf-9557-c2b317aa5438", + "username": "dotnet_kernel", + "session": "cf33a31e-c24a-4eaa-8ee0-887d59ef1feb", + "date": "2023-03-21T23:56:15.4998596Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "634c3651-b45ea130a5fb24ab9c02765f_11964_15", + "username": "username", + "session": "634c3651-b45ea130a5fb24ab9c02765f", + "date": "2023-03-21T23:56:15.533962Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "848489a5-92ea-49cf-9557-c2b317aa5438", + "username": "dotnet_kernel", + "session": "cf33a31e-c24a-4eaa-8ee0-887d59ef1feb", + "date": "2023-03-21T23:56:15.4998596Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:56:15.502442Z", + "dependencies_met": true, + "engine": "1a52d21a-3b4d-42af-9ab2-166b42d13964", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "634c3651-b45ea130a5fb24ab9c02765f_11964_16", + "username": "username", + "session": "634c3651-b45ea130a5fb24ab9c02765f", + "date": "2023-03-21T23:56:15.533962Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "848489a5-92ea-49cf-9557-c2b317aa5438", + "username": "dotnet_kernel", + "session": "cf33a31e-c24a-4eaa-8ee0-887d59ef1feb", + "date": "2023-03-21T23:56:15.4998596Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "634c3651-b45ea130a5fb24ab9c02765f_11964_17", + "username": "username", + "session": "634c3651-b45ea130a5fb24ab9c02765f", + "date": "2023-03-21T23:56:15.537962Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "eccc829a-c2fd-4df8-af73-84d2ca19a2d4", + "username": "dotnet_kernel", + "session": "37e37434-aa02-47b7-945d-5e6c3115bc5f", + "date": "2023-03-21T23:56:15.5363735Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "634c3651-b45ea130a5fb24ab9c02765f_11964_18", + "username": "username", + "session": "634c3651-b45ea130a5fb24ab9c02765f", + "date": "2023-03-21T23:56:15.537962Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "eccc829a-c2fd-4df8-af73-84d2ca19a2d4", + "username": "dotnet_kernel", + "session": "37e37434-aa02-47b7-945d-5e6c3115bc5f", + "date": "2023-03-21T23:56:15.5363735Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "fa0c266c-28e5-4ec6-8097-665035138d65", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "634c3651-b45ea130a5fb24ab9c02765f_11964_19", + "username": "username", + "session": "634c3651-b45ea130a5fb24ab9c02765f", + "date": "2023-03-21T23:56:15.538995Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "eccc829a-c2fd-4df8-af73-84d2ca19a2d4", + "username": "dotnet_kernel", + "session": "37e37434-aa02-47b7-945d-5e6c3115bc5f", + "date": "2023-03-21T23:56:15.5363735Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "634c3651-b45ea130a5fb24ab9c02765f_11964_20", + "username": "username", + "session": "634c3651-b45ea130a5fb24ab9c02765f", + "date": "2023-03-21T23:56:15.542996Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "5695b931-98a9-4be2-9e55-959d03fcf863", + "username": "dotnet_kernel", + "session": "9d64a98c-3b98-4c95-8e32-1bbe55a0e08e", + "date": "2023-03-21T23:56:15.5424636Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "634c3651-b45ea130a5fb24ab9c02765f_11964_21", + "username": "username", + "session": "634c3651-b45ea130a5fb24ab9c02765f", + "date": "2023-03-21T23:56:15.542996Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "5695b931-98a9-4be2-9e55-959d03fcf863", + "username": "dotnet_kernel", + "session": "9d64a98c-3b98-4c95-8e32-1bbe55a0e08e", + "date": "2023-03-21T23:56:15.5424636Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "for i in range(2):\n\tprint (i, flush=True)", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "634c3651-b45ea130a5fb24ab9c02765f_11964_22", + "username": "username", + "session": "634c3651-b45ea130a5fb24ab9c02765f", + "date": "2023-03-21T23:56:15.544995Z", + "msg_type": "stream", + "version": "5.3" + }, + "parent_header": { + "msg_id": "5695b931-98a9-4be2-9e55-959d03fcf863", + "username": "dotnet_kernel", + "session": "9d64a98c-3b98-4c95-8e32-1bbe55a0e08e", + "date": "2023-03-21T23:56:15.5424636Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "name": "stdout", + "text": "0\n" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "634c3651-b45ea130a5fb24ab9c02765f_11964_23", + "username": "username", + "session": "634c3651-b45ea130a5fb24ab9c02765f", + "date": "2023-03-21T23:56:15.545995Z", + "msg_type": "stream", + "version": "5.3" + }, + "parent_header": { + "msg_id": "5695b931-98a9-4be2-9e55-959d03fcf863", + "username": "dotnet_kernel", + "session": "9d64a98c-3b98-4c95-8e32-1bbe55a0e08e", + "date": "2023-03-21T23:56:15.5424636Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "name": "stdout", + "text": "1\n" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "634c3651-b45ea130a5fb24ab9c02765f_11964_24", + "username": "username", + "session": "634c3651-b45ea130a5fb24ab9c02765f", + "date": "2023-03-21T23:56:15.549993Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "5695b931-98a9-4be2-9e55-959d03fcf863", + "username": "dotnet_kernel", + "session": "9d64a98c-3b98-4c95-8e32-1bbe55a0e08e", + "date": "2023-03-21T23:56:15.5424636Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:56:15.542996Z", + "dependencies_met": true, + "engine": "1a52d21a-3b4d-42af-9ab2-166b42d13964", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "634c3651-b45ea130a5fb24ab9c02765f_11964_25", + "username": "username", + "session": "634c3651-b45ea130a5fb24ab9c02765f", + "date": "2023-03-21T23:56:15.549993Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "5695b931-98a9-4be2-9e55-959d03fcf863", + "username": "dotnet_kernel", + "session": "9d64a98c-3b98-4c95-8e32-1bbe55a0e08e", + "date": "2023-03-21T23:56:15.5424636Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_update_display_produced.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_update_display_produced.python3.json new file mode 100644 index 0000000000..9a14d0c728 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.can_submit_code_and_get_update_display_produced.python3.json @@ -0,0 +1,466 @@ +[ + { + "header": { + "msg_id": "4ee180bd-8bd15d34f8f646082b3ae653_21232_10", + "username": "username", + "session": "4ee180bd-8bd15d34f8f646082b3ae653", + "date": "2023-03-21T23:56:01.807742Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "fcc11c96-10aa-4c25-bd79-c91ff4f89047", + "username": "dotnet_kernel", + "session": "73cdafef-f340-4248-af70-07ddc2bfff7c", + "date": "2023-03-21T23:56:01.7918593Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4ee180bd-8bd15d34f8f646082b3ae653_21232_11", + "username": "username", + "session": "4ee180bd-8bd15d34f8f646082b3ae653", + "date": "2023-03-21T23:56:01.807742Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "fcc11c96-10aa-4c25-bd79-c91ff4f89047", + "username": "dotnet_kernel", + "session": "73cdafef-f340-4248-af70-07ddc2bfff7c", + "date": "2023-03-21T23:56:01.7918593Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4ee180bd-8bd15d34f8f646082b3ae653_21232_12", + "username": "username", + "session": "4ee180bd-8bd15d34f8f646082b3ae653", + "date": "2023-03-21T23:56:01.807742Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "fcc11c96-10aa-4c25-bd79-c91ff4f89047", + "username": "dotnet_kernel", + "session": "73cdafef-f340-4248-af70-07ddc2bfff7c", + "date": "2023-03-21T23:56:01.7918593Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4ee180bd-8bd15d34f8f646082b3ae653_21232_13", + "username": "username", + "session": "4ee180bd-8bd15d34f8f646082b3ae653", + "date": "2023-03-21T23:56:01.811740Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "73a1b9cd-0559-4d50-8590-0536d981e6c1", + "username": "dotnet_kernel", + "session": "ed3580cc-4f9c-420e-a922-d5bb2cbec6f7", + "date": "2023-03-21T23:56:01.8104502Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4ee180bd-8bd15d34f8f646082b3ae653_21232_14", + "username": "username", + "session": "4ee180bd-8bd15d34f8f646082b3ae653", + "date": "2023-03-21T23:56:01.812746Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "73a1b9cd-0559-4d50-8590-0536d981e6c1", + "username": "dotnet_kernel", + "session": "ed3580cc-4f9c-420e-a922-d5bb2cbec6f7", + "date": "2023-03-21T23:56:01.8104502Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4ee180bd-8bd15d34f8f646082b3ae653_21232_15", + "username": "username", + "session": "4ee180bd-8bd15d34f8f646082b3ae653", + "date": "2023-03-21T23:56:01.848680Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "73a1b9cd-0559-4d50-8590-0536d981e6c1", + "username": "dotnet_kernel", + "session": "ed3580cc-4f9c-420e-a922-d5bb2cbec6f7", + "date": "2023-03-21T23:56:01.8104502Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:56:01.812746Z", + "dependencies_met": true, + "engine": "f20ba7de-f246-48c8-a48f-67739aec7caa", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4ee180bd-8bd15d34f8f646082b3ae653_21232_16", + "username": "username", + "session": "4ee180bd-8bd15d34f8f646082b3ae653", + "date": "2023-03-21T23:56:01.848680Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "73a1b9cd-0559-4d50-8590-0536d981e6c1", + "username": "dotnet_kernel", + "session": "ed3580cc-4f9c-420e-a922-d5bb2cbec6f7", + "date": "2023-03-21T23:56:01.8104502Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4ee180bd-8bd15d34f8f646082b3ae653_21232_17", + "username": "username", + "session": "4ee180bd-8bd15d34f8f646082b3ae653", + "date": "2023-03-21T23:56:01.853244Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "dee82d57-433b-4f8a-bc07-bcb26a605304", + "username": "dotnet_kernel", + "session": "d754a819-98c6-44c0-96f8-dba28251d818", + "date": "2023-03-21T23:56:01.8514039Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4ee180bd-8bd15d34f8f646082b3ae653_21232_18", + "username": "username", + "session": "4ee180bd-8bd15d34f8f646082b3ae653", + "date": "2023-03-21T23:56:01.853244Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "dee82d57-433b-4f8a-bc07-bcb26a605304", + "username": "dotnet_kernel", + "session": "d754a819-98c6-44c0-96f8-dba28251d818", + "date": "2023-03-21T23:56:01.8514039Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "9024d194-49cf-4f8d-93de-292a3b66c1f4", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4ee180bd-8bd15d34f8f646082b3ae653_21232_19", + "username": "username", + "session": "4ee180bd-8bd15d34f8f646082b3ae653", + "date": "2023-03-21T23:56:01.854246Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "dee82d57-433b-4f8a-bc07-bcb26a605304", + "username": "dotnet_kernel", + "session": "d754a819-98c6-44c0-96f8-dba28251d818", + "date": "2023-03-21T23:56:01.8514039Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4ee180bd-8bd15d34f8f646082b3ae653_21232_20", + "username": "username", + "session": "4ee180bd-8bd15d34f8f646082b3ae653", + "date": "2023-03-21T23:56:01.858243Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "17c05011-e452-4970-8faf-c54b681547a0", + "username": "dotnet_kernel", + "session": "467f4908-36f6-4853-b246-3de0d335095f", + "date": "2023-03-21T23:56:01.8571404Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4ee180bd-8bd15d34f8f646082b3ae653_21232_21", + "username": "username", + "session": "4ee180bd-8bd15d34f8f646082b3ae653", + "date": "2023-03-21T23:56:01.858243Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "17c05011-e452-4970-8faf-c54b681547a0", + "username": "dotnet_kernel", + "session": "467f4908-36f6-4853-b246-3de0d335095f", + "date": "2023-03-21T23:56:01.8571404Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "dh = display(\"test\", display_id=True)\ndh.update(\"update-test\")", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4ee180bd-8bd15d34f8f646082b3ae653_21232_22", + "username": "username", + "session": "4ee180bd-8bd15d34f8f646082b3ae653", + "date": "2023-03-21T23:56:01.863242Z", + "msg_type": "display_data", + "version": "5.3" + }, + "parent_header": { + "msg_id": "17c05011-e452-4970-8faf-c54b681547a0", + "username": "dotnet_kernel", + "session": "467f4908-36f6-4853-b246-3de0d335095f", + "date": "2023-03-21T23:56:01.8571404Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "data": { + "text/plain": "'test'" + }, + "metadata": {}, + "transient": { + "display_id": "172844eaaee01eb530ac536c65a34543" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4ee180bd-8bd15d34f8f646082b3ae653_21232_23", + "username": "username", + "session": "4ee180bd-8bd15d34f8f646082b3ae653", + "date": "2023-03-21T23:56:01.865244Z", + "msg_type": "update_display_data", + "version": "5.3" + }, + "parent_header": { + "msg_id": "17c05011-e452-4970-8faf-c54b681547a0", + "username": "dotnet_kernel", + "session": "467f4908-36f6-4853-b246-3de0d335095f", + "date": "2023-03-21T23:56:01.8571404Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "data": { + "text/plain": "'update-test'" + }, + "metadata": {}, + "transient": { + "display_id": "172844eaaee01eb530ac536c65a34543" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4ee180bd-8bd15d34f8f646082b3ae653_21232_24", + "username": "username", + "session": "4ee180bd-8bd15d34f8f646082b3ae653", + "date": "2023-03-21T23:56:01.879260Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "17c05011-e452-4970-8faf-c54b681547a0", + "username": "dotnet_kernel", + "session": "467f4908-36f6-4853-b246-3de0d335095f", + "date": "2023-03-21T23:56:01.8571404Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:56:01.858243Z", + "dependencies_met": true, + "engine": "f20ba7de-f246-48c8-a48f-67739aec7caa", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4ee180bd-8bd15d34f8f646082b3ae653_21232_25", + "username": "username", + "session": "4ee180bd-8bd15d34f8f646082b3ae653", + "date": "2023-03-21T23:56:01.879260Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "17c05011-e452-4970-8faf-c54b681547a0", + "username": "dotnet_kernel", + "session": "467f4908-36f6-4853-b246-3de0d335095f", + "date": "2023-03-21T23:56:01.8571404Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.cs b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.cs new file mode 100644 index 0000000000..6f1b12df24 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelCommandTests.cs @@ -0,0 +1,657 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using FluentAssertions; +using Microsoft.DotNet.Interactive.Commands; +using Microsoft.DotNet.Interactive.Events; +using Microsoft.DotNet.Interactive.Formatting; +using Microsoft.DotNet.Interactive.Jupyter.Protocol; +using Microsoft.DotNet.Interactive.Tests.Utility; +using Microsoft.DotNet.Interactive.Utility; +using System.Linq; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.DotNet.Interactive.Jupyter.Tests; + +public class JupyterKernelCommandTests : JupyterKernelTestBase +{ + [Theory] + [JupyterHttpTestData("python", KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterHttpTestData("R", KernelSpecName = RKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("python", KernelSpecName = PythonKernelName)] + [JupyterZMQTestData("R", KernelSpecName = RKernelName)] + [JupyterTestData("python", KernelSpecName = PythonKernelName)] + [JupyterTestData("R", KernelSpecName = RKernelName)] + public async Task can_connect_to_and_setup_kernel(JupyterConnectionTestData connectionData, string languageName) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = CreateCompositeKernelAsync(options); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + var recievedMessages = options.MessageTracker.ReceivedMessages.ToSubscribedList(); + + var result = await kernel.SubmitCodeAsync( + $"#!connect jupyter --kernel-name testKernel --kernel-spec {connectionData.KernelSpecName} {connectionData.GetConnectionString()}"); + + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + // should check on the kernel + sentMessages + .Should() + .ContainSingle(m => m.Header.MessageType == JupyterMessageContentTypes.KernelInfoRequest); + + var kernelInfoReturned = recievedMessages + .Where(m => m.Header.MessageType == JupyterMessageContentTypes.KernelInfoReply) + .Select(m => m.Content) + .Cast() + .First(); + + kernelInfoReturned + .LanguageInfo + .Name + .Should() + .Be(languageName); + + events + .Should() + .ContainSingle(e => e.KernelInfo.LocalName == "testKernel") + .Which + .KernelInfo + .Should() + .BeEquivalentTo(new + { + LanguageName = kernelInfoReturned.LanguageInfo.Name, + LanguageVersion = kernelInfoReturned.LanguageInfo.Version + }, c => c.ExcludingMissingMembers()); + + var testKernel = kernel.FindKernelByName("testKernel"); + Assert.NotNull(testKernel); + + // kernel info should be sent as kernel info produced + testKernel + .KernelInfo + .Should() + .BeEquivalentTo(new + { + LanguageName = kernelInfoReturned.LanguageInfo.Name, + LanguageVersion = kernelInfoReturned.LanguageInfo.Version + }, c => c.ExcludingMissingMembers()); + + // ensure variable sharing is setup + testKernel.KernelInfo.SupportedKernelCommands + .Should().Contain(new KernelCommandInfo(nameof(RequestValue))); + + testKernel.KernelInfo.SupportedKernelCommands + .Should().Contain(new KernelCommandInfo(nameof(RequestValueInfos))); + + testKernel.KernelInfo.SupportedKernelCommands + .Should().Contain(new KernelCommandInfo(nameof(SendValue))); + + var directives = testKernel.KernelInfo.SupportedDirectives.Select(info => info.Name); + directives.Should().Contain("#!who"); + directives.Should().Contain("#!whos"); + + options.SaveState(); + } + + // note that R kernel returns display_data instead of execute_result + [Theory] + [JupyterHttpTestData("1+1", PlainTextFormatter.MimeType, "2", KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("1+1", PlainTextFormatter.MimeType, "2", KernelSpecName = PythonKernelName)] + [JupyterTestData("1+1", PlainTextFormatter.MimeType, "2", KernelSpecName = PythonKernelName)] + public async Task can_submit_code_and_get_return_value_produced(JupyterConnectionTestData connectionData, string codeToRun, string mimeType, string outputReturned) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = CreateCompositeKernelAsync(options); + + await kernel.SubmitCodeAsync( + $"#!connect jupyter --kernel-name testKernel --kernel-spec {connectionData.KernelSpecName} {connectionData.GetConnectionString()}"); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + var recievedMessages = options.MessageTracker.ReceivedMessages.ToSubscribedList(); + + var result = await kernel.SubmitCodeAsync($"#!testKernel\n{codeToRun}"); + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + + sentMessages + .Should() + .ContainSingle(m => m.Header.MessageType == JupyterMessageContentTypes.ExecuteRequest) + .Which + .Content + .As() + .Code + .Should() + .Be(codeToRun); + + events.Should() + .ContainSingle() + .Which + .FormattedValues + .Should() + .ContainSingle(v => v.MimeType == mimeType) + .Which + .Value + .Should() + .Be(outputReturned); + + options.SaveState(); + } + + [Theory] + [JupyterHttpTestData("from IPython.display import display; display(2)", new[] { "text/plain" }, new[] { "2" }, KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("from IPython.display import display; display(2)", new[] { "text/plain" }, new[] { "2" }, KernelSpecName = PythonKernelName)] + [JupyterTestData("from IPython.display import display; display(2)", new[] { "text/plain" }, new[] { "2" }, KernelSpecName = PythonKernelName)] + [JupyterHttpTestData("1+1", new[] { "text/plain", "text/html", "text/latex", "text/markdown" }, new[] { "[1] 2", "2", "2", "2" }, KernelSpecName = RKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("1+1", new[] { "text/plain", "text/html", "text/latex", "text/markdown" }, new[] { "[1] 2", "2", "2", "2" }, KernelSpecName = RKernelName)] + [JupyterTestData("1+1", new[] { "text/plain", "text/html", "text/latex", "text/markdown" }, new[] { "[1] 2", "2", "2", "2" }, KernelSpecName = RKernelName)] + public async Task can_submit_code_and_get_display_value_produced(JupyterConnectionTestData connectionData, string codeToRun, string[] mimeTypes, string[] valuesToExpect) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = CreateCompositeKernelAsync(options); + + await kernel.SubmitCodeAsync( + $"#!connect jupyter --kernel-name testKernel --kernel-spec {connectionData.KernelSpecName} {connectionData.GetConnectionString()}"); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + var recievedMessages = options.MessageTracker.ReceivedMessages.ToSubscribedList(); + + var result = await kernel.SubmitCodeAsync($"#!testKernel\n{codeToRun}"); + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + sentMessages + .Should() + .ContainSingle(m => m.Header.MessageType == JupyterMessageContentTypes.ExecuteRequest) + .Which + .Content + .As() + .Code + .Should() + .Be(codeToRun); + + + var displayValueProduced = events.Should() + .ContainSingle() + .Which; + + for (int i = 0; i < mimeTypes.Length; i++) + { + displayValueProduced + .FormattedValues + .Should() + .ContainSingle(v => v.MimeType == mimeTypes[i]) + .Which + .Value + .Should() + .Be(valuesToExpect[i]); + } + + options.SaveState(); + } + + [Theory] + [JupyterHttpTestData("for i in range(2):\n\tprint (i, flush=True)", new[] { "0\n", "1\n" }, KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("for i in range(2):\n\tprint (i, flush=True)", new[] { "0\n", "1\n" }, KernelSpecName = PythonKernelName)] + [JupyterTestData("for i in range(2):\n\tprint (i, flush=True)", new[] { "0\n", "1\n" }, KernelSpecName = PythonKernelName)] + [JupyterHttpTestData("for (x in 1:2) {\n\tprint(x);\n\tflush.console()\n}", new[] { "[1] 1\n", "[1] 2\n" }, KernelSpecName = RKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("for (x in 1:2) {\n\tprint(x);\n\tflush.console()\n}", new[] { "[1] 1\n", "[1] 2\n" }, KernelSpecName = RKernelName)] + [JupyterTestData("for (x in 1:2) {\n\tprint(x);\n\tflush.console()\n}", new[] { "[1] 1\n", "[1] 2\n" }, KernelSpecName = RKernelName)] + public async Task can_submit_code_and_get_stream_stdout_produced(JupyterConnectionTestData connectionData, string codeToRun, string[] outputReturned) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = CreateCompositeKernelAsync(options); + + await kernel.SubmitCodeAsync( + $"#!connect jupyter --kernel-name testKernel --kernel-spec {connectionData.KernelSpecName} {connectionData.GetConnectionString()}"); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + var recievedMessages = options.MessageTracker.ReceivedMessages.ToSubscribedList(); + + var result = await kernel.SubmitCodeAsync($"#!testKernel\n{codeToRun}"); + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + + sentMessages + .Should() + .ContainSingle(m => m.Header.MessageType == JupyterMessageContentTypes.ExecuteRequest) + .Which + .Content + .As() + .Code + .Should() + .Be(codeToRun); + + events.OfType() + .Should() + .HaveCount(outputReturned.Length); + + for (int i = 0; i < outputReturned.Length; i++) + { + events.OfType() + .ElementAt(i) + .FormattedValues + .Should() + .ContainSingle(v => v.MimeType == PlainTextFormatter.MimeType) + .Which + .Value + .Should() + .Be(outputReturned[i]); + } + + options.SaveState(); + } + + + [Theory] + [JupyterHttpTestData("import sys\n\nprint('stderr', file=sys.stderr)", "stderr\n", KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterHttpTestData("message('stderr')", "stderr\n", KernelSpecName = RKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("import sys\n\nprint('stderr', file=sys.stderr)", "stderr\n", KernelSpecName = PythonKernelName)] + [JupyterZMQTestData("message('stderr')", "stderr\n", KernelSpecName = RKernelName)] + [JupyterTestData("import sys\n\nprint('stderr', file=sys.stderr)", "stderr\n", KernelSpecName = PythonKernelName)] + [JupyterTestData("message('stderr')", "stderr\n", KernelSpecName = RKernelName)] + public async Task can_submit_code_and_get_stderr_produced(JupyterConnectionTestData connectionData, string codeToRun, string outputReturned) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = CreateCompositeKernelAsync(options); + + await kernel.SubmitCodeAsync( + $"#!connect jupyter --kernel-name testKernel --kernel-spec {connectionData.KernelSpecName} {connectionData.GetConnectionString()}"); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + var recievedMessages = options.MessageTracker.ReceivedMessages.ToSubscribedList(); + + var result = await kernel.SubmitCodeAsync($"#!testKernel\n{codeToRun}"); + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + sentMessages + .Should() + .ContainSingle(m => m.Header.MessageType == JupyterMessageContentTypes.ExecuteRequest) + .Which + .Content + .As() + .Code + .Should() + .Be(codeToRun); + + events.Should() + .ContainSingle() + .Which + .FormattedValues + .Should() + .ContainSingle(v => v.MimeType == PlainTextFormatter.MimeType) + .Which + .Value + .Should() + .Be(outputReturned); + + options.SaveState(); + } + + [Theory] + [JupyterHttpTestData("prin()", new[] { "\u001B[1;31mNameError\u001B[0m: name 'prin' is not defined", "Traceback (most recent call last)" }, KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterHttpTestData("prin()", new[] { "Error in prin(): could not find function \"prin\"\nTraceback:\n" }, KernelSpecName = RKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("prin()", new[] { "\u001B[1;31mNameError\u001B[0m: name 'prin' is not defined", "Traceback (most recent call last)" }, KernelSpecName = PythonKernelName)] + [JupyterZMQTestData("prin()", new[] { "Error in prin(): could not find function \"prin\"\nTraceback:\n" }, KernelSpecName = RKernelName)] + [JupyterTestData("prin()", new[] { "\u001B[1;31mNameError\u001B[0m: name 'prin' is not defined", "Traceback (most recent call last)" }, KernelSpecName = PythonKernelName)] + [JupyterTestData("prin()", new[] { "Error in prin(): could not find function \"prin\"\nTraceback:\n" }, KernelSpecName = RKernelName)] + public async Task can_submit_code_and_get_error_produced(JupyterConnectionTestData connectionData, string codeToRun, string[] errorMessages) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = CreateCompositeKernelAsync(options); + + await kernel.SubmitCodeAsync( + $"#!connect jupyter --kernel-name testKernel --kernel-spec {connectionData.KernelSpecName} {connectionData.GetConnectionString()}"); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + var recievedMessages = options.MessageTracker.ReceivedMessages.ToSubscribedList(); + + var result = await kernel.SubmitCodeAsync($"#!testKernel\n{codeToRun}"); + var events = result.Events; + + events + .Should() + .Contain(e => e is CommandFailed); + + var request = sentMessages + .Should() + .ContainSingle(m => m.Header.MessageType == JupyterMessageContentTypes.ExecuteRequest) + .Which + .Content + .As(); + + request + .Code + .Should() + .Be(codeToRun); + + request + .StopOnError + .Should().BeTrue(); + + // should be returning ErrorProduced but there is a bug on the front end + // using stderr to display errors to the user + events.Should() + .ContainSingle() + .Which + .FormattedValues + .Should() + .ContainSingle(v => v.MimeType == PlainTextFormatter.MimeType) + .Which + .Value + .Should() + .ContainAll(errorMessages); + + options.SaveState(); + } + + [Theory] + [JupyterHttpTestData("dh = display(\"test\", display_id=True)\ndh.update(\"update-test\")", "'test'", "'update-test'", KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("dh = display(\"test\", display_id=True)\ndh.update(\"update-test\")", "'test'", "'update-test'", KernelSpecName = PythonKernelName)] + [JupyterTestData("dh = display(\"test\", display_id=True)\ndh.update(\"update-test\")", "'test'", "'update-test'", KernelSpecName = PythonKernelName)] + public async Task can_submit_code_and_get_update_display_produced(JupyterConnectionTestData connectionData, string codeToRun, string displayValue, string updateDisplayValue) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = CreateCompositeKernelAsync(options); + + await kernel.SubmitCodeAsync( + $"#!connect jupyter --kernel-name testKernel --kernel-spec {connectionData.KernelSpecName} {connectionData.GetConnectionString()}"); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + var recievedMessages = options.MessageTracker.ReceivedMessages.ToSubscribedList(); + + var result = await kernel.SubmitCodeAsync($"#!testKernel\n{codeToRun}"); + var events = result.Events; + + + sentMessages + .Should() + .ContainSingle(m => m.Header.MessageType == JupyterMessageContentTypes.ExecuteRequest) + .Which + .Content + .As() + .Code + .Should() + .Be(codeToRun); + + var display = events + .Should() + .ContainSingle(); + + display + .Which + .FormattedValues + .Should() + .ContainSingle(v => v.MimeType == PlainTextFormatter.MimeType) + .Which + .Value + .Should() + .Be(displayValue); + + var updateDisplay = events + .Should() + .ContainSingle(); + + updateDisplay + .Which + .FormattedValues + .Should() + .ContainSingle(v => v.MimeType == PlainTextFormatter.MimeType) + .Which + .Value + .Should() + .Be(updateDisplayValue); + + Assert.NotNull(display.Which.ValueId); + + updateDisplay + .Which + .ValueId + .Should() + .Be(display.Which.ValueId); + + options.SaveState(); + } + + [Theory] + [JupyterHttpTestData("print (\"test\")", 3, new[] { "text/plain" }, new[] { "Docstring:\nprint(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n\nPrints the values to a stream, or to sys.stdout by default.\n" }, KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("print (\"test\")", 3, new[] { "text/plain" }, new[] { "Docstring:\nprint(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n\nPrints the values to a stream, or to sys.stdout by default.\n" }, KernelSpecName = PythonKernelName)] + [JupyterTestData("print (\"test\")", 3, new[] { "text/plain" }, new[] { "Docstring:\nprint(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n\nPrints the values to a stream, or to sys.stdout by default.\n" }, KernelSpecName = PythonKernelName)] + [JupyterHttpTestData("print (\"test\")", 3, new[] { "text/html", "text/latex", "text/plain" }, new[] { "", "\\inputencoding{utf8}\n\\HeaderA{print}{Print Values}{print}\n", "print' prints its argument and returns it _invisibly_" }, KernelSpecName = RKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("print (\"test\")", 3, new[] { "text/html", "text/latex", "text/plain" }, new[] { "
print {base}R Documentation
", "\\inputencoding{utf8}\n\\HeaderA{print}{Print Values}{print}\n", "print' prints its argument and returns it _invisibly_" }, KernelSpecName = RKernelName)] + [JupyterTestData("print (\"test\")", 3, new[] { "text/html", "text/latex", "text/plain" }, new[] { "
print {base}R Documentation
", "\\inputencoding{utf8}\n\\HeaderA{print}{Print Values}{print}\n", "print' prints its argument and returns it _invisibly_" }, KernelSpecName = RKernelName)] + public async Task can_request_hover_text_and_get_value_produced(JupyterConnectionTestData connectionData, string codeToInspect, int curPosition, string[] mimeTypes, string[] textValueSnippets) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = await CreateJupyterKernelAsync(options, connectionData.KernelSpecName, connectionData.GetConnectionString()); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + + var linePosition = SourceUtilities.GetPositionFromCursorOffset(codeToInspect, curPosition); + var command = new RequestHoverText(codeToInspect, linePosition); + var result = await kernel.SendAsync(command); + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + var request = sentMessages + .Should() + .ContainSingle(m => m.Header.MessageType == JupyterMessageContentTypes.InspectRequest) + .Which + .Content + .As(); + + request + .Code + .Should() + .Be(codeToInspect); + + request + .CursorPos + .Should() + .Be(curPosition); + + var hoverTextProduced = events.Should() + .ContainSingle(); + + hoverTextProduced + .Which + .LinePositionSpan + .Should() + .BeEquivalentToRespectingRuntimeTypes(new LinePositionSpan(linePosition, linePosition)); + + for (int i = 0; i < mimeTypes.Length; i++) + { + hoverTextProduced + .Which + .Content + .Should() + .ContainSingle(v => v.MimeType == mimeTypes[i]) + .Which + .Value + .Should() + .Contain(textValueSnippets[i]); + } + + options.SaveState(); + } + + [Theory] + [JupyterHttpTestData("print (\"test\")", 3, new[] { "text/plain" }, new[] { "Docstring:\nprint(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n\nPrints the values to a stream, or to sys.stdout by default.\n" }, KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("print (\"test\")", 3, new[] { "text/plain" }, new[] { "Docstring:\nprint(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n\nPrints the values to a stream, or to sys.stdout by default.\n" }, KernelSpecName = PythonKernelName)] + [JupyterTestData("print (\"test\")", 3, new[] { "text/plain" }, new[] { "Docstring:\nprint(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n\nPrints the values to a stream, or to sys.stdout by default.\n" }, KernelSpecName = PythonKernelName)] + [JupyterHttpTestData("print (\"test\")", 3, new[] { "text/html", "text/latex", "text/plain" }, new[] { "
print {base}R Documentation
", "\\inputencoding{utf8}\n\\HeaderA{print}{Print Values}{print}\n", "print' prints its argument and returns it _invisibly_" }, KernelSpecName = RKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("print (\"test\")", 3, new[] { "text/html", "text/latex", "text/plain" }, new[] { "
print {base}R Documentation
", "\\inputencoding{utf8}\n\\HeaderA{print}{Print Values}{print}\n", "print' prints its argument and returns it _invisibly_" }, KernelSpecName = RKernelName)] + [JupyterTestData("print (\"test\")", 3, new[] { "text/html", "text/latex", "text/plain" }, new[] { "
print {base}R Documentation
", "\\inputencoding{utf8}\n\\HeaderA{print}{Print Values}{print}\n", "print' prints its argument and returns it _invisibly_" }, KernelSpecName = RKernelName)] + public async Task can_request_signature_help_and_get_value_produced(JupyterConnectionTestData connectionData, string codeToInspect, int curPosition, string[] mimeTypes, string[] textValueSnippets) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = await CreateJupyterKernelAsync(options, connectionData.KernelSpecName, connectionData.GetConnectionString()); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + + var linePosition = SourceUtilities.GetPositionFromCursorOffset(codeToInspect, curPosition); + var command = new RequestSignatureHelp(codeToInspect, linePosition); + var result = await kernel.SendAsync(command); + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + var request = sentMessages + .Should() + .ContainSingle(m => m.Header.MessageType == JupyterMessageContentTypes.InspectRequest) + .Which + .Content + .As(); + + request + .Code + .Should() + .Be(codeToInspect); + + request + .CursorPos + .Should() + .Be(curPosition); + + var signaturesProduced = events + .Should() + .ContainSingle() + .Which + .Signatures + .Select(s => s.Documentation); + + signaturesProduced.Should().HaveCount(mimeTypes.Length); + + for (int i = 0; i < mimeTypes.Length; i++) + { + signaturesProduced + .Should() + .ContainSingle(v => v.MimeType == mimeTypes[i]) + .Which + .Value + .Should() + .Contain(textValueSnippets[i]); + } + + options.SaveState(); + } + + [Theory] + [JupyterHttpTestData("pr", 0, 0, 2, new[] { "print", "property" }, KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("pr", 0, 0, 2, new[] { "print", "property" }, KernelSpecName = PythonKernelName)] + [JupyterTestData("pr", 0, 0, 2, new[] { "print", "property" }, KernelSpecName = PythonKernelName)] + [JupyterHttpTestData("pr", 0, 0, 2, new[] { "print", "predict" }, KernelSpecName = RKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("pr", 0, 0, 2, new[] { "print", "predict" }, KernelSpecName = RKernelName)] + [JupyterTestData("pr", 0, 0, 2, new[] { "print", "predict" }, KernelSpecName = RKernelName)] + public async Task can_request_completions_and_get_value_produced(JupyterConnectionTestData connectionData, string codeToInspect, int linePos, int startPos, int curPosition, string[] exampleMatches) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = await CreateJupyterKernelAsync(options, connectionData.KernelSpecName, connectionData.GetConnectionString()); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + var receivedMessages = options.MessageTracker.ReceivedMessages.ToSubscribedList(); + + var linePosition = SourceUtilities.GetPositionFromCursorOffset(codeToInspect, curPosition); + var command = new RequestCompletions(codeToInspect, linePosition); + var result = await kernel.SendAsync(command); + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + var request = sentMessages + .Should() + .ContainSingle(m => m.Header.MessageType == JupyterMessageContentTypes.CompleteRequest) + .Which + .Content + .As(); + + request + .Code + .Should() + .Be(codeToInspect); + + request + .CursorPosition + .Should() + .Be(curPosition); + + var completionsProduced = events + .Should() + .ContainSingle(); + + completionsProduced + .Which + .LinePositionSpan + .Should() + .BeEquivalentToRespectingRuntimeTypes( + new LinePositionSpan( + new LinePosition(linePos, startPos), + new LinePosition(linePos, curPosition))); + + completionsProduced + .Which + .Completions + .Select(c => c.DisplayText) + .Should() + .Contain(exampleMatches); + + var completionsFromKernel = receivedMessages + .Where(m => m.Header.MessageType == JupyterMessageContentTypes.CompleteReply) + .FirstOrDefault() + .Content + .As(); + + completionsProduced + .Which + .Completions + .Select(c => c.DisplayText) + .Should() + .Contain(completionsFromKernel.Matches); + + completionsProduced + .Which + .Completions + .Select(c => c.InsertText) + .Should() + .Contain(completionsFromKernel.Matches); + + options.SaveState(); + } +} diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelTestBase.cs b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelTestBase.cs new file mode 100644 index 0000000000..c5067e0646 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelTestBase.cs @@ -0,0 +1,90 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using FluentAssertions; +using Microsoft.DotNet.Interactive.CSharp; +using Microsoft.DotNet.Interactive.Formatting; +using Microsoft.DotNet.Interactive.Formatting.Csv; +using Microsoft.DotNet.Interactive.Formatting.TabularData; +using Microsoft.DotNet.Interactive.Jupyter.Connection; +using Microsoft.DotNet.Interactive.Jupyter.Protocol; +using Microsoft.DotNet.Interactive.Tests.Utility; +using System; +using System.Collections.Generic; +using System.Reactive.Disposables; +using System.Threading.Tasks; +using Formatter = Microsoft.DotNet.Interactive.Formatting.Formatter; +using Message = Microsoft.DotNet.Interactive.Jupyter.Messaging.Message; + +namespace Microsoft.DotNet.Interactive.Jupyter.Tests; + +public abstract class JupyterKernelTestBase : IDisposable +{ + protected CompositeDisposable _disposables = new(); + + // to re-record the tests for simulated playback with JuptyerTestData, set this to true + protected const bool RECORD_FOR_PLAYBACK = false; + protected const string PythonKernelName = "python3"; + protected const string RKernelName = "ir"; + + public virtual void Dispose() + { + _disposables.Dispose(); + } + + protected CompositeKernel CreateCompositeKernelAsync(IJupyterKernelConnectionOptions options) + { + Formatter.SetPreferredMimeTypesFor(typeof(TabularDataResource), HtmlFormatter.MimeType, CsvFormatter.MimeType); + + var csharpKernel = new CSharpKernel() + .UseKernelHelpers() + .UseValueSharing(); + + var kernel = new CompositeKernel { csharpKernel }; + kernel.DefaultKernelName = csharpKernel.Name; + + var jupyterKernelCommand = new ConnectJupyterKernelCommand(); + kernel.AddKernelConnector(jupyterKernelCommand.AddConnectionOptions(options)); + + _disposables.Add(kernel); + return kernel; + } + + protected static List GenerateReplies(IReadOnlyCollection messages = null, string languageName = "name") + { + var replies = new List() + { + // always sent as a first request + Message.CreateReply( + new KernelInfoReply("protocolVersion", "implementation", null, + new LanguageInfo(languageName, "version", "mimeType", "fileExt")), + Message.Create(new KernelInfoRequest())) + }; + + if (messages is not null) + { + // replies from the kernel start and end with status messages + foreach (var m in messages) + { + replies.Add(Message.Create(new Status(StatusValues.Busy), m.ParentHeader)); + replies.Add(m); + replies.Add(Message.Create(new Status(StatusValues.Idle), m.ParentHeader)); + } + } + + return replies; + } + + protected async Task CreateJupyterKernelAsync(TestJupyterConnectionOptions options, string kernelSpecName = null, string connectionString = null) + { + var kernel = CreateCompositeKernelAsync(options); + + var result = await kernel.SubmitCodeAsync($"#!connect jupyter --kernel-name testKernel --kernel-spec {kernelSpecName ?? "testKernelSpec"} {connectionString}"); + + result.Events + .Should() + .NotContainErrors(); + + return kernel.FindKernelByName("testKernel"); + } +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelTests.cs b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelTests.cs new file mode 100644 index 0000000000..976ec55f9c --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelTests.cs @@ -0,0 +1,601 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using FluentAssertions; +using Microsoft.DotNet.Interactive.Commands; +using Microsoft.DotNet.Interactive.Events; +using Microsoft.DotNet.Interactive.Formatting; +using Microsoft.DotNet.Interactive.Jupyter.Protocol; +using Microsoft.DotNet.Interactive.Tests.Utility; +using Microsoft.DotNet.Interactive.Utility; +using System.Collections.Generic; +using System.Linq; +using System.Reactive.Linq; +using System.Reactive.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; +using Xunit; +using Message = Microsoft.DotNet.Interactive.Jupyter.Messaging.Message; + +namespace Microsoft.DotNet.Interactive.Jupyter.Tests; + +public class JupyterKernelTests : JupyterKernelTestBase +{ + [Fact] + public async Task variable_sharing_not_enabled_for_unsupported_languages() + { + var options = new TestJupyterConnectionOptions(GenerateReplies(null, "unsupportedLanguage")); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + var kernel = await CreateJupyterKernelAsync(options); + + sentMessages + .Select(m => m.Header.MessageType) + .Should() + .NotContain(JupyterMessageContentTypes.ExecuteRequest); + + kernel.KernelInfo.SupportedKernelCommands + .Should().NotContain(new KernelCommandInfo(nameof(RequestValue))); + + kernel.KernelInfo.SupportedKernelCommands + .Should().NotContain(new KernelCommandInfo(nameof(RequestValueInfos))); + + kernel.KernelInfo.SupportedKernelCommands + .Should().NotContain(new KernelCommandInfo(nameof(SendValue))); + + var directives = kernel.KernelInfo.SupportedDirectives.Select(info => info.Name); + directives.Should().NotContain("#!who"); + directives.Should().NotContain("#!whos"); + } + + [Fact] + public async Task variable_sharing_not_enabled_for_when_target_not_found() + { + var options = new TestJupyterConnectionOptions(GenerateReplies(new[] { + Message.CreateReply(new ExecuteReplyOk(), Message.Create(new ExecuteRequest("target_setup"))), + Message.Create(new CommClose("commId"), Message.Create(new CommOpen("commId", "target_setup", null)).Header) + }, "python")); + + var kernel = await CreateJupyterKernelAsync(options); + + kernel.KernelInfo.SupportedKernelCommands + .Should().NotContain(new KernelCommandInfo(nameof(RequestValue))); + + kernel.KernelInfo.SupportedKernelCommands + .Should().NotContain(new KernelCommandInfo(nameof(RequestValueInfos))); + + kernel.KernelInfo.SupportedKernelCommands + .Should().NotContain(new KernelCommandInfo(nameof(SendValue))); + + var directives = kernel.KernelInfo.SupportedDirectives.Select(info => info.Name); + directives.Should().NotContain("#!who"); + directives.Should().NotContain("#!whos"); + } + + [Fact] + public async Task can_setup_kernel_using_script() + { + string initScript = "kernel_setup_script"; + var options = new TestJupyterConnectionOptions(GenerateReplies(new[] { + Message.CreateReply(new ExecuteReplyOk(), Message.Create(new ExecuteRequest(initScript))), + })); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + var kernel = await CreateJupyterKernelAsync(options, null, $"--init-script {initScript}"); + + sentMessages + .Should() + .ContainSingle(m => m.Header.MessageType == JupyterMessageContentTypes.ExecuteRequest) + .Which + .Content + .As() + .Code + .Should() + .Be(initScript); + } + + [Fact] + public void can_get_a_list_of_kernelspecs_from_completions() + { + var specs = new List + { + new KernelSpec() { Name = "testKernelSpec", DisplayName = "Test Kernel Spec", Language = "testLanguage" }, + new KernelSpec() { Name = "sampleSpec", DisplayName = "Sample Spec", Language = "sampleLanguage" } + }; + + var options = new TestJupyterConnectionOptions(new TestJupyterConnection(new TestJupyterKernelConnection(null), specs)); + var jupyterKernelCommand = new ConnectJupyterKernelCommand(); + jupyterKernelCommand.AddConnectionOptions(options); + + var kernelSpecCompletions = jupyterKernelCommand.KernelSpecName.GetCompletions(); + kernelSpecCompletions + .Should() + .BeEquivalentTo(specs.Select(s => new System.CommandLine.Completions.CompletionItem(s.Name))); + } + + [Fact] + public async Task jupyter_and_kernel_connection_is_disposed_on_dispose() + { + var options = new TestJupyterConnectionOptions(GenerateReplies()); + var kernel = CreateCompositeKernelAsync(options); + + var result = await kernel.SubmitCodeAsync($"#!connect jupyter --kernel-name testKernel --kernel-spec testKernelSpec"); + + result.Events + .Should() + .NotContainErrors(); + + options.Connection.IsDisposed.Should().BeFalse(); + options.Connection.KernelConnection.IsDisposed.Should().BeFalse(); + + kernel.Dispose(); + + options.Connection.IsDisposed.Should().BeTrue(); + options.Connection.KernelConnection.IsDisposed.Should().BeTrue(); + } + + [Fact] + public async Task can_cancel_submit_code_and_interrupt_kernel() + { + var options = new TestJupyterConnectionOptions(GenerateReplies(new[] { + Message.CreateReply(new InterruptReply(), Message.Create(new InterruptRequest())), + })); + + var kernel = await CreateJupyterKernelAsync(options); + + var waitForCommandReceieved = options.MessageTracker.SentMessages + .TakeUntil(m => m.Header.MessageType == JupyterMessageContentTypes.ExecuteRequest) + .ToTask(); + + var cts = new CancellationTokenSource(); + var request = new SubmitCode("test"); + var codeSubmissionTask = kernel.SendAsync(request, cts.Token); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + await waitForCommandReceieved; + cts.Cancel(); + + // wait until task is done + await codeSubmissionTask.ContinueWith(t => { }, + new CancellationToken(), + TaskContinuationOptions.OnlyOnCanceled, + TaskScheduler.Default); + + codeSubmissionTask + .IsCanceled + .Should() + .BeTrue(); + + sentMessages + .Should() + .ContainSingle(m => m.Header.MessageType == JupyterMessageContentTypes.InterruptRequest); + } + + + [Fact] + public async Task submit_code_line_endings_are_normalized_to_LF() + { + string code = "\r\ntest\r\ncode\r\n\n"; + + var options = new TestJupyterConnectionOptions(GenerateReplies(new[] { + Message.CreateReply(new ExecuteReplyOk(), Message.Create(new ExecuteRequest(code))) + })); + + var kernel = await CreateJupyterKernelAsync(options); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + var result = await kernel.SubmitCodeAsync(code); + + sentMessages + .Should() + .ContainSingle(m => m.Header.MessageType == JupyterMessageContentTypes.ExecuteRequest) + .Which + .Content + .As() + .Code + .Should() + .Be("\ntest\ncode\n\n"); + } + + [Fact] + public async Task can_fail_on_execute_reply_status_error() + { + string code = "test"; + var request = Message.Create(new ExecuteRequest(code)); + var replies = GenerateReplies(); + replies.AddRange(new[] { + Message.CreatePubSub(new Status(StatusValues.Busy), request, "id"), + Message.CreatePubSub(new Stream(Stream.StandardOutput, "line1"), request), + Message.CreatePubSub(new DisplayData("source", new Dictionary { { "text/plain", "line2"} }), request), + Message.CreateReply(new ExecuteReply(StatusValues.Error), request), + Message.CreatePubSub(new Stream(Stream.StandardError, "line2"), request), + Message.CreatePubSub(new Status(StatusValues.Idle), request, "id"), + }); + var options = new TestJupyterConnectionOptions(replies); + + var kernel = await CreateJupyterKernelAsync(options); + + var result = await kernel.SubmitCodeAsync(code); + var events = result.Events; + + events + .Should() + .Contain(e => e is CommandFailed); + + // command should fail but it should still process messages sent for the request until idle + events.Should() + .ContainSingle(); + events.Should() + .ContainSingle(); + events.Should() + .ContainSingle(); + } + + [Fact] + public async Task can_cancel_hover_text_without_kernel_interrupt() + { + var options = new TestJupyterConnectionOptions(GenerateReplies(new[] { + Message.CreateReply(new InterruptReply(), Message.Create(new InterruptRequest())), + })); + + var kernel = await CreateJupyterKernelAsync(options); + + var waitForCommandReceieved = options.MessageTracker.SentMessages + .TakeUntil(m => m.Header.MessageType == JupyterMessageContentTypes.InspectRequest) + .ToTask(); + + var cts = new CancellationTokenSource(); + var request = new RequestHoverText("test", new LinePosition(0, 1)); + var requestHoverTextTask = kernel.SendAsync(request, cts.Token); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + await waitForCommandReceieved; + cts.Cancel(); + + // wait until task is done + await requestHoverTextTask.ContinueWith(t => { }, + new CancellationToken(), + TaskContinuationOptions.OnlyOnCanceled, + TaskScheduler.Default); + + sentMessages + .Select(m => m.Header.MessageType) + .Should() + .NotContain(JupyterMessageContentTypes.InterruptRequest); + + requestHoverTextTask + .IsCanceled + .Should() + .BeTrue(); + } + + [Fact] + public async Task can_handle_hover_text_not_found() + { + var code = "test"; + var options = new TestJupyterConnectionOptions(GenerateReplies(new[] { + Message.CreateReply(new InspectReply(StatusValues.Ok, false), Message.Create(new InspectRequest(code, 1, 0))), + })); + + var kernel = await CreateJupyterKernelAsync(options); + + var command = new RequestHoverText(code, SourceUtilities.GetPositionFromCursorOffset(code, 1)); + var result = await kernel.SendAsync(command); + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + events + .OfType() + .Should() + .BeEmpty(); + } + + [Fact] + public async Task can_fail_on_hover_text_status_error() + { + var code = "test"; + var options = new TestJupyterConnectionOptions(GenerateReplies(new[] { + Message.CreateReply(new InspectReply(StatusValues.Error, + true, + new Dictionary{ { "text/plain", "doc-comment"} } ), + Message.Create(new InspectRequest(code, 1, 0))), + })); + + var kernel = await CreateJupyterKernelAsync(options); + + var command = new RequestHoverText(code, SourceUtilities.GetPositionFromCursorOffset(code, 1)); + var result = await kernel.SendAsync(command); + var events = result.Events; + + events + .Should() + .Contain(e => e is CommandFailed); + + events + .OfType() + .Should() + .BeEmpty(); + } + + [Fact] + public async Task hover_text_unrecognized_text_formatting_is_removed() + { + var ansiEscapedText = + "\u001b[30mBlack,\u001b[31mRed,\u001b[32mGreen,\u001b[33mYellow,\u001b[34mBlue,\u001b[35mMagenta,\u001b[36mCyan,\u001b[37mWhite,\u001b[0mReset," + + "\u001b[30;1mBright Black,\u001b[31;1mBright Red,\u001b[32;1mBright Green,\u001b[33;1mBright Yellow,\u001b[34;1mBright Blue,\u001b[35;1mBright Magenta,\u001b[36;1mBright Cyan,\u001b[37;1mBright White," + + "\u001b[1mBold,\u001b[4mUnderline,\u001b[7mReversed," + + "\u001b[1mm\u001b[3009567mi\u001b[30m\u001B[1mc"; + var code = "test"; + var options = new TestJupyterConnectionOptions(GenerateReplies(new[] { + Message.CreateReply(new InspectReply(StatusValues.Ok, + true, + new Dictionary{ + { "text/plain", ansiEscapedText} } ), + Message.Create(new InspectRequest(code, 1, 0))), + })); + + var kernel = await CreateJupyterKernelAsync(options); + + var command = new RequestHoverText(code, SourceUtilities.GetPositionFromCursorOffset(code, 1)); + var result = await kernel.SendAsync(command); + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + events + .Should() + .ContainSingle() + .Which + .Content + .Should() + .ContainSingle(v => v.MimeType == PlainTextFormatter.MimeType) + .Which + .Value + .Should() + .Be("Black,Red,Green,Yellow,Blue,Magenta,Cyan,White,Reset," + + "Bright Black,Bright Red,Bright Green,Bright Yellow,Bright Blue,Bright Magenta,Bright Cyan,Bright White," + + "Bold,Underline,Reversed," + + "mic"); + } + + [Fact] + public async Task can_cancel_signature_help_without_kernel_interrupt() + { + var options = new TestJupyterConnectionOptions(GenerateReplies(new[] { + Message.CreateReply(new InterruptReply(), Message.Create(new InterruptRequest())), + })); + + var kernel = await CreateJupyterKernelAsync(options); + + var waitForCommandReceieved = options.MessageTracker.SentMessages + .TakeUntil(m => m.Header.MessageType == JupyterMessageContentTypes.InspectRequest) + .ToTask(); + + var cts = new CancellationTokenSource(); + var request = new RequestSignatureHelp("test", new LinePosition(0, 1)); + var requestSigHelpTask = kernel.SendAsync(request, cts.Token); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + await waitForCommandReceieved; + cts.Cancel(); + + // wait until task is done + await requestSigHelpTask.ContinueWith(t => { }, + new CancellationToken(), + TaskContinuationOptions.OnlyOnCanceled, + TaskScheduler.Default); + + sentMessages + .Select(m => m.Header.MessageType) + .Should() + .NotContain(JupyterMessageContentTypes.InterruptRequest); + + requestSigHelpTask + .IsCanceled + .Should() + .BeTrue(); + } + + [Fact] + public async Task can_handle_signature_help_not_found() + { + var code = "test"; + var options = new TestJupyterConnectionOptions(GenerateReplies(new[] { + Message.CreateReply(new InspectReply(StatusValues.Ok, false), Message.Create(new InspectRequest(code, 1, 0))), + })); + + var kernel = await CreateJupyterKernelAsync(options); + + var command = new RequestSignatureHelp(code, SourceUtilities.GetPositionFromCursorOffset(code, 1)); + var result = await kernel.SendAsync(command); + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + events + .OfType() + .Should() + .BeEmpty(); + } + + [Fact] + public async Task can_fail_on_signature_help_status_error() + { + var code = "test"; + var options = new TestJupyterConnectionOptions(GenerateReplies(new[] { + Message.CreateReply(new InspectReply(StatusValues.Error, + true, + new Dictionary{ { "text/plain", "doc-comment"} } ), + Message.Create(new InspectRequest(code, 1, 0))), + })); + + var kernel = await CreateJupyterKernelAsync(options); + + var command = new RequestSignatureHelp(code, SourceUtilities.GetPositionFromCursorOffset(code, 1)); + var result = await kernel.SendAsync(command); + var events = result.Events; + + events + .Should() + .Contain(e => e is CommandFailed); + + events + .OfType() + .Should() + .BeEmpty(); + } + + [Fact] + public async Task signature_help_unrecognized_text_formatting_is_removed() + { + var ansiEscapedText = + "\u001b[30mBlack,\u001b[31mRed,\u001b[32mGreen,\u001b[33mYellow,\u001b[34mBlue,\u001b[35mMagenta,\u001b[36mCyan,\u001b[37mWhite,\u001b[0mReset," + + "\u001b[30;1mBright Black,\u001b[31;1mBright Red,\u001b[32;1mBright Green,\u001b[33;1mBright Yellow,\u001b[34;1mBright Blue,\u001b[35;1mBright Magenta,\u001b[36;1mBright Cyan,\u001b[37;1mBright White," + + "\u001b[1mBold,\u001b[4mUnderline,\u001b[7mReversed," + + "\u001b[1mm\u001b[3009567mi\u001b[30m\u001B[1mc"; + var code = "test"; + var options = new TestJupyterConnectionOptions(GenerateReplies(new[] { + Message.CreateReply(new InspectReply(StatusValues.Ok, + true, + new Dictionary{ + { "text/plain", ansiEscapedText} } ), + Message.Create(new InspectRequest(code, 1, 0))), + })); + + var kernel = await CreateJupyterKernelAsync(options); + + var command = new RequestSignatureHelp(code, SourceUtilities.GetPositionFromCursorOffset(code, 1)); + var result = await kernel.SendAsync(command); + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + events + .Should() + .ContainSingle() + .Which + .Signatures + .Select(s => s.Documentation) + .Should() + .ContainSingle(v => v.MimeType == PlainTextFormatter.MimeType) + .Which + .Value + .Should() + .Be("Black,Red,Green,Yellow,Blue,Magenta,Cyan,White,Reset," + + "Bright Black,Bright Red,Bright Green,Bright Yellow,Bright Blue,Bright Magenta,Bright Cyan,Bright White," + + "Bold,Underline,Reversed," + + "mic"); + } + + [Fact] + public async Task can_cancel_completions_without_kernel_interrupt() + { + var options = new TestJupyterConnectionOptions(GenerateReplies(new[] { + Message.CreateReply(new InterruptReply(), Message.Create(new InterruptRequest())), + })); + + var kernel = await CreateJupyterKernelAsync(options); + + var waitForCommandReceieved = options.MessageTracker.SentMessages + .TakeUntil(m => m.Header.MessageType == JupyterMessageContentTypes.CompleteRequest) + .ToTask(); + + var cts = new CancellationTokenSource(); + var request = new RequestCompletions("test", new LinePosition(0, 1)); + var requestCompletionsTask = kernel.SendAsync(request, cts.Token); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + await waitForCommandReceieved; + cts.Cancel(); + + await requestCompletionsTask.ContinueWith(t => { }, + new CancellationToken(), + TaskContinuationOptions.OnlyOnCanceled, + TaskScheduler.Default); + + sentMessages + .Select(m => m.Header.MessageType) + .Should() + .NotContain(JupyterMessageContentTypes.InterruptRequest); + + requestCompletionsTask + .IsCanceled + .Should() + .BeTrue(); + } + + [Fact] + public async Task can_fail_on_completions_status_error() + { + var code = "test"; + var options = new TestJupyterConnectionOptions(GenerateReplies(new[] { + Message.CreateReply(new CompleteReply(0, 1, new[] {"test1", "test2"}, null, StatusValues.Error), + Message.Create(new CompleteRequest(code, 1))), + })); + + var kernel = await CreateJupyterKernelAsync(options); + + var command = new RequestCompletions(code, SourceUtilities.GetPositionFromCursorOffset(code, 1)); + var result = await kernel.SendAsync(command); + var events = result.Events; + + events + .Should() + .Contain(e => e is CommandFailed); + + events + .OfType() + .Should() + .BeEmpty(); + } + + [Fact] + public async Task can_translate_completion_item_metadata_for_completions_produce() + { + var code = "test"; + var metadata = new Dictionary> + { + { + CompletionResultMetadata.Experimental, new[] + { + new CompletionResultMetadata(0, 1, "test1-test", "function", "TEST1TEST"), + new CompletionResultMetadata(0, 1, "test2-test", "class", null) + } + } + }; + var options = new TestJupyterConnectionOptions(GenerateReplies(new[] { + Message.CreateReply(new CompleteReply(0, 1, new[] {"test1", "test2"}, metadata, StatusValues.Ok), + Message.Create(new CompleteRequest(code, 1))), + })); + + var kernel = await CreateJupyterKernelAsync(options); + + var command = new RequestCompletions(code, SourceUtilities.GetPositionFromCursorOffset(code, 1)); + var result = await kernel.SendAsync(command); + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + events + .Should() + .ContainSingle() + .Which + .Completions + .Should() + .BeEquivalentToRespectingRuntimeTypes(new[] { + new CompletionItem("TEST1TEST", "Method", "test1-test", "test1-test", "test1-test"), + new CompletionItem("test2-test", "Class", "test2-test", "test2-test", "test2-test") + }); + } +} diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelTestsHelper.cs b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelTestsHelper.cs new file mode 100644 index 0000000000..63d6961192 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelTestsHelper.cs @@ -0,0 +1,167 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Runtime.CompilerServices; +using Xunit.Sdk; + +namespace Microsoft.DotNet.Interactive.Jupyter.Tests; + +public class JupyterConnectionTestData +{ + private readonly string _type; + private readonly string _connectionString; + private TestJupyterConnectionOptions _connectionOptions; + + public JupyterConnectionTestData(string type, TestJupyterConnectionOptions connectionOptions = null, string connectionString = "") + { + _type = type; + _connectionString = connectionString; + _connectionOptions = connectionOptions; + } + + public string ConnectionType => _type; + public string GetConnectionString() => _connectionString; + public TestJupyterConnectionOptions GetConnectionOptions([CallerFilePath] string filePath = "", [CallerMemberName] string fileName = "") + { + if (_connectionOptions is null) + { + _connectionOptions = new TestJupyterConnectionOptions(KernelSpecName, filePath, fileName); + } + return _connectionOptions; + } + public string KernelSpecName { get; set; } +} + +[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] +internal class JupyterTestDataAttribute : DataAttribute +{ + private readonly object[] _data; + public const string JUPYTER_TEST = nameof(JUPYTER_TEST); + + public JupyterTestDataAttribute(params object[] data) + { + _data = data; + } + + public override IEnumerable GetData(MethodInfo testMethod) + { + List testData = new(); + var connData = GetConnectionTestData(); + connData.KernelSpecName = KernelSpecName; + testData.Add(connData); + testData.AddRange(_data); + return new[] { testData.ToArray() }; + } + protected virtual JupyterConnectionTestData GetConnectionTestData() + { + return new JupyterConnectionTestData(JUPYTER_TEST); + } + + public string KernelSpecName { get; set; } +} + +internal sealed class JupyterZMQTestDataAttribute : JupyterTestDataAttribute +{ + public const string TEST_DOTNET_JUPYTER_ZMQ_CONN = nameof(TEST_DOTNET_JUPYTER_ZMQ_CONN); + public const string JUPYTER_ZMQ = nameof(JUPYTER_ZMQ); + private static readonly string _skipReason; + + static JupyterZMQTestDataAttribute() + { + _skipReason = TestConnectionAndReturnSkipReason(); + } + + public JupyterZMQTestDataAttribute(params object[] data) : base(data) + { + if (_skipReason is not null) + { + Skip = _skipReason; + } + } + + internal static string TestConnectionAndReturnSkipReason() + { + string connectionString = GetConnectionString(); + if (string.IsNullOrWhiteSpace(connectionString)) + { + return $"Environment variable {TEST_DOTNET_JUPYTER_ZMQ_CONN} is not set. To run tests that require " + + "Jupyter server running, this environment variable must be set"; + } + + return null; + } + + public static string GetConnectionString() + { + return Environment.GetEnvironmentVariable(TEST_DOTNET_JUPYTER_ZMQ_CONN); + } + + protected override JupyterConnectionTestData GetConnectionTestData() + { + return new JupyterConnectionTestData(JUPYTER_ZMQ, + new TestJupyterConnectionOptions(new JupyterLocalKernelConnectionOptions(), KernelSpecName, AllowPlayback) + ); + } + + /// + /// Allows playing back the record of the connection by enabling save to a file + /// and reading back from it at the point of save. + /// + public bool AllowPlayback { get; set; } +} + +internal sealed class JupyterHttpTestDataAttribute : JupyterTestDataAttribute +{ + public const string TEST_DOTNET_JUPYTER_HTTP_CONN = nameof(TEST_DOTNET_JUPYTER_HTTP_CONN); + public const string JUPYTER_HTTP = nameof(JUPYTER_HTTP); + private static readonly string _skipReason; + + static JupyterHttpTestDataAttribute() + { + _skipReason = TestConnectionAndReturnSkipReason(); + } + + public JupyterHttpTestDataAttribute(params object[] data) : base(data) + { + if (_skipReason is not null) + { + Skip = _skipReason; + } + } + + internal static string TestConnectionAndReturnSkipReason() + { + string connectionString = GetConnectionString(); + if (string.IsNullOrWhiteSpace(connectionString)) + { + return $"Environment variable {TEST_DOTNET_JUPYTER_HTTP_CONN} is not set. To run tests that require " + + "Jupyter server running, this environment variable must be set to a valid connection string value with --url and --token."; + } + + return null; + } + + public static string GetConnectionString() + { + // e.g. --url --token + return Environment.GetEnvironmentVariable(TEST_DOTNET_JUPYTER_HTTP_CONN); + } + + protected override JupyterConnectionTestData GetConnectionTestData() + { + return new JupyterConnectionTestData(JUPYTER_HTTP, + new TestJupyterConnectionOptions(new JupyterHttpKernelConnectionOptions(), KernelSpecName, AllowPlayback), + GetConnectionString() + ); + } + + /// + /// Allows playing back the record of the connection by enabling save to a file + /// and reading back from it at the point of save. + /// + public bool AllowPlayback { get; set; } +} + diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_errors_for_request_value_from_kernel.ir.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_errors_for_request_value_from_kernel.ir.json new file mode 100644 index 0000000000..d8f781846c --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_errors_for_request_value_from_kernel.ir.json @@ -0,0 +1,315 @@ +[ + { + "header": { + "msg_id": "0ebf7fca-c844-11ed-aa31-316a0338c1a9", + "username": "dotnet_kernel", + "session": "109cddf6-9f71-4671-8d1c-2ec5f3ec5deb", + "date": "2023-03-21T23:56:54.913097Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "58b79c6c-6f66-4844-a606-b11eb0b28cd1", + "username": "dotnet_kernel", + "session": "109cddf6-9f71-4671-8d1c-2ec5f3ec5deb", + "date": "2023-03-21T23:56:54.8434156Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0ebf7fcb-c844-11ed-aa31-316a0338c1a9", + "username": "dotnet_kernel", + "session": "109cddf6-9f71-4671-8d1c-2ec5f3ec5deb", + "date": "2023-03-21T23:56:54.916109Z", + "msg_type": "kernel_info_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "58b79c6c-6f66-4844-a606-b11eb0b28cd1", + "username": "dotnet_kernel", + "session": "109cddf6-9f71-4671-8d1c-2ec5f3ec5deb", + "date": "2023-03-21T23:56:54.8434156Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.0", + "implementation": "IRkernel", + "implementation_version": "0.8.15", + "language_info": { + "name": "R", + "version": "3.6.1", + "mimetype": "text/x-r-source", + "file_extension": ".r", + "pygments_lexer": "r", + "codemirror_mode": "r" + }, + "banner": "R version 3.6.1 (2019-07-05)", + "status": "ok", + "help_links": [] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0ec03082-c844-11ed-aa31-316a0338c1a9", + "username": "dotnet_kernel", + "session": "109cddf6-9f71-4671-8d1c-2ec5f3ec5deb", + "date": "2023-03-21T23:56:54.918108Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "58b79c6c-6f66-4844-a606-b11eb0b28cd1", + "username": "dotnet_kernel", + "session": "109cddf6-9f71-4671-8d1c-2ec5f3ec5deb", + "date": "2023-03-21T23:56:54.8434156Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0ec11ad8-c844-11ed-aa31-316a0338c1a9", + "username": "dotnet_kernel", + "session": "b0368efa-b301-4406-9a9e-5c7e4ea625c7", + "date": "2023-03-21T23:56:54.923107Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "6b074f16-73a9-4178-a4da-4b79f2634cf3", + "username": "dotnet_kernel", + "session": "b0368efa-b301-4406-9a9e-5c7e4ea625c7", + "date": "2023-03-21T23:56:54.9180581Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0ec16902-c844-11ed-aa31-316a0338c1a9", + "username": "dotnet_kernel", + "session": "b0368efa-b301-4406-9a9e-5c7e4ea625c7", + "date": "2023-03-21T23:56:54.926106Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "6b074f16-73a9-4178-a4da-4b79f2634cf3", + "username": "dotnet_kernel", + "session": "b0368efa-b301-4406-9a9e-5c7e4ea625c7", + "date": "2023-03-21T23:56:54.9180581Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0ed08c98-c844-11ed-aa31-316a0338c1a9", + "username": "dotnet_kernel", + "session": "b0368efa-b301-4406-9a9e-5c7e4ea625c7", + "date": "2023-03-21T23:56:55.025328Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "6b074f16-73a9-4178-a4da-4b79f2634cf3", + "username": "dotnet_kernel", + "session": "b0368efa-b301-4406-9a9e-5c7e4ea625c7", + "date": "2023-03-21T23:56:54.9180581Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0ed0dae0-c844-11ed-aa31-316a0338c1a9", + "username": "dotnet_kernel", + "session": "b0368efa-b301-4406-9a9e-5c7e4ea625c7", + "date": "2023-03-21T23:56:55.028327Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "6b074f16-73a9-4178-a4da-4b79f2634cf3", + "username": "dotnet_kernel", + "session": "b0368efa-b301-4406-9a9e-5c7e4ea625c7", + "date": "2023-03-21T23:56:54.9180581Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0ed2ea88-c844-11ed-aa31-316a0338c1a9", + "username": "dotnet_kernel", + "session": "761a5bc2-580c-41e6-804a-86f77f188de5", + "date": "2023-03-21T23:56:55.040840Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1fa02a73-3a6e-4330-a2ac-4fef61d40c23", + "username": "dotnet_kernel", + "session": "761a5bc2-580c-41e6-804a-86f77f188de5", + "date": "2023-03-21T23:56:55.0288581Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0ed386e6-c844-11ed-aa31-316a0338c1a9", + "username": "dotnet_kernel", + "session": "761a5bc2-580c-41e6-804a-86f77f188de5", + "date": "2023-03-21T23:56:55.044840Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1fa02a73-3a6e-4330-a2ac-4fef61d40c23", + "username": "dotnet_kernel", + "session": "761a5bc2-580c-41e6-804a-86f77f188de5", + "date": "2023-03-21T23:56:55.0288581Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "6896d78c-20bd-44fc-8e55-7c6a95ed09ba", + "data": { + "commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0ed3ae00-c844-11ed-aa31-316a0338c1a9", + "username": "dotnet_kernel", + "session": "761a5bc2-580c-41e6-804a-86f77f188de5", + "date": "2023-03-21T23:56:55.045840Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1fa02a73-3a6e-4330-a2ac-4fef61d40c23", + "username": "dotnet_kernel", + "session": "761a5bc2-580c-41e6-804a-86f77f188de5", + "date": "2023-03-21T23:56:55.0288581Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0ed49810-c844-11ed-aa31-316a0338c1a9", + "username": "dotnet_kernel", + "session": "47f40259-a2c4-43db-a1ef-c35a90ff13e2", + "date": "2023-03-21T23:56:55.050833Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e5c06655-9eb3-40b6-8e29-4f2f8e5937e6", + "username": "dotnet_kernel", + "session": "47f40259-a2c4-43db-a1ef-c35a90ff13e2", + "date": "2023-03-21T23:56:55.0482436Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0ed75780-c844-11ed-aa31-316a0338c1a9", + "username": "dotnet_kernel", + "session": "47f40259-a2c4-43db-a1ef-c35a90ff13e2", + "date": "2023-03-21T23:56:55.070352Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e5c06655-9eb3-40b6-8e29-4f2f8e5937e6", + "username": "dotnet_kernel", + "session": "47f40259-a2c4-43db-a1ef-c35a90ff13e2", + "date": "2023-03-21T23:56:55.0482436Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "6896d78c-20bd-44fc-8e55-7c6a95ed09ba", + "data": { + "commandOrEvent": "{\"event\":{\"message\":\"Variable \\\"unknownVar\\\" not found.\"},\"eventType\":\"CommandFailed\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_errors_for_request_value_from_kernel.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_errors_for_request_value_from_kernel.python3.json new file mode 100644 index 0000000000..a41bd6536b --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_errors_for_request_value_from_kernel.python3.json @@ -0,0 +1,377 @@ +[ + { + "header": { + "msg_id": "c35543ba-547e32dbaee2eab15e1cadfd_22572_10", + "username": "username", + "session": "c35543ba-547e32dbaee2eab15e1cadfd", + "date": "2023-03-21T23:56:53.875498Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "47ba9ca1-1165-4ad2-a99a-db97f4566059", + "username": "dotnet_kernel", + "session": "e98b29c6-2336-4887-ba0b-c3679f3055f1", + "date": "2023-03-21T23:56:53.8581709Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "c35543ba-547e32dbaee2eab15e1cadfd_22572_11", + "username": "username", + "session": "c35543ba-547e32dbaee2eab15e1cadfd", + "date": "2023-03-21T23:56:53.875498Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "47ba9ca1-1165-4ad2-a99a-db97f4566059", + "username": "dotnet_kernel", + "session": "e98b29c6-2336-4887-ba0b-c3679f3055f1", + "date": "2023-03-21T23:56:53.8581709Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "c35543ba-547e32dbaee2eab15e1cadfd_22572_12", + "username": "username", + "session": "c35543ba-547e32dbaee2eab15e1cadfd", + "date": "2023-03-21T23:56:53.877497Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "47ba9ca1-1165-4ad2-a99a-db97f4566059", + "username": "dotnet_kernel", + "session": "e98b29c6-2336-4887-ba0b-c3679f3055f1", + "date": "2023-03-21T23:56:53.8581709Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "c35543ba-547e32dbaee2eab15e1cadfd_22572_13", + "username": "username", + "session": "c35543ba-547e32dbaee2eab15e1cadfd", + "date": "2023-03-21T23:56:53.881499Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "40882bb8-fa55-432c-a916-067543043442", + "username": "dotnet_kernel", + "session": "618d17a8-cba7-4dc4-8e0b-de8f78ff1b8e", + "date": "2023-03-21T23:56:53.8796886Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "c35543ba-547e32dbaee2eab15e1cadfd_22572_14", + "username": "username", + "session": "c35543ba-547e32dbaee2eab15e1cadfd", + "date": "2023-03-21T23:56:53.881499Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "40882bb8-fa55-432c-a916-067543043442", + "username": "dotnet_kernel", + "session": "618d17a8-cba7-4dc4-8e0b-de8f78ff1b8e", + "date": "2023-03-21T23:56:53.8796886Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "c35543ba-547e32dbaee2eab15e1cadfd_22572_15", + "username": "username", + "session": "c35543ba-547e32dbaee2eab15e1cadfd", + "date": "2023-03-21T23:56:53.915127Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "40882bb8-fa55-432c-a916-067543043442", + "username": "dotnet_kernel", + "session": "618d17a8-cba7-4dc4-8e0b-de8f78ff1b8e", + "date": "2023-03-21T23:56:53.8796886Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:56:53.881499Z", + "dependencies_met": true, + "engine": "16b4d52d-1d92-4f66-ac4e-0a9aef738d51", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "c35543ba-547e32dbaee2eab15e1cadfd_22572_16", + "username": "username", + "session": "c35543ba-547e32dbaee2eab15e1cadfd", + "date": "2023-03-21T23:56:53.915127Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "40882bb8-fa55-432c-a916-067543043442", + "username": "dotnet_kernel", + "session": "618d17a8-cba7-4dc4-8e0b-de8f78ff1b8e", + "date": "2023-03-21T23:56:53.8796886Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "c35543ba-547e32dbaee2eab15e1cadfd_22572_17", + "username": "username", + "session": "c35543ba-547e32dbaee2eab15e1cadfd", + "date": "2023-03-21T23:56:53.920128Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "652c750d-b8e5-4400-afaa-51809817408a", + "username": "dotnet_kernel", + "session": "b0c11cfe-214b-43d9-8937-bcfee2edfb79", + "date": "2023-03-21T23:56:53.9179237Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "c35543ba-547e32dbaee2eab15e1cadfd_22572_18", + "username": "username", + "session": "c35543ba-547e32dbaee2eab15e1cadfd", + "date": "2023-03-21T23:56:53.920128Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "652c750d-b8e5-4400-afaa-51809817408a", + "username": "dotnet_kernel", + "session": "b0c11cfe-214b-43d9-8937-bcfee2edfb79", + "date": "2023-03-21T23:56:53.9179237Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "166717bc-5fb4-49ed-bc0c-3be0409f2849", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "c35543ba-547e32dbaee2eab15e1cadfd_22572_19", + "username": "username", + "session": "c35543ba-547e32dbaee2eab15e1cadfd", + "date": "2023-03-21T23:56:53.921126Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "652c750d-b8e5-4400-afaa-51809817408a", + "username": "dotnet_kernel", + "session": "b0c11cfe-214b-43d9-8937-bcfee2edfb79", + "date": "2023-03-21T23:56:53.9179237Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "c35543ba-547e32dbaee2eab15e1cadfd_22572_20", + "username": "username", + "session": "c35543ba-547e32dbaee2eab15e1cadfd", + "date": "2023-03-21T23:56:53.927124Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "3bfae014-a4d1-432a-a7fa-c6e67abf1db7", + "username": "dotnet_kernel", + "session": "a5886626-6974-4f2a-861d-909688d10ece", + "date": "2023-03-21T23:56:53.9259491Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "c35543ba-547e32dbaee2eab15e1cadfd_22572_21", + "username": "username", + "session": "c35543ba-547e32dbaee2eab15e1cadfd", + "date": "2023-03-21T23:56:53.927124Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "3bfae014-a4d1-432a-a7fa-c6e67abf1db7", + "username": "dotnet_kernel", + "session": "a5886626-6974-4f2a-861d-909688d10ece", + "date": "2023-03-21T23:56:53.9259491Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "166717bc-5fb4-49ed-bc0c-3be0409f2849", + "data": { + "commandOrEvent": "{\"event\": {\"message\": \"Variable \\\"unknownVar\\\" not found.\"}, \"eventType\": \"CommandFailed\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "c35543ba-547e32dbaee2eab15e1cadfd_22572_22", + "username": "username", + "session": "c35543ba-547e32dbaee2eab15e1cadfd", + "date": "2023-03-21T23:56:53.928125Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "3bfae014-a4d1-432a-a7fa-c6e67abf1db7", + "username": "dotnet_kernel", + "session": "a5886626-6974-4f2a-861d-909688d10ece", + "date": "2023-03-21T23:56:53.9259491Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_errors_for_send_value_from_kernel.ir.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_errors_for_send_value_from_kernel.ir.json new file mode 100644 index 0000000000..52e8ed89f5 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_errors_for_send_value_from_kernel.ir.json @@ -0,0 +1,315 @@ +[ + { + "header": { + "msg_id": "2000a462-c844-11ed-97b1-b11731d51456", + "username": "dotnet_kernel", + "session": "d750f592-415f-41f9-9499-2c57318ba187", + "date": "2023-03-21T23:57:23.861772Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e802030d-82f3-4654-aa84-f784ddb030d2", + "username": "dotnet_kernel", + "session": "d750f592-415f-41f9-9499-2c57318ba187", + "date": "2023-03-21T23:57:23.7910120Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "2000f278-c844-11ed-97b1-b11731d51456", + "username": "dotnet_kernel", + "session": "d750f592-415f-41f9-9499-2c57318ba187", + "date": "2023-03-21T23:57:23.863776Z", + "msg_type": "kernel_info_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e802030d-82f3-4654-aa84-f784ddb030d2", + "username": "dotnet_kernel", + "session": "d750f592-415f-41f9-9499-2c57318ba187", + "date": "2023-03-21T23:57:23.7910120Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.0", + "implementation": "IRkernel", + "implementation_version": "0.8.15", + "language_info": { + "name": "R", + "version": "3.6.1", + "mimetype": "text/x-r-source", + "file_extension": ".r", + "pygments_lexer": "r", + "codemirror_mode": "r" + }, + "banner": "R version 3.6.1 (2019-07-05)", + "status": "ok", + "help_links": [] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "200140c0-c844-11ed-97b1-b11731d51456", + "username": "dotnet_kernel", + "session": "d750f592-415f-41f9-9499-2c57318ba187", + "date": "2023-03-21T23:57:23.864774Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e802030d-82f3-4654-aa84-f784ddb030d2", + "username": "dotnet_kernel", + "session": "d750f592-415f-41f9-9499-2c57318ba187", + "date": "2023-03-21T23:57:23.7910120Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "2001dd46-c844-11ed-97b1-b11731d51456", + "username": "dotnet_kernel", + "session": "2c3f0782-deec-4a1b-9b0c-9a0050d78d35", + "date": "2023-03-21T23:57:23.869785Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "83851705-76fe-4285-80a9-36830dbce5cf", + "username": "dotnet_kernel", + "session": "2c3f0782-deec-4a1b-9b0c-9a0050d78d35", + "date": "2023-03-21T23:57:23.8653139Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "20025262-c844-11ed-97b1-b11731d51456", + "username": "dotnet_kernel", + "session": "2c3f0782-deec-4a1b-9b0c-9a0050d78d35", + "date": "2023-03-21T23:57:23.872783Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "83851705-76fe-4285-80a9-36830dbce5cf", + "username": "dotnet_kernel", + "session": "2c3f0782-deec-4a1b-9b0c-9a0050d78d35", + "date": "2023-03-21T23:57:23.8653139Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "2012a9f0-c844-11ed-97b1-b11731d51456", + "username": "dotnet_kernel", + "session": "2c3f0782-deec-4a1b-9b0c-9a0050d78d35", + "date": "2023-03-21T23:57:23.979881Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "83851705-76fe-4285-80a9-36830dbce5cf", + "username": "dotnet_kernel", + "session": "2c3f0782-deec-4a1b-9b0c-9a0050d78d35", + "date": "2023-03-21T23:57:23.8653139Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "2012d100-c844-11ed-97b1-b11731d51456", + "username": "dotnet_kernel", + "session": "2c3f0782-deec-4a1b-9b0c-9a0050d78d35", + "date": "2023-03-21T23:57:23.980877Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "83851705-76fe-4285-80a9-36830dbce5cf", + "username": "dotnet_kernel", + "session": "2c3f0782-deec-4a1b-9b0c-9a0050d78d35", + "date": "2023-03-21T23:57:23.8653139Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "20136d18-c844-11ed-97b1-b11731d51456", + "username": "dotnet_kernel", + "session": "e5cadbe9-e4a5-4801-a9cd-5d4da0145456", + "date": "2023-03-21T23:57:23.984880Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "a415f7a4-93d8-4553-aea5-0318330ea01d", + "username": "dotnet_kernel", + "session": "e5cadbe9-e4a5-4801-a9cd-5d4da0145456", + "date": "2023-03-21T23:57:23.9814043Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "2014305e-c844-11ed-97b1-b11731d51456", + "username": "dotnet_kernel", + "session": "e5cadbe9-e4a5-4801-a9cd-5d4da0145456", + "date": "2023-03-21T23:57:23.988879Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "a415f7a4-93d8-4553-aea5-0318330ea01d", + "username": "dotnet_kernel", + "session": "e5cadbe9-e4a5-4801-a9cd-5d4da0145456", + "date": "2023-03-21T23:57:23.9814043Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "f2644c4f-f6e3-48a3-aa33-797ac22afcf8", + "data": { + "commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "20145796-c844-11ed-97b1-b11731d51456", + "username": "dotnet_kernel", + "session": "e5cadbe9-e4a5-4801-a9cd-5d4da0145456", + "date": "2023-03-21T23:57:23.989879Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "a415f7a4-93d8-4553-aea5-0318330ea01d", + "username": "dotnet_kernel", + "session": "e5cadbe9-e4a5-4801-a9cd-5d4da0145456", + "date": "2023-03-21T23:57:23.9814043Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "20151b72-c844-11ed-97b1-b11731d51456", + "username": "dotnet_kernel", + "session": "3b78d53a-ddd7-4fb7-a8d5-5275de3227b4", + "date": "2023-03-21T23:57:23.995893Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "158887d0-14bf-4f4e-8809-8c2e126bd3df", + "username": "dotnet_kernel", + "session": "3b78d53a-ddd7-4fb7-a8d5-5275de3227b4", + "date": "2023-03-21T23:57:23.9918735Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "20183c8a-c844-11ed-97b1-b11731d51456", + "username": "dotnet_kernel", + "session": "3b78d53a-ddd7-4fb7-a8d5-5275de3227b4", + "date": "2023-03-21T23:57:24.017402Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "158887d0-14bf-4f4e-8809-8c2e126bd3df", + "username": "dotnet_kernel", + "session": "3b78d53a-ddd7-4fb7-a8d5-5275de3227b4", + "date": "2023-03-21T23:57:23.9918735Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "f2644c4f-f6e3-48a3-aa33-797ac22afcf8", + "data": { + "commandOrEvent": "{\"event\":{\"message\":\"Invalid Identifier: \\\"_ab\\\"\"},\"eventType\":\"CommandFailed\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_errors_for_send_value_from_kernel.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_errors_for_send_value_from_kernel.python3.json new file mode 100644 index 0000000000..e47a0e1294 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_errors_for_send_value_from_kernel.python3.json @@ -0,0 +1,353 @@ +[ + { + "header": { + "msg_id": "acfef954-3dc1fbdf0174fbe77b594b9f_21516_10", + "username": "username", + "session": "acfef954-3dc1fbdf0174fbe77b594b9f", + "date": "2023-03-21T23:57:22.796317Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "cc7c8dae-734a-4369-b423-d670be0c8047", + "username": "dotnet_kernel", + "session": "fdb3e29d-2eed-496a-a275-0aa3dd8a5be7", + "date": "2023-03-21T23:57:22.7781131Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acfef954-3dc1fbdf0174fbe77b594b9f_21516_11", + "username": "username", + "session": "acfef954-3dc1fbdf0174fbe77b594b9f", + "date": "2023-03-21T23:57:22.796317Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "cc7c8dae-734a-4369-b423-d670be0c8047", + "username": "dotnet_kernel", + "session": "fdb3e29d-2eed-496a-a275-0aa3dd8a5be7", + "date": "2023-03-21T23:57:22.7781131Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acfef954-3dc1fbdf0174fbe77b594b9f_21516_12", + "username": "username", + "session": "acfef954-3dc1fbdf0174fbe77b594b9f", + "date": "2023-03-21T23:57:22.797316Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "cc7c8dae-734a-4369-b423-d670be0c8047", + "username": "dotnet_kernel", + "session": "fdb3e29d-2eed-496a-a275-0aa3dd8a5be7", + "date": "2023-03-21T23:57:22.7781131Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acfef954-3dc1fbdf0174fbe77b594b9f_21516_13", + "username": "username", + "session": "acfef954-3dc1fbdf0174fbe77b594b9f", + "date": "2023-03-21T23:57:22.801318Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "af6b61d0-7d40-42af-8c35-391eb87c662c", + "username": "dotnet_kernel", + "session": "22a1fc49-fba7-4f2a-b0a7-2a147e8ae8a5", + "date": "2023-03-21T23:57:22.7993326Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acfef954-3dc1fbdf0174fbe77b594b9f_21516_14", + "username": "username", + "session": "acfef954-3dc1fbdf0174fbe77b594b9f", + "date": "2023-03-21T23:57:22.801318Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "af6b61d0-7d40-42af-8c35-391eb87c662c", + "username": "dotnet_kernel", + "session": "22a1fc49-fba7-4f2a-b0a7-2a147e8ae8a5", + "date": "2023-03-21T23:57:22.7993326Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acfef954-3dc1fbdf0174fbe77b594b9f_21516_15", + "username": "username", + "session": "acfef954-3dc1fbdf0174fbe77b594b9f", + "date": "2023-03-21T23:57:22.834836Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "af6b61d0-7d40-42af-8c35-391eb87c662c", + "username": "dotnet_kernel", + "session": "22a1fc49-fba7-4f2a-b0a7-2a147e8ae8a5", + "date": "2023-03-21T23:57:22.7993326Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:57:22.801318Z", + "dependencies_met": true, + "engine": "415590a7-f835-4aeb-8059-c8fa613d0052", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acfef954-3dc1fbdf0174fbe77b594b9f_21516_16", + "username": "username", + "session": "acfef954-3dc1fbdf0174fbe77b594b9f", + "date": "2023-03-21T23:57:22.835842Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "af6b61d0-7d40-42af-8c35-391eb87c662c", + "username": "dotnet_kernel", + "session": "22a1fc49-fba7-4f2a-b0a7-2a147e8ae8a5", + "date": "2023-03-21T23:57:22.7993326Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acfef954-3dc1fbdf0174fbe77b594b9f_21516_17", + "username": "username", + "session": "acfef954-3dc1fbdf0174fbe77b594b9f", + "date": "2023-03-21T23:57:22.840852Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c85e8ac8-edde-4d31-b719-1f5a0090595a", + "username": "dotnet_kernel", + "session": "194aa72b-216e-43fe-88ae-339e0a25ffa2", + "date": "2023-03-21T23:57:22.8390988Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acfef954-3dc1fbdf0174fbe77b594b9f_21516_18", + "username": "username", + "session": "acfef954-3dc1fbdf0174fbe77b594b9f", + "date": "2023-03-21T23:57:22.840852Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c85e8ac8-edde-4d31-b719-1f5a0090595a", + "username": "dotnet_kernel", + "session": "194aa72b-216e-43fe-88ae-339e0a25ffa2", + "date": "2023-03-21T23:57:22.8390988Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "96fb7d64-2ba7-4468-90ba-66b590fe5d3c", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acfef954-3dc1fbdf0174fbe77b594b9f_21516_19", + "username": "username", + "session": "acfef954-3dc1fbdf0174fbe77b594b9f", + "date": "2023-03-21T23:57:22.841851Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c85e8ac8-edde-4d31-b719-1f5a0090595a", + "username": "dotnet_kernel", + "session": "194aa72b-216e-43fe-88ae-339e0a25ffa2", + "date": "2023-03-21T23:57:22.8390988Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acfef954-3dc1fbdf0174fbe77b594b9f_21516_20", + "username": "username", + "session": "acfef954-3dc1fbdf0174fbe77b594b9f", + "date": "2023-03-21T23:57:22.846848Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "f71e85b3-efe5-4668-8223-6858aefacb44", + "username": "dotnet_kernel", + "session": "8a93c36a-353a-4dcd-8e40-17bb28f4f4b3", + "date": "2023-03-21T23:57:22.8455872Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acfef954-3dc1fbdf0174fbe77b594b9f_21516_21", + "username": "username", + "session": "acfef954-3dc1fbdf0174fbe77b594b9f", + "date": "2023-03-21T23:57:22.847853Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "f71e85b3-efe5-4668-8223-6858aefacb44", + "username": "dotnet_kernel", + "session": "8a93c36a-353a-4dcd-8e40-17bb28f4f4b3", + "date": "2023-03-21T23:57:22.8455872Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "96fb7d64-2ba7-4468-90ba-66b590fe5d3c", + "data": { + "commandOrEvent": "{\"event\": {\"message\": \"Invalid Identifier: \\\"a.b\\\"\"}, \"eventType\": \"CommandFailed\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_multiple_df_on_kernel.ir.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_multiple_df_on_kernel.ir.json new file mode 100644 index 0000000000..0835e4b986 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_multiple_df_on_kernel.ir.json @@ -0,0 +1,567 @@ +[ + { + "header": { + "msg_id": "8f5eb3ea-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "b90d3c5c-dbc7-498d-a2c1-174b80a455f2", + "date": "2023-03-22T05:15:28.560406Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "260df64a-9005-4964-a67c-bf94aa7bff78", + "username": "dotnet_kernel", + "session": "b90d3c5c-dbc7-498d-a2c1-174b80a455f2", + "date": "2023-03-22T05:15:28.4987392Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f5edadc-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "b90d3c5c-dbc7-498d-a2c1-174b80a455f2", + "date": "2023-03-22T05:15:28.562407Z", + "msg_type": "kernel_info_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "260df64a-9005-4964-a67c-bf94aa7bff78", + "username": "dotnet_kernel", + "session": "b90d3c5c-dbc7-498d-a2c1-174b80a455f2", + "date": "2023-03-22T05:15:28.4987392Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.0", + "implementation": "IRkernel", + "implementation_version": "0.8.15", + "language_info": { + "name": "R", + "version": "3.6.1", + "mimetype": "text/x-r-source", + "file_extension": ".r", + "pygments_lexer": "r", + "codemirror_mode": "r" + }, + "banner": "R version 3.6.1 (2019-07-05)", + "status": "ok", + "help_links": [] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f5f2906-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "b90d3c5c-dbc7-498d-a2c1-174b80a455f2", + "date": "2023-03-22T05:15:28.563406Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "260df64a-9005-4964-a67c-bf94aa7bff78", + "username": "dotnet_kernel", + "session": "b90d3c5c-dbc7-498d-a2c1-174b80a455f2", + "date": "2023-03-22T05:15:28.4987392Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f5fec92-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "07871ee8-bce6-4883-8d3a-a7a25f01e869", + "date": "2023-03-22T05:15:28.568414Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "b7774091-9e7f-4fe0-ab56-5e04f9926455", + "username": "dotnet_kernel", + "session": "07871ee8-bce6-4883-8d3a-a7a25f01e869", + "date": "2023-03-22T05:15:28.5646556Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f603abc-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "07871ee8-bce6-4883-8d3a-a7a25f01e869", + "date": "2023-03-22T05:15:28.571446Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "b7774091-9e7f-4fe0-ab56-5e04f9926455", + "username": "dotnet_kernel", + "session": "07871ee8-bce6-4883-8d3a-a7a25f01e869", + "date": "2023-03-22T05:15:28.5646556Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f6dbee4-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "07871ee8-bce6-4883-8d3a-a7a25f01e869", + "date": "2023-03-22T05:15:28.659998Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "b7774091-9e7f-4fe0-ab56-5e04f9926455", + "username": "dotnet_kernel", + "session": "07871ee8-bce6-4883-8d3a-a7a25f01e869", + "date": "2023-03-22T05:15:28.5646556Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f6de612-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "07871ee8-bce6-4883-8d3a-a7a25f01e869", + "date": "2023-03-22T05:15:28.659998Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "b7774091-9e7f-4fe0-ab56-5e04f9926455", + "username": "dotnet_kernel", + "session": "07871ee8-bce6-4883-8d3a-a7a25f01e869", + "date": "2023-03-22T05:15:28.5646556Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f6e823e-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "6449e4cd-1931-4567-9ec4-5cc87961e0e2", + "date": "2023-03-22T05:15:28.664507Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "13a781f4-61fb-4ef4-b6b5-7a3e4d49e39b", + "username": "dotnet_kernel", + "session": "6449e4cd-1931-4567-9ec4-5cc87961e0e2", + "date": "2023-03-22T05:15:28.6614663Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f6f0bbe-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "6449e4cd-1931-4567-9ec4-5cc87961e0e2", + "date": "2023-03-22T05:15:28.668517Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "13a781f4-61fb-4ef4-b6b5-7a3e4d49e39b", + "username": "dotnet_kernel", + "session": "6449e4cd-1931-4567-9ec4-5cc87961e0e2", + "date": "2023-03-22T05:15:28.6614663Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4facea6f-4735-4b5d-959f-ccc98f1b12d1", + "data": { + "commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f6f32c4-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "6449e4cd-1931-4567-9ec4-5cc87961e0e2", + "date": "2023-03-22T05:15:28.669521Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "13a781f4-61fb-4ef4-b6b5-7a3e4d49e39b", + "username": "dotnet_kernel", + "session": "6449e4cd-1931-4567-9ec4-5cc87961e0e2", + "date": "2023-03-22T05:15:28.6614663Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f70443e-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "4562c770-6192-441e-8d50-7209808d627d", + "date": "2023-03-22T05:15:28.675514Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "7c96ee0c-2ec8-4392-ae05-721879fe4249", + "username": "dotnet_kernel", + "session": "4562c770-6192-441e-8d50-7209808d627d", + "date": "2023-03-22T05:15:28.6729897Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f732aa0-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "4562c770-6192-441e-8d50-7209808d627d", + "date": "2023-03-22T05:15:28.696036Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "7c96ee0c-2ec8-4392-ae05-721879fe4249", + "username": "dotnet_kernel", + "session": "4562c770-6192-441e-8d50-7209808d627d", + "date": "2023-03-22T05:15:28.6729897Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4facea6f-4735-4b5d-959f-ccc98f1b12d1", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f738ce8-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "4562c770-6192-441e-8d50-7209808d627d", + "date": "2023-03-22T05:15:28.697036Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "7c96ee0c-2ec8-4392-ae05-721879fe4249", + "username": "dotnet_kernel", + "session": "4562c770-6192-441e-8d50-7209808d627d", + "date": "2023-03-22T05:15:28.6729897Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f73daf4-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "07e5d158-f561-42c2-981f-6087ba61431c", + "date": "2023-03-22T05:15:28.700033Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e23121af-2473-4050-aa15-5f0c61da8bee", + "username": "dotnet_kernel", + "session": "07e5d158-f561-42c2-981f-6087ba61431c", + "date": "2023-03-22T05:15:28.6966713Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f769a1e-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "07e5d158-f561-42c2-981f-6087ba61431c", + "date": "2023-03-22T05:15:28.718040Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e23121af-2473-4050-aa15-5f0c61da8bee", + "username": "dotnet_kernel", + "session": "07e5d158-f561-42c2-981f-6087ba61431c", + "date": "2023-03-22T05:15:28.6966713Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4facea6f-4735-4b5d-959f-ccc98f1b12d1", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f76c12e-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "07e5d158-f561-42c2-981f-6087ba61431c", + "date": "2023-03-22T05:15:28.719040Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e23121af-2473-4050-aa15-5f0c61da8bee", + "username": "dotnet_kernel", + "session": "07e5d158-f561-42c2-981f-6087ba61431c", + "date": "2023-03-22T05:15:28.6966713Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f773672-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "1b6f4786-af1e-4dcc-989d-df71e1b63440", + "date": "2023-03-22T05:15:28.722038Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1e616e86-ee90-4db5-afb3-c76b33ee70c7", + "username": "dotnet_kernel", + "session": "1b6f4786-af1e-4dcc-989d-df71e1b63440", + "date": "2023-03-22T05:15:28.7194456Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f7d5214-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "1b6f4786-af1e-4dcc-989d-df71e1b63440", + "date": "2023-03-22T05:15:28.762066Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1e616e86-ee90-4db5-afb3-c76b33ee70c7", + "username": "dotnet_kernel", + "session": "1b6f4786-af1e-4dcc-989d-df71e1b63440", + "date": "2023-03-22T05:15:28.7194456Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4facea6f-4735-4b5d-959f-ccc98f1b12d1", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"df1\",\"value\":[{\"name\":\"Granny Smith apple\",\"deliciousness\":0,\"color\":\"red\"},{\"name\":\"Rainier cherry\",\"deliciousness\":9000,\"color\":\"yellow\"}],\"formattedValue\":{\"mimeType\":\"application/table-schema+json\",\"value\":\"[{\\\"name\\\":\\\"Granny Smith apple\\\",\\\"deliciousness\\\":0,\\\"color\\\":\\\"red\\\"},{\\\"name\\\":\\\"Rainier cherry\\\",\\\"deliciousness\\\":9000,\\\"color\\\":\\\"yellow\\\"}]\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"RmYPX7aIarat7Z/9fnVYYCDYMq1SyiQBWfe9lkyWtCc=\",\"id\":\"dd4234ce06dc4a50b3d6f104a91aba06\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"df1\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f7d7910-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "1b6f4786-af1e-4dcc-989d-df71e1b63440", + "date": "2023-03-22T05:15:28.763070Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1e616e86-ee90-4db5-afb3-c76b33ee70c7", + "username": "dotnet_kernel", + "session": "1b6f4786-af1e-4dcc-989d-df71e1b63440", + "date": "2023-03-22T05:15:28.7194456Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f7e3c60-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "ff07b7d6-7c4d-474c-8603-e7997740eb22", + "date": "2023-03-22T05:15:28.768067Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "cd66e372-ea6e-4e84-8779-a0e1fa61879c", + "username": "dotnet_kernel", + "session": "ff07b7d6-7c4d-474c-8603-e7997740eb22", + "date": "2023-03-22T05:15:28.7653154Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f7f4dda-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "ff07b7d6-7c4d-474c-8603-e7997740eb22", + "date": "2023-03-22T05:15:28.774066Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "cd66e372-ea6e-4e84-8779-a0e1fa61879c", + "username": "dotnet_kernel", + "session": "ff07b7d6-7c4d-474c-8603-e7997740eb22", + "date": "2023-03-22T05:15:28.7653154Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4facea6f-4735-4b5d-959f-ccc98f1b12d1", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"df2\",\"value\":[{\"a\":\"1\",\"b\":1},{\"a\":\"2\",\"b\":2}],\"formattedValue\":{\"mimeType\":\"application/table-schema+json\",\"value\":\"[{\\\"a\\\":\\\"1\\\",\\\"b\\\":1},{\\\"a\\\":\\\"2\\\",\\\"b\\\":2}]\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"2MBiAYrMqWQz0R0SNZm+bSl3jCjC7ccActRLSQ9QF8s=\",\"id\":\"e34a22686bb74622af4052280f5dac1b\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"df2\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "8f7f74f4-c870-11ed-bde9-a308e49dbb86", + "username": "dotnet_kernel", + "session": "ff07b7d6-7c4d-474c-8603-e7997740eb22", + "date": "2023-03-22T05:15:28.775076Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "cd66e372-ea6e-4e84-8779-a0e1fa61879c", + "username": "dotnet_kernel", + "session": "ff07b7d6-7c4d-474c-8603-e7997740eb22", + "date": "2023-03-22T05:15:28.7653154Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_multiple_df_on_kernel.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_multiple_df_on_kernel.python3.json new file mode 100644 index 0000000000..d1b9ed81f4 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_multiple_df_on_kernel.python3.json @@ -0,0 +1,605 @@ +[ + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_10", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.262248Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "cd53e652-d783-4c12-bb8f-b0a38c94c81f", + "username": "dotnet_kernel", + "session": "e90337fa-e091-433e-8c17-180622fd2260", + "date": "2023-03-22T05:15:26.2469851Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_11", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.262248Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "cd53e652-d783-4c12-bb8f-b0a38c94c81f", + "username": "dotnet_kernel", + "session": "e90337fa-e091-433e-8c17-180622fd2260", + "date": "2023-03-22T05:15:26.2469851Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_12", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.263247Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "cd53e652-d783-4c12-bb8f-b0a38c94c81f", + "username": "dotnet_kernel", + "session": "e90337fa-e091-433e-8c17-180622fd2260", + "date": "2023-03-22T05:15:26.2469851Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_13", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.287254Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "bfaaca88-87c7-43ab-afc8-db54e30dac3c", + "username": "dotnet_kernel", + "session": "e6ed1657-3899-4266-9615-4848b0898238", + "date": "2023-03-22T05:15:26.2803181Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_14", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.287254Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "bfaaca88-87c7-43ab-afc8-db54e30dac3c", + "username": "dotnet_kernel", + "session": "e6ed1657-3899-4266-9615-4848b0898238", + "date": "2023-03-22T05:15:26.2803181Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_15", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.330280Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "bfaaca88-87c7-43ab-afc8-db54e30dac3c", + "username": "dotnet_kernel", + "session": "e6ed1657-3899-4266-9615-4848b0898238", + "date": "2023-03-22T05:15:26.2803181Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-22T05:15:26.287254Z", + "dependencies_met": true, + "engine": "cbb0aef7-c7f2-434f-bdfe-2bc1019f100a", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_16", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.330280Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "bfaaca88-87c7-43ab-afc8-db54e30dac3c", + "username": "dotnet_kernel", + "session": "e6ed1657-3899-4266-9615-4848b0898238", + "date": "2023-03-22T05:15:26.2803181Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_17", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.340293Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "30786a60-2a61-473a-a9d8-3ee97abdda58", + "username": "dotnet_kernel", + "session": "7a098d2f-0aa3-410c-a2f1-2530cb754d4b", + "date": "2023-03-22T05:15:26.3389726Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_18", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.341287Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "30786a60-2a61-473a-a9d8-3ee97abdda58", + "username": "dotnet_kernel", + "session": "7a098d2f-0aa3-410c-a2f1-2530cb754d4b", + "date": "2023-03-22T05:15:26.3389726Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "b714afc0-7381-4618-a0b3-764b47be4d18", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_19", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.341287Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "30786a60-2a61-473a-a9d8-3ee97abdda58", + "username": "dotnet_kernel", + "session": "7a098d2f-0aa3-410c-a2f1-2530cb754d4b", + "date": "2023-03-22T05:15:26.3389726Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_20", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.418830Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "38bf31e8-dc9b-4d10-8512-98b6f90ce8e4", + "username": "dotnet_kernel", + "session": "2adfcf84-b89e-4413-8923-59d696fbb46e", + "date": "2023-03-22T05:15:26.4172827Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_21", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.888390Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "38bf31e8-dc9b-4d10-8512-98b6f90ce8e4", + "username": "dotnet_kernel", + "session": "2adfcf84-b89e-4413-8923-59d696fbb46e", + "date": "2023-03-22T05:15:26.4172827Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "b714afc0-7381-4618-a0b3-764b47be4d18", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_22", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.889417Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "38bf31e8-dc9b-4d10-8512-98b6f90ce8e4", + "username": "dotnet_kernel", + "session": "2adfcf84-b89e-4413-8923-59d696fbb46e", + "date": "2023-03-22T05:15:26.4172827Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_23", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.892417Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "faf92953-c06f-4277-8513-51c88085ae62", + "username": "dotnet_kernel", + "session": "d31fc49d-f7a1-4abd-9a1f-598f96197f23", + "date": "2023-03-22T05:15:26.8920208Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_24", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.893417Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "faf92953-c06f-4277-8513-51c88085ae62", + "username": "dotnet_kernel", + "session": "d31fc49d-f7a1-4abd-9a1f-598f96197f23", + "date": "2023-03-22T05:15:26.8920208Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "b714afc0-7381-4618-a0b3-764b47be4d18", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_25", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.894416Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "faf92953-c06f-4277-8513-51c88085ae62", + "username": "dotnet_kernel", + "session": "d31fc49d-f7a1-4abd-9a1f-598f96197f23", + "date": "2023-03-22T05:15:26.8920208Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_26", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.907422Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "e6a52095-7a40-4f08-b683-ce7eea6d79ba", + "username": "dotnet_kernel", + "session": "a8227c36-304c-4fcb-98b9-7a97ba9214ca", + "date": "2023-03-22T05:15:26.9066306Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_27", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.924714Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "e6a52095-7a40-4f08-b683-ce7eea6d79ba", + "username": "dotnet_kernel", + "session": "a8227c36-304c-4fcb-98b9-7a97ba9214ca", + "date": "2023-03-22T05:15:26.9066306Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "b714afc0-7381-4618-a0b3-764b47be4d18", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"df1\", \"value\": [{\"name\": \"Granny Smith apple\", \"deliciousness\": 0, \"color\": \"red\"}, {\"name\": \"Rainier cherry\", \"deliciousness\": 9000, \"color\": \"yellow\"}], \"formattedValue\": {\"mimeType\": \"application/table-schema+json\", \"value\": \" name deliciousness color\\nGranny Smith apple 0 red\\n Rainier cherry 9000 yellow\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"8l35wqhXLvYQr1zVPrvVQqKjYWvIqM7NCa1BaSWh8gg=\", \"id\": \"f8d716ad11074fb892de7448e06e2746\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"df1\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_28", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.925714Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "e6a52095-7a40-4f08-b683-ce7eea6d79ba", + "username": "dotnet_kernel", + "session": "a8227c36-304c-4fcb-98b9-7a97ba9214ca", + "date": "2023-03-22T05:15:26.9066306Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_29", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.984262Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "0cb0830f-8f89-426e-b934-094b81a6132a", + "username": "dotnet_kernel", + "session": "8881f93b-0a05-414b-ae5b-4dfd80b8b1a2", + "date": "2023-03-22T05:15:26.9835301Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_30", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.985260Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "0cb0830f-8f89-426e-b934-094b81a6132a", + "username": "dotnet_kernel", + "session": "8881f93b-0a05-414b-ae5b-4dfd80b8b1a2", + "date": "2023-03-22T05:15:26.9835301Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "b714afc0-7381-4618-a0b3-764b47be4d18", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"df2\", \"value\": [{\"a\": \"1\", \"b\": 1}, {\"a\": \"2\", \"b\": 2}], \"formattedValue\": {\"mimeType\": \"application/table-schema+json\", \"value\": \"a b\\n1 1\\n2 2\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"DGpDjtPQ1zGVG6SeTJjoRqpDX1ytVzH462OEAma8wSU=\", \"id\": \"b78d4735166d4de496308c5836bebf06\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"df2\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "198a5713-129a4e888f9b58bac7a7efb1_21344_31", + "username": "username", + "session": "198a5713-129a4e888f9b58bac7a7efb1", + "date": "2023-03-22T05:15:26.986260Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "0cb0830f-8f89-426e-b934-094b81a6132a", + "username": "dotnet_kernel", + "session": "8881f93b-0a05-414b-ae5b-4dfd80b8b1a2", + "date": "2023-03-22T05:15:26.9835301Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_single_df_in_enumerable_on_kernel.ir.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_single_df_in_enumerable_on_kernel.ir.json new file mode 100644 index 0000000000..9bda21b00f --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_single_df_in_enumerable_on_kernel.ir.json @@ -0,0 +1,415 @@ +[ + { + "header": { + "msg_id": "9f0e491c-c871-11ed-b446-47b4cb2f2ade", + "username": "dotnet_kernel", + "session": "fb5a50cd-7d3a-4254-9c58-938f47d7eaf1", + "date": "2023-03-22T05:23:04.373663Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2179d329-ad90-4d18-af94-890bf099bf0a", + "username": "dotnet_kernel", + "session": "fb5a50cd-7d3a-4254-9c58-938f47d7eaf1", + "date": "2023-03-22T05:23:04.3090485Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9f0e7036-c871-11ed-b446-47b4cb2f2ade", + "username": "dotnet_kernel", + "session": "fb5a50cd-7d3a-4254-9c58-938f47d7eaf1", + "date": "2023-03-22T05:23:04.374665Z", + "msg_type": "kernel_info_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2179d329-ad90-4d18-af94-890bf099bf0a", + "username": "dotnet_kernel", + "session": "fb5a50cd-7d3a-4254-9c58-938f47d7eaf1", + "date": "2023-03-22T05:23:04.3090485Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.0", + "implementation": "IRkernel", + "implementation_version": "0.8.15", + "language_info": { + "name": "R", + "version": "3.6.1", + "mimetype": "text/x-r-source", + "file_extension": ".r", + "pygments_lexer": "r", + "codemirror_mode": "r" + }, + "banner": "R version 3.6.1 (2019-07-05)", + "status": "ok", + "help_links": [] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9f0e975a-c871-11ed-b446-47b4cb2f2ade", + "username": "dotnet_kernel", + "session": "fb5a50cd-7d3a-4254-9c58-938f47d7eaf1", + "date": "2023-03-22T05:23:04.376668Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2179d329-ad90-4d18-af94-890bf099bf0a", + "username": "dotnet_kernel", + "session": "fb5a50cd-7d3a-4254-9c58-938f47d7eaf1", + "date": "2023-03-22T05:23:04.3090485Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9f0fae42-c871-11ed-b446-47b4cb2f2ade", + "username": "dotnet_kernel", + "session": "ccaf8673-e3cb-4f29-a3c2-f7ea67e0b88f", + "date": "2023-03-22T05:23:04.383810Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "4216a518-d36b-45a0-a908-934e8551f44f", + "username": "dotnet_kernel", + "session": "ccaf8673-e3cb-4f29-a3c2-f7ea67e0b88f", + "date": "2023-03-22T05:23:04.3771771Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9f10237c-c871-11ed-b446-47b4cb2f2ade", + "username": "dotnet_kernel", + "session": "ccaf8673-e3cb-4f29-a3c2-f7ea67e0b88f", + "date": "2023-03-22T05:23:04.386808Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "4216a518-d36b-45a0-a908-934e8551f44f", + "username": "dotnet_kernel", + "session": "ccaf8673-e3cb-4f29-a3c2-f7ea67e0b88f", + "date": "2023-03-22T05:23:04.3771771Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9f1dce64-c871-11ed-b446-47b4cb2f2ade", + "username": "dotnet_kernel", + "session": "ccaf8673-e3cb-4f29-a3c2-f7ea67e0b88f", + "date": "2023-03-22T05:23:04.476386Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "4216a518-d36b-45a0-a908-934e8551f44f", + "username": "dotnet_kernel", + "session": "ccaf8673-e3cb-4f29-a3c2-f7ea67e0b88f", + "date": "2023-03-22T05:23:04.3771771Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9f1e1cd4-c871-11ed-b446-47b4cb2f2ade", + "username": "dotnet_kernel", + "session": "ccaf8673-e3cb-4f29-a3c2-f7ea67e0b88f", + "date": "2023-03-22T05:23:04.477394Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "4216a518-d36b-45a0-a908-934e8551f44f", + "username": "dotnet_kernel", + "session": "ccaf8673-e3cb-4f29-a3c2-f7ea67e0b88f", + "date": "2023-03-22T05:23:04.3771771Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9f1e920e-c871-11ed-b446-47b4cb2f2ade", + "username": "dotnet_kernel", + "session": "dc5b551d-b764-4d05-ad9c-2af7c2e6297f", + "date": "2023-03-22T05:23:04.480387Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "422e7ab4-d71e-41d1-91cc-ba0b840a84c7", + "username": "dotnet_kernel", + "session": "dc5b551d-b764-4d05-ad9c-2af7c2e6297f", + "date": "2023-03-22T05:23:04.4781093Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9f1f2e44-c871-11ed-b446-47b4cb2f2ade", + "username": "dotnet_kernel", + "session": "dc5b551d-b764-4d05-ad9c-2af7c2e6297f", + "date": "2023-03-22T05:23:04.484387Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "422e7ab4-d71e-41d1-91cc-ba0b840a84c7", + "username": "dotnet_kernel", + "session": "dc5b551d-b764-4d05-ad9c-2af7c2e6297f", + "date": "2023-03-22T05:23:04.4781093Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "8cdd8150-5e15-49f6-bac4-e04a037f8a6d", + "data": { + "commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9f1f555e-c871-11ed-b446-47b4cb2f2ade", + "username": "dotnet_kernel", + "session": "dc5b551d-b764-4d05-ad9c-2af7c2e6297f", + "date": "2023-03-22T05:23:04.485387Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "422e7ab4-d71e-41d1-91cc-ba0b840a84c7", + "username": "dotnet_kernel", + "session": "dc5b551d-b764-4d05-ad9c-2af7c2e6297f", + "date": "2023-03-22T05:23:04.4781093Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9f221654-c871-11ed-b446-47b4cb2f2ade", + "username": "dotnet_kernel", + "session": "53b78010-e04b-46e1-a97c-ebbe8dba1e1c", + "date": "2023-03-22T05:23:04.503434Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "105df145-b63d-40bb-8b2e-9f5f6d7e5256", + "username": "dotnet_kernel", + "session": "53b78010-e04b-46e1-a97c-ebbe8dba1e1c", + "date": "2023-03-22T05:23:04.4897101Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9f2510ac-c871-11ed-b446-47b4cb2f2ade", + "username": "dotnet_kernel", + "session": "53b78010-e04b-46e1-a97c-ebbe8dba1e1c", + "date": "2023-03-22T05:23:04.523954Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "105df145-b63d-40bb-8b2e-9f5f6d7e5256", + "username": "dotnet_kernel", + "session": "53b78010-e04b-46e1-a97c-ebbe8dba1e1c", + "date": "2023-03-22T05:23:04.4897101Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "8cdd8150-5e15-49f6-bac4-e04a037f8a6d", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9f255ef4-c871-11ed-b446-47b4cb2f2ade", + "username": "dotnet_kernel", + "session": "53b78010-e04b-46e1-a97c-ebbe8dba1e1c", + "date": "2023-03-22T05:23:04.524962Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "105df145-b63d-40bb-8b2e-9f5f6d7e5256", + "username": "dotnet_kernel", + "session": "53b78010-e04b-46e1-a97c-ebbe8dba1e1c", + "date": "2023-03-22T05:23:04.4897101Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9f25d438-c871-11ed-b446-47b4cb2f2ade", + "username": "dotnet_kernel", + "session": "37046079-df8c-47ad-9d17-3d3317c409d8", + "date": "2023-03-22T05:23:04.527955Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "5cfaa05c-8ec6-4ec4-87f5-935f8d84a4e0", + "username": "dotnet_kernel", + "session": "37046079-df8c-47ad-9d17-3d3317c409d8", + "date": "2023-03-22T05:23:04.5255647Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9f2dfff0-c871-11ed-b446-47b4cb2f2ade", + "username": "dotnet_kernel", + "session": "37046079-df8c-47ad-9d17-3d3317c409d8", + "date": "2023-03-22T05:23:04.582503Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "5cfaa05c-8ec6-4ec4-87f5-935f8d84a4e0", + "username": "dotnet_kernel", + "session": "37046079-df8c-47ad-9d17-3d3317c409d8", + "date": "2023-03-22T05:23:04.5255647Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "8cdd8150-5e15-49f6-bac4-e04a037f8a6d", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"df\",\"value\":[{\"name\":\"Granny Smith apple\",\"deliciousness\":0,\"color\":\"red\"},{\"name\":\"Rainier cherry\",\"deliciousness\":9000,\"color\":\"yellow\"}],\"formattedValue\":{\"mimeType\":\"application/table-schema+json\",\"value\":\"[{\\\"name\\\":\\\"Granny Smith apple\\\",\\\"deliciousness\\\":0,\\\"color\\\":\\\"red\\\"},{\\\"name\\\":\\\"Rainier cherry\\\",\\\"deliciousness\\\":9000,\\\"color\\\":\\\"yellow\\\"}]\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"6CyxzUncID/7e1A3xVljo8vm6F5OEe7a65V/dyOM4tM=\",\"id\":\"2e82e0728cc14af9b9d9898467ddb391\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"df\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9f2e270a-c871-11ed-b446-47b4cb2f2ade", + "username": "dotnet_kernel", + "session": "37046079-df8c-47ad-9d17-3d3317c409d8", + "date": "2023-03-22T05:23:04.582503Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "5cfaa05c-8ec6-4ec4-87f5-935f8d84a4e0", + "username": "dotnet_kernel", + "session": "37046079-df8c-47ad-9d17-3d3317c409d8", + "date": "2023-03-22T05:23:04.5255647Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_single_df_in_enumerable_on_kernel.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_single_df_in_enumerable_on_kernel.python3.json new file mode 100644 index 0000000000..1cde22032c --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_single_df_in_enumerable_on_kernel.python3.json @@ -0,0 +1,453 @@ +[ + { + "header": { + "msg_id": "6e7bda28-3c6a7a75ec0c4d0d14412c51_21572_10", + "username": "username", + "session": "6e7bda28-3c6a7a75ec0c4d0d14412c51", + "date": "2023-03-22T05:23:02.606655Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "bb740e0b-5e51-46c8-ad4c-5dae96f5e10f", + "username": "dotnet_kernel", + "session": "ddeeaafe-9da3-4f9b-8d3a-177a266288cc", + "date": "2023-03-22T05:23:02.5917309Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6e7bda28-3c6a7a75ec0c4d0d14412c51_21572_12", + "username": "username", + "session": "6e7bda28-3c6a7a75ec0c4d0d14412c51", + "date": "2023-03-22T05:23:02.608652Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "bb740e0b-5e51-46c8-ad4c-5dae96f5e10f", + "username": "dotnet_kernel", + "session": "ddeeaafe-9da3-4f9b-8d3a-177a266288cc", + "date": "2023-03-22T05:23:02.5917309Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6e7bda28-3c6a7a75ec0c4d0d14412c51_21572_11", + "username": "username", + "session": "6e7bda28-3c6a7a75ec0c4d0d14412c51", + "date": "2023-03-22T05:23:02.607651Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "bb740e0b-5e51-46c8-ad4c-5dae96f5e10f", + "username": "dotnet_kernel", + "session": "ddeeaafe-9da3-4f9b-8d3a-177a266288cc", + "date": "2023-03-22T05:23:02.5917309Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6e7bda28-3c6a7a75ec0c4d0d14412c51_21572_13", + "username": "username", + "session": "6e7bda28-3c6a7a75ec0c4d0d14412c51", + "date": "2023-03-22T05:23:02.633189Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "385c4294-c929-4f38-a71a-a33cefc409b5", + "username": "dotnet_kernel", + "session": "03613423-0a36-4cd6-968f-f8259716220d", + "date": "2023-03-22T05:23:02.6257795Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6e7bda28-3c6a7a75ec0c4d0d14412c51_21572_14", + "username": "username", + "session": "6e7bda28-3c6a7a75ec0c4d0d14412c51", + "date": "2023-03-22T05:23:02.634187Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "385c4294-c929-4f38-a71a-a33cefc409b5", + "username": "dotnet_kernel", + "session": "03613423-0a36-4cd6-968f-f8259716220d", + "date": "2023-03-22T05:23:02.6257795Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6e7bda28-3c6a7a75ec0c4d0d14412c51_21572_15", + "username": "username", + "session": "6e7bda28-3c6a7a75ec0c4d0d14412c51", + "date": "2023-03-22T05:23:02.673722Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "385c4294-c929-4f38-a71a-a33cefc409b5", + "username": "dotnet_kernel", + "session": "03613423-0a36-4cd6-968f-f8259716220d", + "date": "2023-03-22T05:23:02.6257795Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-22T05:23:02.634187Z", + "dependencies_met": true, + "engine": "916d7613-f3f6-4080-8eca-5aa4f4ce7194", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6e7bda28-3c6a7a75ec0c4d0d14412c51_21572_16", + "username": "username", + "session": "6e7bda28-3c6a7a75ec0c4d0d14412c51", + "date": "2023-03-22T05:23:02.673722Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "385c4294-c929-4f38-a71a-a33cefc409b5", + "username": "dotnet_kernel", + "session": "03613423-0a36-4cd6-968f-f8259716220d", + "date": "2023-03-22T05:23:02.6257795Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6e7bda28-3c6a7a75ec0c4d0d14412c51_21572_17", + "username": "username", + "session": "6e7bda28-3c6a7a75ec0c4d0d14412c51", + "date": "2023-03-22T05:23:02.683727Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a367d404-4443-4282-991e-2688e8ff7017", + "username": "dotnet_kernel", + "session": "4b6daea7-17ad-4695-9406-4729f95dfd2e", + "date": "2023-03-22T05:23:02.6825290Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6e7bda28-3c6a7a75ec0c4d0d14412c51_21572_18", + "username": "username", + "session": "6e7bda28-3c6a7a75ec0c4d0d14412c51", + "date": "2023-03-22T05:23:02.684729Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a367d404-4443-4282-991e-2688e8ff7017", + "username": "dotnet_kernel", + "session": "4b6daea7-17ad-4695-9406-4729f95dfd2e", + "date": "2023-03-22T05:23:02.6825290Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "5f1e929a-4e63-434a-9802-35bdf2398dd1", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6e7bda28-3c6a7a75ec0c4d0d14412c51_21572_19", + "username": "username", + "session": "6e7bda28-3c6a7a75ec0c4d0d14412c51", + "date": "2023-03-22T05:23:02.685728Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a367d404-4443-4282-991e-2688e8ff7017", + "username": "dotnet_kernel", + "session": "4b6daea7-17ad-4695-9406-4729f95dfd2e", + "date": "2023-03-22T05:23:02.6825290Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6e7bda28-3c6a7a75ec0c4d0d14412c51_21572_20", + "username": "username", + "session": "6e7bda28-3c6a7a75ec0c4d0d14412c51", + "date": "2023-03-22T05:23:02.760788Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a4bd7a22-1d0d-4ae5-a4c3-e273e6580a0a", + "username": "dotnet_kernel", + "session": "89cb3b0c-e0fb-407c-acf8-213db1c7db44", + "date": "2023-03-22T05:23:02.7591949Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6e7bda28-3c6a7a75ec0c4d0d14412c51_21572_21", + "username": "username", + "session": "6e7bda28-3c6a7a75ec0c4d0d14412c51", + "date": "2023-03-22T05:23:03.225019Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a4bd7a22-1d0d-4ae5-a4c3-e273e6580a0a", + "username": "dotnet_kernel", + "session": "89cb3b0c-e0fb-407c-acf8-213db1c7db44", + "date": "2023-03-22T05:23:02.7591949Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "5f1e929a-4e63-434a-9802-35bdf2398dd1", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6e7bda28-3c6a7a75ec0c4d0d14412c51_21572_22", + "username": "username", + "session": "6e7bda28-3c6a7a75ec0c4d0d14412c51", + "date": "2023-03-22T05:23:03.226031Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a4bd7a22-1d0d-4ae5-a4c3-e273e6580a0a", + "username": "dotnet_kernel", + "session": "89cb3b0c-e0fb-407c-acf8-213db1c7db44", + "date": "2023-03-22T05:23:02.7591949Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6e7bda28-3c6a7a75ec0c4d0d14412c51_21572_23", + "username": "username", + "session": "6e7bda28-3c6a7a75ec0c4d0d14412c51", + "date": "2023-03-22T05:23:03.236028Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "81abe68f-f93a-4b72-bbb3-fa5577b3fb4e", + "username": "dotnet_kernel", + "session": "bfec9337-b178-40b7-90dc-cfd6a8d923a1", + "date": "2023-03-22T05:23:03.2351904Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6e7bda28-3c6a7a75ec0c4d0d14412c51_21572_24", + "username": "username", + "session": "6e7bda28-3c6a7a75ec0c4d0d14412c51", + "date": "2023-03-22T05:23:03.238026Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "81abe68f-f93a-4b72-bbb3-fa5577b3fb4e", + "username": "dotnet_kernel", + "session": "bfec9337-b178-40b7-90dc-cfd6a8d923a1", + "date": "2023-03-22T05:23:03.2351904Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "5f1e929a-4e63-434a-9802-35bdf2398dd1", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"df\", \"value\": [{\"name\": \"Granny Smith apple\", \"deliciousness\": 0, \"color\": \"red\"}, {\"name\": \"Rainier cherry\", \"deliciousness\": 9000, \"color\": \"yellow\"}], \"formattedValue\": {\"mimeType\": \"application/table-schema+json\", \"value\": \" name deliciousness color\\nGranny Smith apple 0 red\\n Rainier cherry 9000 yellow\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"KqqvrqsF+Vjy6j1c54uzeEmZdOkQPtBVYoeJQNDXj+g=\", \"id\": \"85e105398e2446bf8a7bf8ffa4979b10\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"df\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6e7bda28-3c6a7a75ec0c4d0d14412c51_21572_25", + "username": "username", + "session": "6e7bda28-3c6a7a75ec0c4d0d14412c51", + "date": "2023-03-22T05:23:03.239026Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "81abe68f-f93a-4b72-bbb3-fa5577b3fb4e", + "username": "dotnet_kernel", + "session": "bfec9337-b178-40b7-90dc-cfd6a8d923a1", + "date": "2023-03-22T05:23:03.2351904Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_single_df_on_kernel.ir.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_single_df_on_kernel.ir.json new file mode 100644 index 0000000000..2e4718dfee --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_single_df_on_kernel.ir.json @@ -0,0 +1,415 @@ +[ + { + "header": { + "msg_id": "62ed0274-c872-11ed-befe-611761a3c07d", + "username": "dotnet_kernel", + "session": "dce60c38-2e8d-4d93-a1bd-32058e377459", + "date": "2023-03-22T05:28:33.014537Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "683f6834-78a0-431c-a1c6-07a3c9031275", + "username": "dotnet_kernel", + "session": "dce60c38-2e8d-4d93-a1bd-32058e377459", + "date": "2023-03-22T05:28:32.9619996Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "62f10e5a-c872-11ed-befe-611761a3c07d", + "username": "dotnet_kernel", + "session": "dce60c38-2e8d-4d93-a1bd-32058e377459", + "date": "2023-03-22T05:28:33.016539Z", + "msg_type": "kernel_info_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "683f6834-78a0-431c-a1c6-07a3c9031275", + "username": "dotnet_kernel", + "session": "dce60c38-2e8d-4d93-a1bd-32058e377459", + "date": "2023-03-22T05:28:32.9619996Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.0", + "implementation": "IRkernel", + "implementation_version": "0.8.15", + "language_info": { + "name": "R", + "version": "3.6.1", + "mimetype": "text/x-r-source", + "file_extension": ".r", + "pygments_lexer": "r", + "codemirror_mode": "r" + }, + "banner": "R version 3.6.1 (2019-07-05)", + "status": "ok", + "help_links": [] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "62f15c8e-c872-11ed-befe-611761a3c07d", + "username": "dotnet_kernel", + "session": "dce60c38-2e8d-4d93-a1bd-32058e377459", + "date": "2023-03-22T05:28:33.017540Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "683f6834-78a0-431c-a1c6-07a3c9031275", + "username": "dotnet_kernel", + "session": "dce60c38-2e8d-4d93-a1bd-32058e377459", + "date": "2023-03-22T05:28:32.9619996Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "62f22088-c872-11ed-befe-611761a3c07d", + "username": "dotnet_kernel", + "session": "f9cc4a93-48c5-4532-9886-96668edddb61", + "date": "2023-03-22T05:28:33.022555Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "7f8f4f7f-0ac9-4e1a-aa2f-ddba9a6ea90a", + "username": "dotnet_kernel", + "session": "f9cc4a93-48c5-4532-9886-96668edddb61", + "date": "2023-03-22T05:28:33.0190724Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "62f2478e-c872-11ed-befe-611761a3c07d", + "username": "dotnet_kernel", + "session": "f9cc4a93-48c5-4532-9886-96668edddb61", + "date": "2023-03-22T05:28:33.024554Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "7f8f4f7f-0ac9-4e1a-aa2f-ddba9a6ea90a", + "username": "dotnet_kernel", + "session": "f9cc4a93-48c5-4532-9886-96668edddb61", + "date": "2023-03-22T05:28:33.0190724Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "63022ae6-c872-11ed-befe-611761a3c07d", + "username": "dotnet_kernel", + "session": "f9cc4a93-48c5-4532-9886-96668edddb61", + "date": "2023-03-22T05:28:33.127683Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "7f8f4f7f-0ac9-4e1a-aa2f-ddba9a6ea90a", + "username": "dotnet_kernel", + "session": "f9cc4a93-48c5-4532-9886-96668edddb61", + "date": "2023-03-22T05:28:33.0190724Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6302521e-c872-11ed-befe-611761a3c07d", + "username": "dotnet_kernel", + "session": "f9cc4a93-48c5-4532-9886-96668edddb61", + "date": "2023-03-22T05:28:33.129193Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "7f8f4f7f-0ac9-4e1a-aa2f-ddba9a6ea90a", + "username": "dotnet_kernel", + "session": "f9cc4a93-48c5-4532-9886-96668edddb61", + "date": "2023-03-22T05:28:33.0190724Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "630302a4-c872-11ed-befe-611761a3c07d", + "username": "dotnet_kernel", + "session": "5c3183a7-efd5-4bb6-a53d-1aafe6db6a92", + "date": "2023-03-22T05:28:33.133202Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "65b56faf-d262-41ac-838c-ded28c71eeba", + "username": "dotnet_kernel", + "session": "5c3183a7-efd5-4bb6-a53d-1aafe6db6a92", + "date": "2023-03-22T05:28:33.1305017Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "63039ee4-c872-11ed-befe-611761a3c07d", + "username": "dotnet_kernel", + "session": "5c3183a7-efd5-4bb6-a53d-1aafe6db6a92", + "date": "2023-03-22T05:28:33.137201Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "65b56faf-d262-41ac-838c-ded28c71eeba", + "username": "dotnet_kernel", + "session": "5c3183a7-efd5-4bb6-a53d-1aafe6db6a92", + "date": "2023-03-22T05:28:33.1305017Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "df8be862-97eb-46bc-96f0-dac06a422ebc", + "data": { + "commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6303c5ea-c872-11ed-befe-611761a3c07d", + "username": "dotnet_kernel", + "session": "5c3183a7-efd5-4bb6-a53d-1aafe6db6a92", + "date": "2023-03-22T05:28:33.138202Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "65b56faf-d262-41ac-838c-ded28c71eeba", + "username": "dotnet_kernel", + "session": "5c3183a7-efd5-4bb6-a53d-1aafe6db6a92", + "date": "2023-03-22T05:28:33.1305017Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6304fe88-c872-11ed-befe-611761a3c07d", + "username": "dotnet_kernel", + "session": "54f6f6e4-7c26-45ee-8a37-96d70dc8f45d", + "date": "2023-03-22T05:28:33.146213Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "7ab7c1e5-1225-49c5-891d-16f75d687562", + "username": "dotnet_kernel", + "session": "54f6f6e4-7c26-45ee-8a37-96d70dc8f45d", + "date": "2023-03-22T05:28:33.1426483Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "630847a0-c872-11ed-befe-611761a3c07d", + "username": "dotnet_kernel", + "session": "54f6f6e4-7c26-45ee-8a37-96d70dc8f45d", + "date": "2023-03-22T05:28:33.168736Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "7ab7c1e5-1225-49c5-891d-16f75d687562", + "username": "dotnet_kernel", + "session": "54f6f6e4-7c26-45ee-8a37-96d70dc8f45d", + "date": "2023-03-22T05:28:33.1426483Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "df8be862-97eb-46bc-96f0-dac06a422ebc", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "63086eb0-c872-11ed-befe-611761a3c07d", + "username": "dotnet_kernel", + "session": "54f6f6e4-7c26-45ee-8a37-96d70dc8f45d", + "date": "2023-03-22T05:28:33.169737Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "7ab7c1e5-1225-49c5-891d-16f75d687562", + "username": "dotnet_kernel", + "session": "54f6f6e4-7c26-45ee-8a37-96d70dc8f45d", + "date": "2023-03-22T05:28:33.1426483Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "63090af0-c872-11ed-befe-611761a3c07d", + "username": "dotnet_kernel", + "session": "778bccaf-5ae2-45a0-8112-4cfa402f51cc", + "date": "2023-03-22T05:28:33.172736Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2b7c46d1-7d36-480a-9fef-34c87077b079", + "username": "dotnet_kernel", + "session": "778bccaf-5ae2-45a0-8112-4cfa402f51cc", + "date": "2023-03-22T05:28:33.1707788Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "63119904-c872-11ed-befe-611761a3c07d", + "username": "dotnet_kernel", + "session": "778bccaf-5ae2-45a0-8112-4cfa402f51cc", + "date": "2023-03-22T05:28:33.228802Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2b7c46d1-7d36-480a-9fef-34c87077b079", + "username": "dotnet_kernel", + "session": "778bccaf-5ae2-45a0-8112-4cfa402f51cc", + "date": "2023-03-22T05:28:33.1707788Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "df8be862-97eb-46bc-96f0-dac06a422ebc", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"df\",\"value\":[{\"name\":\"Granny Smith apple\",\"deliciousness\":0,\"color\":\"red\"},{\"name\":\"Rainier cherry\",\"deliciousness\":9000,\"color\":\"yellow\"}],\"formattedValue\":{\"mimeType\":\"application/table-schema+json\",\"value\":\"[{\\\"name\\\":\\\"Granny Smith apple\\\",\\\"deliciousness\\\":0,\\\"color\\\":\\\"red\\\"},{\\\"name\\\":\\\"Rainier cherry\\\",\\\"deliciousness\\\":9000,\\\"color\\\":\\\"yellow\\\"}]\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"rCUS5/qhTdK/40aNYJj3RnJQ+T+V+oOcE9STiJTQwZ8=\",\"id\":\"f635749456f54541a4e8284ae8a187d8\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"df\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "6311c014-c872-11ed-befe-611761a3c07d", + "username": "dotnet_kernel", + "session": "778bccaf-5ae2-45a0-8112-4cfa402f51cc", + "date": "2023-03-22T05:28:33.229803Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "2b7c46d1-7d36-480a-9fef-34c87077b079", + "username": "dotnet_kernel", + "session": "778bccaf-5ae2-45a0-8112-4cfa402f51cc", + "date": "2023-03-22T05:28:33.1707788Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_single_df_on_kernel.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_single_df_on_kernel.python3.json new file mode 100644 index 0000000000..686df5919f --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_handle_setting_single_df_on_kernel.python3.json @@ -0,0 +1,453 @@ +[ + { + "header": { + "msg_id": "319bc77b-87855daeb115d13f6bb3042b_20572_10", + "username": "username", + "session": "319bc77b-87855daeb115d13f6bb3042b", + "date": "2023-03-22T05:28:30.700187Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "99f43496-3f37-48e8-8f88-ab7d5f3771c6", + "username": "dotnet_kernel", + "session": "15f44c99-7849-4a1a-99f3-4bae0270c6cf", + "date": "2023-03-22T05:28:30.6840421Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "319bc77b-87855daeb115d13f6bb3042b_20572_12", + "username": "username", + "session": "319bc77b-87855daeb115d13f6bb3042b", + "date": "2023-03-22T05:28:30.701185Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "99f43496-3f37-48e8-8f88-ab7d5f3771c6", + "username": "dotnet_kernel", + "session": "15f44c99-7849-4a1a-99f3-4bae0270c6cf", + "date": "2023-03-22T05:28:30.6840421Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "319bc77b-87855daeb115d13f6bb3042b_20572_11", + "username": "username", + "session": "319bc77b-87855daeb115d13f6bb3042b", + "date": "2023-03-22T05:28:30.700187Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "99f43496-3f37-48e8-8f88-ab7d5f3771c6", + "username": "dotnet_kernel", + "session": "15f44c99-7849-4a1a-99f3-4bae0270c6cf", + "date": "2023-03-22T05:28:30.6840421Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "319bc77b-87855daeb115d13f6bb3042b_20572_13", + "username": "username", + "session": "319bc77b-87855daeb115d13f6bb3042b", + "date": "2023-03-22T05:28:30.723714Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "fec53a79-c77e-4ec7-ad48-8b2320e4a9ab", + "username": "dotnet_kernel", + "session": "326bf6f3-d932-4f63-8cd6-5e80e8c500f3", + "date": "2023-03-22T05:28:30.7165750Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "319bc77b-87855daeb115d13f6bb3042b_20572_14", + "username": "username", + "session": "319bc77b-87855daeb115d13f6bb3042b", + "date": "2023-03-22T05:28:30.723714Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "fec53a79-c77e-4ec7-ad48-8b2320e4a9ab", + "username": "dotnet_kernel", + "session": "326bf6f3-d932-4f63-8cd6-5e80e8c500f3", + "date": "2023-03-22T05:28:30.7165750Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "319bc77b-87855daeb115d13f6bb3042b_20572_15", + "username": "username", + "session": "319bc77b-87855daeb115d13f6bb3042b", + "date": "2023-03-22T05:28:30.765024Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "fec53a79-c77e-4ec7-ad48-8b2320e4a9ab", + "username": "dotnet_kernel", + "session": "326bf6f3-d932-4f63-8cd6-5e80e8c500f3", + "date": "2023-03-22T05:28:30.7165750Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-22T05:28:30.723714Z", + "dependencies_met": true, + "engine": "e77eb370-bb48-4d74-9703-fdb7e0cb1e84", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "319bc77b-87855daeb115d13f6bb3042b_20572_16", + "username": "username", + "session": "319bc77b-87855daeb115d13f6bb3042b", + "date": "2023-03-22T05:28:30.765024Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "fec53a79-c77e-4ec7-ad48-8b2320e4a9ab", + "username": "dotnet_kernel", + "session": "326bf6f3-d932-4f63-8cd6-5e80e8c500f3", + "date": "2023-03-22T05:28:30.7165750Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "319bc77b-87855daeb115d13f6bb3042b_20572_17", + "username": "username", + "session": "319bc77b-87855daeb115d13f6bb3042b", + "date": "2023-03-22T05:28:30.775071Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "dfde242f-acd9-40d1-8dd7-629b75f878b2", + "username": "dotnet_kernel", + "session": "15e98147-2479-4d6c-8d33-a589c41cef16", + "date": "2023-03-22T05:28:30.7736677Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "319bc77b-87855daeb115d13f6bb3042b_20572_18", + "username": "username", + "session": "319bc77b-87855daeb115d13f6bb3042b", + "date": "2023-03-22T05:28:30.776073Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "dfde242f-acd9-40d1-8dd7-629b75f878b2", + "username": "dotnet_kernel", + "session": "15e98147-2479-4d6c-8d33-a589c41cef16", + "date": "2023-03-22T05:28:30.7736677Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "196608e6-e55f-4194-91ab-7232033b3af9", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "319bc77b-87855daeb115d13f6bb3042b_20572_19", + "username": "username", + "session": "319bc77b-87855daeb115d13f6bb3042b", + "date": "2023-03-22T05:28:30.777073Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "dfde242f-acd9-40d1-8dd7-629b75f878b2", + "username": "dotnet_kernel", + "session": "15e98147-2479-4d6c-8d33-a589c41cef16", + "date": "2023-03-22T05:28:30.7736677Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "319bc77b-87855daeb115d13f6bb3042b_20572_20", + "username": "username", + "session": "319bc77b-87855daeb115d13f6bb3042b", + "date": "2023-03-22T05:28:30.855647Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "edcbbe92-de1d-4557-b056-592b8b56f373", + "username": "dotnet_kernel", + "session": "44c2f406-3cba-4e8d-b884-459281ef9565", + "date": "2023-03-22T05:28:30.8536046Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "319bc77b-87855daeb115d13f6bb3042b_20572_21", + "username": "username", + "session": "319bc77b-87855daeb115d13f6bb3042b", + "date": "2023-03-22T05:28:31.325709Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "edcbbe92-de1d-4557-b056-592b8b56f373", + "username": "dotnet_kernel", + "session": "44c2f406-3cba-4e8d-b884-459281ef9565", + "date": "2023-03-22T05:28:30.8536046Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "196608e6-e55f-4194-91ab-7232033b3af9", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "319bc77b-87855daeb115d13f6bb3042b_20572_22", + "username": "username", + "session": "319bc77b-87855daeb115d13f6bb3042b", + "date": "2023-03-22T05:28:31.326708Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "edcbbe92-de1d-4557-b056-592b8b56f373", + "username": "dotnet_kernel", + "session": "44c2f406-3cba-4e8d-b884-459281ef9565", + "date": "2023-03-22T05:28:30.8536046Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "319bc77b-87855daeb115d13f6bb3042b_20572_23", + "username": "username", + "session": "319bc77b-87855daeb115d13f6bb3042b", + "date": "2023-03-22T05:28:31.336715Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a9434f96-1241-4fdb-9dd5-f67c7bb90fe1", + "username": "dotnet_kernel", + "session": "bf48e3f0-7456-4459-8290-dc7a90683474", + "date": "2023-03-22T05:28:31.3356686Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "319bc77b-87855daeb115d13f6bb3042b_20572_24", + "username": "username", + "session": "319bc77b-87855daeb115d13f6bb3042b", + "date": "2023-03-22T05:28:31.338716Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a9434f96-1241-4fdb-9dd5-f67c7bb90fe1", + "username": "dotnet_kernel", + "session": "bf48e3f0-7456-4459-8290-dc7a90683474", + "date": "2023-03-22T05:28:31.3356686Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "196608e6-e55f-4194-91ab-7232033b3af9", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"df\", \"value\": [{\"name\": \"Granny Smith apple\", \"deliciousness\": 0, \"color\": \"red\"}, {\"name\": \"Rainier cherry\", \"deliciousness\": 9000, \"color\": \"yellow\"}], \"formattedValue\": {\"mimeType\": \"application/table-schema+json\", \"value\": \" name deliciousness color\\nGranny Smith apple 0 red\\n Rainier cherry 9000 yellow\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"EdPUZoA4jq/CHgDLG4Rl2qdoBHI1pHUly4OF9pPNp+E=\", \"id\": \"74bb865bb7724c04994d2dc6f449b2aa\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"df\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "319bc77b-87855daeb115d13f6bb3042b_20572_25", + "username": "username", + "session": "319bc77b-87855daeb115d13f6bb3042b", + "date": "2023-03-22T05:28:31.339713Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a9434f96-1241-4fdb-9dd5-f67c7bb90fe1", + "username": "dotnet_kernel", + "session": "bf48e3f0-7456-4459-8290-dc7a90683474", + "date": "2023-03-22T05:28:31.3356686Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_request_value_infos_for_shared_and_kernel_variables.ir.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_request_value_infos_for_shared_and_kernel_variables.ir.json new file mode 100644 index 0000000000..4d2a6a2980 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_request_value_infos_for_shared_and_kernel_variables.ir.json @@ -0,0 +1,591 @@ +[ + { + "header": { + "msg_id": "0a156a5c-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "fa6a3cc0-ab97-4cae-b284-97bcf65fbbf8", + "date": "2023-03-21T23:56:47.088035Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3a1c7c9d-3d59-40d1-8d9c-58d974f6dfc5", + "username": "dotnet_kernel", + "session": "fa6a3cc0-ab97-4cae-b284-97bcf65fbbf8", + "date": "2023-03-21T23:56:47.0223099Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a159162-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "fa6a3cc0-ab97-4cae-b284-97bcf65fbbf8", + "date": "2023-03-21T23:56:47.090035Z", + "msg_type": "kernel_info_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3a1c7c9d-3d59-40d1-8d9c-58d974f6dfc5", + "username": "dotnet_kernel", + "session": "fa6a3cc0-ab97-4cae-b284-97bcf65fbbf8", + "date": "2023-03-21T23:56:47.0223099Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.0", + "implementation": "IRkernel", + "implementation_version": "0.8.15", + "language_info": { + "name": "R", + "version": "3.6.1", + "mimetype": "text/x-r-source", + "file_extension": ".r", + "pygments_lexer": "r", + "codemirror_mode": "r" + }, + "banner": "R version 3.6.1 (2019-07-05)", + "status": "ok", + "help_links": [] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a15df78-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "fa6a3cc0-ab97-4cae-b284-97bcf65fbbf8", + "date": "2023-03-21T23:56:47.091036Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3a1c7c9d-3d59-40d1-8d9c-58d974f6dfc5", + "username": "dotnet_kernel", + "session": "fa6a3cc0-ab97-4cae-b284-97bcf65fbbf8", + "date": "2023-03-21T23:56:47.0223099Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a19011c-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "bc6b9f62-0e24-4176-a3e7-b36463862f41", + "date": "2023-03-21T23:56:47.112559Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "b3eead97-3461-4f07-9a81-486145d6ea45", + "username": "dotnet_kernel", + "session": "bc6b9f62-0e24-4176-a3e7-b36463862f41", + "date": "2023-03-21T23:56:47.0915983Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a197656-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "bc6b9f62-0e24-4176-a3e7-b36463862f41", + "date": "2023-03-21T23:56:47.115557Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "b3eead97-3461-4f07-9a81-486145d6ea45", + "username": "dotnet_kernel", + "session": "bc6b9f62-0e24-4176-a3e7-b36463862f41", + "date": "2023-03-21T23:56:47.0915983Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a2acde8-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "bc6b9f62-0e24-4176-a3e7-b36463862f41", + "date": "2023-03-21T23:56:47.228212Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "b3eead97-3461-4f07-9a81-486145d6ea45", + "username": "dotnet_kernel", + "session": "bc6b9f62-0e24-4176-a3e7-b36463862f41", + "date": "2023-03-21T23:56:47.0915983Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a2af50c-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "bc6b9f62-0e24-4176-a3e7-b36463862f41", + "date": "2023-03-21T23:56:47.229212Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "b3eead97-3461-4f07-9a81-486145d6ea45", + "username": "dotnet_kernel", + "session": "bc6b9f62-0e24-4176-a3e7-b36463862f41", + "date": "2023-03-21T23:56:47.0915983Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a2bb848-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "18dc5c6a-08d4-49a1-a3fa-3bd9d5439494", + "date": "2023-03-21T23:56:47.233211Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3bdc61ca-8aa8-4457-ad02-c78207a72702", + "username": "dotnet_kernel", + "session": "18dc5c6a-08d4-49a1-a3fa-3bd9d5439494", + "date": "2023-03-21T23:56:47.2298628Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a2c547e-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "18dc5c6a-08d4-49a1-a3fa-3bd9d5439494", + "date": "2023-03-21T23:56:47.238214Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3bdc61ca-8aa8-4457-ad02-c78207a72702", + "username": "dotnet_kernel", + "session": "18dc5c6a-08d4-49a1-a3fa-3bd9d5439494", + "date": "2023-03-21T23:56:47.2298628Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "2b45dbf7-6446-46eb-8c3d-111d8e3a5f5e", + "data": { + "commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a2c7b8e-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "18dc5c6a-08d4-49a1-a3fa-3bd9d5439494", + "date": "2023-03-21T23:56:47.239214Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3bdc61ca-8aa8-4457-ad02-c78207a72702", + "username": "dotnet_kernel", + "session": "18dc5c6a-08d4-49a1-a3fa-3bd9d5439494", + "date": "2023-03-21T23:56:47.2298628Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a2d3f9c-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "54c43f94-cccb-4165-894b-062831638278", + "date": "2023-03-21T23:56:47.243231Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d202f529-4101-4a13-9c0d-f3ea178fc5d3", + "username": "dotnet_kernel", + "session": "54c43f94-cccb-4165-894b-062831638278", + "date": "2023-03-21T23:56:47.2409616Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a30879c-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "54c43f94-cccb-4165-894b-062831638278", + "date": "2023-03-21T23:56:47.265740Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d202f529-4101-4a13-9c0d-f3ea178fc5d3", + "username": "dotnet_kernel", + "session": "54c43f94-cccb-4165-894b-062831638278", + "date": "2023-03-21T23:56:47.2409616Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "a <- 12345", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a3283a8-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "54c43f94-cccb-4165-894b-062831638278", + "date": "2023-03-21T23:56:47.278741Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d202f529-4101-4a13-9c0d-f3ea178fc5d3", + "username": "dotnet_kernel", + "session": "54c43f94-cccb-4165-894b-062831638278", + "date": "2023-03-21T23:56:47.2409616Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a32d1d2-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "54c43f94-cccb-4165-894b-062831638278", + "date": "2023-03-21T23:56:47.279743Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d202f529-4101-4a13-9c0d-f3ea178fc5d3", + "username": "dotnet_kernel", + "session": "54c43f94-cccb-4165-894b-062831638278", + "date": "2023-03-21T23:56:47.2409616Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a33473e-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "bfe4c886-3677-4c6b-98dd-c82a9481274b", + "date": "2023-03-21T23:56:47.283746Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "de672a93-2ba1-4809-b4b7-1444fd8c6dc3", + "username": "dotnet_kernel", + "session": "bfe4c886-3677-4c6b-98dd-c82a9481274b", + "date": "2023-03-21T23:56:47.2809049Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a364150-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "bfe4c886-3677-4c6b-98dd-c82a9481274b", + "date": "2023-03-21T23:56:47.303257Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "de672a93-2ba1-4809-b4b7-1444fd8c6dc3", + "username": "dotnet_kernel", + "session": "bfe4c886-3677-4c6b-98dd-c82a9481274b", + "date": "2023-03-21T23:56:47.2809049Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "2b45dbf7-6446-46eb-8c3d-111d8e3a5f5e", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a368f7a-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "bfe4c886-3677-4c6b-98dd-c82a9481274b", + "date": "2023-03-21T23:56:47.304258Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "de672a93-2ba1-4809-b4b7-1444fd8c6dc3", + "username": "dotnet_kernel", + "session": "bfe4c886-3677-4c6b-98dd-c82a9481274b", + "date": "2023-03-21T23:56:47.2809049Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a37050e-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "e0db4d9c-106c-4055-b082-7716decb9cae", + "date": "2023-03-21T23:56:47.308264Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "f86f89aa-3a97-4f34-94a6-e157db62cad4", + "username": "dotnet_kernel", + "session": "e0db4d9c-106c-4055-b082-7716decb9cae", + "date": "2023-03-21T23:56:47.3047619Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a39b10a-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "e0db4d9c-106c-4055-b082-7716decb9cae", + "date": "2023-03-21T23:56:47.324777Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "f86f89aa-3a97-4f34-94a6-e157db62cad4", + "username": "dotnet_kernel", + "session": "e0db4d9c-106c-4055-b082-7716decb9cae", + "date": "2023-03-21T23:56:47.3047619Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "2b45dbf7-6446-46eb-8c3d-111d8e3a5f5e", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a39d81a-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "e0db4d9c-106c-4055-b082-7716decb9cae", + "date": "2023-03-21T23:56:47.325778Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "f86f89aa-3a97-4f34-94a6-e157db62cad4", + "username": "dotnet_kernel", + "session": "e0db4d9c-106c-4055-b082-7716decb9cae", + "date": "2023-03-21T23:56:47.3047619Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a3a4d68-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "286df63a-93e3-428e-88eb-224c93620531", + "date": "2023-03-21T23:56:47.328778Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "62038628-03bd-433c-abfb-a53be66f7742", + "username": "dotnet_kernel", + "session": "286df63a-93e3-428e-88eb-224c93620531", + "date": "2023-03-21T23:56:47.3265787Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a3c7066-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "286df63a-93e3-428e-88eb-224c93620531", + "date": "2023-03-21T23:56:47.343787Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "62038628-03bd-433c-abfb-a53be66f7742", + "username": "dotnet_kernel", + "session": "286df63a-93e3-428e-88eb-224c93620531", + "date": "2023-03-21T23:56:47.3265787Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "2b45dbf7-6446-46eb-8c3d-111d8e3a5f5e", + "data": { + "commandOrEvent": "{\"event\":{\"valueInfos\":[{\"name\":\"a\",\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"12345\"},\"typeName\":\"double\"},{\"name\":\"b\",\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"6789\"},\"typeName\":\"integer\"},{\"name\":\"df\",\"formattedValue\":{\"mimeType\":\"application/table-schema+json\",\"value\":\"[{\\\"name\\\":\\\"Granny Smith apple\\\",\\\"deliciousness\\\":0,\\\"color\\\":\\\"red\\\"},{\\\"name\\\":\\\"Rainier cherry\\\",\\\"deliciousness\\\":9000,\\\"color\\\":\\\"yellow\\\"}]\"},\"typeName\":\"data.frame\"}]},\"eventType\":\"ValueInfosProduced\",\"command\":{\"token\":\"O6rdFhO1S2DPt61g137KtdEted7H2CSZwWO1kdH6t3M=\",\"id\":\"e61585c72300431f9f304ec2abc23489\",\"commandType\":\"RequestValueInfos\",\"command\":{\"mimeType\":\"text/plain+summary\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "0a3c9776-c844-11ed-9f26-275fcd7e285e", + "username": "dotnet_kernel", + "session": "286df63a-93e3-428e-88eb-224c93620531", + "date": "2023-03-21T23:56:47.343787Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "62038628-03bd-433c-abfb-a53be66f7742", + "username": "dotnet_kernel", + "session": "286df63a-93e3-428e-88eb-224c93620531", + "date": "2023-03-21T23:56:47.3265787Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_request_value_infos_for_shared_and_kernel_variables.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_request_value_infos_for_shared_and_kernel_variables.python3.json new file mode 100644 index 0000000000..6b1052837c --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_request_value_infos_for_shared_and_kernel_variables.python3.json @@ -0,0 +1,634 @@ +[ + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_10", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.542778Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b6a6fbe0-1c28-4a89-8d3d-d746972dbe2b", + "username": "dotnet_kernel", + "session": "efa755ae-73f0-430e-9d39-50219e0b8353", + "date": "2023-03-21T23:56:45.5255712Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_11", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.543777Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b6a6fbe0-1c28-4a89-8d3d-d746972dbe2b", + "username": "dotnet_kernel", + "session": "efa755ae-73f0-430e-9d39-50219e0b8353", + "date": "2023-03-21T23:56:45.5255712Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_12", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.544774Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b6a6fbe0-1c28-4a89-8d3d-d746972dbe2b", + "username": "dotnet_kernel", + "session": "efa755ae-73f0-430e-9d39-50219e0b8353", + "date": "2023-03-21T23:56:45.5255712Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_13", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.549776Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9f1bf5c4-634b-4cdb-bf5f-d969d03ad8ea", + "username": "dotnet_kernel", + "session": "f02de828-9f88-43e7-af97-481bce5e9061", + "date": "2023-03-21T23:56:45.5474704Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_14", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.549776Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9f1bf5c4-634b-4cdb-bf5f-d969d03ad8ea", + "username": "dotnet_kernel", + "session": "f02de828-9f88-43e7-af97-481bce5e9061", + "date": "2023-03-21T23:56:45.5474704Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_16", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.581306Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9f1bf5c4-634b-4cdb-bf5f-d969d03ad8ea", + "username": "dotnet_kernel", + "session": "f02de828-9f88-43e7-af97-481bce5e9061", + "date": "2023-03-21T23:56:45.5474704Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_15", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.581306Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9f1bf5c4-634b-4cdb-bf5f-d969d03ad8ea", + "username": "dotnet_kernel", + "session": "f02de828-9f88-43e7-af97-481bce5e9061", + "date": "2023-03-21T23:56:45.5474704Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:56:45.549776Z", + "dependencies_met": true, + "engine": "6f2bf6eb-a79f-4b2a-865a-206320794ba2", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_17", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.585306Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "45616ef3-7ee0-4148-a96d-f2efe96d2853", + "username": "dotnet_kernel", + "session": "dca1f25d-fadc-40cf-90c7-30fb7084e246", + "date": "2023-03-21T23:56:45.5840543Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_18", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.586320Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "45616ef3-7ee0-4148-a96d-f2efe96d2853", + "username": "dotnet_kernel", + "session": "dca1f25d-fadc-40cf-90c7-30fb7084e246", + "date": "2023-03-21T23:56:45.5840543Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "1c21b789-58c2-48f1-8fc9-fd3c5b8bed7b", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_19", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.587314Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "45616ef3-7ee0-4148-a96d-f2efe96d2853", + "username": "dotnet_kernel", + "session": "dca1f25d-fadc-40cf-90c7-30fb7084e246", + "date": "2023-03-21T23:56:45.5840543Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_20", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.591316Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "bae5b417-8c51-4be7-841d-2f06c17bf251", + "username": "dotnet_kernel", + "session": "0e12ad8d-a122-4239-81b7-9973a0bd4c52", + "date": "2023-03-21T23:56:45.5903321Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_21", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.591316Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "bae5b417-8c51-4be7-841d-2f06c17bf251", + "username": "dotnet_kernel", + "session": "0e12ad8d-a122-4239-81b7-9973a0bd4c52", + "date": "2023-03-21T23:56:45.5903321Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "a = 12345", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_23", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.597311Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "bae5b417-8c51-4be7-841d-2f06c17bf251", + "username": "dotnet_kernel", + "session": "0e12ad8d-a122-4239-81b7-9973a0bd4c52", + "date": "2023-03-21T23:56:45.5903321Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_22", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.597311Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "bae5b417-8c51-4be7-841d-2f06c17bf251", + "username": "dotnet_kernel", + "session": "0e12ad8d-a122-4239-81b7-9973a0bd4c52", + "date": "2023-03-21T23:56:45.5903321Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:56:45.591316Z", + "dependencies_met": true, + "engine": "6f2bf6eb-a79f-4b2a-865a-206320794ba2", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_24", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.600831Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "ae3cbe13-e56d-4740-a1b4-f79d46384359", + "username": "dotnet_kernel", + "session": "19d08d64-a49a-4e94-ba07-ca42fc4ba34b", + "date": "2023-03-21T23:56:45.5999059Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_25", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.601845Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "ae3cbe13-e56d-4740-a1b4-f79d46384359", + "username": "dotnet_kernel", + "session": "19d08d64-a49a-4e94-ba07-ca42fc4ba34b", + "date": "2023-03-21T23:56:45.5999059Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "1c21b789-58c2-48f1-8fc9-fd3c5b8bed7b", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_26", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.601845Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "ae3cbe13-e56d-4740-a1b4-f79d46384359", + "username": "dotnet_kernel", + "session": "19d08d64-a49a-4e94-ba07-ca42fc4ba34b", + "date": "2023-03-21T23:56:45.5999059Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_27", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:45.604841Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "1688d7e5-8cc7-4df2-8e59-43ed5971025b", + "username": "dotnet_kernel", + "session": "1efb686f-c9d4-4459-a71c-4aeb1523db82", + "date": "2023-03-21T23:56:45.6037065Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_28", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:46.069197Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "1688d7e5-8cc7-4df2-8e59-43ed5971025b", + "username": "dotnet_kernel", + "session": "1efb686f-c9d4-4459-a71c-4aeb1523db82", + "date": "2023-03-21T23:56:45.6037065Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "1c21b789-58c2-48f1-8fc9-fd3c5b8bed7b", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_29", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:46.070208Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "1688d7e5-8cc7-4df2-8e59-43ed5971025b", + "username": "dotnet_kernel", + "session": "1efb686f-c9d4-4459-a71c-4aeb1523db82", + "date": "2023-03-21T23:56:45.6037065Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_30", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:46.076206Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "65889611-3daa-43d9-9b6d-ce89a1b468a4", + "username": "dotnet_kernel", + "session": "3d08dc42-e896-4fa0-88be-9e69d16005b0", + "date": "2023-03-21T23:56:46.0748451Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_31", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:46.078206Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "65889611-3daa-43d9-9b6d-ce89a1b468a4", + "username": "dotnet_kernel", + "session": "3d08dc42-e896-4fa0-88be-9e69d16005b0", + "date": "2023-03-21T23:56:46.0748451Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "1c21b789-58c2-48f1-8fc9-fd3c5b8bed7b", + "data": { + "commandOrEvent": "{\"event\": {\"valueInfos\": [{\"name\": \"a\", \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"12345\"}, \"typeName\": \"\"}, {\"name\": \"b\", \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"6789\"}, \"typeName\": \"\"}, {\"name\": \"df\", \"formattedValue\": {\"mimeType\": \"application/table-schema+json\", \"value\": \" name deliciousness color\\nGranny Smith apple 0 red\\n Rainier cherry 9000 yellow\"}, \"typeName\": \"\"}]}, \"eventType\": \"ValueInfosProduced\", \"command\": {\"token\": \"ycbYQ4OqzXfSA8qYapVondpL/Tr3bKfTXxvWZ8Amu8M=\", \"id\": \"e1f73c4d3d104e2eae02d588315cff88\", \"commandType\": \"RequestValueInfos\", \"command\": {\"mimeType\": \"text/plain+summary\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "83614ffe-d079ea44a0225bc36f6d4e61_2640_32", + "username": "username", + "session": "83614ffe-d079ea44a0225bc36f6d4e61", + "date": "2023-03-21T23:56:46.079203Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "65889611-3daa-43d9-9b6d-ce89a1b468a4", + "username": "dotnet_kernel", + "session": "3d08dc42-e896-4fa0-88be-9e69d16005b0", + "date": "2023-03-21T23:56:46.0748451Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_share_dataframe_to_from_kernel.ir.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_share_dataframe_to_from_kernel.ir.json new file mode 100644 index 0000000000..a2241e2495 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_share_dataframe_to_from_kernel.ir.json @@ -0,0 +1,698 @@ +[ + { + "header": { + "msg_id": "4c302ae0-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "8c55f071-cc8a-47f5-97ef-6cc20d4bc5f2", + "date": "2023-03-22T06:25:10.842901Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e6ae07cc-8684-49b4-b1d8-1bf7e6a84de4", + "username": "dotnet_kernel", + "session": "8c55f071-cc8a-47f5-97ef-6cc20d4bc5f2", + "date": "2023-03-22T06:25:10.7869415Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c3484d2-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "8c55f071-cc8a-47f5-97ef-6cc20d4bc5f2", + "date": "2023-03-22T06:25:10.844904Z", + "msg_type": "kernel_info_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e6ae07cc-8684-49b4-b1d8-1bf7e6a84de4", + "username": "dotnet_kernel", + "session": "8c55f071-cc8a-47f5-97ef-6cc20d4bc5f2", + "date": "2023-03-22T06:25:10.7869415Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.0", + "implementation": "IRkernel", + "implementation_version": "0.8.15", + "language_info": { + "name": "R", + "version": "3.6.1", + "mimetype": "text/x-r-source", + "file_extension": ".r", + "pygments_lexer": "r", + "codemirror_mode": "r" + }, + "banner": "R version 3.6.1 (2019-07-05)", + "status": "ok", + "help_links": [] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c34d310-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "8c55f071-cc8a-47f5-97ef-6cc20d4bc5f2", + "date": "2023-03-22T06:25:10.845904Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e6ae07cc-8684-49b4-b1d8-1bf7e6a84de4", + "username": "dotnet_kernel", + "session": "8c55f071-cc8a-47f5-97ef-6cc20d4bc5f2", + "date": "2023-03-22T06:25:10.7869415Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c35484a-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "046b82fa-0fef-453d-9b44-b9738a9b171f", + "date": "2023-03-22T06:25:10.848902Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "08eda955-53ef-4d54-84e5-78fc3bcb4745", + "username": "dotnet_kernel", + "session": "046b82fa-0fef-453d-9b44-b9738a9b171f", + "date": "2023-03-22T06:25:10.8471006Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c359688-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "046b82fa-0fef-453d-9b44-b9738a9b171f", + "date": "2023-03-22T06:25:10.851907Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "08eda955-53ef-4d54-84e5-78fc3bcb4745", + "username": "dotnet_kernel", + "session": "046b82fa-0fef-453d-9b44-b9738a9b171f", + "date": "2023-03-22T06:25:10.8471006Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c43a32c-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "046b82fa-0fef-453d-9b44-b9738a9b171f", + "date": "2023-03-22T06:25:10.943999Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "08eda955-53ef-4d54-84e5-78fc3bcb4745", + "username": "dotnet_kernel", + "session": "046b82fa-0fef-453d-9b44-b9738a9b171f", + "date": "2023-03-22T06:25:10.8471006Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c43f1f6-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "046b82fa-0fef-453d-9b44-b9738a9b171f", + "date": "2023-03-22T06:25:10.945003Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "08eda955-53ef-4d54-84e5-78fc3bcb4745", + "username": "dotnet_kernel", + "session": "046b82fa-0fef-453d-9b44-b9738a9b171f", + "date": "2023-03-22T06:25:10.8471006Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c4466fe-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "2fe7b7b1-85e6-40c0-b8cc-4f7033b4dd87", + "date": "2023-03-22T06:25:10.947996Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0f2ff3b7-6f99-4c82-b985-9e02f6ae3eec", + "username": "dotnet_kernel", + "session": "2fe7b7b1-85e6-40c0-b8cc-4f7033b4dd87", + "date": "2023-03-22T06:25:10.9456454Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c45033e-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "2fe7b7b1-85e6-40c0-b8cc-4f7033b4dd87", + "date": "2023-03-22T06:25:10.951995Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0f2ff3b7-6f99-4c82-b985-9e02f6ae3eec", + "username": "dotnet_kernel", + "session": "2fe7b7b1-85e6-40c0-b8cc-4f7033b4dd87", + "date": "2023-03-22T06:25:10.9456454Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "02a315d5-6725-445c-b4da-2d349e9c53ef", + "data": { + "commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c452a4e-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "2fe7b7b1-85e6-40c0-b8cc-4f7033b4dd87", + "date": "2023-03-22T06:25:10.952995Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0f2ff3b7-6f99-4c82-b985-9e02f6ae3eec", + "username": "dotnet_kernel", + "session": "2fe7b7b1-85e6-40c0-b8cc-4f7033b4dd87", + "date": "2023-03-22T06:25:10.9456454Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c4b6e5e-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "d00e248b-fba5-4be7-8fed-dd24bcc48113", + "date": "2023-03-22T06:25:10.995063Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "487e741b-14eb-441c-a01b-8af069473893", + "username": "dotnet_kernel", + "session": "d00e248b-fba5-4be7-8fed-dd24bcc48113", + "date": "2023-03-22T06:25:10.9917910Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c4ea2e0-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "d00e248b-fba5-4be7-8fed-dd24bcc48113", + "date": "2023-03-22T06:25:11.015064Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "487e741b-14eb-441c-a01b-8af069473893", + "username": "dotnet_kernel", + "session": "d00e248b-fba5-4be7-8fed-dd24bcc48113", + "date": "2023-03-22T06:25:10.9917910Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "02a315d5-6725-445c-b4da-2d349e9c53ef", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c4ec9f0-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "d00e248b-fba5-4be7-8fed-dd24bcc48113", + "date": "2023-03-22T06:25:11.016066Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "487e741b-14eb-441c-a01b-8af069473893", + "username": "dotnet_kernel", + "session": "d00e248b-fba5-4be7-8fed-dd24bcc48113", + "date": "2023-03-22T06:25:10.9917910Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c4f3f34-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "d433b6e6-705c-407d-b501-06609541db03", + "date": "2023-03-22T06:25:11.019064Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "8b825b12-deb8-4354-98c6-2a02b79d0fad", + "username": "dotnet_kernel", + "session": "d433b6e6-705c-407d-b501-06609541db03", + "date": "2023-03-22T06:25:11.0165790Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c57cbf4-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "d433b6e6-705c-407d-b501-06609541db03", + "date": "2023-03-22T06:25:11.075098Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "8b825b12-deb8-4354-98c6-2a02b79d0fad", + "username": "dotnet_kernel", + "session": "d433b6e6-705c-407d-b501-06609541db03", + "date": "2023-03-22T06:25:11.0165790Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "02a315d5-6725-445c-b4da-2d349e9c53ef", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"df_in_kernel\",\"value\":[{\"name\":\"Granny Smith apple\",\"deliciousness\":0,\"color\":\"red\"},{\"name\":\"Rainier cherry\",\"deliciousness\":9000,\"color\":\"yellow\"}],\"formattedValue\":{\"mimeType\":\"application/table-schema+json\",\"value\":\"[{\\\"name\\\":\\\"Granny Smith apple\\\",\\\"deliciousness\\\":0,\\\"color\\\":\\\"red\\\"},{\\\"name\\\":\\\"Rainier cherry\\\",\\\"deliciousness\\\":9000,\\\"color\\\":\\\"yellow\\\"}]\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"engElPO0ZnJ4qG/zF8477zj8xVUWdDPwVL98wYAmEqc=\",\"id\":\"7f23c2d9dcf740009bb9f8c96188a099\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"df_in_kernel\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c57f304-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "d433b6e6-705c-407d-b501-06609541db03", + "date": "2023-03-22T06:25:11.076101Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "8b825b12-deb8-4354-98c6-2a02b79d0fad", + "username": "dotnet_kernel", + "session": "d433b6e6-705c-407d-b501-06609541db03", + "date": "2023-03-22T06:25:11.0165790Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c588f58-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "c7f699df-4332-4148-8965-d5ddc03d22f1", + "date": "2023-03-22T06:25:11.080101Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "169d66c8-2579-46fd-82e6-a0734fa6e44e", + "username": "dotnet_kernel", + "session": "c7f699df-4332-4148-8965-d5ddc03d22f1", + "date": "2023-03-22T06:25:11.0784729Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c598dfe-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "c7f699df-4332-4148-8965-d5ddc03d22f1", + "date": "2023-03-22T06:25:11.086619Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "169d66c8-2579-46fd-82e6-a0734fa6e44e", + "username": "dotnet_kernel", + "session": "c7f699df-4332-4148-8965-d5ddc03d22f1", + "date": "2023-03-22T06:25:11.0784729Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "02a315d5-6725-445c-b4da-2d349e9c53ef", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"df_in_kernel\",\"value\":[{\"name\":\"Granny Smith apple\",\"deliciousness\":0,\"color\":\"red\"},{\"name\":\"Rainier cherry\",\"deliciousness\":9000,\"color\":\"yellow\"}],\"formattedValue\":{\"mimeType\":\"application/table-schema+json\",\"value\":\"[{\\\"name\\\":\\\"Granny Smith apple\\\",\\\"deliciousness\\\":0,\\\"color\\\":\\\"red\\\"},{\\\"name\\\":\\\"Rainier cherry\\\",\\\"deliciousness\\\":9000,\\\"color\\\":\\\"yellow\\\"}]\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"ZAy5ClL/wSFFIHDWSek9DkjBBjV8CPJFg65yQoFcoDY=\",\"id\":\"e06e45d3834d4fc393b7a698351f30f9\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"df_in_kernel\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c59b50e-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "c7f699df-4332-4148-8965-d5ddc03d22f1", + "date": "2023-03-22T06:25:11.087621Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "169d66c8-2579-46fd-82e6-a0734fa6e44e", + "username": "dotnet_kernel", + "session": "c7f699df-4332-4148-8965-d5ddc03d22f1", + "date": "2023-03-22T06:25:11.0784729Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c6254e8-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "184eb04a-be67-46fd-9bc3-52af0ca5aafb", + "date": "2023-03-22T06:25:11.144139Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3c2cc995-80f1-4e01-88c3-b9f606ecaaa8", + "username": "dotnet_kernel", + "session": "184eb04a-be67-46fd-9bc3-52af0ca5aafb", + "date": "2023-03-22T06:25:11.1398899Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c630578-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "184eb04a-be67-46fd-9bc3-52af0ca5aafb", + "date": "2023-03-22T06:25:11.148659Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3c2cc995-80f1-4e01-88c3-b9f606ecaaa8", + "username": "dotnet_kernel", + "session": "184eb04a-be67-46fd-9bc3-52af0ca5aafb", + "date": "2023-03-22T06:25:11.1398899Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "02a315d5-6725-445c-b4da-2d349e9c53ef", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c632c7e-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "184eb04a-be67-46fd-9bc3-52af0ca5aafb", + "date": "2023-03-22T06:25:11.149658Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3c2cc995-80f1-4e01-88c3-b9f606ecaaa8", + "username": "dotnet_kernel", + "session": "184eb04a-be67-46fd-9bc3-52af0ca5aafb", + "date": "2023-03-22T06:25:11.1398899Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c63efce-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "d698f6ef-8198-4c85-9f25-b4e68a05295b", + "date": "2023-03-22T06:25:11.153659Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "b98bd471-e671-4041-9334-e78b7e88656e", + "username": "dotnet_kernel", + "session": "d698f6ef-8198-4c85-9f25-b4e68a05295b", + "date": "2023-03-22T06:25:11.1513820Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c6687f2-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "d698f6ef-8198-4c85-9f25-b4e68a05295b", + "date": "2023-03-22T06:25:11.171660Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "b98bd471-e671-4041-9334-e78b7e88656e", + "username": "dotnet_kernel", + "session": "d698f6ef-8198-4c85-9f25-b4e68a05295b", + "date": "2023-03-22T06:25:11.1513820Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "identical(df_in_kernel, df_roundtrip)", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c6836b0-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "d698f6ef-8198-4c85-9f25-b4e68a05295b", + "date": "2023-03-22T06:25:11.184688Z", + "msg_type": "display_data", + "version": "5.0" + }, + "parent_header": { + "msg_id": "b98bd471-e671-4041-9334-e78b7e88656e", + "username": "dotnet_kernel", + "session": "d698f6ef-8198-4c85-9f25-b4e68a05295b", + "date": "2023-03-22T06:25:11.1513820Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "data": { + "text/html": "TRUE", + "text/markdown": "TRUE", + "text/latex": "TRUE", + "text/plain": "[1] TRUE" + }, + "metadata": {}, + "transient": {} + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c69212e-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "d698f6ef-8198-4c85-9f25-b4e68a05295b", + "date": "2023-03-22T06:25:11.189693Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "b98bd471-e671-4041-9334-e78b7e88656e", + "username": "dotnet_kernel", + "session": "d698f6ef-8198-4c85-9f25-b4e68a05295b", + "date": "2023-03-22T06:25:11.1513820Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "4c694848-c87a-11ed-9d3a-3b1d746effdc", + "username": "dotnet_kernel", + "session": "d698f6ef-8198-4c85-9f25-b4e68a05295b", + "date": "2023-03-22T06:25:11.189693Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "b98bd471-e671-4041-9334-e78b7e88656e", + "username": "dotnet_kernel", + "session": "d698f6ef-8198-4c85-9f25-b4e68a05295b", + "date": "2023-03-22T06:25:11.1513820Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_share_dataframe_to_from_kernel.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_share_dataframe_to_from_kernel.python3.json new file mode 100644 index 0000000000..0801bbef56 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_share_dataframe_to_from_kernel.python3.json @@ -0,0 +1,739 @@ +[ + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_10", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:08.197036Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a84c1525-045f-4d4a-8a16-62cf6d79ba6e", + "username": "dotnet_kernel", + "session": "6782b114-246f-4ade-86a1-0348fe1431d9", + "date": "2023-03-22T06:25:08.1832115Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_12", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:08.198035Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a84c1525-045f-4d4a-8a16-62cf6d79ba6e", + "username": "dotnet_kernel", + "session": "6782b114-246f-4ade-86a1-0348fe1431d9", + "date": "2023-03-22T06:25:08.1832115Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_11", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:08.198035Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a84c1525-045f-4d4a-8a16-62cf6d79ba6e", + "username": "dotnet_kernel", + "session": "6782b114-246f-4ade-86a1-0348fe1431d9", + "date": "2023-03-22T06:25:08.1832115Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_13", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:08.221547Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "e4ab9a76-a368-4b7a-8f5f-68797964885c", + "username": "dotnet_kernel", + "session": "23818c1e-0a11-4748-abe1-f3c8a8d94e71", + "date": "2023-03-22T06:25:08.2145505Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_14", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:08.222549Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "e4ab9a76-a368-4b7a-8f5f-68797964885c", + "username": "dotnet_kernel", + "session": "23818c1e-0a11-4748-abe1-f3c8a8d94e71", + "date": "2023-03-22T06:25:08.2145505Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_15", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:08.264410Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "e4ab9a76-a368-4b7a-8f5f-68797964885c", + "username": "dotnet_kernel", + "session": "23818c1e-0a11-4748-abe1-f3c8a8d94e71", + "date": "2023-03-22T06:25:08.2145505Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-22T06:25:08.222549Z", + "dependencies_met": true, + "engine": "3f032ab3-beed-442e-8ef5-5df45cc4be42", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_16", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:08.264410Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "e4ab9a76-a368-4b7a-8f5f-68797964885c", + "username": "dotnet_kernel", + "session": "23818c1e-0a11-4748-abe1-f3c8a8d94e71", + "date": "2023-03-22T06:25:08.2145505Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_17", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:08.274966Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "587cbd7f-44c1-4b5c-9835-ea225db923d1", + "username": "dotnet_kernel", + "session": "c448c544-9f46-4c6e-b62f-4bf6d171f28e", + "date": "2023-03-22T06:25:08.2731406Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_18", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:08.274966Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "587cbd7f-44c1-4b5c-9835-ea225db923d1", + "username": "dotnet_kernel", + "session": "c448c544-9f46-4c6e-b62f-4bf6d171f28e", + "date": "2023-03-22T06:25:08.2731406Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "6143770f-f353-411e-8703-77970ba7aeda", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_19", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:08.275968Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "587cbd7f-44c1-4b5c-9835-ea225db923d1", + "username": "dotnet_kernel", + "session": "c448c544-9f46-4c6e-b62f-4bf6d171f28e", + "date": "2023-03-22T06:25:08.2731406Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_20", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.199491Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "13fdfcac-6cdc-45fa-b7ae-05807876af54", + "username": "dotnet_kernel", + "session": "e043d657-c736-4630-867b-f38a1b1df33f", + "date": "2023-03-22T06:25:09.1978164Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_21", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.664659Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "13fdfcac-6cdc-45fa-b7ae-05807876af54", + "username": "dotnet_kernel", + "session": "e043d657-c736-4630-867b-f38a1b1df33f", + "date": "2023-03-22T06:25:09.1978164Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "6143770f-f353-411e-8703-77970ba7aeda", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_22", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.664659Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "13fdfcac-6cdc-45fa-b7ae-05807876af54", + "username": "dotnet_kernel", + "session": "e043d657-c736-4630-867b-f38a1b1df33f", + "date": "2023-03-22T06:25:09.1978164Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_23", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.671659Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "66c3e67a-1d61-4b15-92d8-5e50b674eddb", + "username": "dotnet_kernel", + "session": "85e0d0f8-5c0a-4101-989d-867da8cfac12", + "date": "2023-03-22T06:25:09.6708498Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_24", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.673663Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "66c3e67a-1d61-4b15-92d8-5e50b674eddb", + "username": "dotnet_kernel", + "session": "85e0d0f8-5c0a-4101-989d-867da8cfac12", + "date": "2023-03-22T06:25:09.6708498Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "6143770f-f353-411e-8703-77970ba7aeda", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"df_in_kernel\", \"value\": [{\"name\": \"Granny Smith apple\", \"deliciousness\": 0, \"color\": \"red\"}, {\"name\": \"Rainier cherry\", \"deliciousness\": 9000, \"color\": \"yellow\"}], \"formattedValue\": {\"mimeType\": \"application/table-schema+json\", \"value\": \" name deliciousness color\\nGranny Smith apple 0 red\\n Rainier cherry 9000 yellow\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"ZO8pl9XXSExYRzPN7K0G8Z5SFrhgsh3VSVaiqnQBScU=\", \"id\": \"8c0f54cdf8e044c7b117238c49167868\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"df_in_kernel\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/.NET?tag=arrived\", \"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_25", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.674661Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "66c3e67a-1d61-4b15-92d8-5e50b674eddb", + "username": "dotnet_kernel", + "session": "85e0d0f8-5c0a-4101-989d-867da8cfac12", + "date": "2023-03-22T06:25:09.6708498Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_26", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.737728Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "19fe5ab7-2c56-4213-8a33-a3b1332c04f3", + "username": "dotnet_kernel", + "session": "bb604efa-e3fa-4ba8-a4f1-50e8d6de33a3", + "date": "2023-03-22T06:25:09.7376032Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_27", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.740243Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "19fe5ab7-2c56-4213-8a33-a3b1332c04f3", + "username": "dotnet_kernel", + "session": "bb604efa-e3fa-4ba8-a4f1-50e8d6de33a3", + "date": "2023-03-22T06:25:09.7376032Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "6143770f-f353-411e-8703-77970ba7aeda", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"df_in_kernel\", \"value\": [{\"name\": \"Granny Smith apple\", \"deliciousness\": 0, \"color\": \"red\"}, {\"name\": \"Rainier cherry\", \"deliciousness\": 9000, \"color\": \"yellow\"}], \"formattedValue\": {\"mimeType\": \"application/table-schema+json\", \"value\": \" name deliciousness color\\nGranny Smith apple 0 red\\n Rainier cherry 9000 yellow\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"TYVFH5vnNO+Xyf4rrNf6dOOriYH4uBqdOB/IJUzwE+I=\", \"id\": \"910913cfeb94470e823bc7b1f8c9ff83\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"df_in_kernel\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_28", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.740243Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "19fe5ab7-2c56-4213-8a33-a3b1332c04f3", + "username": "dotnet_kernel", + "session": "bb604efa-e3fa-4ba8-a4f1-50e8d6de33a3", + "date": "2023-03-22T06:25:09.7376032Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_29", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.777765Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "72e3acd8-ae8f-4728-ba76-345f5f32e095", + "username": "dotnet_kernel", + "session": "b61268fb-33e3-4818-b3a5-6518d40e2954", + "date": "2023-03-22T06:25:09.7764770Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_30", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.778763Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "72e3acd8-ae8f-4728-ba76-345f5f32e095", + "username": "dotnet_kernel", + "session": "b61268fb-33e3-4818-b3a5-6518d40e2954", + "date": "2023-03-22T06:25:09.7764770Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "6143770f-f353-411e-8703-77970ba7aeda", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_31", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.779766Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "72e3acd8-ae8f-4728-ba76-345f5f32e095", + "username": "dotnet_kernel", + "session": "b61268fb-33e3-4818-b3a5-6518d40e2954", + "date": "2023-03-22T06:25:09.7764770Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_32", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.785765Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "21d60350-270e-4cf9-8f80-4ef5d3e07362", + "username": "dotnet_kernel", + "session": "2fedd614-95e7-4a83-88be-fe7b61f7eb2c", + "date": "2023-03-22T06:25:09.7840797Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_33", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.785765Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "21d60350-270e-4cf9-8f80-4ef5d3e07362", + "username": "dotnet_kernel", + "session": "2fedd614-95e7-4a83-88be-fe7b61f7eb2c", + "date": "2023-03-22T06:25:09.7840797Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "df_in_kernel.equals(df_roundtrip)", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_34", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.787781Z", + "msg_type": "execute_result", + "version": "5.3" + }, + "parent_header": { + "msg_id": "21d60350-270e-4cf9-8f80-4ef5d3e07362", + "username": "dotnet_kernel", + "session": "2fedd614-95e7-4a83-88be-fe7b61f7eb2c", + "date": "2023-03-22T06:25:09.7840797Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "data": { + "text/plain": "True" + }, + "metadata": {}, + "transient": {}, + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_35", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.797776Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "21d60350-270e-4cf9-8f80-4ef5d3e07362", + "username": "dotnet_kernel", + "session": "2fedd614-95e7-4a83-88be-fe7b61f7eb2c", + "date": "2023-03-22T06:25:09.7840797Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-22T06:25:09.785765Z", + "dependencies_met": true, + "engine": "3f032ab3-beed-442e-8ef5-5df45cc4be42", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "acaaac62-d2eb11c1b1405a5b196d4931_21864_36", + "username": "username", + "session": "acaaac62-d2eb11c1b1405a5b196d4931", + "date": "2023-03-22T06:25:09.797776Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "21d60350-270e-4cf9-8f80-4ef5d3e07362", + "username": "dotnet_kernel", + "session": "2fedd614-95e7-4a83-88be-fe7b61f7eb2c", + "date": "2023-03-22T06:25:09.7840797Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_share_primitives_to_and_from_kernel.ir.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_share_primitives_to_and_from_kernel.ir.json new file mode 100644 index 0000000000..f26c26eed9 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_share_primitives_to_and_from_kernel.ir.json @@ -0,0 +1,3607 @@ +[ + { + "header": { + "msg_id": "12f08f76-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "3b430baa-01a1-49e2-8d22-822c4845214d", + "date": "2023-03-21T23:57:01.945518Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "c834d8cd-7703-4970-b4cb-4626838903b1", + "username": "dotnet_kernel", + "session": "3b430baa-01a1-49e2-8d22-822c4845214d", + "date": "2023-03-21T23:57:01.8586467Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "12f0a34e-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "3b430baa-01a1-49e2-8d22-822c4845214d", + "date": "2023-03-21T23:57:01.947517Z", + "msg_type": "kernel_info_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "c834d8cd-7703-4970-b4cb-4626838903b1", + "username": "dotnet_kernel", + "session": "3b430baa-01a1-49e2-8d22-822c4845214d", + "date": "2023-03-21T23:57:01.8586467Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.0", + "implementation": "IRkernel", + "implementation_version": "0.8.15", + "language_info": { + "name": "R", + "version": "3.6.1", + "mimetype": "text/x-r-source", + "file_extension": ".r", + "pygments_lexer": "r", + "codemirror_mode": "r" + }, + "banner": "R version 3.6.1 (2019-07-05)", + "status": "ok", + "help_links": [] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "12f118e2-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "3b430baa-01a1-49e2-8d22-822c4845214d", + "date": "2023-03-21T23:57:01.949516Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "c834d8cd-7703-4970-b4cb-4626838903b1", + "username": "dotnet_kernel", + "session": "3b430baa-01a1-49e2-8d22-822c4845214d", + "date": "2023-03-21T23:57:01.8586467Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "12f2034c-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "98d21179-106a-4231-9e82-a008c652d0b9", + "date": "2023-03-21T23:57:01.954517Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "42f8aee7-ca6c-4526-b068-1f57f18a27c5", + "username": "dotnet_kernel", + "session": "98d21179-106a-4231-9e82-a008c652d0b9", + "date": "2023-03-21T23:57:01.9495754Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "12f25162-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "98d21179-106a-4231-9e82-a008c652d0b9", + "date": "2023-03-21T23:57:01.958516Z", + "msg_type": "execute_input", + "version": "5.0" + }, + "parent_header": { + "msg_id": "42f8aee7-ca6c-4526-b068-1f57f18a27c5", + "username": "dotnet_kernel", + "session": "98d21179-106a-4231-9e82-a008c652d0b9", + "date": "2023-03-21T23:57:01.9495754Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nlibrary(IRkernel);\nlibrary(jsonlite);\n\n.dotnet_coe_comm_hander_env <- new.env();\n\n.dotnet_coe_comm_hander_env$emptyEvent <- fromJSON(\"{}\")\n\n# events\n.dotnet_coe_comm_hander_env$KernelReady <- 'KernelReady';\n.dotnet_coe_comm_hander_env$CommandSucceeded <- 'CommandSucceeded';\n.dotnet_coe_comm_hander_env$CommandFailed <- 'CommandFailed';\n.dotnet_coe_comm_hander_env$ValueProduced <- 'ValueProduced';\n.dotnet_coe_comm_hander_env$ValueInfosProduced <- 'ValueInfosProduced';\n\n#commands\n.dotnet_coe_comm_hander_env$SendValue <- 'SendValue';\n.dotnet_coe_comm_hander_env$RequestValue <- 'RequestValue';\n.dotnet_coe_comm_hander_env$RequestValueInfos <- 'RequestValueInfos';\n\n.dotnet_coe_comm_hander_env$json <- function(value) {\n return (toJSON(value, auto_unbox = TRUE, null=\"null\", force = TRUE))\n}\n \n.dotnet_coe_comm_hander_env$payload <- function(envelope, type) {\n payload <- list(commandOrEvent = .dotnet_coe_comm_hander_env$json(envelope), type = type);\n return (payload);\n}\n\n.dotnet_coe_comm_hander_env$eventEnvelope <- function(event, eventType, command = NA) {\n if (!is.na(command) && !is.null(command)) {\n # we don't care about routing slip here and there are some json serialization issues with R un-boxing\n # for now, let's remove it or make it empty\n command$routingSlip <- list()\n }\n envelope <- list(event=event, eventType=eventType, command=command);\n return (.dotnet_coe_comm_hander_env$payload(envelope, 'event'));\n}\n\n.dotnet_coe_comm_hander_env$is_ready <- function() {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(kernelInfos=list()), \n .dotnet_coe_comm_hander_env$KernelReady)\n );\n}\n\n.dotnet_coe_comm_hander_env$fail <- function(message = NA, command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n list(message=message), \n .dotnet_coe_comm_hander_env$CommandFailed, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$pass <- function(command = NA) {\n return (\n .dotnet_coe_comm_hander_env$eventEnvelope(\n .dotnet_coe_comm_hander_env$emptyEvent, \n .dotnet_coe_comm_hander_env$CommandSucceeded, \n command)\n );\n}\n\n.dotnet_coe_comm_hander_env$get_formatted_value <- function(value, mimeType = 'application/json') {\n formattedValue = NULL\n if (is.data.frame(value)) {\n mimeType <- 'application/table-schema+json'\n formattedValue <- .dotnet_coe_comm_hander_env$json(head(value))\n } else if (mimeType == 'application/json') {\n formattedValue <- .dotnet_coe_comm_hander_env$json(value)\n }\n return (list(\n mimeType=mimeType,\n value=formattedValue\n ))\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value_infos <- function(commandOrEvent) {\n variables <- ls(all=TRUE, globalenv()) # we only retrieve the global variables \n results <- list();\n \n for (var in variables) {\n if (!startsWith(var, '.')) {\n value <- get(var);\n type <- if (is.data.frame(value)) 'data.frame' else toString(typeof(value));\n if (type != 'closure') {\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(value);\n results <- append(results, list(list(name=var, formattedValue=formattedValue, typeName=type)));\n }\n };\n };\n \n \n valueInfosProduced = list(valueInfos=results)\n \n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueInfosProduced, \n .dotnet_coe_comm_hander_env$ValueInfosProduced, \n commandOrEvent)\n}\n\n.dotnet_coe_comm_hander_env$handle_request_value <- function(commandOrEvent) {\n requestValue <- commandOrEvent$command\n mimeType <- requestValue$mimeType\n name <- requestValue$name\n \n if (is.na(name) || name == '' || !exists(name)) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Variable \"%s\" not found.', name))\n )\n }\n \n rawValue <- get(name);\n mimeType <- if (is.data.frame(rawValue)) 'application/table-schema+json' else mimeType;\n formattedValue <- .dotnet_coe_comm_hander_env$get_formatted_value(rawValue, mimeType);\n\n valueProduced = list(\n name=name, \n value=rawValue, \n formattedValue=formattedValue\n )\n response <- .dotnet_coe_comm_hander_env$eventEnvelope(\n valueProduced, \n .dotnet_coe_comm_hander_env$ValueProduced, \n commandOrEvent)\n \n return (response)\n}\n\n.dotnet_coe_comm_hander_env$handle_send_value <- function(commandOrEvent) {\n sendValue <- commandOrEvent$command\n mimeType <- sendValue$formattedValue$mimeType\n name <- sendValue$name\n rawValue <- sendValue$formattedValue$value\n resultValue = NA\n \n if (make.names(name) != name) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Invalid Identifier: \"%s\"', name))\n )\n }\n \n if (mimeType == 'application/table-schema+json') {\n resultValue <- fromJSON(rawValue)\n resultValue <- data.frame(resultValue$data)\n } else if (mimeType == 'application/json') {\n resultValue <- fromJSON(rawValue)\n } else {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('Failed to set value for \"%s\". \"%s\" mimetype not supported.', name, mimeType))\n )\n }\n \n \n assign(name, resultValue, globalenv());\n return (.dotnet_coe_comm_hander_env$pass())\n}\n\n.dotnet_coe_comm_hander_env$handle_command <- function(commandOrEvent) {\n commandType <- commandOrEvent$commandType\n\n result <- .dotnet_coe_comm_hander_env$fail(\n sprintf('command \"%s\" not supported', commandType)\n )\n\n if (commandType == .dotnet_coe_comm_hander_env$SendValue) {\n result <- .dotnet_coe_comm_hander_env$handle_send_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValue) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value(commandOrEvent)\n } else if (commandType == .dotnet_coe_comm_hander_env$RequestValueInfos) {\n result <- .dotnet_coe_comm_hander_env$handle_request_value_infos(commandOrEvent)\n }\n\n return (result)\n}\n\n.dotnet_coe_comm_hander_env$handle_command_or_event <- function(msg) {\n response <- tryCatch({\n msg_type <- msg$type\n commandOrEvent <- fromJSON(msg$commandOrEvent)\n \n if (msg_type == 'command') {\n return (.dotnet_coe_comm_hander_env$handle_command(commandOrEvent))\n } \n },\n error=function(cond) {\n return (\n .dotnet_coe_comm_hander_env$fail(\n sprintf('failed to process comm data. %s', cond$message))\n )\n }) \n \n return(response)\n}\n\n.dotnet_coe_comm_hander_env$coe_handler_connect_to_comm <- function(comm, data) {\n comm$on_msg(function(msg) {\n # assign('.debug.onmsg', msg, globalenv());\n response <- .dotnet_coe_comm_hander_env$handle_command_or_event(msg);\n comm$send(response); \n })\n\n ready <- .dotnet_coe_comm_hander_env$is_ready()\n comm$send(ready); \n \n};\n\ncomm_manager()$register_target('dotnet_coe_handler_comm', .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm);\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1303e134-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "98d21179-106a-4231-9e82-a008c652d0b9", + "date": "2023-03-21T23:57:02.072615Z", + "msg_type": "execute_reply", + "version": "5.0" + }, + "parent_header": { + "msg_id": "42f8aee7-ca6c-4526-b068-1f57f18a27c5", + "username": "dotnet_kernel", + "session": "98d21179-106a-4231-9e82-a008c652d0b9", + "date": "2023-03-21T23:57:01.9495754Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13040862-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "98d21179-106a-4231-9e82-a008c652d0b9", + "date": "2023-03-21T23:57:02.073609Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "42f8aee7-ca6c-4526-b068-1f57f18a27c5", + "username": "dotnet_kernel", + "session": "98d21179-106a-4231-9e82-a008c652d0b9", + "date": "2023-03-21T23:57:01.9495754Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1304cb80-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "dd00fe52-67ba-4646-9a01-5abb1ea9e023", + "date": "2023-03-21T23:57:02.077607Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0c21bb6c-c00e-496d-88f0-126139e6ead8", + "username": "dotnet_kernel", + "session": "dd00fe52-67ba-4646-9a01-5abb1ea9e023", + "date": "2023-03-21T23:57:02.0744065Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "130567b6-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "dd00fe52-67ba-4646-9a01-5abb1ea9e023", + "date": "2023-03-21T23:57:02.081608Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0c21bb6c-c00e-496d-88f0-126139e6ead8", + "username": "dotnet_kernel", + "session": "dd00fe52-67ba-4646-9a01-5abb1ea9e023", + "date": "2023-03-21T23:57:02.0744065Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"kernelInfos\":[]},\"eventType\":\"KernelReady\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13058ed0-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "dd00fe52-67ba-4646-9a01-5abb1ea9e023", + "date": "2023-03-21T23:57:02.082610Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0c21bb6c-c00e-496d-88f0-126139e6ead8", + "username": "dotnet_kernel", + "session": "dd00fe52-67ba-4646-9a01-5abb1ea9e023", + "date": "2023-03-21T23:57:02.0744065Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "130a85de-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "31bed06a-aed9-4b29-b710-ad9ee0963d4f", + "date": "2023-03-21T23:57:02.116146Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "ca799047-022f-4047-ab45-9e2cc1231558", + "username": "dotnet_kernel", + "session": "31bed06a-aed9-4b29-b710-ad9ee0963d4f", + "date": "2023-03-21T23:57:02.1121710Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "130d805e-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "31bed06a-aed9-4b29-b710-ad9ee0963d4f", + "date": "2023-03-21T23:57:02.135662Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "ca799047-022f-4047-ab45-9e2cc1231558", + "username": "dotnet_kernel", + "session": "31bed06a-aed9-4b29-b710-ad9ee0963d4f", + "date": "2023-03-21T23:57:02.1121710Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "130dce4c-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "31bed06a-aed9-4b29-b710-ad9ee0963d4f", + "date": "2023-03-21T23:57:02.136664Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "ca799047-022f-4047-ab45-9e2cc1231558", + "username": "dotnet_kernel", + "session": "31bed06a-aed9-4b29-b710-ad9ee0963d4f", + "date": "2023-03-21T23:57:02.1121710Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "130e4390-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "a222ebda-fd48-4bb3-ad8c-de5fd2d7935a", + "date": "2023-03-21T23:57:02.139664Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "dc7197cd-ff52-4935-9b0a-9044d11e08e0", + "username": "dotnet_kernel", + "session": "a222ebda-fd48-4bb3-ad8c-de5fd2d7935a", + "date": "2023-03-21T23:57:02.1377050Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13127686-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "a222ebda-fd48-4bb3-ad8c-de5fd2d7935a", + "date": "2023-03-21T23:57:02.169185Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "dc7197cd-ff52-4935-9b0a-9044d11e08e0", + "username": "dotnet_kernel", + "session": "a222ebda-fd48-4bb3-ad8c-de5fd2d7935a", + "date": "2023-03-21T23:57:02.1377050Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":2,\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"2\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"uq/P9NU0Dd9O9FqaudSfIrnsGWnfgKV3b5trhgG4HeI=\",\"id\":\"6ac9f4572ea249e49c88ab554274bf4c\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13129d96-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "a222ebda-fd48-4bb3-ad8c-de5fd2d7935a", + "date": "2023-03-21T23:57:02.169185Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "dc7197cd-ff52-4935-9b0a-9044d11e08e0", + "username": "dotnet_kernel", + "session": "a222ebda-fd48-4bb3-ad8c-de5fd2d7935a", + "date": "2023-03-21T23:57:02.1377050Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "131ac8d6-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "79abd5ab-6f64-453b-991b-0acd9f156fc3", + "date": "2023-03-21T23:57:02.222719Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "22445369-4c0c-4a5a-9699-8d2c7cf87308", + "username": "dotnet_kernel", + "session": "79abd5ab-6f64-453b-991b-0acd9f156fc3", + "date": "2023-03-21T23:57:02.2185804Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "131bc786-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "79abd5ab-6f64-453b-991b-0acd9f156fc3", + "date": "2023-03-21T23:57:02.229237Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "22445369-4c0c-4a5a-9699-8d2c7cf87308", + "username": "dotnet_kernel", + "session": "79abd5ab-6f64-453b-991b-0acd9f156fc3", + "date": "2023-03-21T23:57:02.2185804Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "131bee8c-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "79abd5ab-6f64-453b-991b-0acd9f156fc3", + "date": "2023-03-21T23:57:02.230242Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "22445369-4c0c-4a5a-9699-8d2c7cf87308", + "username": "dotnet_kernel", + "session": "79abd5ab-6f64-453b-991b-0acd9f156fc3", + "date": "2023-03-21T23:57:02.2185804Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "131c8acc-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "7355ede4-6910-4b61-b02e-6d8e7f057c24", + "date": "2023-03-21T23:57:02.233237Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "356c32e8-4402-4e72-ab5c-46228242e8a1", + "username": "dotnet_kernel", + "session": "7355ede4-6910-4b61-b02e-6d8e7f057c24", + "date": "2023-03-21T23:57:02.2309667Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "131d4e12-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "7355ede4-6910-4b61-b02e-6d8e7f057c24", + "date": "2023-03-21T23:57:02.239240Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "356c32e8-4402-4e72-ab5c-46228242e8a1", + "username": "dotnet_kernel", + "session": "7355ede4-6910-4b61-b02e-6d8e7f057c24", + "date": "2023-03-21T23:57:02.2309667Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":-2147483648,\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"-2147483648\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"N+TjQiMtin7M2zCXiUModctH0jMLilawt83heDo8DQ4=\",\"id\":\"23aac29c96e1447c80bd003f7f4ba300\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "131d7522-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "7355ede4-6910-4b61-b02e-6d8e7f057c24", + "date": "2023-03-21T23:57:02.240238Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "356c32e8-4402-4e72-ab5c-46228242e8a1", + "username": "dotnet_kernel", + "session": "7355ede4-6910-4b61-b02e-6d8e7f057c24", + "date": "2023-03-21T23:57:02.2309667Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "132650d4-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "6a643980-668a-471c-b80a-4cda01ab6f19", + "date": "2023-03-21T23:57:02.298291Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "9bdbfe28-ea43-4f37-b5e3-93cbb32ddc99", + "username": "dotnet_kernel", + "session": "6a643980-668a-471c-b80a-4cda01ab6f19", + "date": "2023-03-21T23:57:02.2939696Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13269efe-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "6a643980-668a-471c-b80a-4cda01ab6f19", + "date": "2023-03-21T23:57:02.299293Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "9bdbfe28-ea43-4f37-b5e3-93cbb32ddc99", + "username": "dotnet_kernel", + "session": "6a643980-668a-471c-b80a-4cda01ab6f19", + "date": "2023-03-21T23:57:02.2939696Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1326c622-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "6a643980-668a-471c-b80a-4cda01ab6f19", + "date": "2023-03-21T23:57:02.301292Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "9bdbfe28-ea43-4f37-b5e3-93cbb32ddc99", + "username": "dotnet_kernel", + "session": "6a643980-668a-471c-b80a-4cda01ab6f19", + "date": "2023-03-21T23:57:02.2939696Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1327624e-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "84353acf-6ee7-42b7-889e-b9ab4b039c93", + "date": "2023-03-21T23:57:02.304289Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "de742eda-21de-489f-b119-4e72ebb72c2f", + "username": "dotnet_kernel", + "session": "84353acf-6ee7-42b7-889e-b9ab4b039c93", + "date": "2023-03-21T23:57:02.3014105Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1327b0aa-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "84353acf-6ee7-42b7-889e-b9ab4b039c93", + "date": "2023-03-21T23:57:02.307296Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "de742eda-21de-489f-b119-4e72ebb72c2f", + "username": "dotnet_kernel", + "session": "84353acf-6ee7-42b7-889e-b9ab4b039c93", + "date": "2023-03-21T23:57:02.3014105Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":2147483647,\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"2147483647\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"rCBk+noLMvKygTUYwZY3aIYfClLqAS3SzgAWNa2hzxs=\",\"id\":\"39097db4780143d78dbdc82719370255\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1327fec0-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "84353acf-6ee7-42b7-889e-b9ab4b039c93", + "date": "2023-03-21T23:57:02.308298Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "de742eda-21de-489f-b119-4e72ebb72c2f", + "username": "dotnet_kernel", + "session": "84353acf-6ee7-42b7-889e-b9ab4b039c93", + "date": "2023-03-21T23:57:02.3014105Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1331c4e6-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "5a51f4c1-b457-4587-97ce-255089d60196", + "date": "2023-03-21T23:57:02.372351Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "01ea46ed-c178-4789-9889-07e7e138278f", + "username": "dotnet_kernel", + "session": "5a51f4c1-b457-4587-97ce-255089d60196", + "date": "2023-03-21T23:57:02.3691584Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13321310-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "5a51f4c1-b457-4587-97ce-255089d60196", + "date": "2023-03-21T23:57:02.375353Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "01ea46ed-c178-4789-9889-07e7e138278f", + "username": "dotnet_kernel", + "session": "5a51f4c1-b457-4587-97ce-255089d60196", + "date": "2023-03-21T23:57:02.3691584Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13323a16-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "5a51f4c1-b457-4587-97ce-255089d60196", + "date": "2023-03-21T23:57:02.376351Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "01ea46ed-c178-4789-9889-07e7e138278f", + "username": "dotnet_kernel", + "session": "5a51f4c1-b457-4587-97ce-255089d60196", + "date": "2023-03-21T23:57:02.3691584Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1332d656-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "82eeba8b-1f2d-43fd-9f67-8aedc9409be2", + "date": "2023-03-21T23:57:02.379351Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "4166ee9b-8a57-4834-8dea-0a518eeaac1e", + "username": "dotnet_kernel", + "session": "82eeba8b-1f2d-43fd-9f67-8aedc9409be2", + "date": "2023-03-21T23:57:02.3769591Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13332476-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "82eeba8b-1f2d-43fd-9f67-8aedc9409be2", + "date": "2023-03-21T23:57:02.381860Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "4166ee9b-8a57-4834-8dea-0a518eeaac1e", + "username": "dotnet_kernel", + "session": "82eeba8b-1f2d-43fd-9f67-8aedc9409be2", + "date": "2023-03-21T23:57:02.3769591Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":-123456789012345,\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"-123456789012345\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"1QQt3fwbJrcidhbTDpMcU0qy06ocjgb58gpdVRcBXYg=\",\"id\":\"e7c2b571057d4abaa44aa31dd3d6ef64\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13332477-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "82eeba8b-1f2d-43fd-9f67-8aedc9409be2", + "date": "2023-03-21T23:57:02.382873Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "4166ee9b-8a57-4834-8dea-0a518eeaac1e", + "username": "dotnet_kernel", + "session": "82eeba8b-1f2d-43fd-9f67-8aedc9409be2", + "date": "2023-03-21T23:57:02.3769591Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "133b3d0a-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "2872f6f7-9df4-4fb4-a85f-f826c4fefb69", + "date": "2023-03-21T23:57:02.435409Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "7213ebf2-70e8-4e8b-98b4-52bef22ccf34", + "username": "dotnet_kernel", + "session": "2872f6f7-9df4-4fb4-a85f-f826c4fefb69", + "date": "2023-03-21T23:57:02.4315593Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "133b8b2a-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "2872f6f7-9df4-4fb4-a85f-f826c4fefb69", + "date": "2023-03-21T23:57:02.436409Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "7213ebf2-70e8-4e8b-98b4-52bef22ccf34", + "username": "dotnet_kernel", + "session": "2872f6f7-9df4-4fb4-a85f-f826c4fefb69", + "date": "2023-03-21T23:57:02.4315593Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "133b8b2b-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "2872f6f7-9df4-4fb4-a85f-f826c4fefb69", + "date": "2023-03-21T23:57:02.437413Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "7213ebf2-70e8-4e8b-98b4-52bef22ccf34", + "username": "dotnet_kernel", + "session": "2872f6f7-9df4-4fb4-a85f-f826c4fefb69", + "date": "2023-03-21T23:57:02.4315593Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "133c2760-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "1276afc5-c9cc-4b19-97e4-e785e8ceedbc", + "date": "2023-03-21T23:57:02.441411Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "23a908b2-dad4-4919-800c-1676c5c818a0", + "username": "dotnet_kernel", + "session": "1276afc5-c9cc-4b19-97e4-e785e8ceedbc", + "date": "2023-03-21T23:57:02.4379231Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "133c759e-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "1276afc5-c9cc-4b19-97e4-e785e8ceedbc", + "date": "2023-03-21T23:57:02.442412Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "23a908b2-dad4-4919-800c-1676c5c818a0", + "username": "dotnet_kernel", + "session": "1276afc5-c9cc-4b19-97e4-e785e8ceedbc", + "date": "2023-03-21T23:57:02.4379231Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":123456789012345,\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"123456789012345\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"9YlIk01bv/G69flkdcoiWph2OOy5HKsc8bnSkbzzzz0=\",\"id\":\"f47fc53155664c208d5eaff20a6040e3\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "133c9cb8-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "1276afc5-c9cc-4b19-97e4-e785e8ceedbc", + "date": "2023-03-21T23:57:02.443411Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "23a908b2-dad4-4919-800c-1676c5c818a0", + "username": "dotnet_kernel", + "session": "1276afc5-c9cc-4b19-97e4-e785e8ceedbc", + "date": "2023-03-21T23:57:02.4379231Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13443ffe-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "e9ce9850-3cdb-4ba9-a516-cc6adc0790b8", + "date": "2023-03-21T23:57:02.493466Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "a935583d-af54-4e9c-8d70-1b6e60467f7b", + "username": "dotnet_kernel", + "session": "e9ce9850-3cdb-4ba9-a516-cc6adc0790b8", + "date": "2023-03-21T23:57:02.4905113Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13446704-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "e9ce9850-3cdb-4ba9-a516-cc6adc0790b8", + "date": "2023-03-21T23:57:02.495468Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "a935583d-af54-4e9c-8d70-1b6e60467f7b", + "username": "dotnet_kernel", + "session": "e9ce9850-3cdb-4ba9-a516-cc6adc0790b8", + "date": "2023-03-21T23:57:02.4905113Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13448e28-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "e9ce9850-3cdb-4ba9-a516-cc6adc0790b8", + "date": "2023-03-21T23:57:02.496468Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "a935583d-af54-4e9c-8d70-1b6e60467f7b", + "username": "dotnet_kernel", + "session": "e9ce9850-3cdb-4ba9-a516-cc6adc0790b8", + "date": "2023-03-21T23:57:02.4905113Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13450358-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "825ad1bb-a052-412c-8a8f-eb7217dfc9f7", + "date": "2023-03-21T23:57:02.498472Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0a37ed3f-853a-4b40-a2aa-382e4868ae16", + "username": "dotnet_kernel", + "session": "825ad1bb-a052-412c-8a8f-eb7217dfc9f7", + "date": "2023-03-21T23:57:02.4965632Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13455178-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "825ad1bb-a052-412c-8a8f-eb7217dfc9f7", + "date": "2023-03-21T23:57:02.500467Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0a37ed3f-853a-4b40-a2aa-382e4868ae16", + "username": "dotnet_kernel", + "session": "825ad1bb-a052-412c-8a8f-eb7217dfc9f7", + "date": "2023-03-21T23:57:02.4965632Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":true,\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"true\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"Tk3xcKGVcPqv5d+ZpQ+WTJcVpcbMqgeW4WI2Jf4d9j0=\",\"id\":\"0473aae25dea474d88cf0e9d9023e391\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1345787e-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "825ad1bb-a052-412c-8a8f-eb7217dfc9f7", + "date": "2023-03-21T23:57:02.501470Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "0a37ed3f-853a-4b40-a2aa-382e4868ae16", + "username": "dotnet_kernel", + "session": "825ad1bb-a052-412c-8a8f-eb7217dfc9f7", + "date": "2023-03-21T23:57:02.4965632Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "134d1b1a-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "21807ea2-3d69-4a9d-95dc-be84470d3424", + "date": "2023-03-21T23:57:02.552504Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d5ac758d-8fea-4272-a8ca-c6ef67aacaaa", + "username": "dotnet_kernel", + "session": "21807ea2-3d69-4a9d-95dc-be84470d3424", + "date": "2023-03-21T23:57:02.5493010Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "134d6930-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "21807ea2-3d69-4a9d-95dc-be84470d3424", + "date": "2023-03-21T23:57:02.553504Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d5ac758d-8fea-4272-a8ca-c6ef67aacaaa", + "username": "dotnet_kernel", + "session": "21807ea2-3d69-4a9d-95dc-be84470d3424", + "date": "2023-03-21T23:57:02.5493010Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "134d9040-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "21807ea2-3d69-4a9d-95dc-be84470d3424", + "date": "2023-03-21T23:57:02.554511Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "d5ac758d-8fea-4272-a8ca-c6ef67aacaaa", + "username": "dotnet_kernel", + "session": "21807ea2-3d69-4a9d-95dc-be84470d3424", + "date": "2023-03-21T23:57:02.5493010Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "134e05ac-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "ac22df6b-530a-42b9-92bf-5113f23c0a6a", + "date": "2023-03-21T23:57:02.557509Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e937592e-db1c-4fde-b85d-4daa4540b27a", + "username": "dotnet_kernel", + "session": "ac22df6b-530a-42b9-92bf-5113f23c0a6a", + "date": "2023-03-21T23:57:02.5554880Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "134e53ea-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "ac22df6b-530a-42b9-92bf-5113f23c0a6a", + "date": "2023-03-21T23:57:02.559509Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e937592e-db1c-4fde-b85d-4daa4540b27a", + "username": "dotnet_kernel", + "session": "ac22df6b-530a-42b9-92bf-5113f23c0a6a", + "date": "2023-03-21T23:57:02.5554880Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":\"hi!\",\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"\\\"hi!\\\"\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"QvENLgVoLcJ4xyIyC+BuAlj2nwurngrrqlv8RIgeE3Q=\",\"id\":\"3e1623c522de471895af106086ed5835\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "134e7ad2-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "ac22df6b-530a-42b9-92bf-5113f23c0a6a", + "date": "2023-03-21T23:57:02.560516Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "e937592e-db1c-4fde-b85d-4daa4540b27a", + "username": "dotnet_kernel", + "session": "ac22df6b-530a-42b9-92bf-5113f23c0a6a", + "date": "2023-03-21T23:57:02.5554880Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1355f62c-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "61a572dc-767d-4006-b60b-cc21f5502884", + "date": "2023-03-21T23:57:02.609543Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1050d786-2293-4f11-a82b-e25f29852a6b", + "username": "dotnet_kernel", + "session": "61a572dc-767d-4006-b60b-cc21f5502884", + "date": "2023-03-21T23:57:02.6065402Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13564460-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "61a572dc-767d-4006-b60b-cc21f5502884", + "date": "2023-03-21T23:57:02.612542Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1050d786-2293-4f11-a82b-e25f29852a6b", + "username": "dotnet_kernel", + "session": "61a572dc-767d-4006-b60b-cc21f5502884", + "date": "2023-03-21T23:57:02.6065402Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13566b66-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "61a572dc-767d-4006-b60b-cc21f5502884", + "date": "2023-03-21T23:57:02.613548Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1050d786-2293-4f11-a82b-e25f29852a6b", + "username": "dotnet_kernel", + "session": "61a572dc-767d-4006-b60b-cc21f5502884", + "date": "2023-03-21T23:57:02.6065402Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1357079c-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "6f14a09e-71ae-418d-a346-fff25fd5821a", + "date": "2023-03-21T23:57:02.617553Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "a4e19e43-58f9-4150-89ad-ee6a16e2df26", + "username": "dotnet_kernel", + "session": "6f14a09e-71ae-418d-a346-fff25fd5821a", + "date": "2023-03-21T23:57:02.6141452Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1357562a-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "6f14a09e-71ae-418d-a346-fff25fd5821a", + "date": "2023-03-21T23:57:02.619548Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "a4e19e43-58f9-4150-89ad-ee6a16e2df26", + "username": "dotnet_kernel", + "session": "6f14a09e-71ae-418d-a346-fff25fd5821a", + "date": "2023-03-21T23:57:02.6141452Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":\"hi!\",\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"\\\"hi!\\\"\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"Nm2Ss4MFdrk3SnPHdmZ6shrR/alwCm/MCsfq3vi8p0k=\",\"id\":\"f0933ffb22814d5bae184bb28e4f740b\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13577d12-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "6f14a09e-71ae-418d-a346-fff25fd5821a", + "date": "2023-03-21T23:57:02.620552Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "a4e19e43-58f9-4150-89ad-ee6a16e2df26", + "username": "dotnet_kernel", + "session": "6f14a09e-71ae-418d-a346-fff25fd5821a", + "date": "2023-03-21T23:57:02.6141452Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "136611c4-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "c5314d66-01fa-40d5-b8e8-fdbee95ef88f", + "date": "2023-03-21T23:57:02.715105Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "de2f24c1-8503-4930-b1b5-36f9c03f61dd", + "username": "dotnet_kernel", + "session": "c5314d66-01fa-40d5-b8e8-fdbee95ef88f", + "date": "2023-03-21T23:57:02.7114599Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "136638ca-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "c5314d66-01fa-40d5-b8e8-fdbee95ef88f", + "date": "2023-03-21T23:57:02.717106Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "de2f24c1-8503-4930-b1b5-36f9c03f61dd", + "username": "dotnet_kernel", + "session": "c5314d66-01fa-40d5-b8e8-fdbee95ef88f", + "date": "2023-03-21T23:57:02.7114599Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13665fee-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "c5314d66-01fa-40d5-b8e8-fdbee95ef88f", + "date": "2023-03-21T23:57:02.718107Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "de2f24c1-8503-4930-b1b5-36f9c03f61dd", + "username": "dotnet_kernel", + "session": "c5314d66-01fa-40d5-b8e8-fdbee95ef88f", + "date": "2023-03-21T23:57:02.7114599Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1366d51e-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "255459d9-3786-4166-b4d2-7265c11f63c4", + "date": "2023-03-21T23:57:02.720108Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "cf1a0f79-b64c-417b-b9ef-d9e7ab285eef", + "username": "dotnet_kernel", + "session": "255459d9-3786-4166-b4d2-7265c11f63c4", + "date": "2023-03-21T23:57:02.7183086Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13672366-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "255459d9-3786-4166-b4d2-7265c11f63c4", + "date": "2023-03-21T23:57:02.722106Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "cf1a0f79-b64c-417b-b9ef-d9e7ab285eef", + "username": "dotnet_kernel", + "session": "255459d9-3786-4166-b4d2-7265c11f63c4", + "date": "2023-03-21T23:57:02.7183086Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":\"\",\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"\\\"\\\"\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"ZFO5v7Don+klQbKO+TzHrMOwyCir7o4P/ZpuVlwT5tA=\",\"id\":\"28de7d6578b14f9ba18bba7dde1649cb\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13674a44-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "255459d9-3786-4166-b4d2-7265c11f63c4", + "date": "2023-03-21T23:57:02.724110Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "cf1a0f79-b64c-417b-b9ef-d9e7ab285eef", + "username": "dotnet_kernel", + "session": "255459d9-3786-4166-b4d2-7265c11f63c4", + "date": "2023-03-21T23:57:02.7183086Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "136e9ec0-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "2009f7cc-d59c-4d70-8617-b758edd01751", + "date": "2023-03-21T23:57:02.771143Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "37357fe1-aba9-4c69-97de-134ae6ae4cab", + "username": "dotnet_kernel", + "session": "2009f7cc-d59c-4d70-8617-b758edd01751", + "date": "2023-03-21T23:57:02.7680619Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "136ec5c6-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "2009f7cc-d59c-4d70-8617-b758edd01751", + "date": "2023-03-21T23:57:02.773152Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "37357fe1-aba9-4c69-97de-134ae6ae4cab", + "username": "dotnet_kernel", + "session": "2009f7cc-d59c-4d70-8617-b758edd01751", + "date": "2023-03-21T23:57:02.7680619Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "136eecea-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "2009f7cc-d59c-4d70-8617-b758edd01751", + "date": "2023-03-21T23:57:02.774159Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "37357fe1-aba9-4c69-97de-134ae6ae4cab", + "username": "dotnet_kernel", + "session": "2009f7cc-d59c-4d70-8617-b758edd01751", + "date": "2023-03-21T23:57:02.7680619Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "136f8966-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "65e3abd8-a580-4fa1-a184-30a00be641a5", + "date": "2023-03-21T23:57:02.777152Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1f63da8e-8ed0-4b8a-a9f1-3d9ed45c861c", + "username": "dotnet_kernel", + "session": "65e3abd8-a580-4fa1-a184-30a00be641a5", + "date": "2023-03-21T23:57:02.7743992Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "136fb080-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "65e3abd8-a580-4fa1-a184-30a00be641a5", + "date": "2023-03-21T23:57:02.779152Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1f63da8e-8ed0-4b8a-a9f1-3d9ed45c861c", + "username": "dotnet_kernel", + "session": "65e3abd8-a580-4fa1-a184-30a00be641a5", + "date": "2023-03-21T23:57:02.7743992Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":\"«ταБЬℓσ»\",\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"\\\"«ταБЬℓσ»\\\"\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"tSIdmplRxcq/E0mmcVijg8TtPA9f6GV7wu2jv/YWCKc=\",\"id\":\"0bba449c111541cda3f7171965d4a3ba\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "136fd786-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "65e3abd8-a580-4fa1-a184-30a00be641a5", + "date": "2023-03-21T23:57:02.779152Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1f63da8e-8ed0-4b8a-a9f1-3d9ed45c861c", + "username": "dotnet_kernel", + "session": "65e3abd8-a580-4fa1-a184-30a00be641a5", + "date": "2023-03-21T23:57:02.7743992Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1377b5aa-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "404bdfae-da56-4219-85ee-66120114e5fc", + "date": "2023-03-21T23:57:02.831714Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "082f40d1-b9e5-475c-a218-b04ecb03601a", + "username": "dotnet_kernel", + "session": "404bdfae-da56-4219-85ee-66120114e5fc", + "date": "2023-03-21T23:57:02.8279339Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "137803d4-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "404bdfae-da56-4219-85ee-66120114e5fc", + "date": "2023-03-21T23:57:02.832714Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "082f40d1-b9e5-475c-a218-b04ecb03601a", + "username": "dotnet_kernel", + "session": "404bdfae-da56-4219-85ee-66120114e5fc", + "date": "2023-03-21T23:57:02.8279339Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13782ae4-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "404bdfae-da56-4219-85ee-66120114e5fc", + "date": "2023-03-21T23:57:02.833713Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "082f40d1-b9e5-475c-a218-b04ecb03601a", + "username": "dotnet_kernel", + "session": "404bdfae-da56-4219-85ee-66120114e5fc", + "date": "2023-03-21T23:57:02.8279339Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1378a078-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "c35bc0c2-8fb9-45df-b57d-a125cca98dfc", + "date": "2023-03-21T23:57:02.836726Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "a4899ee3-4388-4b7e-85f9-a204087f5a4f", + "username": "dotnet_kernel", + "session": "c35bc0c2-8fb9-45df-b57d-a125cca98dfc", + "date": "2023-03-21T23:57:02.8345984Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1378ee8e-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "c35bc0c2-8fb9-45df-b57d-a125cca98dfc", + "date": "2023-03-21T23:57:02.838726Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "a4899ee3-4388-4b7e-85f9-a204087f5a4f", + "username": "dotnet_kernel", + "session": "c35bc0c2-8fb9-45df-b57d-a125cca98dfc", + "date": "2023-03-21T23:57:02.8345984Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":-123456.789,\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"-123456.789\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"rE7YsVSlbUvkLRwa24D+c1REe/tcsCjnMHisoux+fvM=\",\"id\":\"071cde447a91406dab8283ab1bb87d28\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "137915bc-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "c35bc0c2-8fb9-45df-b57d-a125cca98dfc", + "date": "2023-03-21T23:57:02.839721Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "a4899ee3-4388-4b7e-85f9-a204087f5a4f", + "username": "dotnet_kernel", + "session": "c35bc0c2-8fb9-45df-b57d-a125cca98dfc", + "date": "2023-03-21T23:57:02.8345984Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "138069e8-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "2a9bae36-77da-4a28-9940-dcc46a960537", + "date": "2023-03-21T23:57:02.888754Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "84733021-cdb7-4625-ba23-943a9e99c807", + "username": "dotnet_kernel", + "session": "2a9bae36-77da-4a28-9940-dcc46a960537", + "date": "2023-03-21T23:57:02.8852564Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1380b7f4-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "2a9bae36-77da-4a28-9940-dcc46a960537", + "date": "2023-03-21T23:57:02.889754Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "84733021-cdb7-4625-ba23-943a9e99c807", + "username": "dotnet_kernel", + "session": "2a9bae36-77da-4a28-9940-dcc46a960537", + "date": "2023-03-21T23:57:02.8852564Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1380df04-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "2a9bae36-77da-4a28-9940-dcc46a960537", + "date": "2023-03-21T23:57:02.890754Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "84733021-cdb7-4625-ba23-943a9e99c807", + "username": "dotnet_kernel", + "session": "2a9bae36-77da-4a28-9940-dcc46a960537", + "date": "2023-03-21T23:57:02.8852564Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13815434-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "516c5631-d78a-498e-8732-dff378b2bd81", + "date": "2023-03-21T23:57:02.894756Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "18ace591-9f43-4981-8c04-5a487065723e", + "username": "dotnet_kernel", + "session": "516c5631-d78a-498e-8732-dff378b2bd81", + "date": "2023-03-21T23:57:02.8916419Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1381a268-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "516c5631-d78a-498e-8732-dff378b2bd81", + "date": "2023-03-21T23:57:02.896755Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "18ace591-9f43-4981-8c04-5a487065723e", + "username": "dotnet_kernel", + "session": "516c5631-d78a-498e-8732-dff378b2bd81", + "date": "2023-03-21T23:57:02.8916419Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":123456.789,\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"123456.789\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"g6y3qJJUx44t1fQye9lH4H8hAAPt0BwtZVytfqFhBUA=\",\"id\":\"29fd146691634e6faf13074f444e04fd\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1381c978-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "516c5631-d78a-498e-8732-dff378b2bd81", + "date": "2023-03-21T23:57:02.897755Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "18ace591-9f43-4981-8c04-5a487065723e", + "username": "dotnet_kernel", + "session": "516c5631-d78a-498e-8732-dff378b2bd81", + "date": "2023-03-21T23:57:02.8916419Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13cdefba-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "3376dccc-843a-4283-994c-615d86e2a458", + "date": "2023-03-21T23:57:03.396809Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "4c6f8e0a-e806-4e85-a6f0-3c9ba28d76b0", + "username": "dotnet_kernel", + "session": "3376dccc-843a-4283-994c-615d86e2a458", + "date": "2023-03-21T23:57:03.3928275Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13ce3dda-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "3376dccc-843a-4283-994c-615d86e2a458", + "date": "2023-03-21T23:57:03.398816Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "4c6f8e0a-e806-4e85-a6f0-3c9ba28d76b0", + "username": "dotnet_kernel", + "session": "3376dccc-843a-4283-994c-615d86e2a458", + "date": "2023-03-21T23:57:03.3928275Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13ce8c40-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "3376dccc-843a-4283-994c-615d86e2a458", + "date": "2023-03-21T23:57:03.399818Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "4c6f8e0a-e806-4e85-a6f0-3c9ba28d76b0", + "username": "dotnet_kernel", + "session": "3376dccc-843a-4283-994c-615d86e2a458", + "date": "2023-03-21T23:57:03.3928275Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13cf0184-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "fdcd8793-5a17-48c1-90a4-a23140fd4033", + "date": "2023-03-21T23:57:03.403819Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "18044ec7-a1e3-4be4-b394-579b51281b0e", + "username": "dotnet_kernel", + "session": "fdcd8793-5a17-48c1-90a4-a23140fd4033", + "date": "2023-03-21T23:57:03.4009016Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13cf4fae-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "fdcd8793-5a17-48c1-90a4-a23140fd4033", + "date": "2023-03-21T23:57:03.405819Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "18044ec7-a1e3-4be4-b394-579b51281b0e", + "username": "dotnet_kernel", + "session": "fdcd8793-5a17-48c1-90a4-a23140fd4033", + "date": "2023-03-21T23:57:03.4009016Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":123.789,\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"123.789\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"GHE/YbQ/c5B0JaV8uFWDQkJD3RkooFuQJJWnbQHWi5c=\",\"id\":\"0c59afcb756f4a6dabd29abab7b7cbaa\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13cf76aa-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "fdcd8793-5a17-48c1-90a4-a23140fd4033", + "date": "2023-03-21T23:57:03.405819Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "18044ec7-a1e3-4be4-b394-579b51281b0e", + "username": "dotnet_kernel", + "session": "fdcd8793-5a17-48c1-90a4-a23140fd4033", + "date": "2023-03-21T23:57:03.4009016Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13d97934-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "e2cc8cf7-f75a-4ff5-b183-dfd8a0d17fc8", + "date": "2023-03-21T23:57:03.471416Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3c8a826f-e137-4138-9500-c95d0d705447", + "username": "dotnet_kernel", + "session": "e2cc8cf7-f75a-4ff5-b183-dfd8a0d17fc8", + "date": "2023-03-21T23:57:03.4675100Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13d9a030-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "e2cc8cf7-f75a-4ff5-b183-dfd8a0d17fc8", + "date": "2023-03-21T23:57:03.473422Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3c8a826f-e137-4138-9500-c95d0d705447", + "username": "dotnet_kernel", + "session": "e2cc8cf7-f75a-4ff5-b183-dfd8a0d17fc8", + "date": "2023-03-21T23:57:03.4675100Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13d9c77c-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "e2cc8cf7-f75a-4ff5-b183-dfd8a0d17fc8", + "date": "2023-03-21T23:57:03.474420Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3c8a826f-e137-4138-9500-c95d0d705447", + "username": "dotnet_kernel", + "session": "e2cc8cf7-f75a-4ff5-b183-dfd8a0d17fc8", + "date": "2023-03-21T23:57:03.4675100Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13da50a2-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "b6606cbd-1eac-48af-a193-a08a0407e186", + "date": "2023-03-21T23:57:03.476945Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "c108981f-e7eb-409d-a4e2-b7f143c154d0", + "username": "dotnet_kernel", + "session": "b6606cbd-1eac-48af-a193-a08a0407e186", + "date": "2023-03-21T23:57:03.4747960Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13da9f30-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "b6606cbd-1eac-48af-a193-a08a0407e186", + "date": "2023-03-21T23:57:03.478945Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "c108981f-e7eb-409d-a4e2-b7f143c154d0", + "username": "dotnet_kernel", + "session": "b6606cbd-1eac-48af-a193-a08a0407e186", + "date": "2023-03-21T23:57:03.4747960Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":123456.789,\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"123456.789\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"rZEwNYq6VncJjDWNL1m4Ju6S+CYuaEJzHa3yiEnccz8=\",\"id\":\"a53f8465f1624f67a02a50d55450c36b\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13da9f31-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "b6606cbd-1eac-48af-a193-a08a0407e186", + "date": "2023-03-21T23:57:03.479945Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "c108981f-e7eb-409d-a4e2-b7f143c154d0", + "username": "dotnet_kernel", + "session": "b6606cbd-1eac-48af-a193-a08a0407e186", + "date": "2023-03-21T23:57:03.4747960Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13e2a2ca-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "d10a79b3-f2bf-4965-ab5f-ffb2be84219c", + "date": "2023-03-21T23:57:03.531464Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "31023653-08f8-41e0-b139-8986753d3c59", + "username": "dotnet_kernel", + "session": "d10a79b3-f2bf-4965-ab5f-ffb2be84219c", + "date": "2023-03-21T23:57:03.5282013Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13e2c9d0-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "d10a79b3-f2bf-4965-ab5f-ffb2be84219c", + "date": "2023-03-21T23:57:03.533464Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "31023653-08f8-41e0-b139-8986753d3c59", + "username": "dotnet_kernel", + "session": "d10a79b3-f2bf-4965-ab5f-ffb2be84219c", + "date": "2023-03-21T23:57:03.5282013Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13e2f0ea-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "d10a79b3-f2bf-4965-ab5f-ffb2be84219c", + "date": "2023-03-21T23:57:03.534466Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "31023653-08f8-41e0-b139-8986753d3c59", + "username": "dotnet_kernel", + "session": "d10a79b3-f2bf-4965-ab5f-ffb2be84219c", + "date": "2023-03-21T23:57:03.5282013Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13e38d48-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "cdc78134-7bac-47b9-8911-9eab0dd8fa2e", + "date": "2023-03-21T23:57:03.536468Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "47260d93-057e-4a30-97cd-bac96527a76d", + "username": "dotnet_kernel", + "session": "cdc78134-7bac-47b9-8911-9eab0dd8fa2e", + "date": "2023-03-21T23:57:03.5345230Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13e3c830-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "cdc78134-7bac-47b9-8911-9eab0dd8fa2e", + "date": "2023-03-21T23:57:03.538984Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "47260d93-057e-4a30-97cd-bac96527a76d", + "username": "dotnet_kernel", + "session": "cdc78134-7bac-47b9-8911-9eab0dd8fa2e", + "date": "2023-03-21T23:57:03.5345230Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":\"a\",\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"\\\"a\\\"\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"EHRBR6RzxSQfRIf0W+gIcB9JcFTC2GoExh/GVPqbDIc=\",\"id\":\"5dd7567ed5654290a0c0cd8072b551c1\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13e3ef90-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "cdc78134-7bac-47b9-8911-9eab0dd8fa2e", + "date": "2023-03-21T23:57:03.539983Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "47260d93-057e-4a30-97cd-bac96527a76d", + "username": "dotnet_kernel", + "session": "cdc78134-7bac-47b9-8911-9eab0dd8fa2e", + "date": "2023-03-21T23:57:03.5345230Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13eb300c-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "a6e0ae21-6e9b-4e21-bcf6-6109da3b2d14", + "date": "2023-03-21T23:57:03.587508Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "64610994-f1d6-4764-9abb-f45cdf80eec6", + "username": "dotnet_kernel", + "session": "a6e0ae21-6e9b-4e21-bcf6-6109da3b2d14", + "date": "2023-03-21T23:57:03.5842154Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13eb5708-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "a6e0ae21-6e9b-4e21-bcf6-6109da3b2d14", + "date": "2023-03-21T23:57:03.588513Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "64610994-f1d6-4764-9abb-f45cdf80eec6", + "username": "dotnet_kernel", + "session": "a6e0ae21-6e9b-4e21-bcf6-6109da3b2d14", + "date": "2023-03-21T23:57:03.5842154Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13eb7e4a-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "a6e0ae21-6e9b-4e21-bcf6-6109da3b2d14", + "date": "2023-03-21T23:57:03.589512Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "64610994-f1d6-4764-9abb-f45cdf80eec6", + "username": "dotnet_kernel", + "session": "a6e0ae21-6e9b-4e21-bcf6-6109da3b2d14", + "date": "2023-03-21T23:57:03.5842154Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13ebf366-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "835f4da8-b480-4e43-ab78-9429d28a89b8", + "date": "2023-03-21T23:57:03.592509Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3b0912a1-8d06-4a0a-a3a6-5c8b6707e291", + "username": "dotnet_kernel", + "session": "835f4da8-b480-4e43-ab78-9429d28a89b8", + "date": "2023-03-21T23:57:03.5903346Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13ec41ae-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "835f4da8-b480-4e43-ab78-9429d28a89b8", + "date": "2023-03-21T23:57:03.594512Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3b0912a1-8d06-4a0a-a3a6-5c8b6707e291", + "username": "dotnet_kernel", + "session": "835f4da8-b480-4e43-ab78-9429d28a89b8", + "date": "2023-03-21T23:57:03.5903346Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":\"'\",\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"\\\"'\\\"\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"vCWpq7eP76Fcq0DVXwhcwcT1JLI8N2+yXMgP4dIOJ8E=\",\"id\":\"71e0231f5369459d8f4bdaccbaf1dbf6\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13ec41af-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "835f4da8-b480-4e43-ab78-9429d28a89b8", + "date": "2023-03-21T23:57:03.595513Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "3b0912a1-8d06-4a0a-a3a6-5c8b6707e291", + "username": "dotnet_kernel", + "session": "835f4da8-b480-4e43-ab78-9429d28a89b8", + "date": "2023-03-21T23:57:03.5903346Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13f39d6e-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "faf6bf0c-0eff-4223-8b48-55e56e259df3", + "date": "2023-03-21T23:57:03.643737Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "37087ae6-8314-47c0-9645-42b74d09c2b8", + "username": "dotnet_kernel", + "session": "faf6bf0c-0eff-4223-8b48-55e56e259df3", + "date": "2023-03-21T23:57:03.6399708Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13f3eb7a-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "faf6bf0c-0eff-4223-8b48-55e56e259df3", + "date": "2023-03-21T23:57:03.644740Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "37087ae6-8314-47c0-9645-42b74d09c2b8", + "username": "dotnet_kernel", + "session": "faf6bf0c-0eff-4223-8b48-55e56e259df3", + "date": "2023-03-21T23:57:03.6399708Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13f412a8-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "faf6bf0c-0eff-4223-8b48-55e56e259df3", + "date": "2023-03-21T23:57:03.645743Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "37087ae6-8314-47c0-9645-42b74d09c2b8", + "username": "dotnet_kernel", + "session": "faf6bf0c-0eff-4223-8b48-55e56e259df3", + "date": "2023-03-21T23:57:03.6399708Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13f4af42-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "1f60142b-27b3-4d4a-b7d3-881af33aa186", + "date": "2023-03-21T23:57:03.649748Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "fd5f9d00-b624-4210-bd6d-d3929d3cd70b", + "username": "dotnet_kernel", + "session": "1f60142b-27b3-4d4a-b7d3-881af33aa186", + "date": "2023-03-21T23:57:03.6469344Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13f4fd62-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "1f60142b-27b3-4d4a-b7d3-881af33aa186", + "date": "2023-03-21T23:57:03.652748Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "fd5f9d00-b624-4210-bd6d-d3929d3cd70b", + "username": "dotnet_kernel", + "session": "1f60142b-27b3-4d4a-b7d3-881af33aa186", + "date": "2023-03-21T23:57:03.6469344Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":123,\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"123\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"w2Lzz81sk4E92ARmt8Ly0GokltgLwCNf1OjNMHzWahQ=\",\"id\":\"b72586a26f05418fa35a290ea8e663ce\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13f52472-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "1f60142b-27b3-4d4a-b7d3-881af33aa186", + "date": "2023-03-21T23:57:03.652748Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "fd5f9d00-b624-4210-bd6d-d3929d3cd70b", + "username": "dotnet_kernel", + "session": "1f60142b-27b3-4d4a-b7d3-881af33aa186", + "date": "2023-03-21T23:57:03.6469344Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13fc8f00-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "7aef5b3e-5a3f-4081-8ee6-ad49cffbd965", + "date": "2023-03-21T23:57:03.702353Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "75de5fbf-88ca-4790-b1a4-dd7b28df1af6", + "username": "dotnet_kernel", + "session": "7aef5b3e-5a3f-4081-8ee6-ad49cffbd965", + "date": "2023-03-21T23:57:03.6991011Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13fd044e-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "7aef5b3e-5a3f-4081-8ee6-ad49cffbd965", + "date": "2023-03-21T23:57:03.705353Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "75de5fbf-88ca-4790-b1a4-dd7b28df1af6", + "username": "dotnet_kernel", + "session": "7aef5b3e-5a3f-4081-8ee6-ad49cffbd965", + "date": "2023-03-21T23:57:03.6991011Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13fd2b40-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "7aef5b3e-5a3f-4081-8ee6-ad49cffbd965", + "date": "2023-03-21T23:57:03.706355Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "75de5fbf-88ca-4790-b1a4-dd7b28df1af6", + "username": "dotnet_kernel", + "session": "7aef5b3e-5a3f-4081-8ee6-ad49cffbd965", + "date": "2023-03-21T23:57:03.6991011Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13fda07a-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "4a49c337-d399-41d8-959d-52235e7e2093", + "date": "2023-03-21T23:57:03.709353Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "07ef260d-810e-4302-a742-1cc85cbf8498", + "username": "dotnet_kernel", + "session": "4a49c337-d399-41d8-959d-52235e7e2093", + "date": "2023-03-21T23:57:03.7067687Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13fdee9a-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "4a49c337-d399-41d8-959d-52235e7e2093", + "date": "2023-03-21T23:57:03.711363Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "07ef260d-810e-4302-a742-1cc85cbf8498", + "username": "dotnet_kernel", + "session": "4a49c337-d399-41d8-959d-52235e7e2093", + "date": "2023-03-21T23:57:03.7067687Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":123,\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"123\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"zFOZutOSsv2nn69WT+x7JvOnDL4SVUDoiI03cyVMM+A=\",\"id\":\"a90801b60bf847c1bca0d5a387ab1e77\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "13fe15be-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "4a49c337-d399-41d8-959d-52235e7e2093", + "date": "2023-03-21T23:57:03.711363Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "07ef260d-810e-4302-a742-1cc85cbf8498", + "username": "dotnet_kernel", + "session": "4a49c337-d399-41d8-959d-52235e7e2093", + "date": "2023-03-21T23:57:03.7067687Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "143c7fe8-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "f7918a14-0e70-4104-90ca-db5c3fff28c0", + "date": "2023-03-21T23:57:04.120394Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "93c089ca-2cf6-41e9-ba8b-89795eabd9d2", + "username": "dotnet_kernel", + "session": "f7918a14-0e70-4104-90ca-db5c3fff28c0", + "date": "2023-03-21T23:57:04.1168378Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "143ca6e4-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "f7918a14-0e70-4104-90ca-db5c3fff28c0", + "date": "2023-03-21T23:57:04.122396Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "93c089ca-2cf6-41e9-ba8b-89795eabd9d2", + "username": "dotnet_kernel", + "session": "f7918a14-0e70-4104-90ca-db5c3fff28c0", + "date": "2023-03-21T23:57:04.1168378Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "143ccdfe-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "f7918a14-0e70-4104-90ca-db5c3fff28c0", + "date": "2023-03-21T23:57:04.123400Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "93c089ca-2cf6-41e9-ba8b-89795eabd9d2", + "username": "dotnet_kernel", + "session": "f7918a14-0e70-4104-90ca-db5c3fff28c0", + "date": "2023-03-21T23:57:04.1168378Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "143d4342-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "63c45001-0ac8-4280-9709-af907c66f712", + "date": "2023-03-21T23:57:04.126395Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "ed3a2b9a-1f85-4de6-a088-f14eebc3ea4e", + "username": "dotnet_kernel", + "session": "63c45001-0ac8-4280-9709-af907c66f712", + "date": "2023-03-21T23:57:04.1235594Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "143d914e-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "63c45001-0ac8-4280-9709-af907c66f712", + "date": "2023-03-21T23:57:04.127396Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "ed3a2b9a-1f85-4de6-a088-f14eebc3ea4e", + "username": "dotnet_kernel", + "session": "63c45001-0ac8-4280-9709-af907c66f712", + "date": "2023-03-21T23:57:04.1235594Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":123,\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"123\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"C72GEf7dcgmoPm0nnhHnm20HMrvLiiHEisgc9552Gmk=\",\"id\":\"f08daebf2e974f89bd6819dd2804f8c9\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "143db868-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "63c45001-0ac8-4280-9709-af907c66f712", + "date": "2023-03-21T23:57:04.128396Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "ed3a2b9a-1f85-4de6-a088-f14eebc3ea4e", + "username": "dotnet_kernel", + "session": "63c45001-0ac8-4280-9709-af907c66f712", + "date": "2023-03-21T23:57:04.1235594Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1445d0de-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "ef43d7ec-958d-46fc-930b-4f4b29b0c4fb", + "date": "2023-03-21T23:57:04.182450Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "db2ca6c5-842e-4afb-b4aa-024760a5d312", + "username": "dotnet_kernel", + "session": "ef43d7ec-958d-46fc-930b-4f4b29b0c4fb", + "date": "2023-03-21T23:57:04.1789855Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "14461ef4-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "ef43d7ec-958d-46fc-930b-4f4b29b0c4fb", + "date": "2023-03-21T23:57:04.183451Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "db2ca6c5-842e-4afb-b4aa-024760a5d312", + "username": "dotnet_kernel", + "session": "ef43d7ec-958d-46fc-930b-4f4b29b0c4fb", + "date": "2023-03-21T23:57:04.1789855Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1446460e-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "ef43d7ec-958d-46fc-930b-4f4b29b0c4fb", + "date": "2023-03-21T23:57:04.184453Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "db2ca6c5-842e-4afb-b4aa-024760a5d312", + "username": "dotnet_kernel", + "session": "ef43d7ec-958d-46fc-930b-4f4b29b0c4fb", + "date": "2023-03-21T23:57:04.1789855Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1446bb2a-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "369839f6-3763-4b9a-ab27-91a35b0f02da", + "date": "2023-03-21T23:57:04.187448Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "31c633c0-5a87-4b7b-9e69-453283a3763a", + "username": "dotnet_kernel", + "session": "369839f6-3763-4b9a-ab27-91a35b0f02da", + "date": "2023-03-21T23:57:04.1851540Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "14470968-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "369839f6-3763-4b9a-ab27-91a35b0f02da", + "date": "2023-03-21T23:57:04.189450Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "31c633c0-5a87-4b7b-9e69-453283a3763a", + "username": "dotnet_kernel", + "session": "369839f6-3763-4b9a-ab27-91a35b0f02da", + "date": "2023-03-21T23:57:04.1851540Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":123,\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"123\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"RunlsjKguomM3ZnoJLbJGngLLDvSjkNM6yj9MCfl1Js=\",\"id\":\"1b959f9095a9467fad49ba8a79dd23de\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "14470969-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "369839f6-3763-4b9a-ab27-91a35b0f02da", + "date": "2023-03-21T23:57:04.190452Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "31c633c0-5a87-4b7b-9e69-453283a3763a", + "username": "dotnet_kernel", + "session": "369839f6-3763-4b9a-ab27-91a35b0f02da", + "date": "2023-03-21T23:57:04.1851540Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "144e8472-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "9ae6905c-a5e3-4465-9f6a-0bd69f95edc1", + "date": "2023-03-21T23:57:04.238476Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1c4842fd-505d-4c26-8272-b3879d0f4356", + "username": "dotnet_kernel", + "session": "9ae6905c-a5e3-4465-9f6a-0bd69f95edc1", + "date": "2023-03-21T23:57:04.2354340Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "144ed288-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "9ae6905c-a5e3-4465-9f6a-0bd69f95edc1", + "date": "2023-03-21T23:57:04.241476Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1c4842fd-505d-4c26-8272-b3879d0f4356", + "username": "dotnet_kernel", + "session": "9ae6905c-a5e3-4465-9f6a-0bd69f95edc1", + "date": "2023-03-21T23:57:04.2354340Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "144ef998-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "9ae6905c-a5e3-4465-9f6a-0bd69f95edc1", + "date": "2023-03-21T23:57:04.241476Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "1c4842fd-505d-4c26-8272-b3879d0f4356", + "username": "dotnet_kernel", + "session": "9ae6905c-a5e3-4465-9f6a-0bd69f95edc1", + "date": "2023-03-21T23:57:04.2354340Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "144fe452-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "ae7a4f16-2b78-4335-8890-3250bdd01cc4", + "date": "2023-03-21T23:57:04.248485Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "866c1085-f06c-4304-8ba5-bbb6822e65e2", + "username": "dotnet_kernel", + "session": "ae7a4f16-2b78-4335-8890-3250bdd01cc4", + "date": "2023-03-21T23:57:04.2448866Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "14505982-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "ae7a4f16-2b78-4335-8890-3250bdd01cc4", + "date": "2023-03-21T23:57:04.250484Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "866c1085-f06c-4304-8ba5-bbb6822e65e2", + "username": "dotnet_kernel", + "session": "ae7a4f16-2b78-4335-8890-3250bdd01cc4", + "date": "2023-03-21T23:57:04.2448866Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":123456,\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"123456\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"xTd4hFhSzE7nbdXvXou22Kt7lhRJ5NYc6KONB6sXKMQ=\",\"id\":\"8cf703dea01844d5b75c22e2ad635f03\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "14508088-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "ae7a4f16-2b78-4335-8890-3250bdd01cc4", + "date": "2023-03-21T23:57:04.251484Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "866c1085-f06c-4304-8ba5-bbb6822e65e2", + "username": "dotnet_kernel", + "session": "ae7a4f16-2b78-4335-8890-3250bdd01cc4", + "date": "2023-03-21T23:57:04.2448866Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1457ae58-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "204b444c-74c1-4bc9-b148-18fcff6a29d1", + "date": "2023-03-21T23:57:04.299528Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "46ff46b3-bbbc-43dc-87f1-8e6bba08e2c1", + "username": "dotnet_kernel", + "session": "204b444c-74c1-4bc9-b148-18fcff6a29d1", + "date": "2023-03-21T23:57:04.2961853Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1457fc50-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "204b444c-74c1-4bc9-b148-18fcff6a29d1", + "date": "2023-03-21T23:57:04.300530Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "46ff46b3-bbbc-43dc-87f1-8e6bba08e2c1", + "username": "dotnet_kernel", + "session": "204b444c-74c1-4bc9-b148-18fcff6a29d1", + "date": "2023-03-21T23:57:04.2961853Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{},\"eventType\":\"CommandSucceeded\",\"command\":null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "14582374-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "204b444c-74c1-4bc9-b148-18fcff6a29d1", + "date": "2023-03-21T23:57:04.301530Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "46ff46b3-bbbc-43dc-87f1-8e6bba08e2c1", + "username": "dotnet_kernel", + "session": "204b444c-74c1-4bc9-b148-18fcff6a29d1", + "date": "2023-03-21T23:57:04.2961853Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "145898a4-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "56208075-dec0-406a-af5a-d1479ff09ffd", + "date": "2023-03-21T23:57:04.304535Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "08c38fc4-8cfd-4a83-ba39-91422e9934c2", + "username": "dotnet_kernel", + "session": "56208075-dec0-406a-af5a-d1479ff09ffd", + "date": "2023-03-21T23:57:04.3024996Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "1458e732-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "56208075-dec0-406a-af5a-d1479ff09ffd", + "date": "2023-03-21T23:57:04.306539Z", + "msg_type": "comm_msg", + "version": "5.0" + }, + "parent_header": { + "msg_id": "08c38fc4-8cfd-4a83-ba39-91422e9934c2", + "username": "dotnet_kernel", + "session": "56208075-dec0-406a-af5a-d1479ff09ffd", + "date": "2023-03-21T23:57:04.3024996Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4e11b4c6-503d-4bb2-a80c-e241651d9932", + "data": { + "commandOrEvent": "{\"event\":{\"name\":\"x\",\"value\":123456789012345,\"formattedValue\":{\"mimeType\":\"application/json\",\"value\":\"123456789012345\"}},\"eventType\":\"ValueProduced\",\"command\":{\"token\":\"Vq5j9gdIw4usRMLK5YH0sA4XykJjRvmp+pxGbLWwoGQ=\",\"id\":\"40205575784b445ab13a1c087642600c\",\"commandType\":\"RequestValue\",\"command\":{\"name\":\"x\",\"mimeType\":\"application/json\",\"targetKernelName\":\"testKernel\",\"originUri\":null,\"destinationUri\":null},\"routingSlip\":[]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "14590e2e-c844-11ed-90e6-e790cb0749ec", + "username": "dotnet_kernel", + "session": "56208075-dec0-406a-af5a-d1479ff09ffd", + "date": "2023-03-21T23:57:04.307537Z", + "msg_type": "status", + "version": "5.0" + }, + "parent_header": { + "msg_id": "08c38fc4-8cfd-4a83-ba39-91422e9934c2", + "username": "dotnet_kernel", + "session": "56208075-dec0-406a-af5a-d1479ff09ffd", + "date": "2023-03-21T23:57:04.3024996Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_share_primitives_to_and_from_kernel.python3.json b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_share_primitives_to_and_from_kernel.python3.json new file mode 100644 index 0000000000..337663848c --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.can_share_primitives_to_and_from_kernel.python3.json @@ -0,0 +1,3645 @@ +[ + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_10", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:57.602347Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "7107dd84-5b6d-4ca7-a136-f982b4973404", + "username": "dotnet_kernel", + "session": "31b0360d-4b3d-4d71-bb01-4e290e0d735f", + "date": "2023-03-21T23:56:57.5862234Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_12", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:57.603347Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "7107dd84-5b6d-4ca7-a136-f982b4973404", + "username": "dotnet_kernel", + "session": "31b0360d-4b3d-4d71-bb01-4e290e0d735f", + "date": "2023-03-21T23:56:57.5862234Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_11", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:57.602347Z", + "msg_type": "kernel_info_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "7107dd84-5b6d-4ca7-a136-f982b4973404", + "username": "dotnet_kernel", + "session": "31b0360d-4b3d-4d71-bb01-4e290e0d735f", + "date": "2023-03-21T23:56:57.5862234Z", + "msg_type": "kernel_info_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "protocol_version": "5.3", + "implementation": "ipython", + "implementation_version": "7.31.1", + "language_info": { + "name": "python", + "version": "3.9.13", + "mimetype": "text/x-python", + "file_extension": ".py", + "pygments_lexer": "ipython3", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "nbconvert_exporter": "python" + }, + "banner": "Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)]\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.\n", + "status": "ok", + "help_links": [ + { + "text": "Python Reference", + "url": "https://docs.python.org/3.9" + }, + { + "text": "IPython Reference", + "url": "https://ipython.org/documentation.html" + }, + { + "text": "NumPy Reference", + "url": "https://docs.scipy.org/doc/numpy/reference/" + }, + { + "text": "SciPy Reference", + "url": "https://docs.scipy.org/doc/scipy/reference/" + }, + { + "text": "Matplotlib Reference", + "url": "https://matplotlib.org/contents.html" + }, + { + "text": "SymPy Reference", + "url": "http://docs.sympy.org/latest/index.html" + }, + { + "text": "pandas Reference", + "url": "https://pandas.pydata.org/pandas-docs/stable/" + } + ] + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_13", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:57.608349Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9abd81fb-9dc1-4acf-a948-9c2bcf3e5fa8", + "username": "dotnet_kernel", + "session": "9ed32ff0-d18f-4078-bb04-73cf6cf80155", + "date": "2023-03-21T23:56:57.6062685Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_14", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:57.608349Z", + "msg_type": "execute_input", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9abd81fb-9dc1-4acf-a948-9c2bcf3e5fa8", + "username": "dotnet_kernel", + "session": "9ed32ff0-d18f-4078-bb04-73cf6cf80155", + "date": "2023-03-21T23:56:57.6062685Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "code": "# Copyright (c) .NET Foundation and contributors. All rights reserved.\n# Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\ntry:\n get_ipython().__class__.__name__\nexcept NameError:\n raise Exception(\"This script needs to be run in ipython\")\n \nimport json\ndef __get_dotnet_coe_comm_handler(): \n\n class CommandEventCommTarget:\n __control_comm = None\n __coe_handler = None\n\n def handle_control_comm_opened(self, comm, msg):\n if comm is None:\n raise RuntimeError('Control comm required to open')\n \n self.__control_comm = comm\n self.__control_comm.on_msg(self.handle_control_comm_msg)\n\n self.__coe_handler = CommandEventHandler()\n self.__control_comm.send(self.__coe_handler.is_ready())\n\n def handle_control_comm_msg(self, msg):\n # This shouldn't happen unless someone calls this method manually\n if self.__control_comm is None and not self._is_debug:\n raise RuntimeError('Control comm has not been properly opened')\n\n data = msg['content']['data']\n response = self.__coe_handler.handle_command_or_event(data)\n self.__control_comm.send(response)\n \n \n class CommandEventHandler:\n __exclude_types = [\"\"]\n\n \n def handle_command_or_event(self, data):\n try:\n msg_type = data['type']\n commandOrEvent = json.loads(data['commandOrEvent'])\n # self.__debugLog('handle_command_or_event.last_data_recv', commandOrEvent)\n \n if (msg_type == \"command\"):\n return self.__handle_command(commandOrEvent)\n \n except Exception as e: \n self. __debugLog('handle_command_or_event.commandFailed', e)\n return EventEnvelope(CommandFailed(f'failed to process comm data. {str(e)}')).payload()\n \n def __handle_command(self, commandOrEvent):\n commandType = commandOrEvent['commandType']\n\n envelop = None\n if (commandType == SendValue.__name__):\n envelop = self.__handle_send_value(commandOrEvent)\n elif (commandType == RequestValue.__name__):\n envelop = self.__handle_request_value(commandOrEvent)\n elif (commandType == RequestValueInfos.__name__):\n envelop = self.__handle_request_value_infos(commandOrEvent)\n else: \n envelop = EventEnvelope(CommandFailed(f'command \"{commandType}\" not supported'))\n\n return envelop.payload()\n\n def __handle_request_value_infos(self, command):\n results_who_ls = get_ipython().magic('who_ls')\n variables = globals()\n results = [KernelValueInfo(x, FormattedValue.fromValue(variables[x]), str(type(variables[x]))) \n for x in results_who_ls \n if x in variables and str(type(variables[x])) not in self.__exclude_types]\n\n\n return EventEnvelope(ValueInfosProduced(results), command)\n \n def __handle_request_value(self, command):\n requestValue = RequestValue(command['command'])\n name = requestValue.name\n mimeType = requestValue.mimeType\n \n if (name not in globals()):\n return EventEnvelope(CommandFailed(f'Variable \"{name}\" not found.'))\n \n rawValue = globals()[name]\n updatedValue = None\n\n try: \n import pandas as pd; \n if (isinstance(rawValue, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n updatedValue = rawValue.to_dict('records')\n except Exception as e: \n self. __debugLog('__handle_request_value.dataframe.error', e)\n pass\n\n formattedValue = FormattedValue.fromValue(rawValue, mimeType) \n\n return EventEnvelope(ValueProduced(name, rawValue if updatedValue is None else updatedValue, formattedValue), command)\n \n def __handle_send_value(self, command):\n sendValue = SendValue(command['command'])\n mimeType = sendValue.formattedValue['mimeType']\n name = sendValue.name\n rawValue = sendValue.formattedValue['value']\n resultValue = None\n \n if (not str.isidentifier(name)):\n return EventEnvelope(CommandFailed(f'Invalid Identifier: \"{name}\"'))\n \n if (mimeType == 'application/json'):\n import json; resultValue = json.loads(rawValue)\n elif (mimeType == 'application/table-schema+json'):\n import json; resultValue = json.loads(rawValue)\n try:\n import pandas as pd; resultValue = pd.DataFrame(data=resultValue['data'])\n except Exception as e:\n self.__debugLog('__handle_send_value.dataframe.error', e)\n return EventEnvelope(CommandFailed(f'Cannot create pandas dataframe for: \"{name}\". {str(e)}'))\n \n if (resultValue is not None): \n self.__setVariable(name, resultValue) \n return EventEnvelope(CommandSucceeded())\n \n return EventEnvelope(CommandFailed(f'Failed to set value for \"{name}\". \"{mimeType}\" mimetype not supported.'))\n \n def is_ready(self):\n return EventEnvelope(KernelReady()).payload()\n \n @staticmethod\n def __setVariable(name, value):\n globals()[name] = value\n \n @staticmethod\n def __debugLog(event, message):\n globals()[f'__log__coe_handler.{str(event)}'] = message\n \n \n class KernelCommand: \n pass\n\n class SendValue(KernelCommand): \n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValue(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n\n class RequestValueInfos(KernelCommand):\n def __init__(self, entries):\n self.__dict__.update(**entries)\n \n class FormattedValue:\n def __init__(self, mimeType = 'application/json', value = None):\n self.mimeType = mimeType\n self.value = value\n \n @staticmethod\n def fromValue(value, mimeType = 'application/json'):\n formattedValue = None\n try: \n import pandas as pd; \n if (isinstance(value, pd.DataFrame)):\n mimeType = 'application/table-schema+json'\n except Exception: \n pass\n\n if (mimeType == 'application/json'):\n import json; formattedValue = json.dumps(value)\n elif (mimeType == 'application/table-schema+json'):\n formattedValue = value.to_string(index=False, max_rows=5)\n\n return FormattedValue(mimeType, formattedValue)\n\n class KernelValueInfo:\n def __init__(self, name, formattedValue: FormattedValue, typeName = None):\n self.name = name\n self.formattedValue = formattedValue\n self.typeName = typeName\n \n class KernelEvent:\n pass\n\n class KernelReady(KernelEvent):\n def __init__(self, kernelInfos = []):\n self.kernelInfos = kernelInfos\n\n class CommandSucceeded(KernelEvent):\n pass\n\n class CommandFailed(KernelEvent):\n def __init__(self, message = None):\n self.message = message\n\n class ValueProduced(KernelEvent):\n def __init__(self, name, value, formattedValue: FormattedValue):\n self.name = name\n self.value = value \n self.formattedValue = formattedValue\n \n class ValueInfosProduced(KernelEvent):\n def __init__(self, valueInfos: list[KernelValueInfo]):\n self.valueInfos = valueInfos\n \n class Envelope:\n def payload(self):\n return { 'commandOrEvent': self.__to_json_string(self) }\n\n @staticmethod\n def __to_json_string(obj):\n return json.dumps(obj, default=lambda o: o.__dict__)\n\n class EventEnvelope(Envelope):\n def __init__(self, event: KernelEvent = None, command = None):\n self.event = event\n self.eventType = type(event).__name__\n self.command = command\n\n def payload(self):\n ret = super().payload()\n ret['type'] = 'event'\n return ret\n \n return CommandEventCommTarget()\n\nif hasattr(get_ipython(), 'kernel'):\n get_ipython().kernel.comm_manager.register_target('dotnet_coe_handler_comm', __get_dotnet_coe_comm_handler().handle_control_comm_opened)\n", + "execution_count": 1 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_16", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:57.643862Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9abd81fb-9dc1-4acf-a948-9c2bcf3e5fa8", + "username": "dotnet_kernel", + "session": "9ed32ff0-d18f-4078-bb04-73cf6cf80155", + "date": "2023-03-21T23:56:57.6062685Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_15", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:57.643862Z", + "msg_type": "execute_reply", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9abd81fb-9dc1-4acf-a948-9c2bcf3e5fa8", + "username": "dotnet_kernel", + "session": "9ed32ff0-d18f-4078-bb04-73cf6cf80155", + "date": "2023-03-21T23:56:57.6062685Z", + "msg_type": "execute_request", + "version": "5.3" + }, + "metadata": { + "started": "2023-03-21T23:56:57.608349Z", + "dependencies_met": true, + "engine": "b0eb72ff-f1dd-4d3d-b2a5-967c0d86122d", + "status": "ok" + }, + "content": { + "payload": [], + "user_expressions": {}, + "status": "ok", + "execution_count": 0 + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_17", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:57.647862Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "95588b64-4845-4ac9-886e-5c19f758d5cf", + "username": "dotnet_kernel", + "session": "bf519b79-1591-436f-acfd-877d1a93409d", + "date": "2023-03-21T23:56:57.6469686Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_18", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:57.648868Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "95588b64-4845-4ac9-886e-5c19f758d5cf", + "username": "dotnet_kernel", + "session": "bf519b79-1591-436f-acfd-877d1a93409d", + "date": "2023-03-21T23:56:57.6469686Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"kernelInfos\": []}, \"eventType\": \"KernelReady\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_19", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:57.649867Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "95588b64-4845-4ac9-886e-5c19f758d5cf", + "username": "dotnet_kernel", + "session": "bf519b79-1591-436f-acfd-877d1a93409d", + "date": "2023-03-21T23:56:57.6469686Z", + "msg_type": "comm_open", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_20", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.122305Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "5124ed9f-9ce5-47f9-b100-bd680a059641", + "username": "dotnet_kernel", + "session": "85d25ada-77db-4229-a3e9-fdd018b5e9a8", + "date": "2023-03-21T23:56:58.1199018Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_21", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.122305Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "5124ed9f-9ce5-47f9-b100-bd680a059641", + "username": "dotnet_kernel", + "session": "85d25ada-77db-4229-a3e9-fdd018b5e9a8", + "date": "2023-03-21T23:56:58.1199018Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_22", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.123305Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "5124ed9f-9ce5-47f9-b100-bd680a059641", + "username": "dotnet_kernel", + "session": "85d25ada-77db-4229-a3e9-fdd018b5e9a8", + "date": "2023-03-21T23:56:58.1199018Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_23", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.128307Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "2e70bbea-7366-44ec-96ac-d814d745504c", + "username": "dotnet_kernel", + "session": "ef111457-45d4-484d-bdbd-c3e233099593", + "date": "2023-03-21T23:56:58.1272646Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_24", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.591392Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "2e70bbea-7366-44ec-96ac-d814d745504c", + "username": "dotnet_kernel", + "session": "ef111457-45d4-484d-bdbd-c3e233099593", + "date": "2023-03-21T23:56:58.1272646Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": 2, \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"2\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"S2uhEm4J8dDfFxhjzIlI+1qZTrEU5ordzL1dFUT6iDY=\", \"id\": \"9e2a21db61ca485bb8a2c30d9ffea9f8\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_25", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.591392Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "2e70bbea-7366-44ec-96ac-d814d745504c", + "username": "dotnet_kernel", + "session": "ef111457-45d4-484d-bdbd-c3e233099593", + "date": "2023-03-21T23:56:58.1272646Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_26", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.666950Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9b67b628-1110-42d9-8eda-37ec5bc35f0c", + "username": "dotnet_kernel", + "session": "52360324-eb7f-4e19-a1e4-8bb2609b9535", + "date": "2023-03-21T23:56:58.6657428Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_27", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.667949Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9b67b628-1110-42d9-8eda-37ec5bc35f0c", + "username": "dotnet_kernel", + "session": "52360324-eb7f-4e19-a1e4-8bb2609b9535", + "date": "2023-03-21T23:56:58.6657428Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_28", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.668955Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9b67b628-1110-42d9-8eda-37ec5bc35f0c", + "username": "dotnet_kernel", + "session": "52360324-eb7f-4e19-a1e4-8bb2609b9535", + "date": "2023-03-21T23:56:58.6657428Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_29", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.671952Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "17145650-2e9b-45cb-8b5c-0e9f551b3f49", + "username": "dotnet_kernel", + "session": "314f2f9d-e054-493d-a1bf-65662d4b079b", + "date": "2023-03-21T23:56:58.6715124Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_30", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.671952Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "17145650-2e9b-45cb-8b5c-0e9f551b3f49", + "username": "dotnet_kernel", + "session": "314f2f9d-e054-493d-a1bf-65662d4b079b", + "date": "2023-03-21T23:56:58.6715124Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": -2147483648, \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"-2147483648\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"xeRXhgUA0Ga6Rm6PCrDesEzqPoI977dTeJoeEP59os0=\", \"id\": \"64dc992f6446484a87bb80f89c2a8e36\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_31", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.673949Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "17145650-2e9b-45cb-8b5c-0e9f551b3f49", + "username": "dotnet_kernel", + "session": "314f2f9d-e054-493d-a1bf-65662d4b079b", + "date": "2023-03-21T23:56:58.6715124Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_32", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.759017Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "dfacd497-5cd4-4bde-9ef0-5f45a12afc44", + "username": "dotnet_kernel", + "session": "97695a94-8bcd-4023-9fdb-51ca42fe113f", + "date": "2023-03-21T23:56:58.7564064Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_33", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.760017Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "dfacd497-5cd4-4bde-9ef0-5f45a12afc44", + "username": "dotnet_kernel", + "session": "97695a94-8bcd-4023-9fdb-51ca42fe113f", + "date": "2023-03-21T23:56:58.7564064Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_34", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.761022Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "dfacd497-5cd4-4bde-9ef0-5f45a12afc44", + "username": "dotnet_kernel", + "session": "97695a94-8bcd-4023-9fdb-51ca42fe113f", + "date": "2023-03-21T23:56:58.7564064Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_35", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.764021Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "f85c7f5f-e409-484c-87b4-1b82dc7f0c56", + "username": "dotnet_kernel", + "session": "a8bfeec2-8b58-405e-bf4c-8d457ac50c96", + "date": "2023-03-21T23:56:58.7630014Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_36", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.764021Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "f85c7f5f-e409-484c-87b4-1b82dc7f0c56", + "username": "dotnet_kernel", + "session": "a8bfeec2-8b58-405e-bf4c-8d457ac50c96", + "date": "2023-03-21T23:56:58.7630014Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": 2147483647, \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"2147483647\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"afEH75FZlWTLmAOZMQ208yxoxL6vmN42wBhlLQ+2ExA=\", \"id\": \"2f9e779b61c14652aab3bf9cf9c7765a\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_37", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.765017Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "f85c7f5f-e409-484c-87b4-1b82dc7f0c56", + "username": "dotnet_kernel", + "session": "a8bfeec2-8b58-405e-bf4c-8d457ac50c96", + "date": "2023-03-21T23:56:58.7630014Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_38", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.830073Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "8eda2983-21e8-4bc0-a68d-ecf84802bd64", + "username": "dotnet_kernel", + "session": "723e31c7-69c3-47ce-aeed-3c2e61600153", + "date": "2023-03-21T23:56:58.8286893Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_39", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.831072Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "8eda2983-21e8-4bc0-a68d-ecf84802bd64", + "username": "dotnet_kernel", + "session": "723e31c7-69c3-47ce-aeed-3c2e61600153", + "date": "2023-03-21T23:56:58.8286893Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_40", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.832072Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "8eda2983-21e8-4bc0-a68d-ecf84802bd64", + "username": "dotnet_kernel", + "session": "723e31c7-69c3-47ce-aeed-3c2e61600153", + "date": "2023-03-21T23:56:58.8286893Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_41", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.835076Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "fb6e02e8-59c5-4864-b8b7-608f4942e443", + "username": "dotnet_kernel", + "session": "bc5b8cd7-4973-41d2-84b0-c25ff61596dc", + "date": "2023-03-21T23:56:58.8342760Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_42", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.835076Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "fb6e02e8-59c5-4864-b8b7-608f4942e443", + "username": "dotnet_kernel", + "session": "bc5b8cd7-4973-41d2-84b0-c25ff61596dc", + "date": "2023-03-21T23:56:58.8342760Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": -123456789012345, \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"-123456789012345\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"A7++/FiwcVa/uhEtWbtJui5P4Y3QAysQ2kbMyvvlUS0=\", \"id\": \"f69292e53446441e90049f011097ab89\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_43", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.836082Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "fb6e02e8-59c5-4864-b8b7-608f4942e443", + "username": "dotnet_kernel", + "session": "bc5b8cd7-4973-41d2-84b0-c25ff61596dc", + "date": "2023-03-21T23:56:58.8342760Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_44", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.890130Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "69ecddf9-e182-406f-8750-77190c82a135", + "username": "dotnet_kernel", + "session": "5683554f-5308-4557-82bb-d16672823524", + "date": "2023-03-21T23:56:58.8883746Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_45", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.890130Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "69ecddf9-e182-406f-8750-77190c82a135", + "username": "dotnet_kernel", + "session": "5683554f-5308-4557-82bb-d16672823524", + "date": "2023-03-21T23:56:58.8883746Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_46", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.891130Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "69ecddf9-e182-406f-8750-77190c82a135", + "username": "dotnet_kernel", + "session": "5683554f-5308-4557-82bb-d16672823524", + "date": "2023-03-21T23:56:58.8883746Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_47", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.895131Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "30cbbcbc-9969-43e7-adc6-d1a448082b34", + "username": "dotnet_kernel", + "session": "de4cd0c7-2bc2-40ba-b2b2-4043ede3e0ed", + "date": "2023-03-21T23:56:58.8943661Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_48", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.896130Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "30cbbcbc-9969-43e7-adc6-d1a448082b34", + "username": "dotnet_kernel", + "session": "de4cd0c7-2bc2-40ba-b2b2-4043ede3e0ed", + "date": "2023-03-21T23:56:58.8943661Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": 123456789012345, \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"123456789012345\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"yqZW2Frpf7kjFOJOUSBRhdXhOya6Y9gkiZCs8utnr3A=\", \"id\": \"834777e350c54be6962f94e87b8bda15\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_49", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.896130Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "30cbbcbc-9969-43e7-adc6-d1a448082b34", + "username": "dotnet_kernel", + "session": "de4cd0c7-2bc2-40ba-b2b2-4043ede3e0ed", + "date": "2023-03-21T23:56:58.8943661Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_50", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.957224Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c96b5ebe-7cc2-4ffc-8e50-29e65f4f265a", + "username": "dotnet_kernel", + "session": "bac6ff33-a8a1-410b-93a8-a86edfe67a39", + "date": "2023-03-21T23:56:58.9554635Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_51", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.957224Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c96b5ebe-7cc2-4ffc-8e50-29e65f4f265a", + "username": "dotnet_kernel", + "session": "bac6ff33-a8a1-410b-93a8-a86edfe67a39", + "date": "2023-03-21T23:56:58.9554635Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_52", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.958223Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c96b5ebe-7cc2-4ffc-8e50-29e65f4f265a", + "username": "dotnet_kernel", + "session": "bac6ff33-a8a1-410b-93a8-a86edfe67a39", + "date": "2023-03-21T23:56:58.9554635Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_53", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.961230Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "3a50fe86-230c-4cbc-986d-9bd1dc15b947", + "username": "dotnet_kernel", + "session": "f9a60c17-1799-4172-be6e-9e029114873e", + "date": "2023-03-21T23:56:58.9609336Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_54", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.962229Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "3a50fe86-230c-4cbc-986d-9bd1dc15b947", + "username": "dotnet_kernel", + "session": "f9a60c17-1799-4172-be6e-9e029114873e", + "date": "2023-03-21T23:56:58.9609336Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": true, \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"true\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"4MVMFGGB2IWQ7Thf3AjQLDeBKmhy4KcKtK7ReaiB6uE=\", \"id\": \"7874fb0fdee14231b486fd60886e611a\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_55", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:58.963231Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "3a50fe86-230c-4cbc-986d-9bd1dc15b947", + "username": "dotnet_kernel", + "session": "f9a60c17-1799-4172-be6e-9e029114873e", + "date": "2023-03-21T23:56:58.9609336Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_56", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.032807Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "3328bed8-82cf-474f-834f-8569a5fc492c", + "username": "dotnet_kernel", + "session": "16d260ee-0f27-4537-87b0-dbe39c4537be", + "date": "2023-03-21T23:56:59.0307562Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_57", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.032807Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "3328bed8-82cf-474f-834f-8569a5fc492c", + "username": "dotnet_kernel", + "session": "16d260ee-0f27-4537-87b0-dbe39c4537be", + "date": "2023-03-21T23:56:59.0307562Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_58", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.033806Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "3328bed8-82cf-474f-834f-8569a5fc492c", + "username": "dotnet_kernel", + "session": "16d260ee-0f27-4537-87b0-dbe39c4537be", + "date": "2023-03-21T23:56:59.0307562Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_59", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.037805Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "63669cb7-dc2e-4a9c-a861-a6f4e3fcf027", + "username": "dotnet_kernel", + "session": "be304433-4880-45ab-8cbc-925713e911f8", + "date": "2023-03-21T23:56:59.0366472Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_60", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.037805Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "63669cb7-dc2e-4a9c-a861-a6f4e3fcf027", + "username": "dotnet_kernel", + "session": "be304433-4880-45ab-8cbc-925713e911f8", + "date": "2023-03-21T23:56:59.0366472Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": \"hi!\", \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"\\\"hi!\\\"\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"JCAX+ZZwlMqK2isGTJNC/4qRbARagDF+AsgAJBojcPs=\", \"id\": \"94f8c5ef6861481db40a3ce7cf1ad199\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_61", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.039074Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "63669cb7-dc2e-4a9c-a861-a6f4e3fcf027", + "username": "dotnet_kernel", + "session": "be304433-4880-45ab-8cbc-925713e911f8", + "date": "2023-03-21T23:56:59.0366472Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_62", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.111637Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "1bce5d8b-0e68-4f8d-b545-110501d41497", + "username": "dotnet_kernel", + "session": "add4c18b-2e85-4a3b-975c-ac5172554c4c", + "date": "2023-03-21T23:56:59.1092283Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_63", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.111637Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "1bce5d8b-0e68-4f8d-b545-110501d41497", + "username": "dotnet_kernel", + "session": "add4c18b-2e85-4a3b-975c-ac5172554c4c", + "date": "2023-03-21T23:56:59.1092283Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_64", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.112639Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "1bce5d8b-0e68-4f8d-b545-110501d41497", + "username": "dotnet_kernel", + "session": "add4c18b-2e85-4a3b-975c-ac5172554c4c", + "date": "2023-03-21T23:56:59.1092283Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_65", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.115639Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "f98a5cc0-ed0c-41c8-9ff5-90cdec5966d8", + "username": "dotnet_kernel", + "session": "6b7b068e-2d46-459c-a286-50b89164a653", + "date": "2023-03-21T23:56:59.1153287Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_66", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.116639Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "f98a5cc0-ed0c-41c8-9ff5-90cdec5966d8", + "username": "dotnet_kernel", + "session": "6b7b068e-2d46-459c-a286-50b89164a653", + "date": "2023-03-21T23:56:59.1153287Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": \"hi!\", \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"\\\"hi!\\\"\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"LAVnfMiHp4u6uu07+dPqQEA1rB6QtwDcKlK+tj+0hCI=\", \"id\": \"8265147b8215435b98a8b2a4e78d44b5\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_67", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.117645Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "f98a5cc0-ed0c-41c8-9ff5-90cdec5966d8", + "username": "dotnet_kernel", + "session": "6b7b068e-2d46-459c-a286-50b89164a653", + "date": "2023-03-21T23:56:59.1153287Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_68", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.176203Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "099727b9-b856-4bd9-8ed1-cac150a8a9e7", + "username": "dotnet_kernel", + "session": "379e22f6-a8a5-4733-8ac5-3f941d3e049f", + "date": "2023-03-21T23:56:59.1747323Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_69", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.177201Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "099727b9-b856-4bd9-8ed1-cac150a8a9e7", + "username": "dotnet_kernel", + "session": "379e22f6-a8a5-4733-8ac5-3f941d3e049f", + "date": "2023-03-21T23:56:59.1747323Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_70", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.178201Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "099727b9-b856-4bd9-8ed1-cac150a8a9e7", + "username": "dotnet_kernel", + "session": "379e22f6-a8a5-4733-8ac5-3f941d3e049f", + "date": "2023-03-21T23:56:59.1747323Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_71", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.182215Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9881448f-1b29-4aa5-8cdc-36f33e887d0e", + "username": "dotnet_kernel", + "session": "732148cd-f14f-4c58-b01d-c5660e83f186", + "date": "2023-03-21T23:56:59.1812361Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_72", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.182215Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9881448f-1b29-4aa5-8cdc-36f33e887d0e", + "username": "dotnet_kernel", + "session": "732148cd-f14f-4c58-b01d-c5660e83f186", + "date": "2023-03-21T23:56:59.1812361Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": \"\", \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"\\\"\\\"\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"nttQT+PKyFwNdbHCQRC+ZID0H7XqLTjkgwsJlOgKkts=\", \"id\": \"dbf3abe21b93463da9a0ce1de0b7d5aa\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_73", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.183211Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "9881448f-1b29-4aa5-8cdc-36f33e887d0e", + "username": "dotnet_kernel", + "session": "732148cd-f14f-4c58-b01d-c5660e83f186", + "date": "2023-03-21T23:56:59.1812361Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_74", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.236263Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b4439fb0-0995-471f-b04e-77bf1f6f0038", + "username": "dotnet_kernel", + "session": "74d92336-17bb-44f9-bc98-fa6501f1f405", + "date": "2023-03-21T23:56:59.2342380Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_75", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.236263Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b4439fb0-0995-471f-b04e-77bf1f6f0038", + "username": "dotnet_kernel", + "session": "74d92336-17bb-44f9-bc98-fa6501f1f405", + "date": "2023-03-21T23:56:59.2342380Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_76", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.237261Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b4439fb0-0995-471f-b04e-77bf1f6f0038", + "username": "dotnet_kernel", + "session": "74d92336-17bb-44f9-bc98-fa6501f1f405", + "date": "2023-03-21T23:56:59.2342380Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_77", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.241260Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "eac5a822-bc01-4fd8-b12b-e63430695480", + "username": "dotnet_kernel", + "session": "1eca45ae-8ade-415a-81e8-f6374fa9abc2", + "date": "2023-03-21T23:56:59.2401468Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_78", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.241260Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "eac5a822-bc01-4fd8-b12b-e63430695480", + "username": "dotnet_kernel", + "session": "1eca45ae-8ade-415a-81e8-f6374fa9abc2", + "date": "2023-03-21T23:56:59.2401468Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": \"\\u00ab\\u03c4\\u03b1\\u0411\\u042c\\u2113\\u03c3\\u00bb\", \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"\\\"\\\\u00ab\\\\u03c4\\\\u03b1\\\\u0411\\\\u042c\\\\u2113\\\\u03c3\\\\u00bb\\\"\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"01Yn4+myeN7agWEAAIha12qiQzNa2iYTrXHl/EBMHD0=\", \"id\": \"15fcf3698fe24072a873469fd7a59f25\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_79", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.242267Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "eac5a822-bc01-4fd8-b12b-e63430695480", + "username": "dotnet_kernel", + "session": "1eca45ae-8ade-415a-81e8-f6374fa9abc2", + "date": "2023-03-21T23:56:59.2401468Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_80", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.732436Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "4b4dfe7e-d5f8-4926-b7bd-e0d8a3f180a1", + "username": "dotnet_kernel", + "session": "7e58bdec-c11f-480f-a361-6d3673a72c80", + "date": "2023-03-21T23:56:59.7312922Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_81", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.733436Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "4b4dfe7e-d5f8-4926-b7bd-e0d8a3f180a1", + "username": "dotnet_kernel", + "session": "7e58bdec-c11f-480f-a361-6d3673a72c80", + "date": "2023-03-21T23:56:59.7312922Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_82", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.734437Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "4b4dfe7e-d5f8-4926-b7bd-e0d8a3f180a1", + "username": "dotnet_kernel", + "session": "7e58bdec-c11f-480f-a361-6d3673a72c80", + "date": "2023-03-21T23:56:59.7312922Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_83", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.737438Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "2a6d1998-752f-4caf-b748-e7286723c97e", + "username": "dotnet_kernel", + "session": "5ade9ef1-c083-46cc-ad85-c09d231c277a", + "date": "2023-03-21T23:56:59.7371471Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_84", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.738436Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "2a6d1998-752f-4caf-b748-e7286723c97e", + "username": "dotnet_kernel", + "session": "5ade9ef1-c083-46cc-ad85-c09d231c277a", + "date": "2023-03-21T23:56:59.7371471Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": -123456.789, \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"-123456.789\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"RnDAgUipB+JB2L0vH3euN5XrvITSGSzm3BcnURYNKAI=\", \"id\": \"4b954c6927c44ea3a4aabc37c4ce0b20\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_85", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:56:59.739437Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "2a6d1998-752f-4caf-b748-e7286723c97e", + "username": "dotnet_kernel", + "session": "5ade9ef1-c083-46cc-ad85-c09d231c277a", + "date": "2023-03-21T23:56:59.7371471Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_86", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.160873Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a2cedf94-9ecc-46d3-a7ca-8376e5aba6a7", + "username": "dotnet_kernel", + "session": "ace767dc-0268-4efe-8eb0-d77bbda3a22a", + "date": "2023-03-21T23:57:00.1597601Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_87", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.161872Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a2cedf94-9ecc-46d3-a7ca-8376e5aba6a7", + "username": "dotnet_kernel", + "session": "ace767dc-0268-4efe-8eb0-d77bbda3a22a", + "date": "2023-03-21T23:57:00.1597601Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_88", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.162872Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a2cedf94-9ecc-46d3-a7ca-8376e5aba6a7", + "username": "dotnet_kernel", + "session": "ace767dc-0268-4efe-8eb0-d77bbda3a22a", + "date": "2023-03-21T23:57:00.1597601Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_89", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.165904Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "5b5bcb30-42c9-4a77-9800-9ab1c3184990", + "username": "dotnet_kernel", + "session": "7abe959d-62fb-4e8f-92b2-7588d18a98fa", + "date": "2023-03-21T23:57:00.1653282Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_90", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.165904Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "5b5bcb30-42c9-4a77-9800-9ab1c3184990", + "username": "dotnet_kernel", + "session": "7abe959d-62fb-4e8f-92b2-7588d18a98fa", + "date": "2023-03-21T23:57:00.1653282Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": 123456.789, \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"123456.789\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"KGBJEugwhuHpfGzRv9lSoMinaFOvdddldkd78mlGyt4=\", \"id\": \"326ca38f71d14298b7398858173a9cea\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_91", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.166901Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "5b5bcb30-42c9-4a77-9800-9ab1c3184990", + "username": "dotnet_kernel", + "session": "7abe959d-62fb-4e8f-92b2-7588d18a98fa", + "date": "2023-03-21T23:57:00.1653282Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_92", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.222422Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "bab3368f-e0dc-4e23-ac7e-4592777ea3dd", + "username": "dotnet_kernel", + "session": "740cb38d-8992-49cd-a0e0-0582509058f9", + "date": "2023-03-21T23:57:00.2207487Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_93", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.222422Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "bab3368f-e0dc-4e23-ac7e-4592777ea3dd", + "username": "dotnet_kernel", + "session": "740cb38d-8992-49cd-a0e0-0582509058f9", + "date": "2023-03-21T23:57:00.2207487Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_94", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.223421Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "bab3368f-e0dc-4e23-ac7e-4592777ea3dd", + "username": "dotnet_kernel", + "session": "740cb38d-8992-49cd-a0e0-0582509058f9", + "date": "2023-03-21T23:57:00.2207487Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_95", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.226879Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "51c8965c-cf6a-47ac-9024-f3f3304fa72b", + "username": "dotnet_kernel", + "session": "0095a3ac-172f-416d-8f92-906518dc769b", + "date": "2023-03-21T23:57:00.2261116Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_96", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.226879Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "51c8965c-cf6a-47ac-9024-f3f3304fa72b", + "username": "dotnet_kernel", + "session": "0095a3ac-172f-416d-8f92-906518dc769b", + "date": "2023-03-21T23:57:00.2261116Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": 123.789, \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"123.789\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"3R5k6N2Oj5fR62ydmF9eO0Gs2ZkSgeguOGj7apbLKB8=\", \"id\": \"4b65e29a59ca44edbdfd50fd1c227677\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_97", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.227875Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "51c8965c-cf6a-47ac-9024-f3f3304fa72b", + "username": "dotnet_kernel", + "session": "0095a3ac-172f-416d-8f92-906518dc769b", + "date": "2023-03-21T23:57:00.2261116Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_98", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.305972Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b65e571e-69a3-4b85-8d0b-f9b68995f98e", + "username": "dotnet_kernel", + "session": "9dc2e0cf-576c-4a6a-9243-37060499f316", + "date": "2023-03-21T23:57:00.3029328Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_99", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.305972Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b65e571e-69a3-4b85-8d0b-f9b68995f98e", + "username": "dotnet_kernel", + "session": "9dc2e0cf-576c-4a6a-9243-37060499f316", + "date": "2023-03-21T23:57:00.3029328Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_100", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.306973Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b65e571e-69a3-4b85-8d0b-f9b68995f98e", + "username": "dotnet_kernel", + "session": "9dc2e0cf-576c-4a6a-9243-37060499f316", + "date": "2023-03-21T23:57:00.3029328Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_101", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.309974Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a6281b00-3544-445e-9894-8f7c5b2841b4", + "username": "dotnet_kernel", + "session": "39adf1f5-65cd-448d-a748-46f62649cd5f", + "date": "2023-03-21T23:57:00.3095258Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_102", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.310972Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a6281b00-3544-445e-9894-8f7c5b2841b4", + "username": "dotnet_kernel", + "session": "39adf1f5-65cd-448d-a748-46f62649cd5f", + "date": "2023-03-21T23:57:00.3095258Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": 123456.789, \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"123456.789\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"SQPlBK+fMEo/28ETtjhJPV7vAgpEV5jjs+2mVjXljJQ=\", \"id\": \"898dc829ca3049daaf9f86db5fcec9e7\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_103", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.310972Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a6281b00-3544-445e-9894-8f7c5b2841b4", + "username": "dotnet_kernel", + "session": "39adf1f5-65cd-448d-a748-46f62649cd5f", + "date": "2023-03-21T23:57:00.3095258Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_104", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.366552Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b0dbfcda-a330-4195-bcf2-a5704f615489", + "username": "dotnet_kernel", + "session": "fd4b212b-cc4b-4098-8e34-4049ec886c0b", + "date": "2023-03-21T23:57:00.3651557Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_105", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.366552Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b0dbfcda-a330-4195-bcf2-a5704f615489", + "username": "dotnet_kernel", + "session": "fd4b212b-cc4b-4098-8e34-4049ec886c0b", + "date": "2023-03-21T23:57:00.3651557Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_106", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.367558Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b0dbfcda-a330-4195-bcf2-a5704f615489", + "username": "dotnet_kernel", + "session": "fd4b212b-cc4b-4098-8e34-4049ec886c0b", + "date": "2023-03-21T23:57:00.3651557Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_107", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.372558Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "be45f866-b1ca-479e-9e2d-8983c2485b6a", + "username": "dotnet_kernel", + "session": "6ff4f234-64d8-4cd5-abf4-66425ed0890d", + "date": "2023-03-21T23:57:00.3713073Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_108", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.372558Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "be45f866-b1ca-479e-9e2d-8983c2485b6a", + "username": "dotnet_kernel", + "session": "6ff4f234-64d8-4cd5-abf4-66425ed0890d", + "date": "2023-03-21T23:57:00.3713073Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": \"a\", \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"\\\"a\\\"\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"8lqS5+VOuV7C5P+5r7evam7Y1bnulUrRWPl+6UZgxSY=\", \"id\": \"f043def8013f49ca9db7f3fc8e5dd175\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_109", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.373559Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "be45f866-b1ca-479e-9e2d-8983c2485b6a", + "username": "dotnet_kernel", + "session": "6ff4f234-64d8-4cd5-abf4-66425ed0890d", + "date": "2023-03-21T23:57:00.3713073Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_110", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.428112Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "d3334556-8150-4715-a821-9aa8325a37d1", + "username": "dotnet_kernel", + "session": "541fc088-1fc2-4502-9073-f10d5756ce4a", + "date": "2023-03-21T23:57:00.4260694Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_111", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.428112Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "d3334556-8150-4715-a821-9aa8325a37d1", + "username": "dotnet_kernel", + "session": "541fc088-1fc2-4502-9073-f10d5756ce4a", + "date": "2023-03-21T23:57:00.4260694Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_112", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.429110Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "d3334556-8150-4715-a821-9aa8325a37d1", + "username": "dotnet_kernel", + "session": "541fc088-1fc2-4502-9073-f10d5756ce4a", + "date": "2023-03-21T23:57:00.4260694Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_113", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.432116Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "6e363638-1041-40cc-af18-7e1e97fb8d25", + "username": "dotnet_kernel", + "session": "7432b074-d190-4b5f-be6c-1a5144ee20ab", + "date": "2023-03-21T23:57:00.4318745Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_114", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.433116Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "6e363638-1041-40cc-af18-7e1e97fb8d25", + "username": "dotnet_kernel", + "session": "7432b074-d190-4b5f-be6c-1a5144ee20ab", + "date": "2023-03-21T23:57:00.4318745Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": \"'\", \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"\\\"'\\\"\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"ly9eTiHqrO8MCETt77H22bYI9SqF1XjD33upMTKD7OU=\", \"id\": \"e1c9bff4bdba49028f9d7643e57b4aed\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_115", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.434116Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "6e363638-1041-40cc-af18-7e1e97fb8d25", + "username": "dotnet_kernel", + "session": "7432b074-d190-4b5f-be6c-1a5144ee20ab", + "date": "2023-03-21T23:57:00.4318745Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_116", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.490668Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "2f411d3f-e897-4dc7-b7b9-767299907c77", + "username": "dotnet_kernel", + "session": "852e304b-a9a1-4ed6-a7da-16e5c5571c3d", + "date": "2023-03-21T23:57:00.4899660Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_117", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.491667Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "2f411d3f-e897-4dc7-b7b9-767299907c77", + "username": "dotnet_kernel", + "session": "852e304b-a9a1-4ed6-a7da-16e5c5571c3d", + "date": "2023-03-21T23:57:00.4899660Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_118", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.492674Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "2f411d3f-e897-4dc7-b7b9-767299907c77", + "username": "dotnet_kernel", + "session": "852e304b-a9a1-4ed6-a7da-16e5c5571c3d", + "date": "2023-03-21T23:57:00.4899660Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_119", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.495674Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "32225c21-bd7a-4dcc-8cf9-3662a8c87d85", + "username": "dotnet_kernel", + "session": "a9114a25-5bae-4372-a88d-fdf6c9232631", + "date": "2023-03-21T23:57:00.4948164Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_120", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.495674Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "32225c21-bd7a-4dcc-8cf9-3662a8c87d85", + "username": "dotnet_kernel", + "session": "a9114a25-5bae-4372-a88d-fdf6c9232631", + "date": "2023-03-21T23:57:00.4948164Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": 123, \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"123\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"HRXCRz/MmNNTTkCF9J5yuSwluyprABbMHWViOXRG5+k=\", \"id\": \"feb8c48ef449470296b4bd33c316bf8d\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_121", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.496674Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "32225c21-bd7a-4dcc-8cf9-3662a8c87d85", + "username": "dotnet_kernel", + "session": "a9114a25-5bae-4372-a88d-fdf6c9232631", + "date": "2023-03-21T23:57:00.4948164Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_122", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.550748Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "fc9adb66-e559-4b6b-9851-c72ab20aa55d", + "username": "dotnet_kernel", + "session": "8a9b231f-9042-41c2-8dcc-f87e3333772a", + "date": "2023-03-21T23:57:00.5494757Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_123", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.551750Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "fc9adb66-e559-4b6b-9851-c72ab20aa55d", + "username": "dotnet_kernel", + "session": "8a9b231f-9042-41c2-8dcc-f87e3333772a", + "date": "2023-03-21T23:57:00.5494757Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_124", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.552750Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "fc9adb66-e559-4b6b-9851-c72ab20aa55d", + "username": "dotnet_kernel", + "session": "8a9b231f-9042-41c2-8dcc-f87e3333772a", + "date": "2023-03-21T23:57:00.5494757Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_125", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.556756Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "fb84e847-78d6-42a1-ac45-bd3d8ba3fecb", + "username": "dotnet_kernel", + "session": "0d74041d-19d3-459b-96c2-677e47e76f7e", + "date": "2023-03-21T23:57:00.5554537Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_126", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.556756Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "fb84e847-78d6-42a1-ac45-bd3d8ba3fecb", + "username": "dotnet_kernel", + "session": "0d74041d-19d3-459b-96c2-677e47e76f7e", + "date": "2023-03-21T23:57:00.5554537Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": 123, \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"123\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"2tWWBGRjhGmOKQ6p30s1F+Y36Ao8ekHfTNPZwh6IRv4=\", \"id\": \"bc50960dc7ec449da84de01d226ecc68\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_127", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.557757Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "fb84e847-78d6-42a1-ac45-bd3d8ba3fecb", + "username": "dotnet_kernel", + "session": "0d74041d-19d3-459b-96c2-677e47e76f7e", + "date": "2023-03-21T23:57:00.5554537Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_128", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.616316Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b1135178-0168-4038-9319-3283de511f49", + "username": "dotnet_kernel", + "session": "0d411966-4469-4122-b086-4d4dd3018fa3", + "date": "2023-03-21T23:57:00.6143772Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_129", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.616316Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b1135178-0168-4038-9319-3283de511f49", + "username": "dotnet_kernel", + "session": "0d411966-4469-4122-b086-4d4dd3018fa3", + "date": "2023-03-21T23:57:00.6143772Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_130", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.617321Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "b1135178-0168-4038-9319-3283de511f49", + "username": "dotnet_kernel", + "session": "0d411966-4469-4122-b086-4d4dd3018fa3", + "date": "2023-03-21T23:57:00.6143772Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_131", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.620325Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a47fef3c-4f7c-4e4e-a834-e51b8e4e13f2", + "username": "dotnet_kernel", + "session": "bf52b4d9-0f7e-47bb-9b91-ecf25bc6bc8f", + "date": "2023-03-21T23:57:00.6199452Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_132", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.621322Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a47fef3c-4f7c-4e4e-a834-e51b8e4e13f2", + "username": "dotnet_kernel", + "session": "bf52b4d9-0f7e-47bb-9b91-ecf25bc6bc8f", + "date": "2023-03-21T23:57:00.6199452Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": 123, \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"123\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"P4oAlFo4bQEFWjyFiSO2SDkZzGfCURJUZnzuzkgqxlQ=\", \"id\": \"9c0a8b8b1d1749619387ce1f104c3cc6\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_133", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.622323Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "a47fef3c-4f7c-4e4e-a834-e51b8e4e13f2", + "username": "dotnet_kernel", + "session": "bf52b4d9-0f7e-47bb-9b91-ecf25bc6bc8f", + "date": "2023-03-21T23:57:00.6199452Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_134", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.680374Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c1f1ce28-85ec-4cbd-b66b-9495ab4ebf9e", + "username": "dotnet_kernel", + "session": "f39ca0bd-0feb-44cc-83c5-dd6c5b198ffa", + "date": "2023-03-21T23:57:00.6795194Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_135", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.681371Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c1f1ce28-85ec-4cbd-b66b-9495ab4ebf9e", + "username": "dotnet_kernel", + "session": "f39ca0bd-0feb-44cc-83c5-dd6c5b198ffa", + "date": "2023-03-21T23:57:00.6795194Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_136", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.682372Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "c1f1ce28-85ec-4cbd-b66b-9495ab4ebf9e", + "username": "dotnet_kernel", + "session": "f39ca0bd-0feb-44cc-83c5-dd6c5b198ffa", + "date": "2023-03-21T23:57:00.6795194Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_137", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.685372Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "81e63986-b6df-4459-afca-6c8e39867bcb", + "username": "dotnet_kernel", + "session": "39f5629c-ce4e-4996-9290-10176072d75d", + "date": "2023-03-21T23:57:00.6845350Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_138", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.685372Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "81e63986-b6df-4459-afca-6c8e39867bcb", + "username": "dotnet_kernel", + "session": "39f5629c-ce4e-4996-9290-10176072d75d", + "date": "2023-03-21T23:57:00.6845350Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": 123, \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"123\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"o33zxFIbF4c/l9YDxOoChjUQW1WRBrX1OHtJmV8QDwQ=\", \"id\": \"00a814d12d2b49b4a44d70c737ab1f9c\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_139", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.686371Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "81e63986-b6df-4459-afca-6c8e39867bcb", + "username": "dotnet_kernel", + "session": "39f5629c-ce4e-4996-9290-10176072d75d", + "date": "2023-03-21T23:57:00.6845350Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_140", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.738428Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "40aaef75-8787-4289-b27b-aebfa72920cb", + "username": "dotnet_kernel", + "session": "3a9828bf-9d9f-4ffb-b421-360fc52c22a7", + "date": "2023-03-21T23:57:00.7370024Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_141", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.738428Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "40aaef75-8787-4289-b27b-aebfa72920cb", + "username": "dotnet_kernel", + "session": "3a9828bf-9d9f-4ffb-b421-360fc52c22a7", + "date": "2023-03-21T23:57:00.7370024Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_142", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.739427Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "40aaef75-8787-4289-b27b-aebfa72920cb", + "username": "dotnet_kernel", + "session": "3a9828bf-9d9f-4ffb-b421-360fc52c22a7", + "date": "2023-03-21T23:57:00.7370024Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_143", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.743442Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "ff634216-ca2d-490c-b54a-b63aa95b55d1", + "username": "dotnet_kernel", + "session": "92cabae1-67bb-4f2d-84d0-430fb5e86b35", + "date": "2023-03-21T23:57:00.7424323Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_144", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.743442Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "ff634216-ca2d-490c-b54a-b63aa95b55d1", + "username": "dotnet_kernel", + "session": "92cabae1-67bb-4f2d-84d0-430fb5e86b35", + "date": "2023-03-21T23:57:00.7424323Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": 123456, \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"123456\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"RSuLvlOlNtfwK7H6cxs2Nu1qgEm4fI5Uv1GouG29TCg=\", \"id\": \"ef06f1f4631b497b882b4422df5afb09\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_145", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.744447Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "ff634216-ca2d-490c-b54a-b63aa95b55d1", + "username": "dotnet_kernel", + "session": "92cabae1-67bb-4f2d-84d0-430fb5e86b35", + "date": "2023-03-21T23:57:00.7424323Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_146", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.798998Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "96f60247-901f-4af2-bae2-0dfe2a791689", + "username": "dotnet_kernel", + "session": "1b888bef-fc49-46d8-b67a-7aec645d96fc", + "date": "2023-03-21T23:57:00.7981320Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_147", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.799994Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "96f60247-901f-4af2-bae2-0dfe2a791689", + "username": "dotnet_kernel", + "session": "1b888bef-fc49-46d8-b67a-7aec645d96fc", + "date": "2023-03-21T23:57:00.7981320Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {}, \"eventType\": \"CommandSucceeded\", \"command\": null}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_148", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.800995Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "96f60247-901f-4af2-bae2-0dfe2a791689", + "username": "dotnet_kernel", + "session": "1b888bef-fc49-46d8-b67a-7aec645d96fc", + "date": "2023-03-21T23:57:00.7981320Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_149", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.806000Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "2e9275d9-6064-4ec7-9020-6dbf5249a729", + "username": "dotnet_kernel", + "session": "25cf53e0-5337-4e7d-a5a4-5d59b3afe2ff", + "date": "2023-03-21T23:57:00.8047989Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "busy" + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_150", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.806000Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "parent_header": { + "msg_id": "2e9275d9-6064-4ec7-9020-6dbf5249a729", + "username": "dotnet_kernel", + "session": "25cf53e0-5337-4e7d-a5a4-5d59b3afe2ff", + "date": "2023-03-21T23:57:00.8047989Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "comm_id": "4fcb6a5d-8e7c-4aee-b655-291c5997a3f4", + "data": { + "commandOrEvent": "{\"event\": {\"name\": \"x\", \"value\": 123456789012345, \"formattedValue\": {\"mimeType\": \"application/json\", \"value\": \"123456789012345\"}}, \"eventType\": \"ValueProduced\", \"command\": {\"token\": \"Q6lkeLMOzEfAK2TbwBhLmJsdHJiWvYZCZCP3Suy4L9o=\", \"id\": \"b3a1f51e5b3e447d941d6786948f4d1a\", \"commandType\": \"RequestValue\", \"command\": {\"name\": \"x\", \"mimeType\": \"application/json\", \"targetKernelName\": \"testKernel\", \"originUri\": null, \"destinationUri\": null}, \"routingSlip\": [\"kernel://local/testKernel?tag=arrived\"]}}", + "type": "event" + } + }, + "buffers": [], + "channel": "shell" + }, + { + "header": { + "msg_id": "9e2daf5a-89cc8447774ddd337d5d5c87_17556_151", + "username": "username", + "session": "9e2daf5a-89cc8447774ddd337d5d5c87", + "date": "2023-03-21T23:57:00.807002Z", + "msg_type": "status", + "version": "5.3" + }, + "parent_header": { + "msg_id": "2e9275d9-6064-4ec7-9020-6dbf5249a729", + "username": "dotnet_kernel", + "session": "25cf53e0-5337-4e7d-a5a4-5d59b3afe2ff", + "date": "2023-03-21T23:57:00.8047989Z", + "msg_type": "comm_msg", + "version": "5.3" + }, + "metadata": {}, + "content": { + "execution_state": "idle" + }, + "buffers": [], + "channel": "shell" + } +] \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.cs b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.cs new file mode 100644 index 0000000000..b5b783cc4f --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterKernelVariableSharingTests.cs @@ -0,0 +1,631 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using FluentAssertions; +using FluentAssertions.Execution; +using Microsoft.DotNet.Interactive.Commands; +using Microsoft.DotNet.Interactive.Events; +using Microsoft.DotNet.Interactive.Formatting; +using Microsoft.DotNet.Interactive.Formatting.TabularData; +using Microsoft.DotNet.Interactive.Jupyter.Protocol; +using Microsoft.DotNet.Interactive.Tests.Utility; +using Microsoft.DotNet.Interactive.ValueSharing; +using System.Linq; +using System.Text.Json; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.DotNet.Interactive.Jupyter.Tests; + +public static class ValueSharingMessageAssertionExtensions +{ + public static void ShouldContainCommMsgWithValues(this SubscribedList messages, params string[] values) + { + messages + .Should() + .ContainSingle(m => m.Header.MessageType == JupyterMessageContentTypes.CommMsg) + .Which + .Content + .Should() + .BeOfType() + .Which + .ShouldContainValues(values); + } + + public static void ShouldContainValues(this CommMsg commMsg, params string[] values) + { + commMsg + .Data + .Should() + .ContainKey("commandOrEvent") + .WhoseValue + .ToString() + .Should() + .ContainAll(values); + } +} + +public class JupyterKernelVariableSharingTests : JupyterKernelTestBase +{ + private async Task SharedValueShouldBeReturnedBackSame(T expectedValue, string csharpDeclaration, Kernel kernel, TestJupyterConnectionOptions options) + { + var result = await kernel.SubmitCodeAsync(csharpDeclaration); + var events = result.Events; + + events.Should().NotContainErrors(); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + result = await kernel.SubmitCodeAsync($"#!testKernel\n#!share --from csharp x"); + events = result.Events; + + events.Should().NotContainErrors(); + sentMessages.ShouldContainCommMsgWithValues("SendValue", "x"); + + result = await kernel.SubmitCodeAsync($"#!share --from testKernel x"); + events = result.Events; + + events + .Should() + .NotContainErrors(); + + events + .Should() + .ContainSingle() + .Which + .Value + .Should() + .Be(expectedValue); + } + + [Theory] + [JupyterHttpTestData(KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterHttpTestData(KernelSpecName = RKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData(KernelSpecName = PythonKernelName)] + [JupyterZMQTestData(KernelSpecName = RKernelName)] + [JupyterTestData(KernelSpecName = PythonKernelName)] + [JupyterTestData(KernelSpecName = RKernelName)] + public async Task can_share_primitives_to_and_from_kernel(JupyterConnectionTestData connectionData) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = CreateCompositeKernelAsync(options); + + await kernel.SubmitCodeAsync( + $"#!connect jupyter --kernel-name testKernel --kernel-spec {connectionData.KernelSpecName} {connectionData.GetConnectionString()}"); + + using (new AssertionScope()) + { + await SharedValueShouldBeReturnedBackSame((long)2, $"var x = 2;", kernel, options); + await SharedValueShouldBeReturnedBackSame(int.MinValue, $"int x = {int.MinValue};", kernel, options); + await SharedValueShouldBeReturnedBackSame(int.MaxValue, $"int x = {int.MaxValue};", kernel, options); + await SharedValueShouldBeReturnedBackSame(-123456789012345, $"long x = -123456789012345;", kernel, options); + await SharedValueShouldBeReturnedBackSame(123456789012345, $"long x = 123456789012345;", kernel, options); + await SharedValueShouldBeReturnedBackSame(true, $"bool x = true;", kernel, options); + await SharedValueShouldBeReturnedBackSame("hi!", $"var x = \"hi!\";", kernel, options); + await SharedValueShouldBeReturnedBackSame("hi!", $"string x = \"hi!\";", kernel, options); + await SharedValueShouldBeReturnedBackSame("", $"string x = \"\";", kernel, options); + await SharedValueShouldBeReturnedBackSame("«ταБЬℓσ»", $"string x = \"«ταБЬℓσ»\";", kernel, options); + await SharedValueShouldBeReturnedBackSame(-123456.789, $"double x = -123456.789;", kernel, options); + await SharedValueShouldBeReturnedBackSame(123456.789, $"double x = 123456.789;", kernel, options); + await SharedValueShouldBeReturnedBackSame(123.789, $"float x = 123.789f;", kernel, options); + await SharedValueShouldBeReturnedBackSame(123456.789, $"decimal x = 123456.789M;", kernel, options); + await SharedValueShouldBeReturnedBackSame("a", $"char x = 'a';", kernel, options); + await SharedValueShouldBeReturnedBackSame("'", $"char x = '\\'';", kernel, options); + await SharedValueShouldBeReturnedBackSame((long)123, $"byte x = 123;", kernel, options); + await SharedValueShouldBeReturnedBackSame((long)123, $"short x = 123;", kernel, options); + await SharedValueShouldBeReturnedBackSame((long)123, $"sbyte x = 123;", kernel, options); + await SharedValueShouldBeReturnedBackSame((long)123, $"ushort x = 123;", kernel, options); + await SharedValueShouldBeReturnedBackSame((long)123456, $"uint x = 123456;", kernel, options); + await SharedValueShouldBeReturnedBackSame(123456789012345, $"ulong x = 123456789012345;", kernel, options); + } + + options.SaveState(); + } + + [Theory] + [JupyterHttpTestData("df_in_kernel.equals(df_roundtrip)", "True", KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("df_in_kernel.equals(df_roundtrip)", "True", KernelSpecName = PythonKernelName)] + [JupyterTestData("df_in_kernel.equals(df_roundtrip)", "True", KernelSpecName = PythonKernelName)] + [JupyterHttpTestData("identical(df_in_kernel, df_roundtrip)", "[1] TRUE", KernelSpecName = RKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("identical(df_in_kernel, df_roundtrip)", "[1] TRUE", KernelSpecName = RKernelName)] + [JupyterTestData("identical(df_in_kernel, df_roundtrip)", "[1] TRUE", KernelSpecName = RKernelName)] + public async Task can_share_dataframe_to_from_kernel(JupyterConnectionTestData connectionData, string assertIdentical, string expectedAssertionResult) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = CreateCompositeKernelAsync(options); + + await kernel.SubmitCodeAsync( + $"#!connect jupyter --kernel-name testKernel --kernel-spec {connectionData.KernelSpecName} {connectionData.GetConnectionString()}"); + + var df = JsonDocument.Parse(@" +[ + { + ""name"": ""Granny Smith apple"", + ""deliciousness"": 0, + ""color"":""red"" + }, + { + ""name"": ""Rainier cherry"", + ""deliciousness"": 9000, + ""color"":""yellow"" + } +]").ToTabularDataResource(); + + var result = await kernel.SendAsync(new SendValue("df", df, null, "csharp")); + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + + result = await kernel.SubmitCodeAsync($"#!testKernel\n#!share --from csharp df --as df_in_kernel"); + events = result.Events; + + events + .Should() + .NotContainErrors(); + + sentMessages.ShouldContainCommMsgWithValues("SendValue", "df_in_kernel"); + + sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + var dfResult = await kernel.SendAsync(new RequestValue("df_in_kernel", "application/json", "testKernel")); + + dfResult + .Events + .Should() + .NotContainErrors(); + + sentMessages.ShouldContainCommMsgWithValues("RequestValue", "df_in_kernel"); + + dfResult + .Events + .Should() + .ContainSingle() + .Which + .Value + .Should() + .BeAssignableTo() + .Which + .Data + .Should() + .BeEquivalentTo(df.Data); + + result = await kernel.SubmitCodeAsync(@" +#!share --from testKernel df_in_kernel --as df_shared +#!testKernel +#!share --from csharp df_shared --as df_roundtrip +"); + events = result.Events; + + events + .Should() + .NotContainErrors(); + + var csharpDf = await kernel.SendAsync(new RequestValue("df_shared", "application/json", "csharp")); + + csharpDf + .Events + .Should() + .NotContainErrors(); + + csharpDf + .Events + .Should() + .ContainSingle() + .Which + .Value + .Should() + .BeAssignableTo() + .Which + .Data + .Should() + .BeEquivalentTo(df.Data); + + result = await kernel.SubmitCodeAsync($"#!testKernel\n{assertIdentical}"); + events = result.Events; + + events + .Should() + .NotContainErrors(); + + events + .Should() + .ContainSingle() + .Which + .FormattedValues + .Should() + .ContainSingle(v => v.MimeType == PlainTextFormatter.MimeType) + .Which + .Value + .Should() + .Be(expectedAssertionResult); + // kernel was able to validate that round-tripped dataframes were equal + + options.SaveState(); + } + + // for validating the kernel side logic, this test is intended to be run against a jupyter connection that and not just a test connection + [Theory] + [JupyterHttpTestData(KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData(KernelSpecName = PythonKernelName)] + [JupyterTestData(KernelSpecName = PythonKernelName)] + [JupyterHttpTestData(KernelSpecName = RKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData(KernelSpecName = RKernelName)] + [JupyterTestData(KernelSpecName = RKernelName)] + public async Task can_handle_setting_multiple_df_on_kernel(JupyterConnectionTestData connectionData) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = await CreateJupyterKernelAsync(options, connectionData.KernelSpecName, connectionData.GetConnectionString()); + + var dfs = new[] { + JsonDocument.Parse(@" +[ + { + ""name"": ""Granny Smith apple"", + ""deliciousness"": 0, + ""color"":""red"" + }, + { + ""name"": ""Rainier cherry"", + ""deliciousness"": 9000, + ""color"":""yellow"" + } +]").ToTabularDataResource(), + JsonDocument.Parse(@" +[ + { + ""a"": ""1"", + ""b"": 1 + }, + { + ""a"": ""2"", + ""b"": 2 + } +]").ToTabularDataResource() + }; + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + var sendCommand = new SendValue("df", dfs, new FormattedValue("application/json", null)); + var result = await kernel.SendAsync(sendCommand); + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + var commMessages = sentMessages + .Where(m => m.Header.MessageType == JupyterMessageContentTypes.CommMsg) + .ToList(); + + commMessages + .Should() + .HaveCount(2); + + for (int i = 0; i < commMessages.Count; i++) + { + var message = commMessages[i].Content.As(); + message.ShouldContainValues("SendValue", $"df{i+1}"); + } + + events + .Should() + .ContainSingle() + .Which + .FormattedValues + .Should() + .ContainSingle(v => v.MimeType == PlainTextFormatter.MimeType) + .Which + .Value + .Should() + .ContainAll("df1", "df2"); + + var df1Result = await kernel.SendAsync(new RequestValue("df1")); + + df1Result + .Events + .Should() + .NotContainErrors(); + + df1Result + .Events + .Should() + .ContainSingle() + .Which + .Value + .Should() + .BeAssignableTo() + .Which + .Data + .Should() + .BeEquivalentTo(dfs[0].Data); + + var df2Result = await kernel.SendAsync(new RequestValue("df2")); + + df2Result + .Events + .Should() + .NotContainErrors(); + + df2Result + .Events + .Should() + .ContainSingle() + .Which + .Value + .Should() + .BeAssignableTo() + .Which + .Data + .Should() + .BeEquivalentTo(dfs[1].Data); + + options.SaveState(); + } + + // for validating the kernel side logic, this test is intended to be run against a jupyter connection that and not just a test connection + [Theory] + [JupyterHttpTestData(KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData(KernelSpecName = PythonKernelName)] + [JupyterHttpTestData(KernelSpecName = RKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData(KernelSpecName = RKernelName)] + [JupyterTestData(KernelSpecName = PythonKernelName)] + [JupyterTestData(KernelSpecName = RKernelName)] + public async Task can_handle_setting_single_df_in_enumerable_on_kernel(JupyterConnectionTestData connectionData) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = await CreateJupyterKernelAsync(options, connectionData.KernelSpecName, connectionData.GetConnectionString()); + + var dfs = new[] { + JsonDocument.Parse(@" +[ + { + ""name"": ""Granny Smith apple"", + ""deliciousness"": 0, + ""color"":""red"" + }, + { + ""name"": ""Rainier cherry"", + ""deliciousness"": 9000, + ""color"":""yellow"" + } +]").ToTabularDataResource() + }; + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + var sendCommand = new SendValue("df", dfs, new FormattedValue("application/json", null)); + var result = await kernel.SendAsync(sendCommand); + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + events + .Should() + .NotContain(e => e is DisplayedValueProduced); + + sentMessages.ShouldContainCommMsgWithValues("SendValue", "df"); + + var dfResult = await kernel.SendAsync(new RequestValue("df")); + + dfResult + .Events + .Should() + .NotContainErrors(); + + dfResult + .Events + .Should() + .ContainSingle() + .Which + .Value + .Should() + .BeAssignableTo() + .Which + .Data + .Should() + .BeEquivalentTo(dfs[0].Data); + + options.SaveState(); + } + + // for validating the kernel side logic, this test is intended to be run against a jupyter connection that and not just a test connection + [Theory] + [JupyterHttpTestData(KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData(KernelSpecName = PythonKernelName)] + [JupyterHttpTestData(KernelSpecName = RKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData(KernelSpecName = RKernelName)] + [JupyterTestData(KernelSpecName = PythonKernelName)] + [JupyterTestData(KernelSpecName = RKernelName)] + public async Task can_handle_setting_single_df_on_kernel(JupyterConnectionTestData connectionData) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = await CreateJupyterKernelAsync(options, connectionData.KernelSpecName, connectionData.GetConnectionString()); + + var df = JsonDocument.Parse(@" +[ + { + ""name"": ""Granny Smith apple"", + ""deliciousness"": 0, + ""color"":""red"" + }, + { + ""name"": ""Rainier cherry"", + ""deliciousness"": 9000, + ""color"":""yellow"" + } +]").ToTabularDataResource(); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + var sendCommand = new SendValue("df", df, new FormattedValue("application/json", null)); + var result = await kernel.SendAsync(sendCommand); + var events = result.Events; + + events + .Should() + .NotContainErrors(); + + events + .Should() + .NotContain(e => e is DisplayedValueProduced); + + sentMessages.ShouldContainCommMsgWithValues("SendValue", "df"); + + var dfResult = await kernel.SendAsync(new RequestValue("df")); + + dfResult + .Events + .Should() + .NotContainErrors(); + + dfResult + .Events + .Should() + .ContainSingle() + .Which + .Value + .Should() + .BeAssignableTo() + .Which + .Data + .Should() + .BeEquivalentTo(df.Data); + + options.SaveState(); + } + + [Theory] + [JupyterHttpTestData("a.b", KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterHttpTestData("_ab", KernelSpecName = RKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("a.b", KernelSpecName = PythonKernelName)] + [JupyterZMQTestData("_ab", KernelSpecName = RKernelName)] + [JupyterTestData("a.b", KernelSpecName = PythonKernelName)] + [JupyterTestData("_ab", KernelSpecName = RKernelName)] + public async Task can_handle_errors_for_send_value_from_kernel(JupyterConnectionTestData connectionData, string invalidId) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = await CreateJupyterKernelAsync(options, connectionData.KernelSpecName, connectionData.GetConnectionString()); + + var sendCommand = new SendValue(invalidId, "1", new FormattedValue("application/json", "1")); + var result = await kernel.SendAsync(sendCommand); + var events = result.Events; + + events + .Should() + .ContainSingle() + .Which + .Message + .Should() + .ContainAll("Invalid Identifier", invalidId); + + options.SaveState(); + } + + [Theory] + [JupyterHttpTestData(KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterHttpTestData(KernelSpecName = RKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData(KernelSpecName = PythonKernelName)] + [JupyterZMQTestData(KernelSpecName = RKernelName)] + [JupyterTestData(KernelSpecName = PythonKernelName)] + [JupyterTestData(KernelSpecName = RKernelName)] + public async Task can_handle_errors_for_request_value_from_kernel(JupyterConnectionTestData connectionData) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = await CreateJupyterKernelAsync(options, connectionData.KernelSpecName, connectionData.GetConnectionString()); + + var result = await kernel.SendAsync(new RequestValue("unknownVar")); + var events = result.Events; + + events + .Should() + .ContainSingle() + .Which + .Message + .Should() + .ContainAll("not found", "unknownVar"); + + options.SaveState(); + } + + [Theory] + [JupyterHttpTestData("a = 12345", new[] { "a", "b", "df" }, new[] { "application/json", "application/json", "application/table-schema+json" }, new[] { "12345", "6789", " name deliciousness color\nGranny Smith apple 0 red\n Rainier cherry 9000 yellow" }, new[] { "", "", "" }, KernelSpecName = PythonKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("a = 12345", new[] { "a", "b", "df" }, new[] { "application/json", "application/json", "application/table-schema+json" }, new[] { "12345", "6789", " name deliciousness color\nGranny Smith apple 0 red\n Rainier cherry 9000 yellow" }, new[] { "", "", "" }, KernelSpecName = PythonKernelName)] + [JupyterTestData("a = 12345", new[] { "a", "b", "df" }, new[] { "application/json", "application/json", "application/table-schema+json" }, new[] { "12345", "6789", " name deliciousness color\nGranny Smith apple 0 red\n Rainier cherry 9000 yellow" }, new[] { "", "", "" }, KernelSpecName = PythonKernelName)] + [JupyterHttpTestData("a <- 12345", new[] { "a", "b", "df" }, new[] { "application/json", "application/json", "application/table-schema+json" }, new[] { "12345", "6789", "[{\"name\":\"Granny Smith apple\",\"deliciousness\":0,\"color\":\"red\"},{\"name\":\"Rainier cherry\",\"deliciousness\":9000,\"color\":\"yellow\"}]" }, new[] { "double", "integer", "data.frame" }, KernelSpecName = RKernelName, AllowPlayback = RECORD_FOR_PLAYBACK)] + [JupyterZMQTestData("a <- 12345", new[] { "a", "b", "df" }, new[] { "application/json", "application/json", "application/table-schema+json" }, new[] { "12345", "6789", "[{\"name\":\"Granny Smith apple\",\"deliciousness\":0,\"color\":\"red\"},{\"name\":\"Rainier cherry\",\"deliciousness\":9000,\"color\":\"yellow\"}]" }, new[] { "double", "integer", "data.frame" }, KernelSpecName = RKernelName)] + [JupyterTestData("a <- 12345", new[] { "a", "b", "df" }, new[] { "application/json", "application/json", "application/table-schema+json" }, new[] { "12345", "6789", "[{\"name\":\"Granny Smith apple\",\"deliciousness\":0,\"color\":\"red\"},{\"name\":\"Rainier cherry\",\"deliciousness\":9000,\"color\":\"yellow\"}]" }, new[] { "double", "integer", "data.frame" }, KernelSpecName = RKernelName)] + public async Task can_request_value_infos_for_shared_and_kernel_variables(JupyterConnectionTestData connectionData, string kernelVarDeclare, string[] variables, string[] mimeTypes, string[] formattedValues, string[] typeNames) + { + var options = connectionData.GetConnectionOptions(); + + var kernel = await CreateJupyterKernelAsync(options, connectionData.KernelSpecName, connectionData.GetConnectionString()); + + // setting variable on kernel + await kernel.SubmitCodeAsync(kernelVarDeclare); + + // share a variable + await kernel.SendAsync(new SendValue("b", 6789, new FormattedValue("application/json", "6789"))); + + var df = JsonDocument.Parse(@" +[ + { + ""name"": ""Granny Smith apple"", + ""deliciousness"": 0, + ""color"":""red"" + }, + { + ""name"": ""Rainier cherry"", + ""deliciousness"": 9000, + ""color"":""yellow"" + } +]").ToTabularDataResource(); + + // share a dataframe + await kernel.SendAsync(new SendValue("df", df, + new FormattedValue(TabularDataResourceFormatter.MimeType, + JsonSerializer.Serialize(df, TabularDataResourceFormatter.JsonSerializerOptions)))); + + var sentMessages = options.MessageTracker.SentMessages.ToSubscribedList(); + var results = await kernel.SendAsync(new RequestValueInfos()); + var events = results.Events; + + events + .Should() + .NotContainErrors(); + + sentMessages.ShouldContainCommMsgWithValues("RequestValueInfos"); + + var valueInfos = events + .Should() + .ContainSingle() + .Which + .ValueInfos; + + valueInfos + .Select(v => v.Name) + .Should() + .Contain("a", "b", "df"); + + Assert.Equal(variables.Length, valueInfos.Count()); + + for (int i = 0; i < variables.Length; i++) + { + valueInfos + .First(v => v.Name == variables[i]) + .Should() + .BeEquivalentTo( + new KernelValueInfo(variables[i], + new FormattedValue(mimeTypes[i], formattedValues[i]), + null, typeNames[i])); + } + options.SaveState(); + } +} diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterMessageSerializationTests.cs b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterMessageSerializationTests.cs new file mode 100644 index 0000000000..da9c7b000a --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterMessageSerializationTests.cs @@ -0,0 +1,67 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using FluentAssertions; +using Microsoft.DotNet.Interactive.Jupyter.Messaging; +using Microsoft.DotNet.Interactive.Jupyter.Protocol; +using Microsoft.DotNet.Interactive.Tests.Utility; +using System.Collections.Generic; +using System.Text.Json; +using Xunit; +using Xunit.Abstractions; +using Message = Microsoft.DotNet.Interactive.Jupyter.Messaging.Message; + +namespace Microsoft.DotNet.Interactive.Jupyter.Tests; + +public class JupyterMessageSerializationTests +{ + private readonly ITestOutputHelper _output; + + public JupyterMessageSerializationTests(ITestOutputHelper output) + { + _output = output; + } + + [Theory] + [MemberData(nameof(Messages))] + public void All_message_types_are_round_trip_serializable(Message message) + { + var json = JsonSerializer.Serialize(message, MessageFormatter.SerializerOptions); + + _output.WriteLine(json); + + var deserializedMessage = JsonSerializer.Deserialize(json, MessageFormatter.SerializerOptions); + + deserializedMessage + .Should() + .BeEquivalentToRespectingRuntimeTypes(message); + } + + public static IEnumerable Messages() + { + foreach (var message in messages()) + { + yield return new object[] { message }; + } + + // for each message test with values and null values where it's allowed + IEnumerable messages() + { + yield return Message.Create(new KernelInfoRequest()); + + yield return Message.Create(new KernelInfoReply("protocolVersion", "implementation", null, new LanguageInfo("name", "version", "mimeType", "fileExt"))); + + // codeMirror setting + yield return Message.Create(new KernelInfoReply("protocolVersion", "implementation", null, + new LanguageInfo("name", "version", "mimeType", "fileExt", "pygmentsLexer", null , "nbConvertExplorer"), + "banner", null)); + + yield return Message.Create(new Status(StatusValues.Idle)); + + yield return Message.Create(new ExecuteRequest("code")); + + yield return Message.Create(new ExecuteReplyOk()); + + }; + } +} diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/LanguageHandlerTests/run_python_tests.bat b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/LanguageHandlerTests/run_python_tests.bat new file mode 100644 index 0000000000..2654d62481 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/LanguageHandlerTests/run_python_tests.bat @@ -0,0 +1,6 @@ +@ECHO OFF +REM this script needs to be run in a conda environment where ipython is installed + +REM run python tests using ipython +ipython ./tests_python_coe_comm_handler.py + diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/LanguageHandlerTests/run_r_tests.bat b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/LanguageHandlerTests/run_r_tests.bat new file mode 100644 index 0000000000..a2e98bc3cb --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/LanguageHandlerTests/run_r_tests.bat @@ -0,0 +1,6 @@ +@ECHO OFF +REM this script needs to be run in a conda environment where RScript is installed + +REM run R tests using Rscript +RScript tests_r_coe_comm_handler.r + diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/LanguageHandlerTests/run_tests.bat b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/LanguageHandlerTests/run_tests.bat new file mode 100644 index 0000000000..11e065d429 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/LanguageHandlerTests/run_tests.bat @@ -0,0 +1,8 @@ +@ECHO OFF +REM this script needs to be run in a conda environment where IPython and RScript are installed + +ECHO "Running Python tests" +CALL "run_python_tests.bat" + +ECHO "Running R tests" +CALL "run_r_tests.bat" diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/LanguageHandlerTests/tests_python_coe_comm_handler.py b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/LanguageHandlerTests/tests_python_coe_comm_handler.py new file mode 100644 index 0000000000..d21b69862a --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/LanguageHandlerTests/tests_python_coe_comm_handler.py @@ -0,0 +1,276 @@ +# Copyright (c) .NET Foundation and contributors. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +# Run this test using: +# > ipython tests_python_coe_comm_handler.py + +import sys +sys.path.append('../../Microsoft.DotNet.Interactive.Jupyter/CommandEvents/LanguageHandlers/python') + +import json +import unittest +from coe_comm_handler import __get_dotnet_coe_comm_handler as get_dotnet_coe_comm_handler +import coe_comm_handler + +class testComm: + __msg_handler = None + # message sent back to the comm channel + msg_sent = None + def handle_msg(self, msg): + self.__msg_handler(msg) + + def on_msg(self, handler): + self.__msg_handler = handler + + def send(self, msg): + self.msg_sent = msg + +class TestCoeCommHandler(unittest.TestCase): + + def __init__(self, methodName: str = ...) -> None: + super().__init__(methodName) + self.maxDiff = None + + @staticmethod + def create_msg_received(commandType, commandReceived = None): + command = { + "targetKernelName":"python", + "originUri":None, + "destinationUri":None + } + if commandReceived is not None: + command.update(commandReceived) + msg = { + "content": { + "data": { + 'type': 'command', + 'commandOrEvent': json.dumps({ + "token":"19", + "id":"ccc7591568d943c9bbe7dd8254e89b0d", + "commandType":commandType, + "command": command, + "routingSlip":["kernel://pid-17796/python"] + }) + } + } + } + + return msg + + @staticmethod + def create_msg_sent(eventType, eventSent = {}, commandJsonString = None): + command = None if commandJsonString is None else json.loads(commandJsonString) + msg = { + "commandOrEvent": json.dumps({ + "event": eventSent, + "eventType": eventType, + "command": command + }), + "type": "event" + } + + return msg + + def setUp(self): + self.comm = testComm() + self.handler = get_dotnet_coe_comm_handler() + self.handler.handle_control_comm_opened(self.comm, 'test_target') + + def test_can_get_kernel_ready_on_comm_open(self): + self.assertEqual(self.comm.msg_sent, self.create_msg_sent("KernelReady", { "kernelInfos": [] })) + + def test_can_handle_invalid_json(self): + msg_received = {"content": { "data": {'type': 'command', 'commandOrEvent': 'just a string'}}}; + + msg_sent = self.create_msg_sent("CommandFailed", { + "message": "failed to process comm data. Expecting value: line 1 column 1 (char 0)" + }) + self.comm.handle_msg(msg_received) + self.assertEqual(self.comm.msg_sent, msg_sent) + + def test_can_fail_on_unsupported_command_type(self): + msg_received = self.create_msg_received("UnsupportedCommand", {"name":"x"}); + msg_sent = self.create_msg_sent("CommandFailed", { + "message": "command \"UnsupportedCommand\" not supported" + }) + self.comm.handle_msg(msg_received) + self.assertEqual(self.comm.msg_sent, msg_sent) + + def test_can_handle_send_value(self): + msg_received = self.create_msg_received("SendValue", { + "formattedValue":{ + "mimeType":"application/json", + "value":"\"test\"" + }, + "name":"x" + }); + + msg_sent = self.create_msg_sent("CommandSucceeded") + self.comm.handle_msg(msg_received) + self.assertEqual(self.comm.msg_sent, msg_sent) + # below is just a test workaround as tests are not sharing the same + # namespace as the handlers. With .net interactive they will be. + self.assertEqual(coe_comm_handler.x, "test", "variable is not set") + + def test_can_handle_send_value_with_dataframe(self): + data = [ + {"CategoryName":"Road Frames","ProductName":"HL Road Frame - Black, 58"}, + {"CategoryName":"Road Frames","ProductName":"HL Road Frame - Red, 58"}, + {"CategoryName":"Helmets","ProductName":"Sport-100 Helmet, Red"}, + {"CategoryName":"Helmets","ProductName":"Sport-100 Helmet, Black"} + ]; + + import pandas as pd + df_expected = pd.DataFrame(data) + from pandas.testing import assert_frame_equal + + msg_received = self.create_msg_received("SendValue", { + "formattedValue":{ + "mimeType":"application/table-schema+json", + "value": json.dumps({ + "schema": { + "fields":[ + {"name":"CategoryName","type":"string"}, + {"name":"ProductName","type":"string"} + ], + "primaryKey":[] + }, + "data": data + }) + }, + "name":"df_sent" + }); + + msg_sent = self.create_msg_sent("CommandSucceeded") + self.comm.handle_msg(msg_received) + self.assertEqual(self.comm.msg_sent, msg_sent) + assert_frame_equal(coe_comm_handler.df_sent, df_expected) + + def test_can_handle_unsupported_mimetype_in_send_value(self): + msg_received = self.create_msg_received("SendValue", { + "formattedValue":{ + "mimeType":"application/unsupported", + "value":"\"test\"" + }, + "name":"x" + }); + + msg_sent = self.create_msg_sent("CommandFailed", { + "message": "Failed to set value for \"x\". \"application/unsupported\" mimetype not supported." + }) + self.comm.handle_msg(msg_received) + self.assertEqual(self.comm.msg_sent, msg_sent) + + def test_can_handle_invalid_value_for_dataframe_in_send_value(self): + msg_received = self.create_msg_received("SendValue", { + "formattedValue":{ + "mimeType":"application/table-schema+json", + "value":"\"test\"" + }, + "name":"x" + }); + + msg_sent = self.create_msg_sent("CommandFailed", { + "message": "Cannot create pandas dataframe for: \"x\". string indices must be integers" + }) + self.comm.handle_msg(msg_received) + self.assertEqual(self.comm.msg_sent, msg_sent) + + def test_can_handle_invalid_identifier_in_send_value(self): + msg_received = self.create_msg_received("SendValue", { + "formattedValue":{ + "mimeType":"application/json", + "value":"\"test\"" + }, + "name":"x.y" + }); + + msg_sent = self.create_msg_sent("CommandFailed", { + "message": "Invalid Identifier: \"x.y\"" + }) + self.comm.handle_msg(msg_received) + self.assertEqual(self.comm.msg_sent, msg_sent) + + def test_can_handle_request_value_and_get_value(self): + # below is just a test workaround as tests are not sharing the same + # namespace as the handlers. With .net interactive they will be. + coe_comm_handler.x = "test" + msg_received = self.create_msg_received("RequestValue", {"name": "x", "mimeType": "application/json"}); + msg_sent = self.create_msg_sent("ValueProduced", { + "name":"x", + "value":"test", + "formattedValue":{ + "mimeType":"application/json", + "value": json.dumps("test") + } + }, msg_received["content"]["data"]["commandOrEvent"]) + self.comm.handle_msg(msg_received) + self.assertEqual(self.comm.msg_sent, msg_sent) + + def test_can_handle_request_dataframe_and_get_value(self): + data = [ + {"CategoryName":"Road Frames","ProductName":"HL Road Frame - Black, 58"}, + {"CategoryName":"Road Frames","ProductName":"HL Road Frame - Red, 58"}, + {"CategoryName":"Helmets","ProductName":"Sport-100 Helmet, Red"}, + {"CategoryName":"Helmets","ProductName":"Sport-100 Helmet, Black"} + ]; + + import pandas as pd + coe_comm_handler.df_set = pd.DataFrame(data) + msg_received = self.create_msg_received("RequestValue", {"name": "df_set", "mimeType": "application/json"}); + msg_sent = self.create_msg_sent("ValueProduced", { + "name":"df_set", + "value":data, + "formattedValue":{ + "mimeType":"application/table-schema+json", + "value": coe_comm_handler.df_set.to_string(index=False, max_rows=5) + } + }, msg_received["content"]["data"]["commandOrEvent"]) + self.comm.handle_msg(msg_received) + self.assertEqual(self.comm.msg_sent, msg_sent) + + def test_can_handle_unknown_variable_request_value(self): + msg_received = self.create_msg_received("RequestValue", {"name": "unknown_var", "mimeType": "application/json"}); + msg_sent = self.create_msg_sent("CommandFailed", { + "message": "Variable \"unknown_var\" not found." + }) + self.comm.handle_msg(msg_received) + self.assertEqual(self.comm.msg_sent, msg_sent) + + def test_can_handle_request_value_infos_and_get_values(self): + # below is just a test workaround as tests are not sharing the same + # namespace as the handlers, so for now we inject the same variable in both. + # With .net interactive they will be. + global x + x = 456 + coe_comm_handler.x = x + + import pandas as pd + global df + df = pd.DataFrame([{"x": 123}, {"x": 456}]) + coe_comm_handler.df = df + + msg_received = self.create_msg_received("RequestValueInfos"); + msg_sent = self.create_msg_sent("ValueInfosProduced", { + "valueInfos": [ + { + "name": "df", + "formattedValue": { + "mimeType":"application/table-schema+json", + "value": df.to_string(index=False, max_rows=5) + }, + "typeName": "" + }, + { + "name": "x", + "formattedValue": { + "mimeType":"application/json", + "value": "456" + }, + "typeName": "" + }] + }, msg_received["content"]["data"]["commandOrEvent"]) + self.comm.handle_msg(msg_received) + self.assertEqual(self.comm.msg_sent, msg_sent) + +unittest.main(argv=[''], verbosity=2, exit=False) diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/LanguageHandlerTests/tests_r_coe_comm_handler.r b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/LanguageHandlerTests/tests_r_coe_comm_handler.r new file mode 100644 index 0000000000..b5c0d70224 --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/LanguageHandlerTests/tests_r_coe_comm_handler.r @@ -0,0 +1,274 @@ +# Copyright (c) .NET Foundation and contributors. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +# Run this test using: +# RScript tests_r_coe_comm_handler.r + +source('../../Microsoft.DotNet.Interactive.Jupyter/CommandEvents/LanguageHandlers/r/coe_comm_handler.r') + +if (!require(testthat)) install.packages('testthat') +library(testthat) + +wrap_as_json <- function(msg) { + return (toJSON(msg, auto_unbox = TRUE, null="null")) +} + +create_msg_received <- function(commandType, commandReceived = NULL) { + command = list(targetKernelName="r", originUri=NULL, destinationUri=NULL) + + if (!is.null(commandReceived)) { + command = c(command, commandReceived) + } + + msg = list( + content=list( + data=list( + type="command", + commandOrEvent=wrap_as_json(list( + token=19, + id="ccc7591568d943c9bbe7dd8254e89b0d", + commandType=commandType, + command=command, + routingSlip=list() + ) + ) + ) + ) + ) + return (msg) +} + +create_msg_sent <- function(eventType, eventSent = fromJSON('{}'), msg_received = NULL) { + command = NULL + if (!is.null(msg_received)) { + command <- fromJSON(msg_received$content$data$commandOrEvent) + } + + msg = list( + commandOrEvent=wrap_as_json(list( + event=eventSent, + eventType=eventType, + command=command + )), + type="event" + ) + + return (wrap_as_json(msg)) +} + +testComm <- setRefClass( + 'testComm', + fields = list(msg_callback = 'functionOrNULL', msg_sent = 'json'), + methods = list( + send = function(msg = list()) { + msg_sent <<- wrap_as_json(msg) + }, + on_msg = function(a_msg_callback) { + msg_callback <<- a_msg_callback + }, + on_close = function(a_close_callback) { + close_callback <<- a_close_callback + }, + handle_msg = function(msg) { + if (!is.null(msg_callback)) { + data <- msg$content$data + msg_callback(data) + } + } + ) +) + +test_that("test_can_get_kernel_ready_on_comm_open", { + t <- testComm() + .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm(t, list()) + + msg_sent <- create_msg_sent("KernelReady", list(kernelInfos=list())) + expect_equal(t$msg_sent, msg_sent, info=sprintf('expected: %s\n actual: %s', msg_sent, t$msg_sent)) +}) + +test_that("test_can_handle_invalid_json", { + t <- testComm() + .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm(t, list()) + + msg_received <- fromJSON('{"content": {"data": {"type": "command", "commandOrEvent": "just a string"}}}') + msg_sent <- create_msg_sent("CommandFailed", list(message="failed to process comm data. lexical error: invalid char in json text.\n just a string\n (right here) ------^\n")) + t$handle_msg(msg_received) + expect_equal(t$msg_sent, msg_sent, info=sprintf('expected: %s\n actual: %s', msg_sent, t$msg_sent)) +}) + +test_that("test_can_fail_on_unsupported_command_type", { + t <- testComm() + .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm(t, list()) + + msg_received <- create_msg_received("UnsupportedCommand", list(name="x")) + msg_sent <- create_msg_sent("CommandFailed", list(message="command \"UnsupportedCommand\" not supported")) + t$handle_msg(msg_received) + + expect_equal(t$msg_sent, msg_sent, info=sprintf('expected: %s\n actual: %s', msg_sent, t$msg_sent)) +}) + +test_that("test_can_handle_send_value", { + t <- testComm() + .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm(t, list()) + + msg_received <- create_msg_received("SendValue", list( + formattedValue=list(mimeType="application/json", value="\"test\""), + name="x" + )) + + msg_sent <- create_msg_sent("CommandSucceeded") + + t$handle_msg(msg_received) + + expect_equal(t$msg_sent, msg_sent, info=sprintf('expected: %s\n actual: %s', msg_sent, t$msg_sent)) + expect_equal(get("x"), "test", info="value was not set as expected") + + remove("x", envir=globalenv()) +}) + +test_that("test_can_handle_send_value_with_dataframe", { + t <- testComm() + .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm(t, list()) + + data <- fromJSON('[ + {"CategoryName":"Road Frames","ProductName":"HL Road Frame - Black, 58"}, + {"CategoryName":"Road Frames","ProductName":"HL Road Frame - Red, 58"}, + {"CategoryName":"Helmets","ProductName":"Sport-100 Helmet, Red"}, + {"CategoryName":"Helmets","ProductName":"Sport-100 Helmet, Black"} + ]') + + df_expected = data.frame(data) + + msg_received <- create_msg_received("SendValue", list( + formattedValue=list( + mimeType="application/table-schema+json", + value=wrap_as_json(list( + schema=list( + fields=fromJSON('[ + {"name":"CategoryName","type":"string"}, + {"name":"ProductName","type":"string"} + ]'), + primaryKey=list() + ), + data=data + )) + ), + name="df_sent" + ) + ) + + msg_sent <- create_msg_sent("CommandSucceeded") + + t$handle_msg(msg_received) + + expect_equal(t$msg_sent, msg_sent, info=sprintf('expected: %s\n actual: %s', msg_sent, t$msg_sent)) + expect_equal(get("df_sent"), df_expected, info="data.frame was not set as expected") + + remove("df_sent", envir=globalenv()) +}) + +test_that("test_can_handle_unsupported_mimetype_in_send_value", { + t <- testComm() + .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm(t, list()) + + msg_received <- create_msg_received("SendValue", list( + formattedValue=list(mimeType="application/unsupported", value="\"test\""), + name="x" + )) + + msg_sent <- create_msg_sent("CommandFailed", list(message="Failed to set value for \"x\". \"application/unsupported\" mimetype not supported.")) + + t$handle_msg(msg_received) + + expect_equal(t$msg_sent, msg_sent, info=sprintf('expected: %s\n actual: %s', msg_sent, t$msg_sent)) +}) + +test_that("test_can_handle_invalid_identifier_in_send_value", { + t <- testComm() + .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm(t, list()) + + msg_received <- create_msg_received("SendValue", list( + formattedValue=list(mimeType="application/json", value="\"test\""), + name="_xy" + )) + + msg_sent <- create_msg_sent("CommandFailed", list(message="Invalid Identifier: \"_xy\"")) + + t$handle_msg(msg_received) + + expect_equal(t$msg_sent, msg_sent, info=sprintf('expected: %s\n actual: %s', msg_sent, t$msg_sent)) +}) + +test_that("test_can_handle_request_value_and_get_value", { + t <- testComm() + .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm(t, list()) + + assign("test_var", "test_value", globalenv()); + + msg_received <- create_msg_received("RequestValue", list(mimeType="application/json", name="test_var")) + msg_sent <- create_msg_sent("ValueProduced", + list(name="test_var", value="test_value", formattedValue=list(mimeType="application/json", value=wrap_as_json("test_value"))), + msg_received + ) + + t$handle_msg(msg_received) + remove("test_var", envir=globalenv()) + + expect_equal(t$msg_sent, msg_sent, info=sprintf('expected: %s\n actual: %s', msg_sent, t$msg_sent)) +}) + +test_that("test_can_handle_request_dataframe_and_get_value", { + t <- testComm() + .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm(t, list()) + + data <- fromJSON('[ + {"CategoryName":"Road Frames","ProductName":"HL Road Frame - Black, 58"}, + {"CategoryName":"Road Frames","ProductName":"HL Road Frame - Red, 58"}, + {"CategoryName":"Helmets","ProductName":"Sport-100 Helmet, Red"}, + {"CategoryName":"Helmets","ProductName":"Sport-100 Helmet, Black"} + ]') + + assign("df_set", data.frame(data), globalenv()); + + msg_received <- create_msg_received("RequestValue", list(mimeType="application/json", name="df_set")) + msg_sent <- create_msg_sent("ValueProduced", list( + name="df_set", + value=data, + formattedValue=list(mimeType="application/table-schema+json", value=wrap_as_json(df_set)) + ), msg_received) + + t$handle_msg(msg_received) + + expect_equal(t$msg_sent, msg_sent, info=sprintf('expected: %s\n actual: %s', msg_sent, t$msg_sent)) + remove("df_set", envir=globalenv()) +}) + +test_that("test_can_handle_unknown_variable_request_value", { + t <- testComm() + .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm(t, list()) + + msg_received <- create_msg_received("RequestValue", list(mimeType="application/json", name="unknown_var")) + msg_sent <- create_msg_sent("CommandFailed", list(message="Variable \"unknown_var\" not found.")) + t$handle_msg(msg_received) + + expect_equal(t$msg_sent, msg_sent, info=sprintf('expected: %s\n actual: %s', msg_sent, t$msg_sent)) +}) + +test_that("test_can_handle_request_value_infos_and_get_values", { + t <- testComm() + .dotnet_coe_comm_hander_env$coe_handler_connect_to_comm(t, list()) + + assign("test_var", "test_value", globalenv()); + assign("df_var", data.frame(fromJSON('[{"x": 123}, {"x": 456}]')), globalenv()) + + msg_received <- create_msg_received("RequestValueInfos") + msg_sent <- create_msg_sent("ValueInfosProduced", + list(valueInfos=fromJSON('[{"name":"df_var", "formattedValue":{"mimeType":"application/table-schema+json", "value":"[{\\"x\\":123},{\\"x\\":456}]"}, "typeName":"data.frame"}, {"name":"test_var","formattedValue":{"mimeType":"application/json", "value":"\\"test_value\\""},"typeName":"character"}]')), + msg_received + ) + + t$handle_msg(msg_received) + remove("test_var", envir=globalenv()) + remove("df_var", envir=globalenv()) + expect_equal(t$msg_sent, msg_sent, info=sprintf('expected: %s\n actual: %s', msg_sent, t$msg_sent)) +}) \ No newline at end of file diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/RecordingJupyterMessageSender.cs b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/RecordingJupyterMessageSender.cs index a78d6f3010..212cd7a5b9 100644 --- a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/RecordingJupyterMessageSender.cs +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/RecordingJupyterMessageSender.cs @@ -6,7 +6,7 @@ namespace Microsoft.DotNet.Interactive.Jupyter.Tests; -public class RecordingJupyterMessageSender : IJupyterMessageSender +public class RecordingJupyterMessageSender : IJupyterMessageResponseSender { private readonly List _messages; private readonly List _pubSubMessages; diff --git a/src/Microsoft.DotNet.Interactive.Jupyter.Tests/TestJupyterConnectionOptions.cs b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/TestJupyterConnectionOptions.cs new file mode 100644 index 0000000000..234e70687e --- /dev/null +++ b/src/Microsoft.DotNet.Interactive.Jupyter.Tests/TestJupyterConnectionOptions.cs @@ -0,0 +1,380 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Interactive.Jupyter.Connection; +using Microsoft.DotNet.Interactive.Jupyter.Messaging; +using Microsoft.DotNet.Interactive.Jupyter.Protocol; +using Microsoft.DotNet.Interactive.Tests.Utility; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.CommandLine; +using System.CommandLine.Parsing; +using System.IO; +using System.Linq; +using System.Reactive.Subjects; +using System.Runtime.CompilerServices; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Message = Microsoft.DotNet.Interactive.Jupyter.Messaging.Message; + +namespace Microsoft.DotNet.Interactive.Jupyter.Tests; + +public interface IMessageTracker : IMessageSender, IMessageReceiver, IDisposable +{ + public void Attach(IMessageSender sender, IMessageReceiver receiver); + public IObservable SentMessages { get; } + public IObservable ReceivedMessages { get; } +} + +internal class MessageRecorder : IMessageTracker +{ + private IMessageSender _testSender; + private IMessageReceiver _testReceiver; + + private readonly Subject _sentMessages = new(); + private readonly Subject _receivedMessages = new(); + + public IObservable Messages => _testReceiver != null ? _testReceiver.Messages : throw new InvalidOperationException("No connection"); + + public void Attach(IMessageSender sender, IMessageReceiver receiver) + { + _testSender = sender; + _testReceiver = receiver; + + _testReceiver.Messages.Subscribe(_receivedMessages); + } + + public async Task SendAsync(Message message) + { + if (_testSender != null) + { + await _testSender.SendAsync(message); + } + + _sentMessages.OnNext(message); + return; + } + + public void Dispose() + { + _sentMessages.Dispose(); + _receivedMessages.Dispose(); + } + + public IObservable SentMessages => _sentMessages; + public IObservable ReceivedMessages => _receivedMessages; +} + +internal class MessagePlayback : IMessageTracker +{ + private readonly Subject _sentMessages = new(); + private readonly Subject _receivedMessages = new(); + private readonly ConcurrentQueue _processRequests = new(); + private readonly List _playbackMessages = new(); + private readonly CancellationTokenSource _cts = new(); + public IObservable Messages => _receivedMessages; + + public MessagePlayback(IReadOnlyCollection messages) + { + _playbackMessages.AddRange(messages); + var requestProcessing = Task.Run(() => ProcessRequestsAsync()); + } + + public Task SendAsync(Message message) + { + _sentMessages.OnNext(message); + _processRequests.Enqueue(message); + + return Task.CompletedTask; + } + + private async Task ProcessRequestsAsync() + { + await Task.Run(async () => + { + while (!_cts.IsCancellationRequested) + { + if (_processRequests.TryDequeue(out var message)) + { + // find appropriate message from playback to send back since we + // can't match the messageIds. + var responses = _playbackMessages + .GroupBy(m => new { MsgId = m.ParentHeader?.MessageId, MsgType = m.ParentHeader?.MessageType }) + .FirstOrDefault(g => g.Key.MsgType == message.Header.MessageType); + + + foreach (var m in responses) + { + var replyMessage = new Message( + m.Header, + GetContent(message, m), + new Header( + m.ParentHeader?.MessageType, + message.Header.MessageId, // reply back with the sent message id + m.ParentHeader.Version, + m.ParentHeader.Session, + m.ParentHeader.Username, + m.ParentHeader.Date), + m.Signature, m.MetaData, m.Identifiers, m.Buffers, m.Channel); + + _receivedMessages.OnNext(replyMessage); + _playbackMessages.Remove(m); + } + } + else + { + await Task.Delay(50); + } + } + }, _cts.Token); + } + + private Protocol.Message GetContent(Message message, Message m) + { + string commId = null; + if (message.Content is CommOpen commOpen) + { + commId = commOpen.CommId; + } + else if (message.Content is CommMsg commMsg) + { + commId = commMsg.CommId; + } + + if (commId is not null) + { + if (m.Content is CommClose commClose) + { + return new CommClose(commId, commClose.Data as IReadOnlyDictionary); + } + else if (m.Content is CommMsg commMsg) + { + return new CommMsg(commId, commMsg.Data as IReadOnlyDictionary); + } + } + + return m.Content; + } + + public void Attach(IMessageSender sender, IMessageReceiver receiver) + { + // No-op; + } + + public void Dispose() + { + _cts.Cancel(); + _sentMessages.Dispose(); + _receivedMessages.Dispose(); + } + + public IObservable SentMessages => _sentMessages; + public IObservable ReceivedMessages => _receivedMessages; +} + +public class TestJupyterKernelConnection : IJupyterKernelConnection +{ + private IJupyterKernelConnection _kernelConnection; + private IMessageTracker _tracker; + private bool _disposed = false; + + public TestJupyterKernelConnection(IMessageTracker messageTracker) + { + _tracker = messageTracker; + } + + public void Attach(IJupyterKernelConnection kernelConnection) + { + if (kernelConnection == null) + { + throw new ArgumentNullException(nameof(kernelConnection)); + } + + _kernelConnection = kernelConnection; + _tracker.Attach(kernelConnection.Sender, kernelConnection.Receiver); + } + public Uri Uri => _kernelConnection is null ? new Uri("test://") : _kernelConnection.Uri; + + public IMessageSender Sender => _tracker; + + public IMessageReceiver Receiver => _tracker; + + public void Dispose() + { + _kernelConnection?.Dispose(); + _tracker?.Dispose(); + _disposed = true; + } + + public async Task StartAsync() + { + if (_kernelConnection != null) + { + await _kernelConnection.StartAsync(); + } + } + + public bool IsDisposed => _disposed; +} + +public class TestJupyterConnection : IJupyterConnection +{ + private IJupyterConnection _testJupyterConnection; + private TestJupyterKernelConnection _testKernelConnection; + private bool _disposed = false; + private List _kernelSpecs = new(); + + public TestJupyterConnection(TestJupyterKernelConnection testJupyterKernelConnection, List kernelSpecs = null) + { + _testKernelConnection = testJupyterKernelConnection; + if (kernelSpecs != null) + { + _kernelSpecs = kernelSpecs; + } + } + + public void Attach(IJupyterConnection connection) + { + _testJupyterConnection = connection; + } + + public async Task CreateKernelConnectionAsync(string kernelSpecName) + { + if (_testJupyterConnection != null) + { + _testKernelConnection.Attach(await _testJupyterConnection.CreateKernelConnectionAsync(kernelSpecName)); + } + + return _testKernelConnection; + } + + public TestJupyterKernelConnection KernelConnection => _testKernelConnection; + + public void Dispose() + { + _testJupyterConnection?.Dispose(); + _disposed = true; + } + + public Task> GetKernelSpecsAsync() + { + if (_testJupyterConnection == null) + { + return Task.FromResult(_kernelSpecs.AsEnumerable()); + } + + return _testJupyterConnection.GetKernelSpecsAsync(); + } + + public bool IsDisposed => _disposed; +} + +public class TestJupyterConnectionOptions : IJupyterKernelConnectionOptions +{ + private IJupyterKernelConnectionOptions _testOptions; + private TestJupyterConnection _connection; + private SubscribedList _sentMessages; + private SubscribedList _playbackMessages; + private readonly bool _allowPlayback = false; + + public TestJupyterConnectionOptions(string kernelSpecName, string filePath, string fileName) + { + KernelSpecName = kernelSpecName; + var fileToPlayback = GetFilePath(filePath, fileName); + var json = File.ReadAllText(fileToPlayback); + var messages = JsonSerializer.Deserialize>(json, MessageFormatter.SerializerOptions); + Playback(messages); + } + + public TestJupyterConnectionOptions(IReadOnlyCollection messagesToPlayback) + { + Playback(messagesToPlayback); + } + + public TestJupyterConnectionOptions(IJupyterKernelConnectionOptions optionsToTest, string kernelSpecName, bool allowPlayback = false) + { + if (optionsToTest == null) + { + throw new ArgumentNullException(nameof(optionsToTest)); + } + KernelSpecName = kernelSpecName; + _allowPlayback = allowPlayback; + Record(optionsToTest); + } + + public TestJupyterConnectionOptions(TestJupyterConnection connection) + { + if (connection == null) + { + throw new ArgumentNullException(nameof(connection)); + } + + _connection = connection; + } + + public void Record(IJupyterKernelConnectionOptions options) + { + _testOptions = options; + MessageTracker = new MessageRecorder(); + _connection = new TestJupyterConnection(new TestJupyterKernelConnection(MessageTracker)); + if (_allowPlayback) + { + _sentMessages = MessageTracker.SentMessages.ToSubscribedList(); + _playbackMessages = MessageTracker.ReceivedMessages.ToSubscribedList(); + } + } + + public void Playback(IReadOnlyCollection messages) + { + MessageTracker = new MessagePlayback(messages); + _connection = new TestJupyterConnection(new TestJupyterKernelConnection(MessageTracker)); + } + + public IMessageTracker MessageTracker { get; private set; } + + public TestJupyterConnection Connection => _connection; + + public IJupyterConnection GetConnection(ParseResult connectionOptionsParseResult) + { + if (_testOptions != null) + { + _connection.Attach(_testOptions.GetConnection(connectionOptionsParseResult)); + } + + return _connection; + } + + public IReadOnlyCollection
print {base}R Documentation