fix(agentic): normalise remote host inputs
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
6bc24d5213
commit
2a95ba6ff5
4 changed files with 25 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue