< 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@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
0%
Covered lines: 0
Uncovered lines: 23
Coverable lines: 23
Total lines: 70
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@10d476bee71c71ad215bb8ab59f219887b5b4a5e11/14/2025 - 12:29:34 Line coverage: 0% (0/23) Branch coverage: 0% (0/12) Total lines: 70 Tag: Kestrun/Kestrun@5e12b09a6838e68e704cd3dc975331b9e680a626 10/13/2025 - 16:52:37 Line coverage: 0% (0/22) Branch coverage: 0% (0/12) Total lines: 69 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e11/14/2025 - 12:29:34 Line coverage: 0% (0/23) Branch coverage: 0% (0/12) Total lines: 70 Tag: Kestrun/Kestrun@5e12b09a6838e68e704cd3dc975331b9e680a626

Metrics

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

File(s)

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

#LineLine coverage
 1using Kestrun.Languages;
 2using Microsoft.CodeAnalysis;
 3using Microsoft.CodeAnalysis.Scripting;
 4using RoslynCompilationErrorException = Microsoft.CodeAnalysis.Scripting.CompilationErrorException;
 5using SerilogLogger = Serilog.ILogger;
 6using Serilog.Events;
 7using Kestrun.Hosting;
 8
 9namespace Kestrun.Health;
 10/// <summary>
 11/// A health probe implemented via a C# script.
 12/// </summary>
 13/// <param name="host">The Kestrun host instance.</param>
 14/// <param name="name">The name of the probe.</param>
 15/// <param name="tags">The tags associated with the probe.</param>
 16/// <param name="runner">The script runner to execute the probe.</param>
 17/// <param name="locals">The local variables for the script.</param>
 18internal sealed class CSharpScriptProbe(
 19    KestrunHost host,
 20    string name,
 21    IEnumerable<string>? tags,
 22    ScriptRunner<ProbeResult> runner,
 023    IReadOnlyDictionary<string, object?>? locals) : Probe(name, tags), IProbe
 24{
 025    private SerilogLogger Logger => host.Logger;
 26    /// <summary>
 27    /// The script runner to execute the probe.
 28    /// </summary>
 029    private readonly ScriptRunner<ProbeResult> _runner = runner ?? throw new ArgumentNullException(nameof(runner));
 30    /// <summary>
 31    /// The local variables for the script.
 32    /// </summary>
 033    private readonly IReadOnlyDictionary<string, object?>? _locals = locals;
 34
 35    /// <inheritdoc/>
 36    public override async Task<ProbeResult> CheckAsync(CancellationToken ct = default)
 37    {
 038        var globals = _locals is { Count: > 0 }
 039            ? new CsGlobals(host.SharedState.Snapshot(), _locals)
 040            : new CsGlobals(host.SharedState.Snapshot());
 41        try
 42        {
 043            if (Logger.IsEnabled(LogEventLevel.Debug))
 44            {
 045                Logger.Debug("CSharpScriptProbe {Probe} executing", Name);
 46            }
 047            var result = await _runner(globals, ct).ConfigureAwait(false)
 048                ?? new ProbeResult(ProbeStatus.Unhealthy, "Script returned null result");
 049            if (Logger.IsEnabled(LogEventLevel.Debug))
 50            {
 051                Logger.Debug("CSharpScriptProbe {Probe} completed status={Status}", Name, result.Status);
 52            }
 053            return result;
 54        }
 055        catch (OperationCanceledException) when (ct.IsCancellationRequested)
 56        {
 057            throw;
 58        }
 059        catch (RoslynCompilationErrorException ex)
 60        {
 061            Logger.Error(ex, "C# health probe {Probe} failed to execute.", Name);
 062            return new ProbeResult(ProbeStatus.Unhealthy, string.Join("; ", ex.Diagnostics.Select(static d => d.GetMessa
 63        }
 064        catch (Exception ex)
 65        {
 066            Logger.Error(ex, "C# health probe {Probe} threw an exception.", Name);
 067            return new ProbeResult(ProbeStatus.Unhealthy, $"Exception: {ex.Message}");
 68        }
 069    }
 70}