From 1984bb5bbdf784b7215f788da999636209368da3 Mon Sep 17 00:00:00 2001 From: yinwm Date: Sun, 22 Mar 2026 22:21:27 +0800 Subject: [PATCH] fix(test): mock gateway health check in status tests Two gateway tests were flaky due to race conditions: - TestGatewayStatusReturnsRestartingDuringRestartGap - TestGatewayRestartReturnsErrorStatusWhenReplacementFailsToStart The handleGatewayStatus function calls getGatewayHealth which can override the test's expected status. By mocking gatewayHealthGet to return an error, the tests now reliably verify the expected status values. Co-Authored-By: Claude Opus 4.6 --- web/backend/api/gateway_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/web/backend/api/gateway_test.go b/web/backend/api/gateway_test.go index 5c94f0b89..504d091af 100644 --- a/web/backend/api/gateway_test.go +++ b/web/backend/api/gateway_test.go @@ -596,6 +596,11 @@ func TestGatewayStatusReturnsErrorAfterStartupWindowExpires(t *testing.T) { func TestGatewayStatusReturnsRestartingDuringRestartGap(t *testing.T) { resetGatewayTestState(t) + // Mock health check to return error, so it won't override our "restarting" status + gatewayHealthGet = func(url string, timeout time.Duration) (*http.Response, error) { + return nil, errors.New("mock health check error") + } + configPath := filepath.Join(t.TempDir(), "config.json") h := NewHandler(configPath) mux := http.NewServeMux() @@ -738,6 +743,11 @@ func TestGatewayRestartKeepsOldProcessWhenItDoesNotExitInTime(t *testing.T) { func TestGatewayRestartReturnsErrorStatusWhenReplacementFailsToStart(t *testing.T) { resetGatewayTestState(t) + // Mock health check to return error, so it won't override our "error" status + gatewayHealthGet = func(url string, timeout time.Duration) (*http.Response, error) { + return nil, errors.New("mock health check error") + } + configPath := filepath.Join(t.TempDir(), "config.json") cfg := config.DefaultConfig() cfg.Agents.Defaults.ModelName = cfg.ModelList[0].ModelName