Research conducted on modern AI coding assistants (Cursor, GitHub Copilot, Cline,
Aider, Windsurf, Replit Agent) to understand architecture patterns, context management,
code editing workflows, and tool use protocols.
Key Decision: Pivoted from building full CLI (40-50h) to validation-driven MCP-first
approach (10-15h). Build 5 core CODEX MCP tools that work with ANY coding assistant,
validate adoption over 2-4 weeks, then decide on full CLI if demand proven.
Files:
- research/ai-systems/modern-coding-assistants-architecture.md (comprehensive research)
- research/ai-systems/codex-coding-assistant-implementation-plan.md (original CLI plan, preserved)
- research/ai-systems/codex-mcp-tools-implementation-plan.md (approved MCP-first plan)
- ideas/registry.json (updated with approved MCP tools proposal)
Architech Validation: APPROVED with pivot to MCP-first approach
Human Decision: Approved (pragmatic validation-driven development)
Next: Begin Phase 1 implementation (10-15 hours, 5 core MCP tools)
🤖 Generated with CODEX Research System
Co-Authored-By: The Archivist <archivist@codex.svrnty.io>
Co-Authored-By: The Architech <architech@codex.svrnty.io>
Co-Authored-By: Mathias Beaulieu-Duncan <mat@svrnty.io>
219 lines
6.5 KiB
C#
219 lines
6.5 KiB
C#
using Xunit;
|
|
using OpenHarbor.MCP.Gateway.Infrastructure.Routing;
|
|
using OpenHarbor.MCP.Gateway.Core.Models;
|
|
|
|
namespace OpenHarbor.MCP.Gateway.Infrastructure.Tests.Routing;
|
|
|
|
/// <summary>
|
|
/// Unit tests for ToolBasedStrategy following TDD approach.
|
|
/// Tests tool-based routing with pattern matching.
|
|
/// </summary>
|
|
public class ToolBasedStrategyTests
|
|
{
|
|
[Fact]
|
|
public async Task SelectServerAsync_WithExactMatch_ReturnsMatchedServer()
|
|
{
|
|
// Arrange
|
|
var toolMapping = new Dictionary<string, string>
|
|
{
|
|
{ "search_documents", "server-1" },
|
|
{ "get_document", "server-2" }
|
|
};
|
|
var strategy = new ToolBasedStrategy(toolMapping);
|
|
|
|
var servers = new List<ServerInfo>
|
|
{
|
|
new ServerInfo { Id = "server-1", IsHealthy = true },
|
|
new ServerInfo { Id = "server-2", IsHealthy = true }
|
|
};
|
|
|
|
var context = new RoutingContext { ToolName = "search_documents" };
|
|
|
|
// Act
|
|
var selected = await strategy.SelectServerAsync(servers, context);
|
|
|
|
// Assert
|
|
Assert.NotNull(selected);
|
|
Assert.Equal("server-1", selected.Id);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SelectServerAsync_WithWildcardPattern_MatchesCorrectly()
|
|
{
|
|
// Arrange
|
|
var toolMapping = new Dictionary<string, string>
|
|
{
|
|
{ "search_*", "server-1" },
|
|
{ "get_*", "server-2" }
|
|
};
|
|
var strategy = new ToolBasedStrategy(toolMapping);
|
|
|
|
var servers = new List<ServerInfo>
|
|
{
|
|
new ServerInfo { Id = "server-1", IsHealthy = true },
|
|
new ServerInfo { Id = "server-2", IsHealthy = true }
|
|
};
|
|
|
|
var context1 = new RoutingContext { ToolName = "search_documents" };
|
|
var context2 = new RoutingContext { ToolName = "get_user" };
|
|
|
|
// Act
|
|
var selected1 = await strategy.SelectServerAsync(servers, context1);
|
|
var selected2 = await strategy.SelectServerAsync(servers, context2);
|
|
|
|
// Assert
|
|
Assert.Equal("server-1", selected1!.Id);
|
|
Assert.Equal("server-2", selected2!.Id);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SelectServerAsync_WithNoMatch_FallsBackToRoundRobin()
|
|
{
|
|
// Arrange
|
|
var toolMapping = new Dictionary<string, string>
|
|
{
|
|
{ "search_*", "server-1" }
|
|
};
|
|
var strategy = new ToolBasedStrategy(toolMapping);
|
|
|
|
var servers = new List<ServerInfo>
|
|
{
|
|
new ServerInfo { Id = "server-1", IsHealthy = true },
|
|
new ServerInfo { Id = "server-2", IsHealthy = true }
|
|
};
|
|
|
|
var context = new RoutingContext { ToolName = "unknown_tool" };
|
|
|
|
// Act
|
|
var selected = await strategy.SelectServerAsync(servers, context);
|
|
|
|
// Assert - should fall back to round-robin (first healthy server)
|
|
Assert.NotNull(selected);
|
|
Assert.True(selected.Id == "server-1" || selected.Id == "server-2");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SelectServerAsync_WhenMappedServerUnhealthy_SelectsNextHealthy()
|
|
{
|
|
// Arrange
|
|
var toolMapping = new Dictionary<string, string>
|
|
{
|
|
{ "search_documents", "server-1" }
|
|
};
|
|
var strategy = new ToolBasedStrategy(toolMapping);
|
|
|
|
var servers = new List<ServerInfo>
|
|
{
|
|
new ServerInfo { Id = "server-1", IsHealthy = false },
|
|
new ServerInfo { Id = "server-2", IsHealthy = true }
|
|
};
|
|
|
|
var context = new RoutingContext { ToolName = "search_documents" };
|
|
|
|
// Act
|
|
var selected = await strategy.SelectServerAsync(servers, context);
|
|
|
|
// Assert - should select next healthy server
|
|
Assert.NotNull(selected);
|
|
Assert.Equal("server-2", selected.Id);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SelectServerAsync_WithMultiplePatterns_UsesFirstMatch()
|
|
{
|
|
// Arrange
|
|
var toolMapping = new Dictionary<string, string>
|
|
{
|
|
{ "search_*", "server-1" },
|
|
{ "*_documents", "server-2" }
|
|
};
|
|
var strategy = new ToolBasedStrategy(toolMapping);
|
|
|
|
var servers = new List<ServerInfo>
|
|
{
|
|
new ServerInfo { Id = "server-1", IsHealthy = true },
|
|
new ServerInfo { Id = "server-2", IsHealthy = true }
|
|
};
|
|
|
|
var context = new RoutingContext { ToolName = "search_documents" };
|
|
|
|
// Act
|
|
var selected = await strategy.SelectServerAsync(servers, context);
|
|
|
|
// Assert - should use first matching pattern
|
|
Assert.NotNull(selected);
|
|
Assert.Equal("server-1", selected.Id);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SelectServerAsync_WithNullToolName_FallsBackToRoundRobin()
|
|
{
|
|
// Arrange
|
|
var toolMapping = new Dictionary<string, string>
|
|
{
|
|
{ "search_*", "server-1" }
|
|
};
|
|
var strategy = new ToolBasedStrategy(toolMapping);
|
|
|
|
var servers = new List<ServerInfo>
|
|
{
|
|
new ServerInfo { Id = "server-1", IsHealthy = true },
|
|
new ServerInfo { Id = "server-2", IsHealthy = true }
|
|
};
|
|
|
|
var context = new RoutingContext { ToolName = null };
|
|
|
|
// Act
|
|
var selected = await strategy.SelectServerAsync(servers, context);
|
|
|
|
// Assert
|
|
Assert.NotNull(selected);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SelectServerAsync_WithEmptyMapping_UsesRoundRobin()
|
|
{
|
|
// Arrange
|
|
var toolMapping = new Dictionary<string, string>();
|
|
var strategy = new ToolBasedStrategy(toolMapping);
|
|
|
|
var servers = new List<ServerInfo>
|
|
{
|
|
new ServerInfo { Id = "server-1", IsHealthy = true },
|
|
new ServerInfo { Id = "server-2", IsHealthy = true }
|
|
};
|
|
|
|
var context = new RoutingContext { ToolName = "any_tool" };
|
|
|
|
// Act
|
|
var selected = await strategy.SelectServerAsync(servers, context);
|
|
|
|
// Assert - should use round-robin
|
|
Assert.NotNull(selected);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SelectServerAsync_WithNoHealthyServers_ReturnsNull()
|
|
{
|
|
// Arrange
|
|
var toolMapping = new Dictionary<string, string>
|
|
{
|
|
{ "search_*", "server-1" }
|
|
};
|
|
var strategy = new ToolBasedStrategy(toolMapping);
|
|
|
|
var servers = new List<ServerInfo>
|
|
{
|
|
new ServerInfo { Id = "server-1", IsHealthy = false }
|
|
};
|
|
|
|
var context = new RoutingContext { ToolName = "search_documents" };
|
|
|
|
// Act
|
|
var selected = await strategy.SelectServerAsync(servers, context);
|
|
|
|
// Assert
|
|
Assert.Null(selected);
|
|
}
|
|
}
|