Path: redb-route/tests/redb.Route.Tests.Llm/TestHelpers/FakeProvider.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/FakeProvider.cs
----
namespace redb.Route.Tests.Llm.TestHelpers;
///
/// Scriptable provider for engine/producer tests. Returns a queued
/// per call. When the queue empties, defaults to a final
/// EndTurn echoing "(no script)".
///
public sealed class FakeProvider : ILlmProvider
{
private readonly Queue _scripted = new();
public string ProviderId => "fake";
public string ModelId { get; init; } = "fake-model";
public List CapturedRequests { get; } = new();
///
/// The messages of each call as the provider saw them. holds the
/// request objects themselves, and the engine keeps appending to the transcript a request points
/// at, so reading those after a run shows the grown list rather than what was sent.
///
public List> SentMessages { get; } = new();
public int CallCount { get; private set; }
public Func? OnCall { get; set; }
public Exception? ThrowOnCall { get; set; }
public FakeProvider Enqueue(LlmResponse response)
{
_scripted.Enqueue(response);
return this;
}
public FakeProvider EnqueueText(string text, LlmStopReason stop = LlmStopReason.EndTurn,
int tokensIn = 1, int tokensOut = 1)
{
return Enqueue(new LlmResponse
{
Content = [new LlmTextBlock(text)],
StopReason = stop,
Usage = new LlmUsage(tokensIn, tokensOut)
});
}
public FakeProvider EnqueueToolUse(string toolName, string inputJson, string toolUseId = "tu_1",
int tokensIn = 1, int tokensOut = 1)
{
return Enqueue(new LlmResponse
{
Content = [new LlmToolUseBlock(toolUseId, toolName, inputJson)],
StopReason = LlmStopReason.ToolUse,
Usage = new LlmUsage(tokensIn, tokensOut)
});
}
public async Task CompleteAsync(LlmRequest request, CancellationToken ct = default)
{
CallCount++;
CapturedRequests.Add(request);
SentMessages.Add(request.Messages.ToList());
if (OnCall is not null) await OnCall(request, ct).ConfigureAwait(false);
if (ThrowOnCall is not null) throw ThrowOnCall;
if (_scripted.TryDequeue(out var scripted)) return scripted;
return new LlmResponse
{
Content = [new LlmTextBlock("(no script)")],
StopReason = LlmStopReason.EndTurn,
Usage = LlmUsage.Empty
};
}
}