< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Health.CSharpScriptProbe
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Health/CSharpScriptProbe.cs
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
0%
Covered lines: 0
Uncovered lines: 22
Coverable lines: 22
Total lines: 69
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 10/13/2025 - 16:52:37 Line coverage: 0% (0/22) Branch coverage: 0% (0/12) Total lines: 69 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e 10/13/2025 - 16:52:37 Line coverage: 0% (0/22) Branch coverage: 0% (0/12) Total lines: 69 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)0%620%
CheckAsync()0%110100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Health/CSharpScriptProbe.cs

#LineLine coverage
 1using Kestrun.Languages;
 2using Kestrun.SharedState;
 3using Microsoft.CodeAnalysis;
 4using Microsoft.CodeAnalysis.Scripting;
 5using RoslynCompilationErrorException = Microsoft.CodeAnalysis.Scripting.CompilationErrorException;
 6using SerilogLogger = Serilog.ILogger;
 7using Serilog.Events;
 8
 9namespace Kestrun.Health;
 10/// <summary>
 11/// A health probe implemented via a C# script.
 12/// </summary>
 13/// <param name="name">The name of the probe.</param>
 14/// <param name="tags">The tags associated with the probe.</param>
 15/// <param name="runner">The script runner to execute the probe.</param>
 16/// <param name="locals">The local variables for the script.</param>
 17/// <param name="logger">The logger to use for logging.</param>
 18internal sealed class CSharpScriptProbe(
 19    string name,
 20    IEnumerable<string>? tags,
 21    ScriptRunner<ProbeResult> runner,
 22    IReadOnlyDictionary<string, object?>? locals,
 023    SerilogLogger logger) : Probe(name, tags, logger), IProbe
 24{
 25    /// <summary>
 26    /// The script runner to execute the probe.
 27    /// </summary>
 028    private readonly ScriptRunner<ProbeResult> _runner = runner ?? throw new ArgumentNullException(nameof(runner));
 29    /// <summary>
 30    /// The local variables for the script.
 31    /// </summary>
 032    private readonly IReadOnlyDictionary<string, object?>? _locals = locals;
 33
 34    /// <inheritdoc/>
 35    public override async Task<ProbeResult> CheckAsync(CancellationToken ct = default)
 36    {
 037        var globals = _locals is { Count: > 0 }
 038            ? new CsGlobals(SharedStateStore.Snapshot(), _locals)
 039            : new CsGlobals(SharedStateStore.Snapshot());
 40        try
 41        {
 042            if (Logger.IsEnabled(LogEventLevel.Debug))
 43            {
 044                Logger.Debug("CSharpScriptProbe {Probe} executing", Name);
 45            }
 046            var result = await _runner(globals, ct).ConfigureAwait(false)
 047                ?? new ProbeResult(ProbeStatus.Unhealthy, "Script returned null result");
 048            if (Logger.IsEnabled(LogEventLevel.Debug))
 49            {
 050                Logger.Debug("CSharpScriptProbe {Probe} completed status={Status}", Name, result.Status);
 51            }
 052            return result;
 53        }
 054        catch (OperationCanceledException) when (ct.IsCancellationRequested)
 55        {
 056            throw;
 57        }
 058        catch (RoslynCompilationErrorException ex)
 59        {
 060            Logger.Error(ex, "C# health probe {Probe} failed to execute.", Name);
 061            return new ProbeResult(ProbeStatus.Unhealthy, string.Join("; ", ex.Diagnostics.Select(static d => d.GetMessa
 62        }
 063        catch (Exception ex)
 64        {
 065            Logger.Error(ex, "C# health probe {Probe} threw an exception.", Name);
 066            return new ProbeResult(ProbeStatus.Unhealthy, $"Exception: {ex.Message}");
 67        }
 068    }
 69}