Skip to content

Commit f0979a5

Browse files
remove nested commands' events from outer KernelCommandResult.Events (#3177)
* allow explicit parenting, refactor away a bunch of command id usage * remove command id from .NET code * wip: remove id from TypeScript command * Fix tests for polyglot notebook ts project * align bahaviour to C# * remove token property on typescript * cleanup getOrCreateToken usage * fix the child command root * rename nested classes to avoid warning --------- Co-authored-by: Diego Colombo <[email protected]>
1 parent 85fe710 commit f0979a5

File tree

79 files changed

+343
-381
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+343
-381
lines changed

src/Microsoft.DotNet.Interactive.ApiCompatibility.Tests/ApiCompatibilityTests.Interactive_api_is_not_changed.approved.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Microsoft.DotNet.Interactive
179179
public System.Threading.Tasks.Task EndInvoke(System.IAsyncResult result)
180180
public System.Threading.Tasks.Task Invoke(Microsoft.DotNet.Interactive.Commands.KernelCommand command, KernelInvocationContext context, KernelPipelineContinuation next)
181181
public class KernelCommandResult
182-
.ctor(Microsoft.DotNet.Interactive.Commands.KernelCommand command, System.Collections.Generic.IEnumerable<Microsoft.DotNet.Interactive.Events.KernelEvent> events = null)
182+
.ctor(Microsoft.DotNet.Interactive.Commands.KernelCommand command)
183183
public Microsoft.DotNet.Interactive.Commands.KernelCommand Command { get;}
184184
public System.Collections.Generic.IReadOnlyList<Microsoft.DotNet.Interactive.Events.KernelEvent> Events { get;}
185185
public class KernelCommandScheduler : KernelScheduler<Microsoft.DotNet.Interactive.Commands.KernelCommand,KernelCommandResult>, IKernelScheduler<Microsoft.DotNet.Interactive.Commands.KernelCommand,KernelCommandResult>, System.IDisposable
@@ -394,10 +394,9 @@ Microsoft.DotNet.Interactive.Commands
394394
public Microsoft.DotNet.Interactive.CommandRoutingSlip RoutingSlip { get;}
395395
public System.String TargetKernelName { get;}
396396
public System.Boolean Equals(KernelCommand other)
397-
public System.Int32 GetHashCode()
398397
public System.String GetOrCreateToken()
399398
public System.Threading.Tasks.Task InvokeAsync(Microsoft.DotNet.Interactive.KernelInvocationContext context)
400-
public System.Void SetId(System.String id)
399+
public System.Void SetParent(KernelCommand parent)
401400
public System.Void SetToken(System.String token)
402401
public abstract class LanguageServiceCommand : KernelCommand, System.IEquatable<KernelCommand>
403402
public System.String Code { get;}
@@ -478,7 +477,6 @@ Microsoft.DotNet.Interactive.Connection
478477
public System.Threading.Tasks.Task SendAsync(Microsoft.DotNet.Interactive.Events.KernelEvent kernelEvent, System.Threading.CancellationToken cancellationToken)
479478
public abstract class IKernelCommandEnvelope
480479
public Microsoft.DotNet.Interactive.Commands.KernelCommand Command { get;}
481-
public System.String CommandId { get;}
482480
public System.String CommandType { get;}
483481
public System.String Token { get;}
484482
public abstract class IKernelEventEnvelope
@@ -512,7 +510,6 @@ Microsoft.DotNet.Interactive.Connection
512510
public static System.Void RegisterDefaults()
513511
public static System.String Serialize(Microsoft.DotNet.Interactive.Commands.KernelCommand command)
514512
public static System.String Serialize(IKernelCommandEnvelope envelope)
515-
public System.String CommandId { get;}
516513
public System.String CommandType { get;}
517514
public System.String Token { get;}
518515
public class KernelCommandEnvelope<T> : KernelCommandEnvelope, IKernelCommandEnvelope

src/Microsoft.DotNet.Interactive.CSharpProject.Tests/SerializationTests.Command_contract_has_not_been_broken.approved.CompileProject.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"token": "the-token",
3-
"id": "command-id",
43
"commandType": "CompileProject",
54
"command": {
65
"targetKernelName": null,

src/Microsoft.DotNet.Interactive.CSharpProject.Tests/SerializationTests.Command_contract_has_not_been_broken.approved.OpenDocument.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"token": "the-token",
3-
"id": "command-id",
43
"commandType": "OpenDocument",
54
"command": {
65
"relativeFilePath": "./path",

src/Microsoft.DotNet.Interactive.CSharpProject.Tests/SerializationTests.Command_contract_has_not_been_broken.approved.OpenProject.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"token": "the-token",
3-
"id": "command-id",
43
"commandType": "OpenProject",
54
"command": {
65
"project": {

src/Microsoft.DotNet.Interactive.CSharpProject.Tests/SerializationTests.Event_contract_has_not_been_broken.approved.AssemblyProduced.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"eventType": "AssemblyProduced",
88
"command": {
99
"token": "the-token",
10-
"id": "command-id",
1110
"commandType": "CompileProject",
1211
"command": {
1312
"targetKernelName": null,

src/Microsoft.DotNet.Interactive.CSharpProject.Tests/SerializationTests.Event_contract_has_not_been_broken.approved.DocumentOpened.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"eventType": "DocumentOpened",
88
"command": {
99
"token": "the-token",
10-
"id": "command-id",
1110
"commandType": "OpenDocument",
1211
"command": {
1312
"relativeFilePath": "./path",

src/Microsoft.DotNet.Interactive.CSharpProject.Tests/SerializationTests.Event_contract_has_not_been_broken.approved.ProjectOpened.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"eventType": "ProjectOpened",
1616
"command": {
1717
"token": "the-token",
18-
"id": "command-id",
1918
"commandType": "OpenProject",
2019
"command": {
2120
"project": {

src/Microsoft.DotNet.Interactive.CSharpProject.Tests/SerializationTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ public void Command_contract_has_not_been_broken(KernelCommand command)
9797
.UsingExtension($"{command.GetType().Name}.json")
9898
.SetInteractive(Debugger.IsAttached);
9999

100-
command.SetId("command-id");
101100
command.SetToken("the-token");
102101

103102
var json = KernelCommandEnvelope.Serialize(command);
@@ -113,7 +112,6 @@ public void Event_contract_has_not_been_broken(KernelEvent @event)
113112
.UsingExtension($"{@event.GetType().Name}.json")
114113
.SetInteractive(Debugger.IsAttached);
115114

116-
@event.Command?.SetId("command-id");
117115
@event.Command?.SetToken("the-token");
118116

119117
var json = KernelEventEnvelope.Serialize(@event);

src/Microsoft.DotNet.Interactive.Jupyter.Tests/MagicCommandTests.lsmagic.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System;
45
using System.CommandLine;
56
using System.Linq;
67
using System.Threading.Tasks;
@@ -11,20 +12,37 @@
1112
using Microsoft.DotNet.Interactive.Formatting;
1213
using Microsoft.DotNet.Interactive.FSharp;
1314
using Microsoft.DotNet.Interactive.Tests.Utility;
15+
using Microsoft.VisualStudio.TestPlatform.Utilities;
16+
using Pocket;
17+
using Pocket.For.Xunit;
1418
using Xunit;
19+
using Xunit.Abstractions;
1520

1621
namespace Microsoft.DotNet.Interactive.Jupyter.Tests;
1722

1823
public partial class MagicCommandTests
1924
{
20-
public class LSMmagic
25+
[LogToPocketLogger(FileNameEnvironmentVariable = "POCKETLOGGER_LOG_PATH")]
26+
public class LSMmagic : IDisposable
2127
{
28+
private readonly CompositeDisposable _disposables = new();
29+
30+
public LSMmagic(ITestOutputHelper output)
31+
{
32+
_disposables.Add(output.SubscribeToPocketLogger());
33+
}
34+
35+
public void Dispose()
36+
{
37+
_disposables.Dispose();
38+
}
39+
2240
[Fact]
2341
public async Task lsmagic_lists_registered_magic_commands()
2442
{
2543
using var kernel = new CompositeKernel()
26-
.UseDefaultMagicCommands()
27-
.LogEventsToPocketLogger();
44+
.UseDefaultMagicCommands()
45+
.LogEventsToPocketLogger();
2846

2947
kernel.AddDirective(new Command("#!one"));
3048
kernel.AddDirective(new Command("#!two"));

src/Microsoft.DotNet.Interactive.Jupyter/KernelExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ private static Command lsmagic(Kernel kernel)
224224
foreach (var subkernel in subkernels)
225225
{
226226
var command = new SubmitCode(((SubmitCode)context.Command).Code);
227+
command.SetParent(context.Command);
227228

228229
await subkernel.SendAsync(command);
229230
}

0 commit comments

Comments
 (0)