Phase B: Agent registers routes with mc-proxy on deploy
The agent connects to mc-proxy via Unix socket and automatically registers/removes routes during deploy and stop. This eliminates manual mcproxyctl usage or TOML editing. - New ProxyRouter abstraction wraps mc-proxy client library - Deploy: after container starts, registers routes with mc-proxy using host ports from the registry - Stop: removes routes from mc-proxy before stopping container - Config: [mcproxy] section with socket path and cert_dir - Nil-safe: if mc-proxy socket not configured, route registration is silently skipped (backward compatible) - L7 routes use certs from convention path (<cert_dir>/<service>.pem) - L4 routes use TLS passthrough (backend_tls=true) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
57
internal/agent/proxy_test.go
Normal file
57
internal/agent/proxy_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.wntrmute.dev/kyle/mcp/internal/registry"
|
||||
)
|
||||
|
||||
func TestListenerForMode(t *testing.T) {
|
||||
tests := []struct {
|
||||
mode string
|
||||
port int
|
||||
want string
|
||||
}{
|
||||
{"l4", 8443, ":8443"},
|
||||
{"l7", 443, ":443"},
|
||||
{"l4", 9443, ":9443"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
got := listenerForMode(tt.mode, tt.port)
|
||||
if got != tt.want {
|
||||
t.Errorf("listenerForMode(%q, %d) = %q, want %q", tt.mode, tt.port, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNilProxyRouterIsNoop(t *testing.T) {
|
||||
var p *ProxyRouter
|
||||
|
||||
// All methods should return nil on a nil ProxyRouter.
|
||||
if err := p.RegisterRoutes(nil, "svc", nil, nil); err != nil {
|
||||
t.Errorf("RegisterRoutes on nil: %v", err)
|
||||
}
|
||||
if err := p.RemoveRoutes(nil, "svc", nil); err != nil {
|
||||
t.Errorf("RemoveRoutes on nil: %v", err)
|
||||
}
|
||||
if err := p.Close(); err != nil {
|
||||
t.Errorf("Close on nil: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterRoutesSkipsZeroHostPort(t *testing.T) {
|
||||
// A nil ProxyRouter should be a no-op, so this tests the skip logic
|
||||
// indirectly. With a nil proxy, RegisterRoutes returns nil even
|
||||
// with routes that have zero host ports.
|
||||
var p *ProxyRouter
|
||||
|
||||
routes := []registry.Route{
|
||||
{Name: "rest", Port: 8443, Mode: "l4"},
|
||||
}
|
||||
hostPorts := map[string]int{"rest": 0}
|
||||
|
||||
if err := p.RegisterRoutes(nil, "svc", routes, hostPorts); err != nil {
|
||||
t.Errorf("RegisterRoutes: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user