diff --git a/cmd/picoclaw/internal/gateway/command_test.go b/cmd/picoclaw/internal/gateway/command_test.go index 8dc56fc6d..825369abb 100644 --- a/cmd/picoclaw/internal/gateway/command_test.go +++ b/cmd/picoclaw/internal/gateway/command_test.go @@ -43,7 +43,13 @@ func TestResolveGatewayHostOverride(t *testing.T) { {name: "implicit empty host is allowed", explicit: false, host: "", wantHost: "", wantErr: false}, {name: "explicit empty host rejected", explicit: true, host: " ", wantHost: "", wantErr: true}, {name: "explicit localhost kept", explicit: true, host: " localhost ", wantHost: "localhost", wantErr: false}, - {name: "explicit multi host normalized", explicit: true, host: " [::1] , 127.0.0.1 ", wantHost: "::1,127.0.0.1", wantErr: false}, + { + name: "explicit multi host normalized", + explicit: true, + host: " [::1] , 127.0.0.1 ", + wantHost: "::1,127.0.0.1", + wantErr: false, + }, } for _, tt := range tests { diff --git a/pkg/gateway/gateway.go b/pkg/gateway/gateway.go index 79c86fa96..039f45075 100644 --- a/pkg/gateway/gateway.go +++ b/pkg/gateway/gateway.go @@ -417,7 +417,7 @@ func setupAndStartServices( runningServices.authToken = authToken runningServices.HealthServer = health.NewServer(listenResult.ProbeHost, cfg.Gateway.Port, authToken) - listenAddr := "" + var listenAddr string if len(listenResult.Listeners) > 0 { listenAddr = listenResult.Listeners[0].Addr().String() } else { diff --git a/pkg/netbind/netbind.go b/pkg/netbind/netbind.go index 7f6121f28..ceff0757b 100644 --- a/pkg/netbind/netbind.go +++ b/pkg/netbind/netbind.go @@ -506,8 +506,14 @@ func openGroup(group bindGroup, port string) ([]net.Listener, []string, string, func openAdaptiveLoopbackGroup(allowIPv6, allowIPv4 bool, port string) ([]net.Listener, []string, string, error) { if allowIPv6 && allowIPv4 { - if ln6, actualPort, err6 := openExactListener(exactBinding{host: "::1", network: "tcp6", v6Only: true}, port); err6 == nil { - if ln4, _, err4 := openExactListener(exactBinding{host: "127.0.0.1", network: "tcp4"}, actualPort); err4 == nil { + if ln6, actualPort, err6 := openExactListener( + exactBinding{host: "::1", network: "tcp6", v6Only: true}, + port, + ); err6 == nil { + if ln4, _, err4 := openExactListener( + exactBinding{host: "127.0.0.1", network: "tcp4"}, + actualPort, + ); err4 == nil { return []net.Listener{ln6, ln4}, []string{"::1", "127.0.0.1"}, actualPort, nil } _ = ln6.Close() diff --git a/web/backend/api/gateway_test.go b/web/backend/api/gateway_test.go index 9e14bf42d..78bf34a63 100644 --- a/web/backend/api/gateway_test.go +++ b/web/backend/api/gateway_test.go @@ -216,7 +216,8 @@ func startGatewayAndCaptureEnv(t *testing.T, h *Handler) gatewayStartEnvSnapshot raw, err := os.ReadFile(envPath) if err == nil { var snapshot gatewayStartEnvSnapshot - if err := json.Unmarshal(raw, &snapshot); err != nil { + err = json.Unmarshal(raw, &snapshot) + if err != nil { t.Fatalf("Unmarshal(child env) error = %v", err) } return snapshot diff --git a/web/backend/main_test.go b/web/backend/main_test.go index 3047a3fa3..ea2a34104 100644 --- a/web/backend/main_test.go +++ b/web/backend/main_test.go @@ -51,9 +51,21 @@ func TestDashboardTokenConfigHelpPath(t *testing.T) { source launcherconfig.DashboardTokenSource want string }{ - {name: "env token does not expose config path", source: launcherconfig.DashboardTokenSourceEnv, want: ""}, - {name: "config token exposes config path", source: launcherconfig.DashboardTokenSourceConfig, want: launcherPath}, - {name: "random token does not expose config path", source: launcherconfig.DashboardTokenSourceRandom, want: ""}, + { + name: "env token does not expose config path", + source: launcherconfig.DashboardTokenSourceEnv, + want: "", + }, + { + name: "config token exposes config path", + source: launcherconfig.DashboardTokenSourceConfig, + want: launcherPath, + }, + { + name: "random token does not expose config path", + source: launcherconfig.DashboardTokenSourceRandom, + want: "", + }, } for _, tt := range tests { @@ -98,7 +110,14 @@ func TestResolveLauncherHostInput(t *testing.T) { wantActive bool wantErr bool }{ - {name: "flag host wins", flagHost: "127.0.0.1", explicitFlag: true, envHost: "::", wantHost: "127.0.0.1", wantActive: true}, + { + name: "flag host wins", + flagHost: "127.0.0.1", + explicitFlag: true, + envHost: "::", + wantHost: "127.0.0.1", + wantActive: true, + }, {name: "env host used when flag absent", envHost: "127.0.0.1,::1", wantHost: "127.0.0.1,::1", wantActive: true}, {name: "blank env ignored", envHost: " ", wantHost: "", wantActive: false}, {name: "invalid flag rejected", flagHost: "127.0.0.1, ", explicitFlag: true, wantErr: true}, @@ -230,10 +249,34 @@ func TestWildcardAdvertiseIP(t *testing.T) { ipv6 string want string }{ - {name: "ipv4 wildcard prefers ipv6 when available", bindHosts: []string{"0.0.0.0"}, ipv4: "192.168.1.2", ipv6: "2001:db8::1", want: "2001:db8::1"}, - {name: "ipv6 wildcard uses ipv6", bindHosts: []string{"::"}, ipv4: "192.168.1.2", ipv6: "2001:db8::1", want: "2001:db8::1"}, - {name: "ipv6 wildcard falls back to ipv4", bindHosts: []string{"::"}, ipv4: "192.168.1.2", ipv6: "", want: "192.168.1.2"}, - {name: "non wildcard does not advertise", bindHosts: []string{"127.0.0.1"}, ipv4: "192.168.1.2", ipv6: "2001:db8::1", want: ""}, + { + name: "ipv4 wildcard prefers ipv6 when available", + bindHosts: []string{"0.0.0.0"}, + ipv4: "192.168.1.2", + ipv6: "2001:db8::1", + want: "2001:db8::1", + }, + { + name: "ipv6 wildcard uses ipv6", + bindHosts: []string{"::"}, + ipv4: "192.168.1.2", + ipv6: "2001:db8::1", + want: "2001:db8::1", + }, + { + name: "ipv6 wildcard falls back to ipv4", + bindHosts: []string{"::"}, + ipv4: "192.168.1.2", + ipv6: "", + want: "192.168.1.2", + }, + { + name: "non wildcard does not advertise", + bindHosts: []string{"127.0.0.1"}, + ipv4: "192.168.1.2", + ipv6: "2001:db8::1", + want: "", + }, } for _, tt := range tests {