< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Scheduling.RoslynJobFactory
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Scheduling/RoslynJobFactory.cs
Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
100%
Covered lines: 37
Uncovered lines: 0
Coverable lines: 37
Total lines: 81
Line coverage: 100%
Branch coverage
72%
Covered branches: 13
Total branches: 18
Branch coverage: 72.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 08/26/2025 - 14:53:17 Line coverage: 100% (33/33) Branch coverage: 72.2% (13/18) Total lines: 77 Tag: Kestrun/Kestrun@78d1e497d8ba989d121b57aa39aa3c6b22de743111/14/2025 - 12:29:34 Line coverage: 100% (37/37) Branch coverage: 72.2% (13/18) Total lines: 81 Tag: Kestrun/Kestrun@5e12b09a6838e68e704cd3dc975331b9e680a626 08/26/2025 - 14:53:17 Line coverage: 100% (33/33) Branch coverage: 72.2% (13/18) Total lines: 77 Tag: Kestrun/Kestrun@78d1e497d8ba989d121b57aa39aa3c6b22de743111/14/2025 - 12:29:34 Line coverage: 100% (37/37) Branch coverage: 72.2% (13/18) Total lines: 81 Tag: Kestrun/Kestrun@5e12b09a6838e68e704cd3dc975331b9e680a626

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Build(...)80%1010100%
Build(...)62.5%88100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Scheduling/RoslynJobFactory.cs

#LineLine coverage
 1using Kestrun.Hosting;
 2using Kestrun.Languages;
 3using Microsoft.CodeAnalysis.CSharp;
 4using Serilog.Events;
 5using System.Reflection;
 6
 7namespace Kestrun.Scheduling;
 8
 9internal static class RoslynJobFactory
 10{
 11    public static Func<CancellationToken, Task> Build(
 12        KestrunHost host,
 13        string code,
 14        string[]? extraImports,
 15        Assembly[]? extraRefs,
 16        IReadOnlyDictionary<string, object?>? locals,
 17        LanguageVersion languageVersion = LanguageVersion.CSharp12)
 18    {
 519        var log = host.Logger;
 520        if (log.IsEnabled(LogEventLevel.Debug))
 21        {
 522            log.Debug("Building C# job, code length={Length}, imports={ImportsCount}, refs={RefsCount}, lang={Lang}",
 523                code?.Length, extraImports?.Length ?? 0, extraRefs?.Length ?? 0, languageVersion);
 24        }
 25
 526        var script = CSharpDelegateBuilder.Compile(host: host, code: code, extraImports: extraImports, extraRefs: extraR
 427        var runner = script.CreateDelegate();   // returns ScriptRunner<object?>
 428        if (log.IsEnabled(LogEventLevel.Debug))
 29        {
 430            log.Debug("C# job runner created, type={Type}", runner.GetType());
 31        }
 32        /* 5️⃣  Returned delegate = *execute only* */
 433        return async ct =>
 434        {
 435            if (log.IsEnabled(LogEventLevel.Debug))
 436            {
 437                log.Debug("Executing C# job at {Now:O}", DateTimeOffset.UtcNow);
 438            }
 439
 440            var globals = locals is { Count: > 0 }
 441                ? new CsGlobals(globals: host.SharedState.Snapshot(), locals: locals)
 442                : new CsGlobals(globals: host.SharedState.Snapshot());
 443            _ = await runner(globals, ct).ConfigureAwait(false);
 844        };
 45    }
 46
 47
 48
 49    public static Func<CancellationToken, Task> Build(
 50        KestrunHost host,
 51       string code,
 52       string[]? extraImports,
 53       Assembly[]? extraRefs,
 54       IReadOnlyDictionary<string, object?>? locals,
 55       Microsoft.CodeAnalysis.VisualBasic.LanguageVersion languageVersion = Microsoft.CodeAnalysis.VisualBasic.LanguageV
 56    {
 157        var log = host.Logger;
 158        if (log.IsEnabled(LogEventLevel.Debug))
 59        {
 160            log.Debug("Building C# job, code length={Length}, imports={ImportsCount}, refs={RefsCount}, lang={Lang}",
 161                code?.Length, extraImports?.Length ?? 0, extraRefs?.Length ?? 0, languageVersion);
 62        }
 63
 164        var script = VBNetDelegateBuilder.Compile<object>(host: host, code: code,
 165            extraImports: extraImports, extraRefs: extraRefs,
 166            locals: locals, languageVersion: languageVersion);
 67
 168        return async ct =>
 169        {
 170            if (log.IsEnabled(LogEventLevel.Debug))
 171            {
 172                log.Debug("Executing C# job at {Now:O}", DateTimeOffset.UtcNow);
 173            }
 174
 175            var globals = new CsGlobals(globals: host.SharedState.Snapshot());
 176            _ = await script(globals).ConfigureAwait(false);
 277        };
 78    }
 79}
 80
 81