Skip to content

Commit ecf3a63

Browse files
authored
fix #2044 (#2066)
* fix #2044 * fix API compat baseline * fix warning in test * fix test warning * fix some test names
1 parent 3a4a1b4 commit ecf3a63

File tree

11 files changed

+67
-62
lines changed

11 files changed

+67
-62
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ Microsoft.DotNet.Interactive
7272
public System.String MimeType { get;}
7373
public System.String Value { get;}
7474
public abstract class FrontendEnvironment
75-
public System.Boolean AllowStandardInput { get; set;}
7675
public System.Threading.Tasks.Task ExecuteClientScript(System.String code, KernelInvocationContext context)
7776
public class HtmlKernel : Kernel, IKernelCommandHandler<Microsoft.DotNet.Interactive.Commands.RequestKernelInfo>, IKernelCommandHandler<Microsoft.DotNet.Interactive.Commands.RequestValue>, IKernelCommandHandler<Microsoft.DotNet.Interactive.Commands.RequestValueInfos>, IKernelCommandHandler<Microsoft.DotNet.Interactive.Commands.SubmitCode>, System.IDisposable
7877
.ctor()

src/Microsoft.DotNet.Interactive.Jupyter.Tests/ExecuteRequestHandlerTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ public async Task sends_ExecuteReply_message_when_submission_contains_a_language
312312
[Theory]
313313
[InlineData("input()", "", "input-value")]
314314
[InlineData("input(\"User: \")", "User: ", "user name")]
315+
[InlineData("await Microsoft.DotNet.Interactive.Kernel.GetInputAsync(\"User: \")", "User: ", "user name")]
315316
public async Task sends_InputRequest_message_when_submission_requests_user_input_in_csharp(string code, string prompt, string expectedDisplayValue)
316317
{
317318
var scheduler = CreateScheduler();
@@ -426,7 +427,7 @@ public async Task Shows_not_supported_exception_when_stdin_not_allowed_and_input
426427
var errorMessage = string.Join("\n", traceback);
427428
errorMessage
428429
.Should()
429-
.StartWith("System.NotSupportedException: Input request is not supported");
430+
.StartWith("System.NotSupportedException: Input prompt is not supported");
430431
}
431432

432433
[Fact]
@@ -450,7 +451,7 @@ public async Task Shows_not_supported_exception_when_stdin_not_allowed_and_passw
450451
var errorMessage = string.Join("\n", traceback);
451452
errorMessage
452453
.Should()
453-
.StartWith("System.NotSupportedException: Password request is not supported.");
454+
.StartWith("System.NotSupportedException: Password prompt is not supported.");
454455
}
455456

456457
[Fact]

src/Microsoft.DotNet.Interactive.Jupyter.Tests/JupyterRequestHandlerTestBase{T}.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
5+
using System.Threading.Tasks;
56
using Microsoft.DotNet.Interactive.Commands;
67
using Microsoft.DotNet.Interactive.CSharp;
78
using Microsoft.DotNet.Interactive.FSharp;
@@ -14,7 +15,7 @@ namespace Microsoft.DotNet.Interactive.Jupyter.Tests
1415
{
1516
public abstract class JupyterRequestHandlerTestBase : IDisposable
1617
{
17-
private readonly CompositeDisposable _disposables = new CompositeDisposable();
18+
private readonly CompositeDisposable _disposables = new();
1819
private readonly CSharpKernel _cSharpKernel;
1920
private readonly FSharpKernel _fSharpKernel;
2021
private readonly PowerShellKernel _psKernel;
@@ -47,11 +48,12 @@ protected JupyterRequestHandlerTestBase(ITestOutputHelper output)
4748
_cSharpKernel,
4849
_fSharpKernel,
4950
_psKernel,
50-
new HtmlKernel(),
51-
new JavaScriptKernel()
51+
new HtmlKernel()
5252
}
5353
.UseDefaultMagicCommands();
5454

55+
Task.Run(() => new JupyterClientKernelExtension().OnLoadAsync(_compositeKernel)).Wait(5000);
56+
5557
SetKernelLanguage(Language.CSharp);
5658

5759
Kernel = _compositeKernel;

src/Microsoft.DotNet.Interactive.Jupyter.Tests/Microsoft.DotNet.Interactive.Jupyter.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<LangVersion>latest</LangVersion>
66
<AssetTargetFallback>portable-net45+win8+wp8+wpa81</AssetTargetFallback>
77
<NoWarn>$(NoWarn);8002</NoWarn><!-- Assent isn't strongly signed -->
8+
<NoWarn>$(NoWarn);VSTHRD002</NoWarn><!-- Ignore: Synchronously waiting on tasks or awaiters may cause deadlocks. -->
89
<NoWarn>$(NoWarn);VSTHRD003</NoWarn><!-- Ignore: Avoid awaiting foreign Tasks -->
910
<NoWarn>$(NoWarn);VSTHRD200</NoWarn><!-- Ignore: Use "Async" suffix for async methods -->
1011
</PropertyGroup>

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ public async Task Handle(JupyterRequestContext context)
3333
string targetKernelName = context.GetLanguage();
3434

3535
_executionCount = executeRequest.Silent ? _executionCount : Interlocked.Increment(ref _executionCount);
36-
37-
FrontendEnvironment.AllowStandardInput = executeRequest.AllowStdin;
3836

3937
var executeInputPayload = new ExecuteInput(executeRequest.Code, _executionCount);
4038
context.JupyterMessageSender.Send(executeInputPayload);

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System.Threading.Tasks;
5+
using Microsoft.DotNet.Interactive.Commands;
56
using Microsoft.DotNet.Interactive.CSharp;
7+
using Microsoft.DotNet.Interactive.Events;
68
using Microsoft.DotNet.Interactive.PowerShell;
79

810
namespace Microsoft.DotNet.Interactive.Jupyter;
@@ -30,6 +32,28 @@ public Task OnLoadAsync(Kernel kernel)
3032
break;
3133
}
3234
});
35+
36+
root.SetDefaultTargetKernelNameForCommand(
37+
typeof(RequestInput),
38+
root.Name);
39+
40+
root.RegisterCommandHandler<RequestInput>((input, context) =>
41+
{
42+
string result;
43+
44+
if (!input.IsPassword)
45+
{
46+
result = TopLevelMethods.input(input.Prompt);
47+
}
48+
else
49+
{
50+
result = TopLevelMethods.password(input.Prompt).GetClearTextPassword();
51+
}
52+
53+
context.Publish(new InputProduced(result, input));
54+
55+
return Task.CompletedTask;
56+
});
3357
}
3458

3559
return Task.CompletedTask;

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

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
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;
5+
using Microsoft.DotNet.Interactive.Jupyter.Protocol;
6+
47
namespace Microsoft.DotNet.Interactive.Jupyter
58
{
69
public static class TopLevelMethods
710
{
811
public static string input(string prompt = "")
912
{
10-
return JupyterInteractiveHost.GetInput(prompt);
13+
var context = JupyterRequestContext.Current;
14+
15+
if (context.JupyterRequestMessageEnvelope.Content is ExecuteRequest { AllowStdin: false })
16+
{
17+
throw new NotSupportedException("Input prompt is not supported.");
18+
}
19+
20+
var inputReq = new InputRequest(prompt, password: false);
21+
22+
var result = context.JupyterMessageSender.Send(inputReq);
23+
return result;
1124
}
1225

1326
public static PasswordString password(string prompt = "")
1427
{
15-
return JupyterInteractiveHost.GetPassword(prompt);
28+
var context = JupyterRequestContext.Current;
29+
30+
if (context.JupyterRequestMessageEnvelope.Content is ExecuteRequest { AllowStdin: false })
31+
{
32+
throw new NotSupportedException("Password prompt is not supported.");
33+
}
34+
35+
var inputReq = new InputRequest(prompt, password: true);
36+
var password1 = context.JupyterMessageSender.Send(inputReq);
37+
var result = new PasswordString(password1);
38+
return result;
1639
}
1740
}
18-
}
41+
}

src/Microsoft.DotNet.Interactive.Tests/PackageRestoreContextTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public async Task Allows_duplicate_package_specifications()
252252

253253
[Fact]
254254
// Question: should it not throw, or is ignore sufficient
255-
public async Task Ignores__subsequent_package_specifications_with_different_higher_version()
255+
public async Task Ignores_subsequent_package_specifications_with_different_higher_version()
256256
{
257257
using var restoreContext = new PackageRestoreContext();
258258
restoreContext.GetOrAddPackageReference("Microsoft.ML.AutoML", "0.16.0-preview");
@@ -266,7 +266,7 @@ public async Task Ignores__subsequent_package_specifications_with_different_high
266266
}
267267

268268
[Fact]
269-
public async Task Disallows_package_specifications_with_with_different_lower_version()
269+
public async Task Disallows_package_specifications_with_different_lower_version()
270270
{
271271
using var restoreContext = new PackageRestoreContext();
272272
restoreContext.GetOrAddPackageReference("Microsoft.ML.AutoML", "0.17.0-preview");
@@ -279,7 +279,7 @@ public async Task Disallows_package_specifications_with_with_different_lower_ver
279279
}
280280

281281
[Fact]
282-
public async Task Disallows_package_specifications_with_with_different_lower_unspecified_version_first()
282+
public async Task Disallows_package_specifications_with_different_lower_unspecified_version_first()
283283
{
284284
using var restoreContext = new PackageRestoreContext();
285285
restoreContext.GetOrAddPackageReference("Microsoft.ML.AutoML", "*");
@@ -293,7 +293,7 @@ public async Task Disallows_package_specifications_with_with_different_lower_uns
293293
}
294294

295295
[Fact]
296-
public async Task Disallows_package_specifications_with_with_different_lower_unspecified_version_last()
296+
public async Task Disallows_package_specifications_with_different_lower_unspecified_version_last()
297297
{
298298
using var restoreContext = new PackageRestoreContext();
299299
restoreContext.GetOrAddPackageReference("Microsoft.ML.AutoML", "0.16.0-preview");

src/Microsoft.DotNet.Interactive.VSCode/VSCodeClientKernelExtension.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System;
5-
using System.Reactive.Linq;
65
using System.Threading.Tasks;
76
using Microsoft.DotNet.Interactive.Commands;
7+
using Microsoft.DotNet.Interactive.PowerShell;
88
using Microsoft.DotNet.Interactive.ValueSharing;
99

1010
namespace Microsoft.DotNet.Interactive.VSCode;
@@ -34,15 +34,15 @@ public async Task OnLoadAsync(Kernel kernel)
3434

3535
root.VisitSubkernels(subkernel =>
3636
{
37-
if (subkernel is PowerShell.PowerShellKernel powerShellKernel)
37+
if (subkernel is PowerShellKernel powerShellKernel)
3838
{
39-
powerShellKernel.ReadInput = (prompt) =>
39+
powerShellKernel.ReadInput = prompt =>
4040
{
4141
var result = Kernel.GetInputAsync(prompt).GetAwaiter().GetResult();
4242
return result;
4343
};
4444

45-
powerShellKernel.ReadPassword = (prompt) =>
45+
powerShellKernel.ReadPassword = prompt =>
4646
{
4747
var result = Kernel.GetPasswordAsync(prompt).GetAwaiter().GetResult();
4848
return new PasswordString(result);

0 commit comments

Comments
 (0)