< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Tasks.KestrunTask
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Tasks/KestrunTask.cs
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
90%
Covered lines: 18
Uncovered lines: 2
Coverable lines: 20
Total lines: 94
Line coverage: 90%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 10/15/2025 - 01:01:18 Line coverage: 90% (18/20) Branch coverage: 50% (3/6) Total lines: 94 Tag: Kestrun/Kestrun@7c4ce528870211ad6c2d2398c31ec13097fc5840 10/15/2025 - 01:01:18 Line coverage: 90% (18/20) Branch coverage: 50% (3/6) Total lines: 94 Tag: Kestrun/Kestrun@7c4ce528870211ad6c2d2398c31ec13097fc5840

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Id()100%11100%
get_Name()100%11100%
get_Description()100%11100%
get_ScriptCode()100%11100%
get_Work()100%11100%
get_TokenSource()100%11100%
get_State()100%11100%
get_Fault()100%210%
get_Output()100%11100%
get_StartedAtUtc()100%11100%
get_CompletedAtUtc()100%11100%
get_Runner()100%11100%
ToKrTask()75%44100%
get_Finished()0%620%
get_Parent()100%11100%
get_Children()100%11100%
get_Progress()100%11100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Tasks/KestrunTask.cs

#LineLine coverage
 1using Kestrun.Hosting.Options;
 2
 3namespace Kestrun.Tasks;
 4
 5/// <summary>
 6/// Represents a single-shot task execution with its current state and telemetry.
 7/// </summary>
 8/// <param name="Id">Unique task identifier.</param>
 9/// <param name="ScriptCode">The scripting language and code configuration for this task.</param>
 10/// <param name="tokenSource">Cancellation token source for this task.</param>
 1511public sealed class KestrunTask(string Id, LanguageOptions ScriptCode, CancellationTokenSource tokenSource)
 12{
 13    /// <summary>
 14    /// Unique task identifier.
 15    /// </summary>
 2316    public string Id { get; init; } = Id;
 17
 18    /// <summary>
 19    /// Optional human-friendly name of the task.
 20    /// </summary>
 3821    public string Name { get; set; } = "Task " + Id;
 22
 23    /// <summary>
 24    /// Optional description of the task.
 25    /// </summary>
 3826    public string Description { get; set; } = string.Empty;
 27    /// <summary>
 28    /// The scripting language and code configuration for this task.
 29    /// </summary>
 1530    public LanguageOptions ScriptCode { get; init; } = ScriptCode;
 31    /// <summary>
 32    /// Compiled work delegate producing a result.
 33    /// </summary>
 2734    public required Func<CancellationToken, Task<object?>> Work { get; init; }
 35    /// <summary>
 36    /// Cancellation token source for this task.
 37    /// </summary>
 5538    public CancellationTokenSource TokenSource { get; } = tokenSource;
 39
 40    /// <summary>
 41    /// Current state of the task.
 42    /// </summary>
 14243    public TaskState State { get; internal set; } = TaskState.NotStarted;
 44    /// <summary>
 45    /// Fault exception if the task failed.
 46    /// </summary>
 047    public Exception? Fault { get; internal set; }
 48    /// <summary>
 49    /// Output produced by the task (last expression for C#/VB, pipeline for PowerShell).
 50    /// </summary>
 1451    public object? Output { get; internal set; }
 52
 53    /// <summary>
 54    /// UTC timestamp when execution started.
 55    /// </summary>
 1956    public DateTimeOffset? StartedAtUtc { get; internal set; }
 57    /// <summary>
 58    /// UTC timestamp when execution ended.
 59    /// </summary>
 1960    public DateTimeOffset? CompletedAtUtc { get; internal set; }
 61
 62    /// <summary>
 63    /// The background task executing this work.
 64    /// </summary>
 2665    public Task? Runner { get; internal set; }
 66
 67    /// <summary>
 68    /// Creates a basic task info record for this task.
 69    /// </summary>
 70    /// <returns> A basic task info record. </returns>
 771    public KrTask ToKrTask() => new(Id, Name, Description, State, StartedAtUtc, CompletedAtUtc, Progress,
 772        Parent?.Id ?? string.Empty,
 773        [.. Children.Select(c => c.Id)]);
 74
 75    /// <summary>
 76    /// Indicates whether the task has reached a terminal state.
 77    /// </summary>
 078    public bool Finished => State is TaskState.Completed or TaskState.Failed or TaskState.Stopped;
 79
 80    /// <summary>
 81    /// For hierarchical tasks; null for root tasks.
 82    /// </summary>
 1383    public KestrunTask Parent { get; set; } = null!; // For hierarchical tasks; null for root tasks
 84
 85    /// <summary>
 86    /// Child tasks spawned by this task.
 87    /// </summary>
 3688    public List<KestrunTask> Children { get; } = [];
 89
 90    /// <summary>
 91    /// Progress state of the task, if supported by the script.
 92    /// </summary>
 6193    public ProgressiveKestrunTaskState Progress { get; init; } = new();
 94}