Path: redb-route/tests/redb.Route.Tests.Llm.Mcp/SerenaFixture.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.Mcp/SerenaFixture.cs ---- using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging.Abstractions; using redb.Route.Llm.Mcp.Protocol; namespace redb.Route.Tests.Llm.Mcp; /// /// Spawns a single Serena MCP server once per xUnit collection and exposes the /// connected client + tool catalogue. Tests that don't need their own private /// process reuse this fixture to keep startup cost (uvx download / venv) at one /// hit per run. /// public sealed class SerenaFixture : IAsyncLifetime { /// Live MCP client connected to Serena. Null when fixture skipped initialization. public IMcpClient? Client { get; private set; } /// Tool catalogue returned by the initial tools/list. public IReadOnlyList Tools { get; private set; } = []; /// Resolved launch command (for diagnostic display + RestartTests). internal SerenaLaunch? Launch { get; private set; } /// public async Task InitializeAsync() { var launch = SerenaConfig.Launch; if (launch is null) return; Launch = launch; var transport = McpTransport.Stdio(launch.Command, launch.Arguments); var client = new redb.Route.Llm.Mcp.Transport.StdioMcpClient("serena", transport, NullLogger.Instance); using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(2)); try { await client.InitializeAsync(cts.Token).ConfigureAwait(false); Tools = await client.ListToolsAsync(cts.Token).ConfigureAwait(false); Client = client; } catch { await client.DisposeAsync().ConfigureAwait(false); throw; } } /// public async Task DisposeAsync() { if (Client is not null) await Client.DisposeAsync().ConfigureAwait(false); } } /// Collection definition that shares a single across tests. [CollectionDefinition("SerenaSerial", DisableParallelization = true)] public sealed class SerenaCollection : ICollectionFixture { }