Path: redb-route/tests/redb.Route.Tests.Llm/TestHelpers/ToolInvocationSpy.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Llm/TestHelpers/ToolInvocationSpy.cs
----
using System.Collections.Concurrent;
using redb.Route.Llm.Engine.Observability;
namespace redb.Route.Tests.Llm.TestHelpers;
///
/// Captures every call so a live test
/// can assert which tools the model actually invoked, what input JSON it sent and what
/// the tool returned. Other observer events are accepted as no-ops.
///
public sealed class ToolInvocationSpy : IAgentObserver
{
private readonly ConcurrentBag _invocations = new();
/// Snapshot of every captured invocation in registration order.
public IReadOnlyCollection Invocations => _invocations.ToArray();
/// Convenience filter — returns invocations whose tool name matches.
public IReadOnlyCollection ForTool(string name) =>
_invocations.Where(i => i.Tool.Name == name).ToArray();
///
public Task OnRunStartedAsync(AgentRunContext context, CancellationToken ct = default) => Task.CompletedTask;
///
public Task OnIterationCompletedAsync(AgentIterationContext context, CancellationToken ct = default) => Task.CompletedTask;
///
public Task OnToolInvokedAsync(AgentToolInvocationContext context, CancellationToken ct = default)
{
_invocations.Add(context);
return Task.CompletedTask;
}
///
public Task OnRunCompletedAsync(AgentRunCompletedContext context, CancellationToken ct = default) => Task.CompletedTask;
}