< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.Workflows.Sequential.PhaseContext
Assembly: NexusLabs.Needlr.AgentFramework.Workflows
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework.Workflows/Sequential/PhaseContext.cs
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 49
Line coverage: 100%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_PhaseName()100%11100%
get_PhaseIndex()100%11100%
get_TotalPhases()100%11100%
get_Workspace()100%11100%
get_PipelineState()100%11100%
GetRequiredState()50%22100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework.Workflows/Sequential/PhaseContext.cs

#LineLine coverage
 1using NexusLabs.Needlr.AgentFramework.Workspace;
 2
 3namespace NexusLabs.Needlr.AgentFramework.Workflows.Sequential;
 4
 5/// <summary>
 6/// Provides typed access to pipeline state during phase lifecycle hooks
 7/// (<see cref="PipelinePhasePolicy.OnEnterAsync"/> and
 8/// <see cref="PipelinePhasePolicy.OnExitAsync"/>).
 9/// </summary>
 10/// <param name="PhaseName">Human-readable name of the current phase.</param>
 11/// <param name="PhaseIndex">Zero-based index of the current phase in the pipeline.</param>
 12/// <param name="TotalPhases">Total number of phases in the pipeline.</param>
 13/// <param name="Workspace">The shared workspace for the pipeline.</param>
 14/// <param name="PipelineState">
 15/// Optional shared state object passed to all phases. Use
 16/// <see cref="GetRequiredState{T}"/> for type-safe access.
 17/// </param>
 18/// <example>
 19/// <code>
 20/// var policy = new PipelinePhasePolicy
 21/// {
 22///     OnEnterAsync = (ctx, ct) =>
 23///     {
 24///         var state = ctx.GetRequiredState&lt;MyPipelineState&gt;();
 25///         Console.WriteLine($"Phase {ctx.PhaseIndex + 1}/{ctx.TotalPhases}: {ctx.PhaseName}");
 26///         return ValueTask.CompletedTask;
 27///     },
 28/// };
 29/// </code>
 30/// </example>
 4331public sealed record PhaseContext(
 132    string PhaseName,
 133    int PhaseIndex,
 134    int TotalPhases,
 135    IWorkspace Workspace,
 4436    object? PipelineState = null)
 37{
 38    /// <summary>
 39    /// Gets the typed pipeline state, or throws if no state was provided or the type doesn't match.
 40    /// </summary>
 41    /// <typeparam name="T">The expected pipeline state type.</typeparam>
 42    /// <returns>The pipeline state cast to <typeparamref name="T"/>.</returns>
 43    /// <exception cref="InvalidOperationException">
 44    /// Thrown when <see cref="PipelineState"/> is <see langword="null"/> or not of type <typeparamref name="T"/>.
 45    /// </exception>
 46    public T GetRequiredState<T>() where T : class =>
 147        PipelineState as T ?? throw new InvalidOperationException(
 148            $"Pipeline state is not available or is not of type {typeof(T).Name}.");
 49}