From 06575acb0db37345b443cbb02bdffb6f9c8e60fa Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 15 Oct 2026 14:56:27 +0000 Subject: [PATCH 1/6] feat: target net11.0 and read output with Process.ReadAllLines On net11.0, ProcessRunner reads stdout and stderr as one ordered stream of lines with Process.ReadAllLines/ReadAllLinesAsync instead of the OutputDataReceived/ErrorDataReceived events, and a process killed by a POSIX signal is reported by signal name in the ProcessException message. The net10.0 build keeps the event-based reader. The public API is the same on both targets. CI tests both frameworks. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01WVjNn9JyaJVwymS3qRBSz1 --- AGENTS.md | 5 +- README.md | 2 +- docs/getting-started.md | 2 +- src/Invex.Process/Invex.Process.csproj | 2 +- src/Invex.Process/ProcessRunner.cs | 148 ++++++++++++------ src/Invex.Process/_usings.cs | 1 + .../Invex.Process.Tests.csproj | 2 +- .../Invex.Process.Tests/ProcessRunnerTests.cs | 19 +++ 8 files changed, 124 insertions(+), 57 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index e5d6e48..8a7a30a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,8 +18,9 @@ and `toc.yml`. ## Build & language specifics -- **.NET 10 SDK** is required. Library and test projects target `net10.0`. -- C# `LangVersion` 14, `ImplicitUsings` and `Nullable` enabled, `TreatWarningsAsErrors` on. +- **.NET 11 SDK** (currently RC2) is required. Library and test projects target `net10.0` and `net11.0`; + `ProcessRunner` uses the .NET 11 `Process.ReadAllLines` APIs under `#if NET11_0_OR_GREATER`. +- C# `LangVersion` 15, `ImplicitUsings` and `Nullable` enabled, `TreatWarningsAsErrors` on. - Global usings live in each project's `_usings.cs` — add shared usings there, not per-file. - `GenerateDocumentationFile` is on and `CS1591` is **enforced** in `src/` — every public type and member needs XML doc comments. (`_atom` and the test project suppress `CS1591` locally; do diff --git a/README.md b/README.md index 836a4ac..babb1e7 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ full output capture, and fail-fast error handling. It wraps `System.Diagnostics. dotnet add package Invex.Process ``` -The package targets `net10.0`. It depends on +The package targets `net10.0` and `net11.0`. It depends on `Microsoft.Extensions.DependencyInjection.Abstractions` and `Microsoft.Extensions.Hosting.Abstractions`, and logs through `ILogger`, so configure logging on your host (it is by default with `Host.CreateApplicationBuilder`). diff --git a/docs/getting-started.md b/docs/getting-started.md index 1222824..b4827d2 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -9,7 +9,7 @@ if you are adding `Invex.Process` to a host, tool or build for the first time. dotnet add package Invex.Process ``` -The package targets `net10.0`. +The package targets `net10.0` and `net11.0`. On .NET 11 it reads output with the new `Process.ReadAllLines` APIs, so stdout and stderr lines are logged in the order the process wrote them, and a process killed by a signal is reported by signal name. ## Register the service diff --git a/src/Invex.Process/Invex.Process.csproj b/src/Invex.Process/Invex.Process.csproj index 574d735..aa87c76 100644 --- a/src/Invex.Process/Invex.Process.csproj +++ b/src/Invex.Process/Invex.Process.csproj @@ -1,7 +1,7 @@  - net10.0 + net10.0;net11.0 diff --git a/src/Invex.Process/ProcessRunner.cs b/src/Invex.Process/ProcessRunner.cs index 5e647a7..01f8f8a 100644 --- a/src/Invex.Process/ProcessRunner.cs +++ b/src/Invex.Process/ProcessRunner.cs @@ -91,10 +91,11 @@ public interface IProcessRunner /// /// /// -/// stdout and stderr are both redirected and read asynchronously via +/// stdout and stderr are both redirected and streamed to the logger in real time rather than +/// buffered. On .NET 11 and later they are read as one ordered stream of lines with +/// Process.ReadAllLines / Process.ReadAllLinesAsync; on .NET 10 they are read via /// / -/// so that output is streamed -/// to the logger in real time rather than buffered. +/// . /// /// /// Each received line is passed through or @@ -169,6 +170,17 @@ public ProcessRunResult Run(ProcessRunOptions options) var outputBuilder = new StringBuilder(); var errorBuilder = new StringBuilder(); +#if NET11_0_OR_GREATER + process.Start(); + + // stdout and stderr arrive as one stream of lines, in the order the process wrote them. + foreach (var line in process.ReadAllLines()) + OnLine(line.Content, line.StandardError); + + var exitStatus = process.WaitForExitStatus(); + var exitCode = exitStatus.ExitCode; + var signal = exitStatus.Signal; +#else process.OutputDataReceived += OnProcessOnOutputDataReceived; process.ErrorDataReceived += OnProcessOnErrorDataReceived; @@ -185,10 +197,14 @@ public ProcessRunResult Run(ProcessRunOptions options) process.ErrorDataReceived -= OnProcessOnErrorDataReceived; } + var exitCode = process.ExitCode; + PosixSignal? signal = null; +#endif + var output = outputBuilder.ToString(); var error = errorBuilder.ToString(); - var result = new ProcessRunResult(options, process.ExitCode, output, error); + var result = new ProcessRunResult(options, exitCode, output, error); if (result.ExitCode is 0) return result; @@ -206,39 +222,43 @@ public ProcessRunResult Run(ProcessRunOptions options) return result; } - throw new ProcessException(BuildProcessErrorMessage(options, result.ExitCode, error), result); + throw new ProcessException(BuildProcessErrorMessage(options, result.ExitCode, signal, error), result); - void OnProcessOnErrorDataReceived(object _, DataReceivedEventArgs e) + void OnLine(string? data, bool isError) { - if (e.Data is null) + if (data is null) return; - var text = options.TransformError is not null - ? options.TransformError(e.Data) - : e.Data; + var transform = isError + ? options.TransformError + : options.TransformOutput; + + var text = transform is not null + ? transform(data) + : data; if (text is null) return; - errorBuilder.AppendLine(text); - logger.Log(options.ErrorLogLevel, "{Error}", text); + if (isError) + { + errorBuilder.AppendLine(text); + logger.Log(options.ErrorLogLevel, "{Error}", text); + } + else + { + outputBuilder.AppendLine(text); + logger.Log(options.OutputLogLevel, "{Output}", text); + } } - void OnProcessOnOutputDataReceived(object _, DataReceivedEventArgs e) - { - if (e.Data is null) - return; - - var text = options.TransformOutput is not null - ? options.TransformOutput(e.Data) - : e.Data; - - if (text is null) - return; +#if !NET11_0_OR_GREATER + void OnProcessOnErrorDataReceived(object _, DataReceivedEventArgs e) => + OnLine(e.Data, true); - outputBuilder.AppendLine(text); - logger.Log(options.OutputLogLevel, "{Output}", text); - } + void OnProcessOnOutputDataReceived(object _, DataReceivedEventArgs e) => + OnLine(e.Data, false); +#endif } /// @@ -296,6 +316,17 @@ public async Task RunAsync( var outputBuilder = new StringBuilder(); var errorBuilder = new StringBuilder(); +#if NET11_0_OR_GREATER + process.Start(); + + // stdout and stderr arrive as one stream of lines, in the order the process wrote them. + await foreach (var line in process.ReadAllLinesAsync(cancellationToken)) + OnLine(line.Content, line.StandardError); + + var exitStatus = await process.WaitForExitStatusAsync(cancellationToken); + var exitCode = exitStatus.ExitCode; + var signal = exitStatus.Signal; +#else process.OutputDataReceived += OnProcessOnOutputDataReceived; process.ErrorDataReceived += OnProcessOnErrorDataReceived; @@ -312,10 +343,14 @@ public async Task RunAsync( process.ErrorDataReceived -= OnProcessOnErrorDataReceived; } + var exitCode = process.ExitCode; + PosixSignal? signal = null; +#endif + var output = outputBuilder.ToString(); var error = errorBuilder.ToString(); - var result = new ProcessRunResult(options, process.ExitCode, output, error); + var result = new ProcessRunResult(options, exitCode, output, error); if (result.ExitCode is 0) return result; @@ -333,39 +368,43 @@ public async Task RunAsync( return result; } - throw new ProcessException(BuildProcessErrorMessage(options, result.ExitCode, error), result); + throw new ProcessException(BuildProcessErrorMessage(options, result.ExitCode, signal, error), result); - void OnProcessOnErrorDataReceived(object _, DataReceivedEventArgs e) + void OnLine(string? data, bool isError) { - if (e.Data is null) + if (data is null) return; - var text = options.TransformError is not null - ? options.TransformError(e.Data) - : e.Data; + var transform = isError + ? options.TransformError + : options.TransformOutput; + + var text = transform is not null + ? transform(data) + : data; if (text is null) return; - errorBuilder.AppendLine(text); - logger.Log(options.ErrorLogLevel, "{Error}", text); + if (isError) + { + errorBuilder.AppendLine(text); + logger.Log(options.ErrorLogLevel, "{Error}", text); + } + else + { + outputBuilder.AppendLine(text); + logger.Log(options.OutputLogLevel, "{Output}", text); + } } - void OnProcessOnOutputDataReceived(object _, DataReceivedEventArgs e) - { - if (e.Data is null) - return; - - var text = options.TransformOutput is not null - ? options.TransformOutput(e.Data) - : e.Data; +#if !NET11_0_OR_GREATER + void OnProcessOnErrorDataReceived(object _, DataReceivedEventArgs e) => + OnLine(e.Data, true); - if (text is null) - return; - - outputBuilder.AppendLine(text); - logger.Log(options.OutputLogLevel, "{Output}", text); - } + void OnProcessOnOutputDataReceived(object _, DataReceivedEventArgs e) => + OnLine(e.Data, false); +#endif } /// @@ -380,10 +419,17 @@ void OnProcessOnOutputDataReceived(object _, DataReceivedEventArgs e) private static string FormatEnvironmentVariableNames(ProcessRunOptions options) => string.Join(", ", options.EnvironmentVariables.Keys); - private static string BuildProcessErrorMessage(ProcessRunOptions options, int exitCode, string error) + private static string BuildProcessErrorMessage( + ProcessRunOptions options, + int exitCode, + PosixSignal? signal, + string error) { var errorMessage = new StringBuilder(); - errorMessage.AppendLine($"Process '{options.Name}' failed with exit code {exitCode}"); + + errorMessage.AppendLine(signal is { } terminatingSignal + ? $"Process '{options.Name}' was terminated by signal {terminatingSignal} (exit code {exitCode})" + : $"Process '{options.Name}' failed with exit code {exitCode}"); errorMessage.AppendLine($" Command: {options.Name} {options.Args}"); if (options.WorkingDirectory is { Length: > 0 }) diff --git a/src/Invex.Process/_usings.cs b/src/Invex.Process/_usings.cs index d6b71b3..a9fc0e4 100644 --- a/src/Invex.Process/_usings.cs +++ b/src/Invex.Process/_usings.cs @@ -1,6 +1,7 @@ global using System.Diagnostics; global using System.Diagnostics.CodeAnalysis; global using System.Runtime.CompilerServices; +global using System.Runtime.InteropServices; global using System.Text; global using JetBrains.Annotations; global using Microsoft.Extensions.DependencyInjection; diff --git a/tests/Invex.Process.Tests/Invex.Process.Tests.csproj b/tests/Invex.Process.Tests/Invex.Process.Tests.csproj index 2e13ec0..b1479b1 100644 --- a/tests/Invex.Process.Tests/Invex.Process.Tests.csproj +++ b/tests/Invex.Process.Tests/Invex.Process.Tests.csproj @@ -1,7 +1,7 @@ - net10.0 + net10.0;net11.0 false $(NoWarn);CS1591 diff --git a/tests/Invex.Process.Tests/ProcessRunnerTests.cs b/tests/Invex.Process.Tests/ProcessRunnerTests.cs index 41cbf9e..26d8ac1 100644 --- a/tests/Invex.Process.Tests/ProcessRunnerTests.cs +++ b/tests/Invex.Process.Tests/ProcessRunnerTests.cs @@ -531,6 +531,25 @@ public async Task RunAsync_WhenCancelledMidRun_ThrowsOperationCanceledException( await Should.ThrowAsync(() => runner.RunAsync(LongRunningOptions(), cts.Token)); } +#if NET11_0_OR_GREATER + [Test] + public async Task RunAsync_WhenProcessIsKilledBySignal_ErrorMessageNamesTheSignal() + { + if (OperatingSystem.IsWindows()) + Assert.Ignore("POSIX signals are not available on Windows."); + + // Arrange + var runner = CreateRunner(); + var options = new ProcessRunOptions("sh", "-c \"kill -TERM $$\""); + + // Act + var exception = await Should.ThrowAsync(() => runner.RunAsync(options)); + + // Assert + exception.Message.ShouldContain("terminated by signal SIGTERM"); + } + +#endif /// /// A minimal that records every formatted message. /// From c24eb56c056a128ff88097ad4f0137ce1dc52f55 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 15 Oct 2026 14:56:27 +0000 Subject: [PATCH 2/6] chore: build with the .NET 11 RC2 SDK and C# 15 Pins SDK 11.0.100-rc.2.26504.105 in global.json (prereleases allowed, latest-feature roll-forward), sets LangVersion 15, and adds a CI step that installs the RC2 SDK next to the .NET 10 SDK, which still provides the runtime for net10.0 tests. Target frameworks are unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01WVjNn9JyaJVwymS3qRBSz1 --- .github/workflows/Build.yml | 37 ++++++++++++++++++- .github/workflows/Cleanup Prereleases.yml | 5 +++ .../Dependabot Enable auto-merge.yml | 5 +++ .github/workflows/Validate.yml | 27 +++++++++++++- Directory.Build.props | 2 +- _atom/IBuild.cs | 3 ++ global.json | 2 +- 7 files changed, 77 insertions(+), 4 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 4196c28..7a9dadc 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -30,6 +30,11 @@ jobs: with: dotnet-version: 10.0.x + - name: Setup .NET 11.0.100-rc.2.26504.105 + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 11.0.100-rc.2.26504.105 + - name: SetupBuildInfo id: SetupBuildInfo run: dotnet run --project _atom/_atom.csproj -- SetupBuildInfo --skip --headless @@ -48,6 +53,11 @@ jobs: with: dotnet-version: 10.0.x + - name: Setup .NET 11.0.100-rc.2.26504.105 + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 11.0.100-rc.2.26504.105 + - name: PackProjects id: PackProjects run: dotnet run --project _atom/_atom.csproj -- PackProjects --skip --headless @@ -62,7 +72,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - test-framework: [ net10.0 ] + test-framework: [ net10.0, net11.0 ] steps: - name: Checkout @@ -75,6 +85,11 @@ jobs: with: dotnet-version: 10.0.x + - name: Setup .NET 11.0.100-rc.2.26504.105 + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 11.0.100-rc.2.26504.105 + - name: TestProjects id: TestProjects run: dotnet run --project _atom/_atom.csproj -- TestProjects --skip --headless @@ -103,6 +118,11 @@ jobs: with: dotnet-version: 10.0.x + - name: Setup .NET 11.0.100-rc.2.26504.105 + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 11.0.100-rc.2.26504.105 + - name: Retrieve Invex.Process uses: actions/download-artifact@v8 with: @@ -134,6 +154,11 @@ jobs: with: dotnet-version: 10.0.x + - name: Setup .NET 11.0.100-rc.2.26504.105 + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 11.0.100-rc.2.26504.105 + - name: Retrieve Invex.Process uses: actions/download-artifact@v8 with: @@ -162,6 +187,11 @@ jobs: with: dotnet-version: 10.0.x + - name: Setup .NET 11.0.100-rc.2.26504.105 + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 11.0.100-rc.2.26504.105 + - name: BuildDocs id: BuildDocs run: dotnet run --project _atom/_atom.csproj -- BuildDocs --skip --headless @@ -190,6 +220,11 @@ jobs: with: dotnet-version: 10.0.x + - name: Setup .NET 11.0.100-rc.2.26504.105 + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 11.0.100-rc.2.26504.105 + - name: Retrieve GeneratedDocs uses: actions/download-artifact@v8 with: diff --git a/.github/workflows/Cleanup Prereleases.yml b/.github/workflows/Cleanup Prereleases.yml index 5c0899d..b664adb 100644 --- a/.github/workflows/Cleanup Prereleases.yml +++ b/.github/workflows/Cleanup Prereleases.yml @@ -26,6 +26,11 @@ jobs: with: dotnet-version: 10.0.x + - name: Setup .NET 11.0.100-rc.2.26504.105 + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 11.0.100-rc.2.26504.105 + - name: UnlistOldPrereleases id: UnlistOldPrereleases run: dotnet run --project _atom/_atom.csproj -- UnlistOldPrereleases --skip --headless diff --git a/.github/workflows/Dependabot Enable auto-merge.yml b/.github/workflows/Dependabot Enable auto-merge.yml index f9563cf..c46bb37 100644 --- a/.github/workflows/Dependabot Enable auto-merge.yml +++ b/.github/workflows/Dependabot Enable auto-merge.yml @@ -23,6 +23,11 @@ jobs: with: dotnet-version: 10.0.x + - name: Setup .NET 11.0.100-rc.2.26504.105 + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 11.0.100-rc.2.26504.105 + - name: ApproveDependabotPr id: ApproveDependabotPr run: dotnet run --project _atom/_atom.csproj -- ApproveDependabotPr --skip --headless diff --git a/.github/workflows/Validate.yml b/.github/workflows/Validate.yml index bb5809d..83fa9ec 100644 --- a/.github/workflows/Validate.yml +++ b/.github/workflows/Validate.yml @@ -28,6 +28,11 @@ jobs: with: dotnet-version: 10.0.x + - name: Setup .NET 11.0.100-rc.2.26504.105 + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 11.0.100-rc.2.26504.105 + - name: SetupBuildInfo id: SetupBuildInfo run: dotnet run --project _atom/_atom.csproj -- SetupBuildInfo --skip --headless @@ -46,6 +51,11 @@ jobs: with: dotnet-version: 10.0.x + - name: Setup .NET 11.0.100-rc.2.26504.105 + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 11.0.100-rc.2.26504.105 + - name: PackProjects id: PackProjects run: dotnet run --project _atom/_atom.csproj -- PackProjects --skip --headless @@ -54,7 +64,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - test-framework: [ net10.0 ] + test-framework: [ net10.0, net11.0 ] steps: - name: Checkout @@ -67,6 +77,11 @@ jobs: with: dotnet-version: 10.0.x + - name: Setup .NET 11.0.100-rc.2.26504.105 + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 11.0.100-rc.2.26504.105 + - name: TestProjects id: TestProjects run: dotnet run --project _atom/_atom.csproj -- TestProjects --skip --headless @@ -95,6 +110,11 @@ jobs: with: dotnet-version: 10.0.x + - name: Setup .NET 11.0.100-rc.2.26504.105 + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 11.0.100-rc.2.26504.105 + - name: CheckPrForBreakingChanges id: CheckPrForBreakingChanges run: dotnet run --project _atom/_atom.csproj -- CheckPrForBreakingChanges --skip --headless @@ -117,6 +137,11 @@ jobs: with: dotnet-version: 10.0.x + - name: Setup .NET 11.0.100-rc.2.26504.105 + uses: actions/setup-dotnet@v5 + with: + dotnet-version: 11.0.100-rc.2.26504.105 + - name: WaitForCopilotReview id: WaitForCopilotReview run: dotnet run --project _atom/_atom.csproj -- WaitForCopilotReview --skip --headless diff --git a/Directory.Build.props b/Directory.Build.props index fc6cf48..d123f92 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -11,7 +11,7 @@ true true - 14 + 15 enable enable true diff --git a/_atom/IBuild.cs b/_atom/IBuild.cs index c8c83bc..31167bc 100644 --- a/_atom/IBuild.cs +++ b/_atom/IBuild.cs @@ -40,6 +40,7 @@ internal interface IBuild : IWorkflowBuildDefinition, static readonly string[] TestFrameworkNames = [ WorkflowLabels.Dotnet.Framework.Net_10_0, + "net11.0", ]; IEnumerable ICheckPrForBreakingChanges.BreakingChangeFilesToCheck => @@ -53,6 +54,8 @@ internal interface IBuild : IWorkflowBuildDefinition, BuildOptions.GitVersion.ProvideBuildId, BuildOptions.GitVersion.ProvideBuildVersion, BuildOptions.Steps.SetupDotnet.Dotnet100X(), + // .NET 11 SDK (RC2 until GA). The .NET 10 step above still provides the runtime for net10.0 tests. + new SetupDotnetStep("11.0.100-rc.2.26504.105"), ]; Target PackProjects => diff --git a/global.json b/global.json index 2170bab..8a991ef 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "10.0.403", + "version": "11.0.100", "rollForward": "latestMajor", "allowPrerelease": false } From 215d21947fae6d61081344c995821057c3e745a0 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 00:07:17 +0000 Subject: [PATCH 3/6] chore: move to the .NET 11 GA SDK Pins SDK 11.0.100 in global.json (stable only, latest-major roll-forward, matching main) and installs 11.0.x in CI instead of the release candidate. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WVjNn9JyaJVwymS3qRBSz1 --- .github/workflows/Build.yml | 28 +++++++++---------- .github/workflows/Cleanup Prereleases.yml | 4 +-- .../Dependabot Enable auto-merge.yml | 4 +-- .github/workflows/Validate.yml | 20 ++++++------- AGENTS.md | 2 +- _atom/IBuild.cs | 4 +-- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 7a9dadc..ec4a668 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -30,10 +30,10 @@ jobs: with: dotnet-version: 10.0.x - - name: Setup .NET 11.0.100-rc.2.26504.105 + - name: Setup .NET 11.0.x uses: actions/setup-dotnet@v5 with: - dotnet-version: 11.0.100-rc.2.26504.105 + dotnet-version: 11.0.x - name: SetupBuildInfo id: SetupBuildInfo @@ -53,10 +53,10 @@ jobs: with: dotnet-version: 10.0.x - - name: Setup .NET 11.0.100-rc.2.26504.105 + - name: Setup .NET 11.0.x uses: actions/setup-dotnet@v5 with: - dotnet-version: 11.0.100-rc.2.26504.105 + dotnet-version: 11.0.x - name: PackProjects id: PackProjects @@ -85,10 +85,10 @@ jobs: with: dotnet-version: 10.0.x - - name: Setup .NET 11.0.100-rc.2.26504.105 + - name: Setup .NET 11.0.x uses: actions/setup-dotnet@v5 with: - dotnet-version: 11.0.100-rc.2.26504.105 + dotnet-version: 11.0.x - name: TestProjects id: TestProjects @@ -118,10 +118,10 @@ jobs: with: dotnet-version: 10.0.x - - name: Setup .NET 11.0.100-rc.2.26504.105 + - name: Setup .NET 11.0.x uses: actions/setup-dotnet@v5 with: - dotnet-version: 11.0.100-rc.2.26504.105 + dotnet-version: 11.0.x - name: Retrieve Invex.Process uses: actions/download-artifact@v8 @@ -154,10 +154,10 @@ jobs: with: dotnet-version: 10.0.x - - name: Setup .NET 11.0.100-rc.2.26504.105 + - name: Setup .NET 11.0.x uses: actions/setup-dotnet@v5 with: - dotnet-version: 11.0.100-rc.2.26504.105 + dotnet-version: 11.0.x - name: Retrieve Invex.Process uses: actions/download-artifact@v8 @@ -187,10 +187,10 @@ jobs: with: dotnet-version: 10.0.x - - name: Setup .NET 11.0.100-rc.2.26504.105 + - name: Setup .NET 11.0.x uses: actions/setup-dotnet@v5 with: - dotnet-version: 11.0.100-rc.2.26504.105 + dotnet-version: 11.0.x - name: BuildDocs id: BuildDocs @@ -220,10 +220,10 @@ jobs: with: dotnet-version: 10.0.x - - name: Setup .NET 11.0.100-rc.2.26504.105 + - name: Setup .NET 11.0.x uses: actions/setup-dotnet@v5 with: - dotnet-version: 11.0.100-rc.2.26504.105 + dotnet-version: 11.0.x - name: Retrieve GeneratedDocs uses: actions/download-artifact@v8 diff --git a/.github/workflows/Cleanup Prereleases.yml b/.github/workflows/Cleanup Prereleases.yml index b664adb..ed3b071 100644 --- a/.github/workflows/Cleanup Prereleases.yml +++ b/.github/workflows/Cleanup Prereleases.yml @@ -26,10 +26,10 @@ jobs: with: dotnet-version: 10.0.x - - name: Setup .NET 11.0.100-rc.2.26504.105 + - name: Setup .NET 11.0.x uses: actions/setup-dotnet@v5 with: - dotnet-version: 11.0.100-rc.2.26504.105 + dotnet-version: 11.0.x - name: UnlistOldPrereleases id: UnlistOldPrereleases diff --git a/.github/workflows/Dependabot Enable auto-merge.yml b/.github/workflows/Dependabot Enable auto-merge.yml index c46bb37..0b43808 100644 --- a/.github/workflows/Dependabot Enable auto-merge.yml +++ b/.github/workflows/Dependabot Enable auto-merge.yml @@ -23,10 +23,10 @@ jobs: with: dotnet-version: 10.0.x - - name: Setup .NET 11.0.100-rc.2.26504.105 + - name: Setup .NET 11.0.x uses: actions/setup-dotnet@v5 with: - dotnet-version: 11.0.100-rc.2.26504.105 + dotnet-version: 11.0.x - name: ApproveDependabotPr id: ApproveDependabotPr diff --git a/.github/workflows/Validate.yml b/.github/workflows/Validate.yml index 83fa9ec..ffa9f27 100644 --- a/.github/workflows/Validate.yml +++ b/.github/workflows/Validate.yml @@ -28,10 +28,10 @@ jobs: with: dotnet-version: 10.0.x - - name: Setup .NET 11.0.100-rc.2.26504.105 + - name: Setup .NET 11.0.x uses: actions/setup-dotnet@v5 with: - dotnet-version: 11.0.100-rc.2.26504.105 + dotnet-version: 11.0.x - name: SetupBuildInfo id: SetupBuildInfo @@ -51,10 +51,10 @@ jobs: with: dotnet-version: 10.0.x - - name: Setup .NET 11.0.100-rc.2.26504.105 + - name: Setup .NET 11.0.x uses: actions/setup-dotnet@v5 with: - dotnet-version: 11.0.100-rc.2.26504.105 + dotnet-version: 11.0.x - name: PackProjects id: PackProjects @@ -77,10 +77,10 @@ jobs: with: dotnet-version: 10.0.x - - name: Setup .NET 11.0.100-rc.2.26504.105 + - name: Setup .NET 11.0.x uses: actions/setup-dotnet@v5 with: - dotnet-version: 11.0.100-rc.2.26504.105 + dotnet-version: 11.0.x - name: TestProjects id: TestProjects @@ -110,10 +110,10 @@ jobs: with: dotnet-version: 10.0.x - - name: Setup .NET 11.0.100-rc.2.26504.105 + - name: Setup .NET 11.0.x uses: actions/setup-dotnet@v5 with: - dotnet-version: 11.0.100-rc.2.26504.105 + dotnet-version: 11.0.x - name: CheckPrForBreakingChanges id: CheckPrForBreakingChanges @@ -137,10 +137,10 @@ jobs: with: dotnet-version: 10.0.x - - name: Setup .NET 11.0.100-rc.2.26504.105 + - name: Setup .NET 11.0.x uses: actions/setup-dotnet@v5 with: - dotnet-version: 11.0.100-rc.2.26504.105 + dotnet-version: 11.0.x - name: WaitForCopilotReview id: WaitForCopilotReview diff --git a/AGENTS.md b/AGENTS.md index 8a7a30a..e74fd63 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,7 +18,7 @@ and `toc.yml`. ## Build & language specifics -- **.NET 11 SDK** (currently RC2) is required. Library and test projects target `net10.0` and `net11.0`; +- **.NET 11 SDK** is required. Library and test projects target `net10.0` and `net11.0`; `ProcessRunner` uses the .NET 11 `Process.ReadAllLines` APIs under `#if NET11_0_OR_GREATER`. - C# `LangVersion` 15, `ImplicitUsings` and `Nullable` enabled, `TreatWarningsAsErrors` on. - Global usings live in each project's `_usings.cs` — add shared usings there, not per-file. diff --git a/_atom/IBuild.cs b/_atom/IBuild.cs index 31167bc..cd18aa9 100644 --- a/_atom/IBuild.cs +++ b/_atom/IBuild.cs @@ -54,8 +54,8 @@ internal interface IBuild : IWorkflowBuildDefinition, BuildOptions.GitVersion.ProvideBuildId, BuildOptions.GitVersion.ProvideBuildVersion, BuildOptions.Steps.SetupDotnet.Dotnet100X(), - // .NET 11 SDK (RC2 until GA). The .NET 10 step above still provides the runtime for net10.0 tests. - new SetupDotnetStep("11.0.100-rc.2.26504.105"), + // .NET 11 SDK. The .NET 10 step above still provides the runtime for net10.0 tests. + new SetupDotnetStep("11.0.x"), ]; Target PackProjects => From 15657f3783dc7d390998bc0f2ec8df2dc6e4940e Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 00:17:48 +0000 Subject: [PATCH 4/6] fix: roll forward within .NET 11 so setup-dotnet installs the 11 SDK actions/setup-dotnet ignores the version when rollForward is latestMajor and installs the LTS SDK (10.0.x), which can't satisfy 11.0.100. That broke GitHub's NuGet dependency submission scan. latestMinor makes it install 11.x. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WVjNn9JyaJVwymS3qRBSz1 --- global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global.json b/global.json index 8a991ef..85ae47e 100644 --- a/global.json +++ b/global.json @@ -1,7 +1,7 @@ { "sdk": { "version": "11.0.100", - "rollForward": "latestMajor", + "rollForward": "latestMinor", "allowPrerelease": false } } \ No newline at end of file From 7b19c94de2755beb41288918fe83a763fff7d254 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 00:20:03 +0000 Subject: [PATCH 5/6] test: cover mixed streams and sync signal handling in ProcessRunner Adds Run and RunAsync tests that write to both streams with per-stream transforms, a suppressed line on each, and an unterminated final line, and checks the captured text and the log level each line is logged at. Covers the signal path through Run as well as RunAsync. Also corrects the docs: on .NET 11 lines arrive in the order they become available, not strictly write order. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WVjNn9JyaJVwymS3qRBSz1 --- docs/getting-started.md | 2 +- src/Invex.Process/ProcessRunner.cs | 10 +- .../Invex.Process.Tests/ProcessRunnerTests.cs | 108 ++++++++++++++++-- 3 files changed, 108 insertions(+), 12 deletions(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index b4827d2..3cd2c4b 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -9,7 +9,7 @@ if you are adding `Invex.Process` to a host, tool or build for the first time. dotnet add package Invex.Process ``` -The package targets `net10.0` and `net11.0`. On .NET 11 it reads output with the new `Process.ReadAllLines` APIs, so stdout and stderr lines are logged in the order the process wrote them, and a process killed by a signal is reported by signal name. +The package targets `net10.0` and `net11.0`. On .NET 11 it reads output with the new `Process.ReadAllLines` APIs, so stdout and stderr lines are logged as one stream in the order they become available (stderr first when both are ready, so not always the order the process wrote them), and a process killed by a signal is reported by signal name. ## Register the service diff --git a/src/Invex.Process/ProcessRunner.cs b/src/Invex.Process/ProcessRunner.cs index 01f8f8a..7c1e541 100644 --- a/src/Invex.Process/ProcessRunner.cs +++ b/src/Invex.Process/ProcessRunner.cs @@ -92,8 +92,10 @@ public interface IProcessRunner /// /// /// stdout and stderr are both redirected and streamed to the logger in real time rather than -/// buffered. On .NET 11 and later they are read as one ordered stream of lines with -/// Process.ReadAllLines / Process.ReadAllLinesAsync; on .NET 10 they are read via +/// buffered. On .NET 11 and later they are read as one interleaved stream of lines with +/// Process.ReadAllLines / Process.ReadAllLinesAsync, in the order lines become available +/// (stderr first when both are ready), which is not always the order the process wrote them; on .NET 10 +/// they are read via /// / /// . /// @@ -173,7 +175,7 @@ public ProcessRunResult Run(ProcessRunOptions options) #if NET11_0_OR_GREATER process.Start(); - // stdout and stderr arrive as one stream of lines, in the order the process wrote them. + // stdout and stderr arrive as one stream of lines, in the order they become available (not strictly write order). foreach (var line in process.ReadAllLines()) OnLine(line.Content, line.StandardError); @@ -319,7 +321,7 @@ public async Task RunAsync( #if NET11_0_OR_GREATER process.Start(); - // stdout and stderr arrive as one stream of lines, in the order the process wrote them. + // stdout and stderr arrive as one stream of lines, in the order they become available (not strictly write order). await foreach (var line in process.ReadAllLinesAsync(cancellationToken)) OnLine(line.Content, line.StandardError); diff --git a/tests/Invex.Process.Tests/ProcessRunnerTests.cs b/tests/Invex.Process.Tests/ProcessRunnerTests.cs index 26d8ac1..d84c0dc 100644 --- a/tests/Invex.Process.Tests/ProcessRunnerTests.cs +++ b/tests/Invex.Process.Tests/ProcessRunnerTests.cs @@ -44,6 +44,37 @@ private static ProcessRunOptions PrintCwdOptions() => ? new ProcessRunOptions("cmd", "/c cd") : new("pwd", string.Empty); + // Writes to both streams, ending with an stdout line that has no trailing newline. + private static ProcessRunOptions MixedStreamsOptions() => + new("sh", "-c \"echo out1; echo err1 >&2; echo out2; echo drop-err >&2; printf out3\"") + { + TransformOutput = line => line == "out2" + ? null + : $"[O]{line}", + TransformError = line => line.StartsWith("drop", StringComparison.Ordinal) + ? null + : $"[E]{line}", + OutputLogLevel = LogLevel.Information, + ErrorLogLevel = LogLevel.Warning, + }; + + private static void ShouldHaveMixedStreamsResult(ProcessRunResult result, RecordingLogger logger) + { + result.Output.ShouldBe($"[O]out1{Environment.NewLine}[O]out3{Environment.NewLine}"); + result.Error.ShouldBe($"[E]err1{Environment.NewLine}"); + + var entries = logger.Entries; + entries.Where(e => e.Level == LogLevel.Information && e.Message.StartsWith("[O]", StringComparison.Ordinal)) + .Select(e => e.Message) + .ShouldBe(["[O]out1", "[O]out3"], ignoreOrder: true); + entries.Where(e => e.Level == LogLevel.Warning && e.Message.StartsWith("[E]", StringComparison.Ordinal)) + .Select(e => e.Message) + .ShouldBe(["[E]err1"]); + // The invocation log line names the command, so skip it when checking that suppressed lines never reach the log. + entries.Where(e => !e.Message.Contains("echo", StringComparison.Ordinal)) + .ShouldNotContain(e => e.Message.Contains("out2") || e.Message.Contains("drop-err")); + } + private static ProcessRunOptions LongRunningOptions() => // ping sends one packet per second and works reliably with redirected stdout; // unlike `timeout`, it does not exit early when used in a non-interactive context. @@ -531,7 +562,61 @@ public async Task RunAsync_WhenCancelledMidRun_ThrowsOperationCanceledException( await Should.ThrowAsync(() => runner.RunAsync(LongRunningOptions(), cts.Token)); } + [Test] + public void Run_WithMixedStreams_CapturesAndLogsEachStreamSeparately() + { + if (OperatingSystem.IsWindows()) + Assert.Ignore("Uses sh to write to both streams."); + + // Arrange + var logger = new RecordingLogger(); + var runner = new ProcessRunner(logger); + + // Act + var result = runner.Run(MixedStreamsOptions()); + + // Assert + ShouldHaveMixedStreamsResult(result, logger); + } + + [Test] + public async Task RunAsync_WithMixedStreams_CapturesAndLogsEachStreamSeparately() + { + if (OperatingSystem.IsWindows()) + Assert.Ignore("Uses sh to write to both streams."); + + // Arrange + var logger = new RecordingLogger(); + var runner = new ProcessRunner(logger); + + // Act + var result = await runner.RunAsync(MixedStreamsOptions()); + + // Assert + ShouldHaveMixedStreamsResult(result, logger); + } + #if NET11_0_OR_GREATER + private static ProcessRunOptions KilledBySigtermOptions() => + new("sh", "-c \"kill -TERM $$\""); + + [Test] + public void Run_WhenProcessIsKilledBySignal_ErrorMessageNamesTheSignal() + { + if (OperatingSystem.IsWindows()) + Assert.Ignore("POSIX signals are not available on Windows."); + + // Arrange + var runner = CreateRunner(); + + // Act + var exception = Should.Throw(() => runner.Run(KilledBySigtermOptions())); + + // Assert + exception.Message.ShouldContain("terminated by signal SIGTERM"); + exception.Result.ExitCode.ShouldNotBe(0); + } + [Test] public async Task RunAsync_WhenProcessIsKilledBySignal_ErrorMessageNamesTheSignal() { @@ -540,13 +625,13 @@ public async Task RunAsync_WhenProcessIsKilledBySignal_ErrorMessageNamesTheSigna // Arrange var runner = CreateRunner(); - var options = new ProcessRunOptions("sh", "-c \"kill -TERM $$\""); // Act - var exception = await Should.ThrowAsync(() => runner.RunAsync(options)); + var exception = await Should.ThrowAsync(() => runner.RunAsync(KilledBySigtermOptions())); // Assert exception.Message.ShouldContain("terminated by signal SIGTERM"); + exception.Result.ExitCode.ShouldNotBe(0); } #endif @@ -555,14 +640,23 @@ public async Task RunAsync_WhenProcessIsKilledBySignal_ErrorMessageNamesTheSigna /// private sealed class RecordingLogger : ILogger { - private readonly List _messages = []; + private readonly List<(LogLevel Level, string Message)> _entries = []; public IReadOnlyList Messages { get { - lock (_messages) - return [.. _messages]; + lock (_entries) + return [.. _entries.Select(e => e.Message)]; + } + } + + public IReadOnlyList<(LogLevel Level, string Message)> Entries + { + get + { + lock (_entries) + return [.. _entries]; } } @@ -580,8 +674,8 @@ public void Log( Exception? exception, Func formatter) { - lock (_messages) - _messages.Add(formatter(state, exception)); + lock (_entries) + _entries.Add((logLevel, formatter(state, exception))); } } } From 273414bbfa8dcbb404c0696c7654832f95d30b60 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Nov 2026 00:24:21 +0000 Subject: [PATCH 6/6] docs: list the .NET 10 runtime as a build prerequisite The net10.0 tests and the Atom build project need the .NET 10 runtime, which the .NET 11 SDK doesn't include. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WVjNn9JyaJVwymS3qRBSz1 --- AGENTS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index e74fd63..9b6efc5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,7 +18,7 @@ and `toc.yml`. ## Build & language specifics -- **.NET 11 SDK** is required. Library and test projects target `net10.0` and `net11.0`; +- **.NET 11 SDK** is required, plus the .NET 10 runtime (or SDK) to run the `net10.0` tests and build project. Library and test projects target `net10.0` and `net11.0`; `ProcessRunner` uses the .NET 11 `Process.ReadAllLines` APIs under `#if NET11_0_OR_GREATER`. - C# `LangVersion` 15, `ImplicitUsings` and `Nullable` enabled, `TreatWarningsAsErrors` on. - Global usings live in each project's `_usings.cs` — add shared usings there, not per-file.