fix(handlers): pass correct mock-server URL to setupIntegrationRedis

Root cause of 5-minute timeout: setupIntegrationRedis seeded Redis with
http://bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb (the UUID as hostname), which
the Go http.Client cannot resolve. The SSRF validation passes (valid DNS
hostname) but DNS resolution fails → HTTP request hangs for the client's
default 60s timeout before retrying → test times out at 5m.

Fix: change setupIntegrationRedis(t) → setupIntegrationRedis(t, agentURL)
so each test passes the actual mock server address (http://127.0.0.1:PORT)
before the function caches it. Remove the redundant db.RDB.Set override in
Test1 (URL now correct from the start).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Molecule AI · core-be 2026-05-12 11:49:38 +00:00
parent aebe468d3e
commit 9a8b7ee7e4

View File

@ -113,13 +113,11 @@ func setupIntegrationFixtures(t *testing.T, conn *sql.DB) func() {
}
// setupIntegrationRedis starts a miniredis, sets db.RDB, and seeds the target
// workspace URL. Returns the miniredis instance for cleanup.
// Idempotent — safe to call in each test regardless of Redis state.
func setupIntegrationRedis(t *testing.T) *miniredis.Miniredis {
// workspace URL to agentURL. Returns the miniredis instance for cleanup.
func setupIntegrationRedis(t *testing.T, agentURL string) *miniredis.Miniredis {
t.Helper()
mr := setupTestRedis(t)
// Seed the target workspace URL so proxyA2ARequest finds it.
db.CacheURL(context.Background(), testTargetID, "http://"+testTargetID)
db.CacheURL(context.Background(), testTargetID, agentURL)
return mr
}
@ -182,13 +180,11 @@ func TestIntegration_ExecuteDelegation_DeliveryConfirmedProxyError_TreatsAsSucce
// Close immediately — client gets io.EOF on body read
}()
// Wire up mocks.
mr := setupIntegrationRedis(t)
defer mr.Close()
// Override the cached URL with the mock server's actual address.
// Wire up mocks. Agent URL must be known before calling setupIntegrationRedis
// so the correct address is cached in Redis.
agentURL := "http://" + ln.Addr().String()
db.RDB.Set(context.Background(), fmt.Sprintf("ws:%s:url", testTargetID), agentURL, 0)
mr := setupIntegrationRedis(t, agentURL)
defer mr.Close()
broadcaster := newTestBroadcaster()
wh := NewWorkspaceHandler(broadcaster, nil, "http://localhost:8080", t.TempDir())
@ -380,7 +376,7 @@ func TestIntegration_ExecuteDelegation_CleanProxyResponse_Unchanged(t *testing.T
go agentServer.Serve(ln)
defer agentServer.Close()
mr := setupIntegrationRedis(t)
mr := setupIntegrationRedis(t, "http://"+ln.Addr().String())
defer mr.Close()
broadcaster := newTestBroadcaster()