From 2a95ba6ff560ff1c35273a911d756e116ed32715 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 09:12:49 +0000 Subject: [PATCH] fix(agentic): normalise remote host inputs Co-Authored-By: Virgil --- pkg/agentic/remote.go | 2 ++ pkg/agentic/remote_client.go | 1 + pkg/agentic/remote_client_test.go | 11 +++++++++++ pkg/agentic/remote_test.go | 11 +++++++++++ 4 files changed, 25 insertions(+) diff --git a/pkg/agentic/remote.go b/pkg/agentic/remote.go index 3608e77..55d1feb 100644 --- a/pkg/agentic/remote.go +++ b/pkg/agentic/remote.go @@ -124,6 +124,7 @@ func (s *PrepSubsystem) dispatchRemote(ctx context.Context, _ *mcp.CallToolReque // addr := resolveHost("charon") // "10.69.69.165:9101" func resolveHost(host string) string { + host = core.Trim(host) aliases := map[string]string{ "charon": "10.69.69.165:9101", "cladius": "127.0.0.1:9101", @@ -143,6 +144,7 @@ func resolveHost(host string) string { // token := remoteToken("charon") func remoteToken(host string) string { + host = core.Trim(host) envKey := core.Sprintf("AGENT_TOKEN_%s", core.Upper(host)) if token := core.Env(envKey); token != "" { return token diff --git a/pkg/agentic/remote_client.go b/pkg/agentic/remote_client.go index cfc4882..805f3c3 100644 --- a/pkg/agentic/remote_client.go +++ b/pkg/agentic/remote_client.go @@ -19,6 +19,7 @@ type RemoteClient struct { // client := agentic.NewRemoteClient("charon") func NewRemoteClient(host string) RemoteClient { + host = core.Trim(host) address := resolveHost(host) return RemoteClient{ Host: host, diff --git a/pkg/agentic/remote_client_test.go b/pkg/agentic/remote_client_test.go index c549f17..24b9209 100644 --- a/pkg/agentic/remote_client_test.go +++ b/pkg/agentic/remote_client_test.go @@ -297,6 +297,17 @@ func TestRemoteClient_NewRemoteClient_Good(t *testing.T) { assert.Equal(t, "http://10.69.69.165:9101/mcp", client.URL) } +func TestRemoteClient_NewRemoteClient_Good_TrimmedInput(t *testing.T) { + t.Setenv("AGENT_TOKEN_CHARON", "token-123") + + client := NewRemoteClient(" charon ") + + assert.Equal(t, "charon", client.Host) + assert.Equal(t, "10.69.69.165:9101", client.Address) + assert.Equal(t, "token-123", client.Token) + assert.Equal(t, "http://10.69.69.165:9101/mcp", client.URL) +} + func TestRemoteClient_ToolCallBody_Good(t *testing.T) { client := NewRemoteClient("local") diff --git a/pkg/agentic/remote_test.go b/pkg/agentic/remote_test.go index 0d835b9..7e013c5 100644 --- a/pkg/agentic/remote_test.go +++ b/pkg/agentic/remote_test.go @@ -22,6 +22,11 @@ func TestRemote_ResolveHost_Good_CustomHost(t *testing.T) { assert.Equal(t, "192.168.1.100:8080", resolveHost("192.168.1.100:8080")) } +func TestRemote_ResolveHost_Good_TrimmedInput(t *testing.T) { + assert.Equal(t, "10.69.69.165:9101", resolveHost(" charon ")) + assert.Equal(t, "my-server:9101", resolveHost(" my-server ")) +} + // --- remoteToken --- func TestRemote_RemoteToken_Good_FromEnv(t *testing.T) { @@ -44,6 +49,12 @@ func TestRemote_RemoteToken_Good_EnvPrecedence(t *testing.T) { assert.Equal(t, "specific-token", token, "host-specific env should take precedence") } +func TestRemote_RemoteToken_Good_TrimmedInput(t *testing.T) { + t.Setenv("AGENT_TOKEN_CHARON", "trimmed-token") + token := remoteToken(" charon ") + assert.Equal(t, "trimmed-token", token) +} + // --- resolveHost Bad/Ugly --- func TestRemote_ResolveHost_Bad(t *testing.T) {