< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.Progress.ProgressReporter
Assembly: NexusLabs.Needlr.AgentFramework
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/Progress/ProgressReporter.cs
Line coverage
93%
Covered lines: 46
Uncovered lines: 3
Coverable lines: 49
Total lines: 89
Line coverage: 93.8%
Branch coverage
91%
Covered branches: 11
Total branches: 12
Branch coverage: 91.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%22100%
get_WorkflowId()100%11100%
get_AgentId()100%11100%
get_Depth()100%11100%
NextSequence()100%11100%
Report(...)90%101085.71%
CreateChild(...)100%11100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/Progress/ProgressReporter.cs

#LineLine coverage
 1namespace NexusLabs.Needlr.AgentFramework.Progress;
 2
 3/// <summary>
 4/// Default <see cref="IProgressReporter"/> that fans out events to all registered sinks.
 5/// Sink exceptions are surfaced via an <see cref="IProgressReporterErrorHandler"/> instead
 6/// of being silently swallowed.
 7/// </summary>
 8[DoNotAutoRegister]
 9internal sealed class ProgressReporter : IProgressReporter
 10{
 11    private readonly IReadOnlyList<IProgressSink> _sinks;
 12    private readonly IProgressSequence _sequence;
 13    private readonly IProgressReporterErrorHandler _errorHandler;
 14    private readonly string? _parentAgentId;
 15
 3416    internal ProgressReporter(
 3417        string workflowId,
 3418        IReadOnlyList<IProgressSink> sinks,
 3419        IProgressSequence sequence,
 3420        IProgressReporterErrorHandler? errorHandler = null,
 3421        string? agentId = null,
 3422        string? parentAgentId = null,
 3423        int depth = 0)
 24    {
 3425        WorkflowId = workflowId;
 3426        _sinks = sinks;
 3427        _sequence = sequence;
 3428        _errorHandler = errorHandler ?? new NullProgressReporterErrorHandler();
 3429        AgentId = agentId;
 3430        _parentAgentId = parentAgentId;
 3431        Depth = depth;
 3432    }
 33
 34    /// <inheritdoc />
 4135    public string WorkflowId { get; }
 36
 37    /// <inheritdoc />
 3238    public string? AgentId { get; }
 39
 40    /// <inheritdoc />
 3441    public int Depth { get; }
 42
 43    /// <inheritdoc />
 2644    public long NextSequence() => _sequence.Next();
 45
 46    /// <inheritdoc />
 47    public void Report(IProgressEvent progressEvent)
 48    {
 3349        if (_sinks.Count == 0) return;
 50
 12851        for (int i = 0; i < _sinks.Count; i++)
 52        {
 3353            var sink = _sinks[i];
 54            try
 55            {
 3356                var task = sink.OnEventAsync(progressEvent, CancellationToken.None);
 3357                if (!task.IsCompletedSuccessfully)
 58                {
 159                    var handler = _errorHandler;
 160                    var capturedSink = sink;
 161                    var capturedEvent = progressEvent;
 162                    task.AsTask().ContinueWith(
 163                        t =>
 164                        {
 165                            var ex = t.Exception?.GetBaseException();
 166                            if (ex is not null)
 167                                handler.OnSinkException(capturedSink, capturedEvent, ex);
 168                        },
 169                        TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously);
 70                }
 3371            }
 072            catch (Exception ex)
 73            {
 074                _errorHandler.OnSinkException(sink, progressEvent, ex);
 075            }
 76        }
 3177    }
 78
 79    /// <inheritdoc />
 80    public IProgressReporter CreateChild(string agentId) =>
 781        new ProgressReporter(
 782            WorkflowId,
 783            _sinks,
 784            _sequence,
 785            _errorHandler,
 786            agentId: agentId,
 787            parentAgentId: AgentId,
 788            depth: Depth + 1);
 89}