< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Utilities.PowerShellInvokeExtensions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Utilities/PowerShellInvokeExtensions.cs
Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
65%
Covered lines: 13
Uncovered lines: 7
Coverable lines: 20
Total lines: 51
Line coverage: 65%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 12/18/2025 - 21:41:58 Line coverage: 65% (13/20) Branch coverage: 0% (0/2) Total lines: 51 Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff 12/18/2025 - 21:41:58 Line coverage: 65% (13/20) Branch coverage: 0% (0/2) Total lines: 51 Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
InvokeWithRequestAbortAsync()100%1185.71%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Utilities/PowerShellInvokeExtensions.cs

#LineLine coverage
 1using System.Management.Automation;
 2namespace Kestrun.Utilities;
 3
 4/// <summary>
 5/// Utilities for invoking PowerShell with cancellation support.
 6/// </summary>
 7internal static class PowerShellInvokeExtensions
 8{
 9    /// <summary>
 10    /// Invokes a PowerShell instance asynchronously, supporting cancellation via a CancellationToken.
 11    /// </summary>
 12    /// <param name="ps">The PowerShell instance to invoke.</param>
 13    /// <param name="requestAborted">The CancellationToken to observe for cancellation.</param>
 14    /// <param name="onAbortLog">Optional action to log when an abort is requested.</param>
 15    /// <returns>A task representing the asynchronous operation, with the PowerShell results.</returns>
 16    public static async Task<PSDataCollection<PSObject>> InvokeWithRequestAbortAsync(
 17        this PowerShell ps,
 18        CancellationToken requestAborted,
 19        Action? onAbortLog = null)
 20    {
 1121        requestAborted.ThrowIfCancellationRequested();
 22
 23        // If the request aborts, stop the PS pipeline.
 1124        using var reg = requestAborted.Register(() =>
 1125        {
 1126            try
 1127            {
 028                onAbortLog?.Invoke();
 1129
 1130                // Stop is the canonical cancellation mechanism for hosted PS.
 1131                // Safe to call even if invocation hasn't started yet.
 032                ps.Stop();
 033            }
 034            catch
 1135            {
 1136                // Intentionally swallow: abort paths must be "best effort"
 037            }
 1138        });
 39
 40        try
 41        {
 42            // Your current style
 1143            return await ps.InvokeAsync().ConfigureAwait(false);
 44        }
 045        catch (PipelineStoppedException) when (requestAborted.IsCancellationRequested)
 46        {
 47            // Treat as cancellation, not an error.
 048            throw new OperationCanceledException(requestAborted);
 49        }
 1150    }
 51}

Methods/Properties

InvokeWithRequestAbortAsync()