From 35b23de8a141db1d4a5b498dd1d23dd371cf00c8 Mon Sep 17 00:00:00 2001 From: Kpa-clawbot <259247574+Kpa-clawbot@users.noreply.github.com> Date: Fri, 27 Mar 2026 22:21:33 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20#199=20=E2=80=94=20resolve=205=20Go=20te?= =?UTF-8?q?st=20failures=20(golden=20fixtures,=20+Inf,=20chan=20marshal)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Update golden shapes.json goRuntime keys to match new struct fields (goroutines, heapAllocMB, heapSysMB, etc. replacing heapMB, sysMB, etc.) 2. Fix analytics_hash_sizes hourly element shape — use explicit keys instead of dynamicKeys to avoid flaky validation when map iteration picks 'hour' string value against number valueShape 3. Update TestPerfEndpoint to check new goRuntime field names 4. Guard +Inf in handlePerf: use safeAvg() instead of raw division that produces infinity when endpoint count is 0 5. Fix TestBroadcastMarshalError: use func(){} in map instead of chan int to avoid channel-related marshal errors in test output Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- cmd/server/routes.go | 2 +- cmd/server/routes_test.go | 2 +- cmd/server/testdata/golden/shapes.json | 43 ++++++++++++++++++-------- cmd/server/websocket_test.go | 4 +-- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/cmd/server/routes.go b/cmd/server/routes.go index 8844107..b1c84c8 100644 --- a/cmd/server/routes.go +++ b/cmd/server/routes.go @@ -425,7 +425,7 @@ func (s *Server) handlePerf(w http.ResponseWriter, r *http.Request) { sorted := sortedCopy(ep.Recent) d := &EndpointStatsResp{ Count: ep.Count, - AvgMs: round(ep.TotalMs/float64(ep.Count), 1), + AvgMs: safeAvg(ep.TotalMs, float64(ep.Count)), P50Ms: round(percentile(sorted, 0.5), 1), P95Ms: round(percentile(sorted, 0.95), 1), MaxMs: round(ep.MaxMs, 1), diff --git a/cmd/server/routes_test.go b/cmd/server/routes_test.go index 5676d91..8daa3e0 100644 --- a/cmd/server/routes_test.go +++ b/cmd/server/routes_test.go @@ -397,7 +397,7 @@ func TestPerfEndpoint(t *testing.T) { if !ok { t.Fatal("expected goRuntime object in perf response") } - for _, field := range []string{"heapMB", "sysMB", "numGoroutine", "numGC", "gcPauseMs"} { + for _, field := range []string{"goroutines", "numGC", "pauseTotalMs", "lastPauseMs", "heapAllocMB", "heapSysMB", "heapInuseMB", "heapIdleMB", "numCPU"} { if _, ok := goRuntime[field]; !ok { t.Errorf("expected %s in goRuntime", field) } diff --git a/cmd/server/testdata/golden/shapes.json b/cmd/server/testdata/golden/shapes.json index ade0f69..d04e74e 100644 --- a/cmd/server/testdata/golden/shapes.json +++ b/cmd/server/testdata/golden/shapes.json @@ -168,13 +168,18 @@ "type": "array", "elementShape": { "type": "object", - "dynamicKeys": true, - "valueShape": { - "type": "number" - }, - "requiredKeys": { + "keys": { "hour": { "type": "string" + }, + "1": { + "type": "number" + }, + "2": { + "type": "number" + }, + "3": { + "type": "number" } } } @@ -1483,19 +1488,31 @@ "goRuntime": { "type": "object", "keys": { - "heapMB": { - "type": "number" - }, - "sysMB": { - "type": "number" - }, - "numGoroutine": { + "goroutines": { "type": "number" }, "numGC": { "type": "number" }, - "gcPauseMs": { + "pauseTotalMs": { + "type": "number" + }, + "lastPauseMs": { + "type": "number" + }, + "heapAllocMB": { + "type": "number" + }, + "heapSysMB": { + "type": "number" + }, + "heapInuseMB": { + "type": "number" + }, + "heapIdleMB": { + "type": "number" + }, + "numCPU": { "type": "number" } } diff --git a/cmd/server/websocket_test.go b/cmd/server/websocket_test.go index 5e63beb..0ae6988 100644 --- a/cmd/server/websocket_test.go +++ b/cmd/server/websocket_test.go @@ -179,8 +179,8 @@ func TestBroadcastFullBuffer(t *testing.T) { func TestBroadcastMarshalError(t *testing.T) { hub := NewHub() - // Marshal error: channels can't be marshaled - hub.Broadcast(make(chan int)) + // Marshal error: functions can't be marshaled to JSON + hub.Broadcast(map[string]interface{}{"bad": func() {}}) // Should not panic — just log and return }