< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.Diagnostics.ChatCompletionCollectorHolder
Assembly: NexusLabs.Needlr.AgentFramework
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/Diagnostics/ChatCompletionCollectorHolder.cs
Line coverage
100%
Covered lines: 6
Uncovered lines: 0
Coverable lines: 6
Total lines: 33
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
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_HasRealCollector()100%11100%
SetCollector(...)100%11100%
DrainCompletions()100%11100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/Diagnostics/ChatCompletionCollectorHolder.cs

#LineLine coverage
 1namespace NexusLabs.Needlr.AgentFramework.Diagnostics;
 2
 3/// <summary>
 4/// DI-registered singleton that holds the <see cref="IChatCompletionCollector"/> instance.
 5/// The diagnostics middleware sets the real collector during factory construction; consumers
 6/// resolve this to access it. Unlike a static holder, each DI container has its own instance,
 7/// making it testable and thread-safe across containers.
 8/// </summary>
 9[DoNotAutoRegister]
 10public sealed class ChatCompletionCollectorHolder : IChatCompletionCollector
 11{
 9112    private IChatCompletionCollector _inner = NullChatCompletionCollector.Instance;
 13
 14    /// <summary>
 15    /// Gets whether a real (non-null) collector has been installed via
 16    /// <see cref="SetCollector"/>. When <see langword="true"/>,
 17    /// <c>UsingDiagnostics()</c> has already wired a diagnostics middleware
 18    /// onto the chat client pipeline and external consumers should not install
 19    /// a duplicate.
 20    /// </summary>
 221    internal bool HasRealCollector => _inner is not NullChatCompletionCollector;
 22
 23    /// <summary>Sets the real collector. Called by <c>UsingDiagnostics()</c> during factory construction.</summary>
 24    internal void SetCollector(IChatCompletionCollector collector)
 25    {
 3626        ArgumentNullException.ThrowIfNull(collector);
 3627        _inner = collector;
 3628    }
 29
 30    /// <inheritdoc />
 31    public IReadOnlyList<ChatCompletionDiagnostics> DrainCompletions() =>
 2132        _inner.DrainCompletions();
 33}