< 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@5f1d2b981c9d7292c11fd448428c6ab6c811c5de
Line coverage
90%
Covered lines: 19
Uncovered lines: 2
Coverable lines: 21
Total lines: 99
Line coverage: 90.4%
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 11/19/2025 - 17:40:50 Line coverage: 90% (18/20) Branch coverage: 50% (3/6) Total lines: 94 Tag: Kestrun/Kestrun@fcf33342333cef0516fe0d0912a86709874fd02603/27/2026 - 14:18:40 Line coverage: 90.4% (19/21) Branch coverage: 50% (3/6) Total lines: 99 Tag: Kestrun/Kestrun@63388ea9aed376ffbb41cd2727be2fb7646f6402 11/19/2025 - 17:40:50 Line coverage: 90% (18/20) Branch coverage: 50% (3/6) Total lines: 94 Tag: Kestrun/Kestrun@fcf33342333cef0516fe0d0912a86709874fd02603/27/2026 - 14:18:40 Line coverage: 90.4% (19/21) Branch coverage: 50% (3/6) Total lines: 99 Tag: Kestrun/Kestrun@63388ea9aed376ffbb41cd2727be2fb7646f6402

Coverage delta

Coverage delta 1 -1

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_Token()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>
 1611public sealed class KestrunTask(string Id, LanguageOptions ScriptCode, CancellationTokenSource tokenSource)
 12{
 13    /// <summary>
 14    /// Unique task identifier.
 15    /// </summary>
 2416    public string Id { get; init; } = Id;
 17
 18    /// <summary>
 19    /// Optional human-friendly name of the task.
 20    /// </summary>
 4021    public string Name { get; set; } = "Task " + Id;
 22
 23    /// <summary>
 24    /// Optional description of the task.
 25    /// </summary>
 4026    public string Description { get; set; } = string.Empty;
 27    /// <summary>
 28    /// The scripting language and code configuration for this task.
 29    /// </summary>
 1630    public LanguageOptions ScriptCode { get; init; } = ScriptCode;
 31    /// <summary>
 32    /// Compiled work delegate producing a result.
 33    /// </summary>
 2834    public required Func<CancellationToken, Task<object?>> Work { get; init; }
 35    /// <summary>
 36    /// Cancellation token source for this task.
 37    /// </summary>
 2238    public CancellationTokenSource TokenSource { get; } = tokenSource;
 39
 40    /// <summary>
 41    /// Stable cancellation token captured at task creation time.
 42    /// </summary>
 4043    internal CancellationToken Token { get; } = tokenSource.Token;
 44
 45    /// <summary>
 46    /// Current state of the task.
 47    /// </summary>
 26948    public TaskState State { get; internal set; } = TaskState.NotStarted;
 49    /// <summary>
 50    /// Fault exception if the task failed.
 51    /// </summary>
 052    public Exception? Fault { get; internal set; }
 53    /// <summary>
 54    /// Output produced by the task (last expression for C#/VB, pipeline for PowerShell).
 55    /// </summary>
 1556    public object? Output { get; internal set; }
 57
 58    /// <summary>
 59    /// UTC timestamp when execution started.
 60    /// </summary>
 1961    public DateTimeOffset? StartedAtUtc { get; internal set; }
 62    /// <summary>
 63    /// UTC timestamp when execution ended.
 64    /// </summary>
 1965    public DateTimeOffset? CompletedAtUtc { get; internal set; }
 66
 67    /// <summary>
 68    /// The background task executing this work.
 69    /// </summary>
 2970    public Task? Runner { get; internal set; }
 71
 72    /// <summary>
 73    /// Creates a basic task info record for this task.
 74    /// </summary>
 75    /// <returns> A basic task info record. </returns>
 776    public KrTask ToKrTask() => new(Id, Name, Description, State, StartedAtUtc, CompletedAtUtc, Progress,
 777        Parent?.Id ?? string.Empty,
 778        [.. Children.Select(c => c.Id)]);
 79
 80    /// <summary>
 81    /// Indicates whether the task has reached a terminal state.
 82    /// </summary>
 083    public bool Finished => State is TaskState.Completed or TaskState.Failed or TaskState.Stopped;
 84
 85    /// <summary>
 86    /// For hierarchical tasks; null for root tasks.
 87    /// </summary>
 1388    public KestrunTask Parent { get; set; } = null!; // For hierarchical tasks; null for root tasks
 89
 90    /// <summary>
 91    /// Child tasks spawned by this task.
 92    /// </summary>
 3793    public List<KestrunTask> Children { get; } = [];
 94
 95    /// <summary>
 96    /// Progress state of the task, if supported by the script.
 97    /// </summary>
 6398    public ProgressiveKestrunTaskState Progress { get; init; } = new();
 99}