From 71ab957d146d488afd8f46d877dfaa2fbf719d86 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Fri, 29 Mar 2024 16:40:49 -0700 Subject: [PATCH 01/28] improve Peaky tests and environment configuration --- Directory.Packages.props | 8 +- Dockerfile | 1 - PeakyTests.ipynb | 2 +- .../PeakyTestDiscovery.cs | 4 +- .../PeakyTests.cs | 4 +- .../CommandExecutionTests.cs | 134 +++++++++--------- src/Microsoft.TryDotNet/ContentGenerator.cs | 34 ++--- .../PeakyTests/AgentTests.cs | 67 --------- .../PeakyTests/EnvironmentSettings.cs | 39 +---- .../PeakyTests/OrchestratorDeploymentTests.cs | 49 +------ .../PeakyTests/SelfTests.cs | 103 ++++++++++++++ src/Microsoft.TryDotNet/Program.cs | 55 ++++--- .../Properties/launchSettings.json | 25 +++- 13 files changed, 256 insertions(+), 269 deletions(-) delete mode 100644 src/Microsoft.TryDotNet/PeakyTests/AgentTests.cs create mode 100644 src/Microsoft.TryDotNet/PeakyTests/SelfTests.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index ab56aaee6..4ae03b4a0 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -12,11 +12,11 @@ - + - - - + + + diff --git a/Dockerfile b/Dockerfile index 99b361c5d..14a2b402b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,6 @@ COPY --from=build-env /App/out . # Set up to run and expose app on port 80 EXPOSE 80 -ENV ASPNETCORE_ENVIRONMENT=Production ENV ASPNETCORE_URLS=http://*:80/ # This is a workaround for the fact that the Try .NET website is not yet container-aware diff --git a/PeakyTests.ipynb b/PeakyTests.ipynb index 2ddfbeac8..75a0b67dc 100644 --- a/PeakyTests.ipynb +++ b/PeakyTests.ipynb @@ -41,7 +41,7 @@ "outputs": [], "source": [ "var tests = await peakyClient.GetTestsAsync();\n", - "tests" + "tests.Display();" ] }, { diff --git a/src/Microsoft.TryDotNet.IntegrationTests/PeakyTestDiscovery.cs b/src/Microsoft.TryDotNet.IntegrationTests/PeakyTestDiscovery.cs index ea0b6cf99..2c4e348c8 100644 --- a/src/Microsoft.TryDotNet.IntegrationTests/PeakyTestDiscovery.cs +++ b/src/Microsoft.TryDotNet.IntegrationTests/PeakyTestDiscovery.cs @@ -7,13 +7,11 @@ namespace Microsoft.TryDotNet.IntegrationTests; -public class PeakyTestDiscovery : PeakyXunitTestBase, IDisposable +public class PeakyTestDiscovery : PeakyXunitTestBase { private static readonly Uri _testDiscoveryUri = new("https://mls-monitoring.azurewebsites.net/tests/staging/orchestrator?deployment=true"); private readonly PeakyClient _peakyClient = new(_testDiscoveryUri); public override PeakyClient PeakyClient => _peakyClient; - - public void Dispose() => _peakyClient.Dispose(); } \ No newline at end of file diff --git a/src/Microsoft.TryDotNet.IntegrationTests/PeakyTests.cs b/src/Microsoft.TryDotNet.IntegrationTests/PeakyTests.cs index 94822f260..0590e04e7 100644 --- a/src/Microsoft.TryDotNet.IntegrationTests/PeakyTests.cs +++ b/src/Microsoft.TryDotNet.IntegrationTests/PeakyTests.cs @@ -11,7 +11,7 @@ namespace Microsoft.TryDotNet.IntegrationTests; -public class PeakyTests : IDisposable +public class PeakyTests { private readonly ITestOutputHelper _output; @@ -32,6 +32,4 @@ public async Task The_peaky_test_passes(Uri url) result.Passed.Should().BeTrue(); } - - public void Dispose() => _peakyClient.Dispose(); } \ No newline at end of file diff --git a/src/Microsoft.TryDotNet.Tests/CommandExecutionTests.cs b/src/Microsoft.TryDotNet.Tests/CommandExecutionTests.cs index 0da275f30..67f9113c1 100644 --- a/src/Microsoft.TryDotNet.Tests/CommandExecutionTests.cs +++ b/src/Microsoft.TryDotNet.Tests/CommandExecutionTests.cs @@ -11,51 +11,53 @@ namespace Microsoft.TryDotNet.Tests; public class CommandExecutionTests { - [Fact(Skip = "Failing in CI")] + [Fact] public async Task can_compile_projects_with_user_code_in_region() { await using var applicationBuilderFactory = new WebApplicationFactory(); var c = applicationBuilderFactory.CreateDefaultClient(); - var requests = @"{ - ""commands"": [ - { - ""commandType"": ""OpenProject"", - ""command"": { - ""project"": { - ""files"": [ - { - ""relativeFilePath"": ""program.cs"", - ""content"": ""using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Globalization;\nusing System.Text.RegularExpressions;\n\nnamespace Program\n{\n class Program\n {\n static void Main(string[] args)\n {\n #region controller\n\n #endregion\n }\n }\n}"" - } - ] - } - }, - ""token"": ""595d327c-b14f-5ad7-7da0-2579cbfa9961::22||6"" - }, - { - ""commandType"": ""OpenDocument"", - ""command"": { - ""relativeFilePath"": ""./program.cs"", - ""regionName"": ""controller"" - }, - ""token"": ""595d327c-b14f-5ad7-7da0-2579cbfa9961::22||7"" - }, - { - ""commandType"": ""SubmitCode"", - ""command"": { - ""code"": ""var a = 123;"" - }, - ""token"": ""595d327c-b14f-5ad7-7da0-2579cbfa9961::22||8"" - }, - { - ""commandType"": ""CompileProject"", - ""command"": {}, - ""token"": ""595d327c-b14f-5ad7-7da0-2579cbfa9961::22"" - } - ] -}"; + var requests = """ + { + "commands": [ + { + "commandType": "OpenProject", + "command": { + "project": { + "files": [ + { + "relativeFilePath": "program.cs", + "content": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Globalization;\nusing System.Text.RegularExpressions;\n\nnamespace Program\n{\n class Program\n {\n static void Main(string[] args)\n {\n #region controller\n\n #endregion\n }\n }\n}" + } + ] + } + }, + "token": "595d327c-b14f-5ad7-7da0-2579cbfa9961::22||6" + }, + { + "commandType": "OpenDocument", + "command": { + "relativeFilePath": "./program.cs", + "regionName": "controller" + }, + "token": "595d327c-b14f-5ad7-7da0-2579cbfa9961::22||7" + }, + { + "commandType": "SubmitCode", + "command": { + "code": "var a = 123;" + }, + "token": "595d327c-b14f-5ad7-7da0-2579cbfa9961::22||8" + }, + { + "commandType": "CompileProject", + "command": {}, + "token": "595d327c-b14f-5ad7-7da0-2579cbfa9961::22" + } + ] + } + """; var requestBody = JsonContent.Create(JsonDocument.Parse(requests).RootElement); @@ -82,32 +84,34 @@ public async Task can_open_document_with_user_code_in_region() var c = applicationBuilderFactory.CreateDefaultClient(); - var requests = @"{ - ""commands"": [ - { - ""commandType"": ""OpenProject"", - ""command"": { - ""project"": { - ""files"": [ - { - ""relativeFilePath"": ""program.cs"", - ""content"": ""using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Globalization;\nusing System.Text.RegularExpressions;\n\nnamespace Program\n{\n class Program\n {\n static void Main(string[] args)\n {\n #region controller\nConsole.WriteLine(123);\n #endregion\n }\n }\n}"" - } - ] - } - }, - ""token"": ""595d327c-b14f-5ad7-7da0-2579cbfa9961::22||6"" - }, - { - ""commandType"": ""OpenDocument"", - ""command"": { - ""relativeFilePath"": ""program.cs"", - ""regionName"": ""controller"" - }, - ""token"": ""595d327c-b14f-5ad7-7da0-2579cbfa9961::22||7"" - } - ] -}"; + var requests = """ + { + "commands": [ + { + "commandType": "OpenProject", + "command": { + "project": { + "files": [ + { + "relativeFilePath": "program.cs", + "content": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Globalization;\nusing System.Text.RegularExpressions;\n\nnamespace Program\n{\n class Program\n {\n static void Main(string[] args)\n {\n #region controller\nConsole.WriteLine(123);\n #endregion\n }\n }\n}" + } + ] + } + }, + "token": "595d327c-b14f-5ad7-7da0-2579cbfa9961::22||6" + }, + { + "commandType": "OpenDocument", + "command": { + "relativeFilePath": "program.cs", + "regionName": "controller" + }, + "token": "595d327c-b14f-5ad7-7da0-2579cbfa9961::22||7" + } + ] + } + """; var requestBody = JsonContent.Create(JsonDocument.Parse(requests).RootElement); diff --git a/src/Microsoft.TryDotNet/ContentGenerator.cs b/src/Microsoft.TryDotNet/ContentGenerator.cs index 1fe290a38..0fdf34581 100644 --- a/src/Microsoft.TryDotNet/ContentGenerator.cs +++ b/src/Microsoft.TryDotNet/ContentGenerator.cs @@ -38,22 +38,24 @@ public static Task GenerateEditorPageAsync(HttpRequest request) var configString = JsonSerializer.Serialize(configuration); - var value =$@" - - - - TryDotNet Editor - - - - - - - - - - -"; + var value =$""" + + + + + TryDotNet Editor + + + + + + + + + + + + """; return Task.FromResult(value); } diff --git a/src/Microsoft.TryDotNet/PeakyTests/AgentTests.cs b/src/Microsoft.TryDotNet/PeakyTests/AgentTests.cs deleted file mode 100644 index 1f5da491a..000000000 --- a/src/Microsoft.TryDotNet/PeakyTests/AgentTests.cs +++ /dev/null @@ -1,67 +0,0 @@ -// 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. - -#nullable disable - -using System.Net; -using System.Text; -using Newtonsoft.Json; -using Peaky; - -namespace Microsoft.TryDotNet.PeakyTests; - -public class AgentTests : IPeakyTest, IApplyToApplication -{ - private readonly HttpClientWithTelemetry _httpClient; - - public AgentTests(HttpClientWithTelemetry httpClient) - { - _httpClient = httpClient; - } - - public async Task Valid_script_code_sent_to_run_endpoint_returns_200() - { - await RunCode( - "/workspace/run", - "Console.WriteLine(\"{0}!\");"); - } - - public async Task Valid_console_app_code_sent_to_run_endpoint_returns_200() - { - await RunCode( - "/workspace/run", - "using System;\n namespace Test {{public class Program\n {{\n public static void Main()\n {{\n Console.WriteLine(\"{0}!\");\n }}\n }}}}", - "console"); - } - - private async Task RunCode(string uri, string sourceCode, string workspaceType = null) - { - var guidForConsoleOutput = Guid.NewGuid().ToString(); - - var sourceCodeJson = JsonConvert.SerializeObject(new - { - source = string.Format(sourceCode, guidForConsoleOutput), - workspaceType - }); - - var contentPost = new StringContent(sourceCodeJson, Encoding.UTF8, "application/json"); - - var request = new HttpRequestMessage - { - Content = contentPost, - Method = HttpMethod.Post, - RequestUri = new Uri(uri, UriKind.RelativeOrAbsolute) - }; - - var response = await _httpClient.SendAsync(request); - - response.ShouldSucceed(HttpStatusCode.OK); - - return await response.Content.ReadAsStringAsync(); - } - - public bool AppliesToApplication(string application) - { - return application == "trydotnet"; - } -} \ No newline at end of file diff --git a/src/Microsoft.TryDotNet/PeakyTests/EnvironmentSettings.cs b/src/Microsoft.TryDotNet/PeakyTests/EnvironmentSettings.cs index 54da6e16f..03b88c67a 100644 --- a/src/Microsoft.TryDotNet/PeakyTests/EnvironmentSettings.cs +++ b/src/Microsoft.TryDotNet/PeakyTests/EnvironmentSettings.cs @@ -5,44 +5,13 @@ namespace Microsoft.TryDotNet.PeakyTests; -public class EnvironmentSettings : IEquatable +public record EnvironmentSettings(string RegionId, string HostOrigin, bool IsHttpsEnabled) { - public string HostOrigin { get; set; } + public static EnvironmentSettings ForLocal { get; } = new("localhost", "http://localhost:7061", false); - public bool IsHttpsEnabled { get; set; } + public static EnvironmentSettings ForProduction { get; } = new("production", "https://trydotnet.microsoft.com", true); - public string RegionId { get; set; } - - public static EnvironmentSettings ForLocal { get; } = new() - { - HostOrigin = "http://localhost:7061", - IsHttpsEnabled = false, - RegionId = "localhost" - }; - - public static EnvironmentSettings ForProduction { get; } = new() - { - HostOrigin = "https://trydotnet.microsoft.com", - IsHttpsEnabled = true, - RegionId = "production" - }; - - public static EnvironmentSettings ForPreProduction { get; } = new() - { - HostOrigin = "https://try-ppe.dot.net/", - IsHttpsEnabled = true, - RegionId = "ppe" - }; - - public override bool Equals(object obj) => Equals(obj as EnvironmentSettings); - - public override int GetHashCode() => throw new NotSupportedException(); - - public bool Equals(EnvironmentSettings other) => - other != null && - HostOrigin.Equals(other.HostOrigin) && - IsHttpsEnabled == other.IsHttpsEnabled && - RegionId.Equals(other.RegionId); + public static EnvironmentSettings ForPreProduction { get; } = new("ppe", "https://try-ppe.dot.net/", true); public override string ToString() { diff --git a/src/Microsoft.TryDotNet/PeakyTests/OrchestratorDeploymentTests.cs b/src/Microsoft.TryDotNet/PeakyTests/OrchestratorDeploymentTests.cs index 6c6bf4245..7ff5c0965 100644 --- a/src/Microsoft.TryDotNet/PeakyTests/OrchestratorDeploymentTests.cs +++ b/src/Microsoft.TryDotNet/PeakyTests/OrchestratorDeploymentTests.cs @@ -11,13 +11,13 @@ namespace Microsoft.TryDotNet.PeakyTests; -public class OrchestratorDeploymentTests : IPeakyTest, IApplyToApplication, IHaveTags +public class ExternalTests : IPeakyTest, IApplyToApplication, IHaveTags { private readonly HttpClientWithTelemetry _httpClient; private readonly HttpClientWithXsrfCookies _httpClientWithXsrfCookies; private readonly TestTarget _testTarget; - public OrchestratorDeploymentTests( + public ExternalTests( HttpClientWithTelemetry httpClient, HttpClientWithXsrfCookies httpClientWithXsrfCookies, TestTarget testTarget) @@ -136,46 +136,7 @@ public async Task Snippet_without_Xsrf_returns_401() return await response.Content.ReadAsStringAsync(); } - - public async Task Compile_of_valid_workspace_with_Xsrf_and_hostOrigin_returns_200() - { - var cacheAvoidingValue = Guid.NewGuid().ToString(); - - var sourceCode = $"using System;\n public class Program\n {{\n public static void Main()\n {{\n Console.WriteLine(\"{cacheAvoidingValue}!\");\n }}\n }}"; - - var workspace = new - { - workspaceType = "script", - buffers = new[] - { - new - { - id = "Program.cs", - content = sourceCode, - position = 0 - } - - } - }; - - var contentPost = new StringContent(JsonConvert.SerializeObject(workspace), Encoding.UTF8, "application/json"); - - var request = new HttpRequestMessage - { - Content = contentPost, - Method = HttpMethod.Post, - RequestUri = new Uri("/workspace/run?hostOrigin=https%3A%2F%2Ftry.dot.net%2F", UriKind.RelativeOrAbsolute) - }; - - var response = await _httpClientWithXsrfCookies.SendAsync(request); - - response.ShouldSucceed(HttpStatusCode.OK); - - var result = await response.Content.ReadAsStringAsync(); - - result.Should().Contain(cacheAvoidingValue); - } - + public async Task Compile_without_Xsrf_returns_400() { var cacheAvoidingValue = Guid.NewGuid(); @@ -185,7 +146,7 @@ public async Task Compile_without_Xsrf_returns_400() var workspace = new { - workspaceType = "script", + workspaceType = "console", buffers = new[] { new @@ -223,7 +184,7 @@ public async Task Compile_without_hostOrigin_returns_401() var workspace = new { - workspaceType = "script", + workspaceType = "console", buffers = new[] { new diff --git a/src/Microsoft.TryDotNet/PeakyTests/SelfTests.cs b/src/Microsoft.TryDotNet/PeakyTests/SelfTests.cs new file mode 100644 index 000000000..5676f9c9e --- /dev/null +++ b/src/Microsoft.TryDotNet/PeakyTests/SelfTests.cs @@ -0,0 +1,103 @@ +// 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. + +#nullable disable +using FluentAssertions; +using FluentAssertions.Execution; +using Microsoft.DotNet.Interactive; +using Microsoft.DotNet.Interactive.Commands; +using Microsoft.DotNet.Interactive.CSharpProject; +using Microsoft.DotNet.Interactive.CSharpProject.Build; +using Microsoft.DotNet.Interactive.CSharpProject.Commands; +using Microsoft.DotNet.Interactive.Events; +using Peaky; + +namespace Microsoft.TryDotNet.PeakyTests; + +public class SelfTests : IPeakyTest, IHaveTags, IApplyToApplication +{ + public async Task Console_package_is_prebuilt() + { + var package = await Package.GetOrCreateConsolePackageAsync(enableBuild: false); + + package.Directory.Exists.Should().BeTrue(); + + var subdirectories = package.Directory.GetDirectories(); + + subdirectories.Should().Contain(d => d.Name == "bin"); + subdirectories.Should().Contain(d => d.Name == "obj"); + package.Directory.GetFiles().Should().Contain(f => f.Name == "console.csproj.interactive.workspaceData.cache"); + + return package; + } + + public async Task Can_get_signature_help() + { + using var kernel = await Program.CreateKernelAsync(); + + await kernel.SendAsync(new OpenProject(new Project(new[] { new ProjectFile("Program.cs", @"// content will be replaced") }))); + await kernel.SendAsync(new OpenDocument("Program.cs")); + + var code = """ + + public class Program + { + public static void Main(string[] args) + { + var fileInfo = new System.IO.FileInfo("test.file"); + fileInfo.CopyTo( + } + } + + """; + + var result = await kernel.SendAsync(new RequestSignatureHelp(code, new LinePosition(6, 24))); + using var _ = new AssertionScope(); + + var sigHelpProduced = result.Events + .Should() + .ContainSingle(e => e is SignatureHelpProduced) + .Which + .As(); + + sigHelpProduced + .ActiveSignatureIndex + .Should() + .Be(0); + sigHelpProduced + .ActiveParameterIndex + .Should() + .Be(0); + sigHelpProduced + .Signatures + .Should() + .BeEquivalentTo(new[] + { + new SignatureInformation( + "FileInfo FileInfo.CopyTo(string destFileName)", + new FormattedValue("text/markdown", "Copies an existing file to a new file, disallowing the overwriting of an existing file."), + new[] + { + new ParameterInformation( + "string destFileName", + new FormattedValue("text/markdown", "**destFileName**: The name of the new file to copy to.")) + }), + new SignatureInformation( + "FileInfo FileInfo.CopyTo(string destFileName, bool overwrite)", + new FormattedValue("text/markdown", "Copies an existing file to a new file, allowing the overwriting of an existing file."), + new[] + { + new ParameterInformation( + "string destFileName", + new FormattedValue("text/markdown", "**destFileName**: The name of the new file to copy to.")), + new ParameterInformation( + "bool overwrite", + new FormattedValue("text/markdown", "**overwrite**: true to allow an existing file to be overwritten; otherwise, false.")) + }) + }); + } + + public string[] Tags => new[] { "kernel" }; + + public bool AppliesToApplication(string application) => application == "trydotnet"; +} \ No newline at end of file diff --git a/src/Microsoft.TryDotNet/Program.cs b/src/Microsoft.TryDotNet/Program.cs index 8976f2341..0ac91b393 100644 --- a/src/Microsoft.TryDotNet/Program.cs +++ b/src/Microsoft.TryDotNet/Program.cs @@ -14,9 +14,10 @@ namespace Microsoft.TryDotNet; public class Program { - public static void Main(string[] args) + private static Package _consolePackage; { var app = CreateWebApplication(new WebApplicationOptions { Args = args }); + var app = await CreateWebApplicationAsync(new WebApplicationOptions { Args = args }); app.Run(); } @@ -32,45 +33,36 @@ public static IEnumerable ReadCommands(JsonElement bundl } } - public static WebApplication CreateWebApplication(WebApplicationOptions options) + public static async Task CreateWebApplicationAsync(WebApplicationOptions options) { var builder = WebApplication.CreateBuilder(options); builder.Services.AddCors( opts => opts.AddPolicy("trydotnet", policy => policy.AllowAnyOrigin())); - EnvironmentSettings environmentSettings; + _consolePackage = await Package.GetOrCreateConsolePackageAsync(enableBuild: false); - // FIX: (CreateWebApplication) - // if (builder.Environment.IsProduction()) - // { - builder.Services.AddProductionEnvironmentSettings(out environmentSettings); - - builder.Services.AddHostOriginAuth(new HostOriginPolicies(HostOriginPolicies.ForProduction)); - // } - // else - // { - // builder.Services.AddLocalEnvironmentSettings(out environmentSettings); - // - // builder.Services.AddHostOriginAuth(new HostOriginPolicies(HostOriginPolicies.ForLocal)); - // - // builder.Services.AddDataProtection(); - // } - - builder.Services.AddPeakyTests(registry => - registry.Add( - "production", - "trydotnet", - new Uri(environmentSettings.HostOrigin))); - - builder.Services.AddTransient(_ => new TestPageRenderer("/peaky.js", styleSheets: new[] { new PathString("/peaky.css") })); + builder.Services.AddPeakyTests(tests => + { + tests.Add( + "Development", + "trydotnet", + new Uri(EnvironmentSettings.ForLocal.HostOrigin)); + tests.Add( + "Staging", + "trydotnet", + new Uri(EnvironmentSettings.ForPreProduction.HostOrigin)); + tests.Add( + "Production", + "trydotnet", + new Uri(EnvironmentSettings.ForProduction.HostOrigin)); + }); CSharpProjectKernel.RegisterEventsAndCommands(); var app = builder.Build(); - // FIX: (CreateWebApplication) why is this commented out? - // app.UseHttpsRedirection(); + app.UseHttpsRedirection(); app.UseCors("trydotnet"); app.UseBlazorFrameworkFiles("/wasmrunner"); app.UsePeaky(); @@ -91,7 +83,8 @@ public static WebApplication CreateWebApplication(WebApplicationOptions options) await using (var requestBody = request.Body) { - using var kernel = new CSharpProjectKernel("project-kernel"); + using var kernel = await CreateKernelAsync(); + var body = await new StreamReader(requestBody).ReadToEndAsync(); var bundle = JsonDocument.Parse(body).RootElement; @@ -114,4 +107,8 @@ public static WebApplication CreateWebApplication(WebApplicationOptions options) return app; } + internal static async Task CreateKernelAsync() + { + return new CSharpProjectKernel("csharp.console", PackageFinder.Create(() => Task.FromResult(_consolePackage))); + } } \ No newline at end of file diff --git a/src/Microsoft.TryDotNet/Properties/launchSettings.json b/src/Microsoft.TryDotNet/Properties/launchSettings.json index 56fb57b55..dbddb5333 100644 --- a/src/Microsoft.TryDotNet/Properties/launchSettings.json +++ b/src/Microsoft.TryDotNet/Properties/launchSettings.json @@ -9,7 +9,7 @@ } }, "profiles": { - "Microsoft.TryDotNet": { + "TryDotNet-Development": { "commandName": "Project", "launchBrowser": true, "launchUrl": "editor", @@ -19,6 +19,29 @@ "applicationUrl": "https://localhost:7061;http://localhost:5061", "dotnetRunMessages": true }, + + "TryDotNet-Staging": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "editor", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Staging" + }, + "applicationUrl": "https://localhost:7061;http://localhost:5061", + "dotnetRunMessages": true + }, + + "TryDotNet-Production": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "editor", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Production" + }, + "applicationUrl": "https://localhost:7061;http://localhost:5061", + "dotnetRunMessages": true + }, + "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, From f730def8dae22321914a1fe0e2675ce44b374360 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Fri, 29 Mar 2024 16:41:04 -0700 Subject: [PATCH 02/28] prebuild console package at app startup --- Directory.Packages.props | 5 +--- .../ApiEndpointSimulatorGenerator.cs | 1 - .../PeakyTests/SelfTests.cs | 2 +- src/Microsoft.TryDotNet/Program.cs | 23 +++++++++++++------ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 4ae03b4a0..9a6d348f8 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,7 +3,6 @@ true - @@ -12,7 +11,7 @@ - + @@ -27,9 +26,7 @@ - - \ No newline at end of file diff --git a/src/Microsoft.TryDotNet.SimulatorGenerator/ApiEndpointSimulatorGenerator.cs b/src/Microsoft.TryDotNet.SimulatorGenerator/ApiEndpointSimulatorGenerator.cs index 3a85cb9da..cb75d7bd6 100644 --- a/src/Microsoft.TryDotNet.SimulatorGenerator/ApiEndpointSimulatorGenerator.cs +++ b/src/Microsoft.TryDotNet.SimulatorGenerator/ApiEndpointSimulatorGenerator.cs @@ -508,7 +508,6 @@ static void Main(string[] args){ private static async Task ExecuteScenario(ApiContractScenario scenario) { - await using var applicationBuilderFactory = new WebApplicationFactory(); var c = applicationBuilderFactory.CreateDefaultClient(); diff --git a/src/Microsoft.TryDotNet/PeakyTests/SelfTests.cs b/src/Microsoft.TryDotNet/PeakyTests/SelfTests.cs index 5676f9c9e..5ede125b3 100644 --- a/src/Microsoft.TryDotNet/PeakyTests/SelfTests.cs +++ b/src/Microsoft.TryDotNet/PeakyTests/SelfTests.cs @@ -33,7 +33,7 @@ public async Task Console_package_is_prebuilt() public async Task Can_get_signature_help() { - using var kernel = await Program.CreateKernelAsync(); + using var kernel = Program.CreateKernel(); await kernel.SendAsync(new OpenProject(new Project(new[] { new ProjectFile("Program.cs", @"// content will be replaced") }))); await kernel.SendAsync(new OpenDocument("Program.cs")); diff --git a/src/Microsoft.TryDotNet/Program.cs b/src/Microsoft.TryDotNet/Program.cs index 0ac91b393..58af4920a 100644 --- a/src/Microsoft.TryDotNet/Program.cs +++ b/src/Microsoft.TryDotNet/Program.cs @@ -6,6 +6,7 @@ using System.Text.Json; using Microsoft.DotNet.Interactive.Connection; using Microsoft.DotNet.Interactive.CSharpProject; +using Microsoft.DotNet.Interactive.CSharpProject.Build; using Microsoft.DotNet.Interactive.Events; using Microsoft.TryDotNet.PeakyTests; using Peaky; @@ -14,15 +15,18 @@ namespace Microsoft.TryDotNet; public class Program { - private static Package _consolePackage; + private static Package? _consolePackage; + + public static async Task Main(string[] args) { - var app = CreateWebApplication(new WebApplicationOptions { Args = args }); + await EnsurePrebuildPackageIsReadyAsync(); + var app = await CreateWebApplicationAsync(new WebApplicationOptions { Args = args }); - app.Run(); + await app.RunAsync(); } - public static IEnumerable ReadCommands(JsonElement bundle) + private static IEnumerable ReadCommands(JsonElement bundle) { foreach (var commandEnvelope in bundle.GetProperty("commands").EnumerateArray()) { @@ -83,7 +87,7 @@ public static async Task CreateWebApplicationAsync(WebApplicatio await using (var requestBody = request.Body) { - using var kernel = await CreateKernelAsync(); + using var kernel = CreateKernel(); var body = await new StreamReader(requestBody).ReadToEndAsync(); @@ -107,8 +111,13 @@ public static async Task CreateWebApplicationAsync(WebApplicatio return app; } - internal static async Task CreateKernelAsync() + + private static async Task EnsurePrebuildPackageIsReadyAsync() { - return new CSharpProjectKernel("csharp.console", PackageFinder.Create(() => Task.FromResult(_consolePackage))); + var package = await Package.GetOrCreateConsolePackageAsync(true); + await package.EnsureReadyAsync(); } + + internal static CSharpProjectKernel CreateKernel() => + new("csharp.console", PackageFinder.Create(() => Task.FromResult(_consolePackage))); } \ No newline at end of file From a54ee362c7f81a62cf3d0f6730f00e33b0220aef Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 1 Apr 2024 13:21:13 -0700 Subject: [PATCH 03/28] turn off HTTPS redirection --- src/Microsoft.TryDotNet/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.TryDotNet/Program.cs b/src/Microsoft.TryDotNet/Program.cs index 58af4920a..22c75bfd6 100644 --- a/src/Microsoft.TryDotNet/Program.cs +++ b/src/Microsoft.TryDotNet/Program.cs @@ -66,7 +66,7 @@ public static async Task CreateWebApplicationAsync(WebApplicatio var app = builder.Build(); - app.UseHttpsRedirection(); + // app.UseHttpsRedirection(); app.UseCors("trydotnet"); app.UseBlazorFrameworkFiles("/wasmrunner"); app.UsePeaky(); From fdede36d3756366870d9fe1e5ced92333e5b2080 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 1 Apr 2024 13:21:25 -0700 Subject: [PATCH 04/28] remove empty cell --- Developer-guide.ipynb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Developer-guide.ipynb b/Developer-guide.ipynb index e52d9292d..79c168d21 100644 --- a/Developer-guide.ipynb +++ b/Developer-guide.ipynb @@ -183,11 +183,6 @@ "\n", "The core of Try .NET is powered by the `CSharpProjectKernel`, which serves as the backend for .NET Interactive." ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [] } ], "metadata": { From a01747335c8614ab5abeef4e150dd5719b261f78 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 2 Apr 2024 10:43:36 -0700 Subject: [PATCH 05/28] TrySetException --- src/Microsoft.TryDotNet.IntegrationTests/AspNetProcess.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.TryDotNet.IntegrationTests/AspNetProcess.cs b/src/Microsoft.TryDotNet.IntegrationTests/AspNetProcess.cs index 7eaf39a36..d7fb23097 100644 --- a/src/Microsoft.TryDotNet.IntegrationTests/AspNetProcess.cs +++ b/src/Microsoft.TryDotNet.IntegrationTests/AspNetProcess.cs @@ -21,7 +21,9 @@ public async Task Start() var uriFound = false; _process = CommandLine.StartProcess( "dotnet", - @"Microsoft.TryDotNet.dll --urls=""http://127.0.0.1:0""", + """ + Microsoft.TryDotNet.dll --urls="http://127.0.0.1:0" + """, new DirectoryInfo(ToolPublishedPath), output: output => { @@ -39,7 +41,7 @@ public async Task Start() }, error: error => { - completionSource.SetException(new Exception(error)); + completionSource.TrySetException(new Exception(error)); }); return (await completionSource.Task.Timeout(TimeSpan.FromMinutes(1), $"ASP.NET Process failed to start. Output =\n{buffer})")).ToLocalHost(); From a2e508feea48269652a23f7fb7c78fc416151dfd Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 2 Apr 2024 10:43:40 -0700 Subject: [PATCH 06/28] cleanup --- src/Microsoft.TryDotNet.IntegrationTests/EditorTests.cs | 1 - .../Microsoft.TryDotNet.IntegrationTests.csproj | 1 - .../PlaywrightTestBase.cs | 7 ++++--- .../TryDotNetFixture.cs | 7 ++----- test.cmd | 2 -- 5 files changed, 6 insertions(+), 12 deletions(-) delete mode 100644 test.cmd diff --git a/src/Microsoft.TryDotNet.IntegrationTests/EditorTests.cs b/src/Microsoft.TryDotNet.IntegrationTests/EditorTests.cs index 3880590e2..929616219 100644 --- a/src/Microsoft.TryDotNet.IntegrationTests/EditorTests.cs +++ b/src/Microsoft.TryDotNet.IntegrationTests/EditorTests.cs @@ -17,7 +17,6 @@ public class EditorTests : PlaywrightTestBase { public EditorTests(PlaywrightFixture playwright, TryDotNetFixture tryDotNet) : base(playwright, tryDotNet) { - } [IntegrationTestFact] diff --git a/src/Microsoft.TryDotNet.IntegrationTests/Microsoft.TryDotNet.IntegrationTests.csproj b/src/Microsoft.TryDotNet.IntegrationTests/Microsoft.TryDotNet.IntegrationTests.csproj index 0a384f49c..92fa52f4c 100644 --- a/src/Microsoft.TryDotNet.IntegrationTests/Microsoft.TryDotNet.IntegrationTests.csproj +++ b/src/Microsoft.TryDotNet.IntegrationTests/Microsoft.TryDotNet.IntegrationTests.csproj @@ -4,7 +4,6 @@ net8.0 enable false - false GeneratedLocation.cs $(MSBuildThisFileDirectory)bin\$(Configuration)\tool false diff --git a/src/Microsoft.TryDotNet.IntegrationTests/PlaywrightTestBase.cs b/src/Microsoft.TryDotNet.IntegrationTests/PlaywrightTestBase.cs index 43e3d6fd5..9437f0d65 100644 --- a/src/Microsoft.TryDotNet.IntegrationTests/PlaywrightTestBase.cs +++ b/src/Microsoft.TryDotNet.IntegrationTests/PlaywrightTestBase.cs @@ -10,12 +10,13 @@ namespace Microsoft.TryDotNet.IntegrationTests; [Collection("Chromium Edge")] public abstract class PlaywrightTestBase : IClassFixture, IClassFixture { - public PlaywrightFixture Playwright { get; } - public TryDotNetFixture TryDotNet { get; } - protected PlaywrightTestBase(PlaywrightFixture playwright, TryDotNetFixture tryDotNet) { Playwright = playwright; TryDotNet = tryDotNet; } + + public PlaywrightFixture Playwright { get; } + + public TryDotNetFixture TryDotNet { get; } } \ No newline at end of file diff --git a/src/Microsoft.TryDotNet.IntegrationTests/TryDotNetFixture.cs b/src/Microsoft.TryDotNet.IntegrationTests/TryDotNetFixture.cs index fb0e2be79..116d9185e 100644 --- a/src/Microsoft.TryDotNet.IntegrationTests/TryDotNetFixture.cs +++ b/src/Microsoft.TryDotNet.IntegrationTests/TryDotNetFixture.cs @@ -10,24 +10,21 @@ namespace Microsoft.TryDotNet.IntegrationTests; public class TryDotNetFixture : IDisposable, IAsyncLifetime { private AspNetProcess? _process; + public Uri? Url { get; private set; } public async Task InitializeAsync() { - _process = new AspNetProcess(); Url = await _process.Start(); - } - public Task DisposeAsync() - { + { _process!.Dispose(); return Task.CompletedTask; } - public void Dispose() { _process?.Dispose(); diff --git a/test.cmd b/test.cmd deleted file mode 100644 index 6635b2fff..000000000 --- a/test.cmd +++ /dev/null @@ -1,2 +0,0 @@ -@echo off -powershell -noprofile -executionPolicy RemoteSigned -file "%~dp0eng\build.ps1" -test -binaryLog %* From 8e0050fb34ac8c5dc1ec06f729a6e1030fb70cae Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 2 Apr 2024 11:28:42 -0700 Subject: [PATCH 07/28] improve integration test error output --- .../AspNetProcess.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Microsoft.TryDotNet.IntegrationTests/AspNetProcess.cs b/src/Microsoft.TryDotNet.IntegrationTests/AspNetProcess.cs index d7fb23097..1be5afac3 100644 --- a/src/Microsoft.TryDotNet.IntegrationTests/AspNetProcess.cs +++ b/src/Microsoft.TryDotNet.IntegrationTests/AspNetProcess.cs @@ -19,6 +19,9 @@ public async Task Start() var completionSource = new TaskCompletionSource(); var buffer = new StringBuilder(); var uriFound = false; + + var allOutput = new StringBuilder(); + _process = CommandLine.StartProcess( "dotnet", """ @@ -27,6 +30,8 @@ public async Task Start() new DirectoryInfo(ToolPublishedPath), output: output => { + allOutput.Append(output); + if (!uriFound) { buffer.AppendLine(output); @@ -41,6 +46,13 @@ public async Task Start() }, error: error => { + error = $""" + {allOutput} + + ERROR: + ------ + {error} + """; completionSource.TrySetException(new Exception(error)); }); From ed4652aff0df716bd73be5ff25de502c387c66e3 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 2 Apr 2024 12:28:58 -0700 Subject: [PATCH 08/28] remove integration test artifact output from Linux build --- azure-pipelines-CI.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/azure-pipelines-CI.yml b/azure-pipelines-CI.yml index 27d8178fe..993b8c14d 100644 --- a/azure-pipelines-CI.yml +++ b/azure-pipelines-CI.yml @@ -208,12 +208,6 @@ extends: artifactName: Linux_test_results_and_dumps displayName: Publish Test results and Blame dumps condition: failed() - - output: pipelineArtifact - targetPath: $(Build.SourcesDirectory)/artifacts/bin/Microsoft.TryDotNet.IntegrationTests/$(_BuildConfig)/net8.0/playwright_screenshots - artifactName: Linux_playwright_screenshots - displayName: Publish Playwright screen shots - condition: always() - continueOnError: true variables: # Enable signing for internal, non-PR builds - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: From b36aaadf0ea010592de844c0f81bfef002255a24 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Wed, 3 Apr 2024 18:22:04 -0700 Subject: [PATCH 09/28] add PocketLogger to integration tests --- Directory.Packages.props | 3 +++ azure-pipelines-CI.yml | 4 ++++ azure-pipelines.yml | 4 ++++ .../EditorTests.cs | 2 ++ .../Microsoft.TryDotNet.IntegrationTests.csproj | 11 +++++++++-- .../TryDotNetFixture.cs | 11 ++++++++--- .../TryDotNetJsIntegrationTests.cs | 2 ++ .../WasmRunnerTests.cs | 11 +++++------ 8 files changed, 37 insertions(+), 11 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 9a6d348f8..b57821c33 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -16,7 +16,10 @@ + + + diff --git a/azure-pipelines-CI.yml b/azure-pipelines-CI.yml index 993b8c14d..3cc66ca0e 100644 --- a/azure-pipelines-CI.yml +++ b/azure-pipelines-CI.yml @@ -35,6 +35,8 @@ variables: value: '8.0.101' - name: NodeJSVersion value: '16.13.0' +- name: PocketLoggerLogPath + value: $(Build.SourcesDirectory)/artifacts/log - name: TryDotNetPackagesPath value: $(Build.SourcesDirectory)/artifacts/.trydotnet/packages - name: RunIntegrationTests @@ -171,6 +173,7 @@ extends: $(_TestArgs) displayName: Build env: + POCKETLOGGER_LOG_PATH: $(PocketLoggerLogPath) TRYDOTNET_PACKAGES_PATH: $(TryDotNetPackagesPath) - script: dotnet test -l trx --no-build --blame-hang-timeout 15m --blame-hang-dump-type full -c $(_BuildConfig) --results-directory $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) @@ -260,6 +263,7 @@ extends: $(_TestArgs) displayName: Build env: + POCKETLOGGER_LOG_PATH: $(PocketLoggerLogPath) TRYDOTNET_PACKAGES_PATH: $(TryDotNetPackagesPath) - script: dotnet test -l trx --no-build --blame-hang-timeout 15m --blame-hang-dump-type full -c $(_BuildConfig) --results-directory $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 801fffc30..7f39cad69 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -27,6 +27,8 @@ variables: value: '8.0.101' - name: NodeJSVersion value: '16.13.0' + - name: PocketLoggerLogPath + value: $(Build.SourcesDirectory)/artifacts/log - name: TryDotNetPackagesPath value: $(Build.SourcesDirectory)/artifacts/.trydotnet/packages - name: RunIntegrationTests @@ -123,6 +125,7 @@ stages: $(_TestArgs) displayName: Build env: + POCKETLOGGER_LOG_PATH: $(PocketLoggerLogPath) TRYDOTNET_PACKAGES_PATH: $(TryDotNetPackagesPath) - script: dotnet test -l trx --no-build --blame-hang-timeout 15m --blame-hang-dump-type full -c $(_BuildConfig) --results-directory $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) @@ -225,6 +228,7 @@ stages: $(_TestArgs) displayName: Build env: + POCKETLOGGER_LOG_PATH: $(PocketLoggerLogPath) TRYDOTNET_PACKAGES_PATH: $(TryDotNetPackagesPath) - script: dotnet test -l trx --no-build --blame-hang-timeout 15m --blame-hang-dump-type full -c $(_BuildConfig) --results-directory $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) diff --git a/src/Microsoft.TryDotNet.IntegrationTests/EditorTests.cs b/src/Microsoft.TryDotNet.IntegrationTests/EditorTests.cs index 929616219..ab4b52698 100644 --- a/src/Microsoft.TryDotNet.IntegrationTests/EditorTests.cs +++ b/src/Microsoft.TryDotNet.IntegrationTests/EditorTests.cs @@ -10,9 +10,11 @@ using FluentAssertions; using Microsoft.Playwright; +using Pocket.For.Xunit; namespace Microsoft.TryDotNet.IntegrationTests; +[LogToPocketLogger(FileNameEnvironmentVariable = "POCKETLOGGER_LOG_PATH")] public class EditorTests : PlaywrightTestBase { public EditorTests(PlaywrightFixture playwright, TryDotNetFixture tryDotNet) : base(playwright, tryDotNet) diff --git a/src/Microsoft.TryDotNet.IntegrationTests/Microsoft.TryDotNet.IntegrationTests.csproj b/src/Microsoft.TryDotNet.IntegrationTests/Microsoft.TryDotNet.IntegrationTests.csproj index 92fa52f4c..e2e07e481 100644 --- a/src/Microsoft.TryDotNet.IntegrationTests/Microsoft.TryDotNet.IntegrationTests.csproj +++ b/src/Microsoft.TryDotNet.IntegrationTests/Microsoft.TryDotNet.IntegrationTests.csproj @@ -15,13 +15,20 @@ - - runtime; build; native; contentfiles; analyzers; buildtransitive + all all + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + diff --git a/src/Microsoft.TryDotNet.IntegrationTests/TryDotNetFixture.cs b/src/Microsoft.TryDotNet.IntegrationTests/TryDotNetFixture.cs index 116d9185e..305b77526 100644 --- a/src/Microsoft.TryDotNet.IntegrationTests/TryDotNetFixture.cs +++ b/src/Microsoft.TryDotNet.IntegrationTests/TryDotNetFixture.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Reactive.Disposables; using System.Threading.Tasks; using Xunit; @@ -10,23 +11,27 @@ namespace Microsoft.TryDotNet.IntegrationTests; public class TryDotNetFixture : IDisposable, IAsyncLifetime { private AspNetProcess? _process; - + private readonly CompositeDisposable _disposables = new(); + public Uri? Url { get; private set; } public async Task InitializeAsync() { _process = new AspNetProcess(); + + _disposables.Add(_process); + Url = await _process.Start(); } public Task DisposeAsync() { - _process!.Dispose(); + Dispose(); return Task.CompletedTask; } public void Dispose() { - _process?.Dispose(); + _disposables.Dispose(); } } \ No newline at end of file diff --git a/src/Microsoft.TryDotNet.IntegrationTests/TryDotNetJsIntegrationTests.cs b/src/Microsoft.TryDotNet.IntegrationTests/TryDotNetJsIntegrationTests.cs index ea6aecc78..9c3295336 100644 --- a/src/Microsoft.TryDotNet.IntegrationTests/TryDotNetJsIntegrationTests.cs +++ b/src/Microsoft.TryDotNet.IntegrationTests/TryDotNetJsIntegrationTests.cs @@ -8,10 +8,12 @@ using FluentAssertions; using Microsoft.AspNetCore.WebUtilities; using Microsoft.Playwright; +using Pocket.For.Xunit; using Xunit; namespace Microsoft.TryDotNet.IntegrationTests; +[LogToPocketLogger(FileNameEnvironmentVariable = "POCKETLOGGER_LOG_PATH")] public class TryDotNetJsIntegrationTests : PlaywrightTestBase, IClassFixture { public LearnFixture Learn { get; } diff --git a/src/Microsoft.TryDotNet.IntegrationTests/WasmRunnerTests.cs b/src/Microsoft.TryDotNet.IntegrationTests/WasmRunnerTests.cs index 1a4d2135d..ae4583c89 100644 --- a/src/Microsoft.TryDotNet.IntegrationTests/WasmRunnerTests.cs +++ b/src/Microsoft.TryDotNet.IntegrationTests/WasmRunnerTests.cs @@ -6,11 +6,16 @@ using FluentAssertions; using Microsoft.Playwright; +using Pocket.For.Xunit; namespace Microsoft.TryDotNet.IntegrationTests; +[LogToPocketLogger(FileNameEnvironmentVariable = "POCKETLOGGER_LOG_PATH")] public class WasmRunnerTests : PlaywrightTestBase { + public WasmRunnerTests(PlaywrightFixture playwright, TryDotNetFixture tryDotNet) : base(playwright, tryDotNet) + { + } [IntegrationTestFact] public async Task can_load_wasmrunner() @@ -81,11 +86,5 @@ public async Task can_run_assembly_and_produce_output() .ContainSingle(m => m.type == "wasmRunner-stdout") .Which .message.Should().Be("Hello World!\n"); - - } - - - public WasmRunnerTests(PlaywrightFixture playwright, TryDotNetFixture tryDotNet) : base(playwright, tryDotNet) - { } } \ No newline at end of file From 3cbcbd6cdef1f092a576b7660ee7c8d11bef4dae Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Thu, 4 Apr 2024 09:41:38 -0700 Subject: [PATCH 10/28] make Linux integration tests go away --- azure-pipelines-CI.yml | 4 ++-- azure-pipelines.yml | 13 ++----------- .../IntegrationTestFactAttribute.cs | 1 - 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/azure-pipelines-CI.yml b/azure-pipelines-CI.yml index 3cc66ca0e..8ca1bf70f 100644 --- a/azure-pipelines-CI.yml +++ b/azure-pipelines-CI.yml @@ -39,8 +39,6 @@ variables: value: $(Build.SourcesDirectory)/artifacts/log - name: TryDotNetPackagesPath value: $(Build.SourcesDirectory)/artifacts/.trydotnet/packages -- name: RunIntegrationTests - value: true - name: Codeql.Enabled value: true @@ -105,6 +103,8 @@ extends: # displayName: Publish packages to artifacts container variables: + - name: RunIntegrationTests + value: true # Enable signing for internal, non-PR builds - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: - group: DotNet-Blob-Feed diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7f39cad69..5491e7850 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -31,8 +31,6 @@ variables: value: $(Build.SourcesDirectory)/artifacts/log - name: TryDotNetPackagesPath value: $(Build.SourcesDirectory)/artifacts/.trydotnet/packages - - name: RunIntegrationTests - value: true - name: Codeql.Enabled value: true @@ -57,6 +55,8 @@ stages: name: NetCore1ESPool-Internal demands: ImageOverride -equals windows.vs2022.amd64 variables: + - name: RunIntegrationTests + value: true # Enable signing for internal, non-PR builds - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: - group: DotNet-Blob-Feed @@ -251,15 +251,6 @@ stages: artifactType: container condition: failed() - - task: PublishBuildArtifacts@1 - displayName: Publish Playwright screen shots - inputs: - pathToPublish: $(Build.SourcesDirectory)/artifacts/bin/Microsoft.TryDotNet.IntegrationTests/Release/net8.0/playwright_screenshots - artifactName: Linux_playwright_screenshots - artifactType: container - condition: always() - continueOnError: true - #---------------------------------------------------------------------------------------------------------------------# # Post Build # #---------------------------------------------------------------------------------------------------------------------# diff --git a/src/Microsoft.TryDotNet.IntegrationTests/IntegrationTestFactAttribute.cs b/src/Microsoft.TryDotNet.IntegrationTests/IntegrationTestFactAttribute.cs index e87296a2f..995adfc48 100644 --- a/src/Microsoft.TryDotNet.IntegrationTests/IntegrationTestFactAttribute.cs +++ b/src/Microsoft.TryDotNet.IntegrationTests/IntegrationTestFactAttribute.cs @@ -13,7 +13,6 @@ internal class IntegrationTestFactAttribute : FactAttribute private const string EnvironmentVariableName = "RunIntegrationTests"; public IntegrationTestFactAttribute(string? skipReason = null) - { var variableValue = Environment.GetEnvironmentVariable(EnvironmentVariableName) ?? "false"; switch (variableValue.ToLowerInvariant()) From d428b4830de23e47fd993096ca75c7358641b873 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Thu, 4 Apr 2024 12:18:19 -0700 Subject: [PATCH 11/28] publish all artifacts --- azure-pipelines-CI.yml | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/azure-pipelines-CI.yml b/azure-pipelines-CI.yml index 8ca1bf70f..095ba34ea 100644 --- a/azure-pipelines-CI.yml +++ b/azure-pipelines-CI.yml @@ -86,21 +86,10 @@ extends: outputParentDirectory: $(Build.SourcesDirectory)/artifacts outputs: - output: pipelineArtifact - targetPath: $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) - artifactName: Windows_test_results_and_dumps - displayName: Publish Test results and Blame dumps - condition: failed() - - output: pipelineArtifact - targetPath: $(Build.SourcesDirectory)/artifacts/bin/Microsoft.TryDotNet.IntegrationTests/$(_BuildConfig)/net8.0/playwright_screenshots - artifactName: Windows_playwright_screenshots - displayName: Publish Playwright screen shots + targetPath: $(Build.SourcesDirectory)/artifacts + artifactName: Windows_artifacts + displayName: Publish Windows artifacts condition: always() - continueOnError: true - # Packages are not being generated - # - output: pipelineArtifact - # targetPath: $(Build.SourcesDirectory)/artifacts/packages/$(_BuildConfig) - # artifactName: packages - # displayName: Publish packages to artifacts container variables: - name: RunIntegrationTests @@ -207,10 +196,10 @@ extends: outputParentDirectory: $(Build.SourcesDirectory)/artifacts outputs: - output: pipelineArtifact - targetPath: $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) - artifactName: Linux_test_results_and_dumps - displayName: Publish Test results and Blame dumps - condition: failed() + targetPath: $(Build.SourcesDirectory)/artifacts + artifactName: Linux_artifacts + displayName: Publish Linux artifacts + condition: always() variables: # Enable signing for internal, non-PR builds - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: From 092282d59c8fe2e6e02df501d6f6c43b407f0484 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Thu, 4 Apr 2024 12:42:02 -0700 Subject: [PATCH 12/28] logging improvements --- .../LogEvents.SubscribeToPocketLogger.cs | 21 +++++++++++++++++++ .../CodeRunnerTests.cs | 1 - .../CommandExecutionTests.cs | 18 +++++++++++++--- .../Microsoft.TryDotNet.Tests.csproj | 14 +++++++++++++ 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 src/Microsoft.TryDotNet.Tests/(Pocket)/Logger/LogEvents.SubscribeToPocketLogger.cs diff --git a/src/Microsoft.TryDotNet.Tests/(Pocket)/Logger/LogEvents.SubscribeToPocketLogger.cs b/src/Microsoft.TryDotNet.Tests/(Pocket)/Logger/LogEvents.SubscribeToPocketLogger.cs new file mode 100644 index 000000000..95f513606 --- /dev/null +++ b/src/Microsoft.TryDotNet.Tests/(Pocket)/Logger/LogEvents.SubscribeToPocketLogger.cs @@ -0,0 +1,21 @@ +// 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.CSharpProject; +using Microsoft.DotNet.Interactive.Events; +using Xunit.Abstractions; + +namespace Pocket; + +internal partial class LogEvents +{ + public static IDisposable SubscribeToPocketLogger(this ITestOutputHelper output) => + Subscribe( + e => output.WriteLine(e.ToLogString()), + new[] + { + typeof(LogEvents).Assembly, + typeof(KernelEvent).Assembly, + typeof(CSharpProjectKernel).Assembly + }); +} \ No newline at end of file diff --git a/src/Microsoft.TryDotNet.Tests/CodeRunnerTests.cs b/src/Microsoft.TryDotNet.Tests/CodeRunnerTests.cs index 5f63db219..4b40cb9b4 100644 --- a/src/Microsoft.TryDotNet.Tests/CodeRunnerTests.cs +++ b/src/Microsoft.TryDotNet.Tests/CodeRunnerTests.cs @@ -50,7 +50,6 @@ public async Task It_can_run_a_main_method_with_parameters() outputs.Select(o => o.Trim()).Should().BeEquivalentTo( "123"); - } diff --git a/src/Microsoft.TryDotNet.Tests/CommandExecutionTests.cs b/src/Microsoft.TryDotNet.Tests/CommandExecutionTests.cs index 67f9113c1..92d637732 100644 --- a/src/Microsoft.TryDotNet.Tests/CommandExecutionTests.cs +++ b/src/Microsoft.TryDotNet.Tests/CommandExecutionTests.cs @@ -5,12 +5,23 @@ using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.DotNet.Interactive.Connection; using Microsoft.DotNet.Interactive.CSharpProject.Events; +using Pocket; +using Pocket.For.Xunit; using Xunit; +using Xunit.Abstractions; namespace Microsoft.TryDotNet.Tests; -public class CommandExecutionTests +[LogToPocketLogger(FileNameEnvironmentVariable = "POCKETLOGGER_LOG_PATH")] +public class CommandExecutionTests : IDisposable { + private readonly CompositeDisposable _disposables = new(); + + public CommandExecutionTests(ITestOutputHelper output) + { + _disposables.Add(output.SubscribeToPocketLogger()); + } + [Fact] public async Task can_compile_projects_with_user_code_in_region() { @@ -73,8 +84,7 @@ public async Task can_compile_projects_with_user_code_in_region() var assemblyProduced = events.OfType().SingleOrDefault(); assemblyProduced.Should().NotBeNull(); - assemblyProduced!.Assembly - .Value.Should().NotBeNullOrWhiteSpace(); + assemblyProduced!.Assembly.Value.Should().NotBeNullOrWhiteSpace(); } [Fact] @@ -129,4 +139,6 @@ public async Task can_open_document_with_user_code_in_region() documentOpened.Should().NotBeNull(); documentOpened!.Content.Should().Contain("Console.WriteLine(123);"); } + + public void Dispose() => _disposables.Dispose(); } \ No newline at end of file diff --git a/src/Microsoft.TryDotNet.Tests/Microsoft.TryDotNet.Tests.csproj b/src/Microsoft.TryDotNet.Tests/Microsoft.TryDotNet.Tests.csproj index 689863543..d88e88435 100644 --- a/src/Microsoft.TryDotNet.Tests/Microsoft.TryDotNet.Tests.csproj +++ b/src/Microsoft.TryDotNet.Tests/Microsoft.TryDotNet.Tests.csproj @@ -15,6 +15,20 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all + + all + + + all + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + From 4709d30b759a5ac61da89ff5100f8c6521236342 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Fri, 5 Apr 2024 13:04:28 -0700 Subject: [PATCH 13/28] PocketLogger and logging updates --- Directory.Packages.props | 14 ++--- .../AspNetProcess.cs | 36 +++++++++---- .../Microsoft.TryDotNet.csproj | 8 ++- src/Microsoft.TryDotNet/Program.cs | 51 ++++++++++++++++++- 4 files changed, 88 insertions(+), 21 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index b57821c33..748119e51 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -11,23 +11,25 @@ - - + + - - - + + + + + - + diff --git a/src/Microsoft.TryDotNet.IntegrationTests/AspNetProcess.cs b/src/Microsoft.TryDotNet.IntegrationTests/AspNetProcess.cs index 1be5afac3..b2a48f2d5 100644 --- a/src/Microsoft.TryDotNet.IntegrationTests/AspNetProcess.cs +++ b/src/Microsoft.TryDotNet.IntegrationTests/AspNetProcess.cs @@ -7,6 +7,8 @@ using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; +using Pocket; +using static Pocket.Logger; namespace Microsoft.TryDotNet.IntegrationTests; @@ -16,8 +18,9 @@ public partial class AspNetProcess : IDisposable public async Task Start() { + using var operation = Log.OnEnterAndConfirmOnExit(); + var completionSource = new TaskCompletionSource(); - var buffer = new StringBuilder(); var uriFound = false; var allOutput = new StringBuilder(); @@ -30,11 +33,11 @@ public async Task Start() new DirectoryInfo(ToolPublishedPath), output: output => { + operation.Info(output); allOutput.Append(output); if (!uriFound) { - buffer.AppendLine(output); var matches = Regex.Match(output, @"listening on:\s*(?http(s)?://(\d+\.){3}(\d+)(:\d+)?)"); if (matches.Success) { @@ -46,17 +49,28 @@ public async Task Start() }, error: error => { - error = $""" - {allOutput} - - ERROR: - ------ - {error} - """; - completionSource.TrySetException(new Exception(error)); + var outputAndError = $""" + {allOutput} + + ERROR: + ------ + {error} + """; + + operation.Fail(message: error); + + completionSource.TrySetException(new Exception(outputAndError)); }); - return (await completionSource.Task.Timeout(TimeSpan.FromMinutes(1), $"ASP.NET Process failed to start. Output =\n{buffer})")).ToLocalHost(); + var timeout = Debugger.IsAttached ? TimeSpan.FromDays(1) : TimeSpan.FromMinutes(1); + + var readyAtUrl = await completionSource.Task.Timeout(timeout, $"ASP.NET process not ready within {timeout.TotalSeconds}s. Output =\n{allOutput})"); + + var localHostUrl = readyAtUrl.ToLocalHost(); + + operation.Succeed(); + + return localHostUrl; } public void Dispose() diff --git a/src/Microsoft.TryDotNet/Microsoft.TryDotNet.csproj b/src/Microsoft.TryDotNet/Microsoft.TryDotNet.csproj index dc821bf2d..79c4c83d7 100644 --- a/src/Microsoft.TryDotNet/Microsoft.TryDotNet.csproj +++ b/src/Microsoft.TryDotNet/Microsoft.TryDotNet.csproj @@ -16,12 +16,16 @@ all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + all + + + + diff --git a/src/Microsoft.TryDotNet/Program.cs b/src/Microsoft.TryDotNet/Program.cs index 22c75bfd6..fe4bb11af 100644 --- a/src/Microsoft.TryDotNet/Program.cs +++ b/src/Microsoft.TryDotNet/Program.cs @@ -2,14 +2,22 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Net.Mime; +using System.Reflection; using System.Text; using System.Text.Json; +using Microsoft.CodeAnalysis; +using Microsoft.DotNet.Interactive; using Microsoft.DotNet.Interactive.Connection; using Microsoft.DotNet.Interactive.CSharpProject; using Microsoft.DotNet.Interactive.CSharpProject.Build; +using Microsoft.DotNet.Interactive.Documents; using Microsoft.DotNet.Interactive.Events; using Microsoft.TryDotNet.PeakyTests; using Peaky; +using Pocket; +using Serilog.Sinks.RollingFileAlternate; +using static Pocket.Logger; +using SerilogLoggerConfiguration = Serilog.LoggerConfiguration; namespace Microsoft.TryDotNet; @@ -19,6 +27,8 @@ public class Program public static async Task Main(string[] args) { + StartLogging(); + await EnsurePrebuildPackageIsReadyAsync(); var app = await CreateWebApplicationAsync(new WebApplicationOptions { Args = args }); @@ -118,6 +128,43 @@ private static async Task EnsurePrebuildPackageIsReadyAsync() await package.EnsureReadyAsync(); } - internal static CSharpProjectKernel CreateKernel() => + internal static CSharpProjectKernel CreateKernel() => new("csharp.console", PackageFinder.Create(() => Task.FromResult(_consolePackage))); -} \ No newline at end of file + + + private static readonly Assembly[] _assembliesEmittingPocketLoggerLogs = + [ + typeof(Program).Assembly, // Microsoft.TryDotNet.dll + typeof(Kernel).Assembly, // Microsoft.DotNet.Interactive.dll + typeof(CSharpProjectKernel).Assembly, // Microsoft.DotNet.Interactive.CSharpProject.dll + typeof(InteractiveDocument).Assembly // Microsoft.DotNet.Interactive.Documents.dll + ]; + + private static void StartLogging() + { + if (Environment.GetEnvironmentVariable("POCKETLOGGER_LOG_PATH") is { } logFile) + { + var logPath = new FileInfo(logFile).Directory; + + if (logPath is not null) + { + logPath = logPath.CreateSubdirectory("Try .NET logs"); + + var log = new SerilogLoggerConfiguration() + .WriteTo + .RollingFileAlternate(logPath.FullName, outputTemplate: "{Message}{NewLine}") + .CreateLogger(); + + LogEvents.Subscribe( + e => log.Information(e.ToLogString()), + _assembliesEmittingPocketLoggerLogs); + } + } + + TaskScheduler.UnobservedTaskException += (_, args) => + { + Log.Warning($"{nameof(TaskScheduler.UnobservedTaskException)}", args.Exception); + args.SetObserved(); + }; + } +} From 748b83c0abb5b6a9dd25f2f4d087b505bea806ad Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Fri, 5 Apr 2024 16:11:13 -0700 Subject: [PATCH 14/28] fix warning --- src/Microsoft.TryDotNet.IntegrationTests/CommandLine.cs | 4 ++-- src/Microsoft.TryDotNet/Program.cs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.TryDotNet.IntegrationTests/CommandLine.cs b/src/Microsoft.TryDotNet.IntegrationTests/CommandLine.cs index 5b36a8908..b911a308f 100644 --- a/src/Microsoft.TryDotNet.IntegrationTests/CommandLine.cs +++ b/src/Microsoft.TryDotNet.IntegrationTests/CommandLine.cs @@ -198,10 +198,10 @@ private static ConfirmationLogger ConfirmOnExit( [CallerMemberName] string? operationName = null) { return new ConfirmationLogger( - operationName: operationName, + operationName: operationName ?? "", category: Log.Category, message: "> {command} {args}", - args: new[] { command, args }, + args: [command, args], logOnStart: true); } diff --git a/src/Microsoft.TryDotNet/Program.cs b/src/Microsoft.TryDotNet/Program.cs index fe4bb11af..0e3f03912 100644 --- a/src/Microsoft.TryDotNet/Program.cs +++ b/src/Microsoft.TryDotNet/Program.cs @@ -5,7 +5,6 @@ using System.Reflection; using System.Text; using System.Text.Json; -using Microsoft.CodeAnalysis; using Microsoft.DotNet.Interactive; using Microsoft.DotNet.Interactive.Connection; using Microsoft.DotNet.Interactive.CSharpProject; From e07deae66903dd8dc14fe9754e2ac39886ccf7cb Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Sat, 6 Apr 2024 12:01:33 -0700 Subject: [PATCH 15/28] remove separate screenshot publishing step --- azure-pipelines.yml | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5491e7850..7ef6d29e8 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -141,29 +141,12 @@ stages: condition: and(ne(variables['KeepDumps'], 'true'), ne(variables['SkipTests'], 'true')) - task: PublishBuildArtifacts@1 - displayName: Publish Test results and Blame dumps - inputs: - pathToPublish: $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) - artifactName: Windows_test_results_and_dumps - artifactType: container - condition: failed() - - - task: PublishBuildArtifacts@1 - displayName: Publish Playwright screen shots + displayName: Publish Windows artifacts inputs: - pathToPublish: $(Build.SourcesDirectory)\artifacts\bin\Microsoft.TryDotNet.IntegrationTests\Release\net8.0\playwright_screenshots - artifactName: Windows_playwright_screenshots + pathToPublish: $(Build.SourcesDirectory)/artifacts/ + artifactName: Windows_artifacts artifactType: container condition: always() - continueOnError: true - - # Packages are not being generated - # - task: PublishBuildArtifacts@1 - # displayName: Publish packages to artifacts container - # inputs: - # pathToPublish: $(Build.SourcesDirectory)\artifacts\packages\$(_BuildConfig) - # artifactName: packages - # artifactType: container - template: /eng/common/templates/jobs/jobs.yml parameters: From d21884a31b7aaeab5e7c26fd8e2f4b93b6f11cbd Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 8 Apr 2024 13:22:26 -0700 Subject: [PATCH 16/28] disable PDB converter --- eng/Versions.props | 1 + 1 file changed, 1 insertion(+) diff --git a/eng/Versions.props b/eng/Versions.props index 245d6b729..cfa17af61 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -6,6 +6,7 @@ true false true + false -parallel none From ffe90ed8fab554e901bc5e685c0b73949885e9cc Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 8 Apr 2024 14:15:23 -0700 Subject: [PATCH 17/28] don't publish to symbol server --- azure-pipelines-CI.yml | 1 - azure-pipelines.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/azure-pipelines-CI.yml b/azure-pipelines-CI.yml index 095ba34ea..4e7c6d146 100644 --- a/azure-pipelines-CI.yml +++ b/azure-pipelines-CI.yml @@ -116,7 +116,6 @@ extends: /p:DotNetSymbolServerTokenMsdl=$(microsoft-symbol-server-pat) /p:DotNetSymbolServerTokenSymWeb=$(symweb-symbol-server-pat) /p:OfficialBuildId=$(BUILD.BUILDNUMBER) - /p:PublishToSymbolServer=true # else - ${{ if or(eq(variables['System.TeamProject'], 'public'), in(variables['Build.Reason'], 'PullRequest')) }}: - name: _SignType diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7ef6d29e8..dfa894f40 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -79,7 +79,6 @@ stages: /p:DotNetSymbolServerTokenMsdl=$(microsoft-symbol-server-pat) /p:DotNetSymbolServerTokenSymWeb=$(symweb-symbol-server-pat) /p:OfficialBuildId=$(BUILD.BUILDNUMBER) - /p:PublishToSymbolServer=true # else - ${{ if or(eq(variables['System.TeamProject'], 'public'), in(variables['Build.Reason'], 'PullRequest')) }}: - name: _SignType From 8cdd517941f2084b25f3fdfb2558ec50eb8c617b Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 8 Apr 2024 14:49:23 -0700 Subject: [PATCH 18/28] update log path --- azure-pipelines-CI.yml | 2 +- azure-pipelines.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines-CI.yml b/azure-pipelines-CI.yml index 4e7c6d146..d16dd67c3 100644 --- a/azure-pipelines-CI.yml +++ b/azure-pipelines-CI.yml @@ -36,7 +36,7 @@ variables: - name: NodeJSVersion value: '16.13.0' - name: PocketLoggerLogPath - value: $(Build.SourcesDirectory)/artifacts/log + value: $(Build.SourcesDirectory)/artifacts/logs/pocketlogger.log - name: TryDotNetPackagesPath value: $(Build.SourcesDirectory)/artifacts/.trydotnet/packages - name: Codeql.Enabled diff --git a/azure-pipelines.yml b/azure-pipelines.yml index dfa894f40..d13d44636 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -28,7 +28,7 @@ variables: - name: NodeJSVersion value: '16.13.0' - name: PocketLoggerLogPath - value: $(Build.SourcesDirectory)/artifacts/log + value: $(Build.SourcesDirectory)/artifacts/logs/pocketlogger.log - name: TryDotNetPackagesPath value: $(Build.SourcesDirectory)/artifacts/.trydotnet/packages - name: Codeql.Enabled From 971d447ada284e3be1252380e52a663ff7622ec2 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Mon, 8 Apr 2024 16:17:53 -0700 Subject: [PATCH 19/28] remove symbol server parameters --- azure-pipelines-CI.yml | 2 -- azure-pipelines.yml | 2 -- 2 files changed, 4 deletions(-) diff --git a/azure-pipelines-CI.yml b/azure-pipelines-CI.yml index d16dd67c3..4a9f7b46f 100644 --- a/azure-pipelines-CI.yml +++ b/azure-pipelines-CI.yml @@ -113,8 +113,6 @@ extends: /p:DotNetPublishToBlobFeed=true /p:DotNetPublishUsingPipelines=$(_PublishUsingPipelines) /p:DotNetArtifactsCategory=$(_DotNetArtifactsCategory) - /p:DotNetSymbolServerTokenMsdl=$(microsoft-symbol-server-pat) - /p:DotNetSymbolServerTokenSymWeb=$(symweb-symbol-server-pat) /p:OfficialBuildId=$(BUILD.BUILDNUMBER) # else - ${{ if or(eq(variables['System.TeamProject'], 'public'), in(variables['Build.Reason'], 'PullRequest')) }}: diff --git a/azure-pipelines.yml b/azure-pipelines.yml index d13d44636..73b476a5e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -76,8 +76,6 @@ stages: /p:DotNetPublishToBlobFeed=true /p:DotNetPublishUsingPipelines=$(_PublishUsingPipelines) /p:DotNetArtifactsCategory=$(_DotNetArtifactsCategory) - /p:DotNetSymbolServerTokenMsdl=$(microsoft-symbol-server-pat) - /p:DotNetSymbolServerTokenSymWeb=$(symweb-symbol-server-pat) /p:OfficialBuildId=$(BUILD.BUILDNUMBER) # else - ${{ if or(eq(variables['System.TeamProject'], 'public'), in(variables['Build.Reason'], 'PullRequest')) }}: From de967b80766597b589490de4e25cdc29588b6de8 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 9 Apr 2024 09:19:59 -0700 Subject: [PATCH 20/28] false --- Directory.Build.props | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 58d125494..f392ed875 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -10,7 +10,8 @@ false false - + false + $(NoWarn);NU5104 From 0bf6d6816438354a4dcd8aac25f6017ebe1245e2 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 9 Apr 2024 11:02:18 -0700 Subject: [PATCH 21/28] turn on logging regardless of environment variable --- src/Microsoft.TryDotNet/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.TryDotNet/Program.cs b/src/Microsoft.TryDotNet/Program.cs index 0e3f03912..6a66202ed 100644 --- a/src/Microsoft.TryDotNet/Program.cs +++ b/src/Microsoft.TryDotNet/Program.cs @@ -141,7 +141,7 @@ internal static CSharpProjectKernel CreateKernel() => private static void StartLogging() { - if (Environment.GetEnvironmentVariable("POCKETLOGGER_LOG_PATH") is { } logFile) + if (true /* Environment.GetEnvironmentVariable("POCKETLOGGER_LOG_PATH") is { } logFile */ ) { var logPath = new FileInfo(logFile).Directory; From 56a0568f60daf60ebf561b6c0c370a09f79ac42e Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 9 Apr 2024 13:03:50 -0700 Subject: [PATCH 22/28] update Microsoft.DotNet.Interactive.CSharpProject version --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 748119e51..4a21dc3fc 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -11,7 +11,7 @@ - + From ac7dcbfb7649b9ea01200b1284947555b9c6a881 Mon Sep 17 00:00:00 2001 From: Jon Sequeira Date: Tue, 9 Apr 2024 13:07:53 -0700 Subject: [PATCH 23/28] update package versions --- Directory.Packages.props | 8 ++++---- src/Microsoft.TryDotNet/Program.cs | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 4a21dc3fc..a12fe24ec 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -7,10 +7,10 @@ - - - - + + + + diff --git a/src/Microsoft.TryDotNet/Program.cs b/src/Microsoft.TryDotNet/Program.cs index 6a66202ed..979d61aaa 100644 --- a/src/Microsoft.TryDotNet/Program.cs +++ b/src/Microsoft.TryDotNet/Program.cs @@ -141,10 +141,12 @@ internal static CSharpProjectKernel CreateKernel() => private static void StartLogging() { - if (true /* Environment.GetEnvironmentVariable("POCKETLOGGER_LOG_PATH") is { } logFile */ ) + if (Environment.GetEnvironmentVariable("POCKETLOGGER_LOG_PATH") is { } logFile) { var logPath = new FileInfo(logFile).Directory; + Console.WriteLine($"Logging to: {logPath}"); + if (logPath is not null) { logPath = logPath.CreateSubdirectory("Try .NET logs"); From 2e863611a60ea1708c7396198f41329c7ab5ef35 Mon Sep 17 00:00:00 2001 From: "Abhitej John Bandi (from Dev Box)" Date: Tue, 9 Apr 2024 15:50:28 -0700 Subject: [PATCH 24/28] One more shot at getting logs for tests. --- azure-pipelines.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 73b476a5e..9a7e942c1 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -33,6 +33,8 @@ variables: value: $(Build.SourcesDirectory)/artifacts/.trydotnet/packages - name: Codeql.Enabled value: true + - name: system.debug + value: true stages: - stage: build @@ -131,6 +133,7 @@ stages: condition: ne(variables['SkipTests'], 'true') env: RunIntegrationTests: $(RunIntegrationTests) + POCKETLOGGER_LOG_PATH: $(PocketLoggerLogPath) - pwsh: Get-ChildItem *.dmp -Recurse | Remove-Item displayName: Delete dump files From 5854c24085de7209771c6964842ac5092662a2af Mon Sep 17 00:00:00 2001 From: "Abhitej John Bandi (from Dev Box)" Date: Tue, 9 Apr 2024 23:25:07 -0700 Subject: [PATCH 25/28] Setting pocket logger globally instead --- azure-pipelines.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 9a7e942c1..d57156e4c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -27,15 +27,12 @@ variables: value: '8.0.101' - name: NodeJSVersion value: '16.13.0' - - name: PocketLoggerLogPath - value: $(Build.SourcesDirectory)/artifacts/logs/pocketlogger.log - name: TryDotNetPackagesPath value: $(Build.SourcesDirectory)/artifacts/.trydotnet/packages - name: Codeql.Enabled value: true - name: system.debug value: true - stages: - stage: build displayName: Build and Test @@ -59,6 +56,8 @@ stages: variables: - name: RunIntegrationTests value: true + - name: POCKETLOGGER_LOG_PATH + value: $(Build.SourcesDirectory)\artifacts\logs\pocketlogger.log # Enable signing for internal, non-PR builds - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: - group: DotNet-Blob-Feed @@ -124,7 +123,6 @@ stages: $(_TestArgs) displayName: Build env: - POCKETLOGGER_LOG_PATH: $(PocketLoggerLogPath) TRYDOTNET_PACKAGES_PATH: $(TryDotNetPackagesPath) - script: dotnet test -l trx --no-build --blame-hang-timeout 15m --blame-hang-dump-type full -c $(_BuildConfig) --results-directory $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) @@ -133,7 +131,6 @@ stages: condition: ne(variables['SkipTests'], 'true') env: RunIntegrationTests: $(RunIntegrationTests) - POCKETLOGGER_LOG_PATH: $(PocketLoggerLogPath) - pwsh: Get-ChildItem *.dmp -Recurse | Remove-Item displayName: Delete dump files @@ -160,6 +157,8 @@ stages: pool: vmImage: ubuntu-20.04 variables: + - name: POCKETLOGGER_LOG_PATH + value: $(Build.SourcesDirectory)\artifacts\logs\pocketlogger.log # Enable signing for internal, non-PR builds - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: - name: _SignType @@ -211,7 +210,6 @@ stages: $(_TestArgs) displayName: Build env: - POCKETLOGGER_LOG_PATH: $(PocketLoggerLogPath) TRYDOTNET_PACKAGES_PATH: $(TryDotNetPackagesPath) - script: dotnet test -l trx --no-build --blame-hang-timeout 15m --blame-hang-dump-type full -c $(_BuildConfig) --results-directory $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) From b0644a87d8b399bc8ddcbe17c524c2dc0db67e8f Mon Sep 17 00:00:00 2001 From: "Abhitej John Bandi (from Dev Box)" Date: Tue, 9 Apr 2024 23:49:07 -0700 Subject: [PATCH 26/28] Script to kill any remaining dotnet processes and also publish linux logs. --- azure-pipelines.yml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index d57156e4c..69ece36f4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -132,6 +132,10 @@ stages: env: RunIntegrationTests: $(RunIntegrationTests) + - script: taskkill /f /im dotnet.exe + displayName: Cleaning up any stale dotnet.exe processes so log collection is possible. + condition: ne(variables['SkipTests'], 'true') + - pwsh: Get-ChildItem *.dmp -Recurse | Remove-Item displayName: Delete dump files workingDirectory: $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) @@ -219,18 +223,30 @@ stages: env: RunIntegrationTests: $(RunIntegrationTests) + - pwsh: Stop-Process -Name dotnet -Force + displayName: Cleaning up any stale dotnet processes so log collection is possible. + condition: ne(variables['SkipTests'], 'true') + - pwsh: Get-ChildItem *.dmp -Recurse | Remove-Item displayName: Delete dump files workingDirectory: $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) condition: and(ne(variables['KeepDumps'], 'true'), ne(variables['SkipTests'], 'true')) + # - task: PublishBuildArtifacts@1 + # displayName: Publish Test results and Blame dumps + # inputs: + # pathToPublish: $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) + # artifactName: Linux_test_results_and_dumps + # artifactType: container + # condition: failed() + - task: PublishBuildArtifacts@1 - displayName: Publish Test results and Blame dumps + displayName: Publish Linux artifacts inputs: - pathToPublish: $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) - artifactName: Linux_test_results_and_dumps + pathToPublish: $(Build.SourcesDirectory)/artifacts/ + artifactName: Linux_artifacts artifactType: container - condition: failed() + condition: always() #---------------------------------------------------------------------------------------------------------------------# # Post Build # From 7cd5e525117be5694aa7cb86ce01cc541c0bace3 Mon Sep 17 00:00:00 2001 From: "Abhitej John Bandi (from Dev Box)" Date: Wed, 10 Apr 2024 12:12:26 -0700 Subject: [PATCH 27/28] Diagnostics for enabling logging for linux builds. --- azure-pipelines.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 69ece36f4..cd3356a48 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -162,7 +162,7 @@ stages: vmImage: ubuntu-20.04 variables: - name: POCKETLOGGER_LOG_PATH - value: $(Build.SourcesDirectory)\artifacts\logs\pocketlogger.log + value: $(Build.SourcesDirectory)/artifacts/logs/pocketlogger.log # Enable signing for internal, non-PR builds - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: - name: _SignType @@ -208,6 +208,8 @@ stages: Write-Host "##vso[task.setvariable variable=_TestArgs]$testArg" displayName: Promote variables + - bash: echo $(POCKETLOGGER_LOG_PATH) + - script: ./eng/cibuild.sh --configuration $(_BuildConfig) --prepareMachine From 788626a14b666836abc290f148fc27ed8ba55620 Mon Sep 17 00:00:00 2001 From: "Abhitej John Bandi (from Dev Box)" Date: Wed, 10 Apr 2024 12:15:51 -0700 Subject: [PATCH 28/28] Enabling diagnostic logging from test platform. --- azure-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index cd3356a48..af78449b4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -125,7 +125,7 @@ stages: env: TRYDOTNET_PACKAGES_PATH: $(TryDotNetPackagesPath) - - script: dotnet test -l trx --no-build --blame-hang-timeout 15m --blame-hang-dump-type full -c $(_BuildConfig) --results-directory $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) + - script: dotnet test -l trx --no-build --blame-hang-timeout 15m --blame-hang-dump-type full -c $(_BuildConfig) --results-directory $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) --diag $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig)/diag.txt displayName: Test / Blame workingDirectory: $(Build.SourcesDirectory) condition: ne(variables['SkipTests'], 'true') @@ -218,7 +218,7 @@ stages: env: TRYDOTNET_PACKAGES_PATH: $(TryDotNetPackagesPath) - - script: dotnet test -l trx --no-build --blame-hang-timeout 15m --blame-hang-dump-type full -c $(_BuildConfig) --results-directory $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) + - script: dotnet test -l trx --no-build --blame-hang-timeout 15m --blame-hang-dump-type full -c $(_BuildConfig) --results-directory $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig) --diag $(Build.SourcesDirectory)/artifacts/TestResults/$(_BuildConfig)/diag.txt displayName: Test / Blame workingDirectory: $(Build.SourcesDirectory) condition: ne(variables['SkipTests'], 'true')