From a535bbf3cf5f020fb460db42ca2e15901b22559f Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 12 Nov 2026 06:43:10 +0800 Subject: [PATCH] gateway: a Claude TUI test's unanswered call ends with its test tuiCalls.call made Claude Code's MCP call with httptest.NewRequest, whose context is never done, so a call a test didn't answer waited in mcpCall until the package ended. macOS CI's 30m alarm at e787e7b5c (run 43102520567) showed one such goroutine blocked 24 minutes in mcpCall from claude_tui_call_test.go:76. The request now carries a context the test's cleanup cancels, and the cleanup waits for the call to return. Run (mote, at origin/main 152734cd1 plus this change): a throwaway probe test, run after the TUI tests, counting (*tuiCalls).call goroutines still alive: old helper "1 tuiCalls calls still running after their tests", fixed helper ok. go test -race -count=5 -run TestClaudeTUI ./internal/gateway ok (240s); that pattern covers every user of newTUICalls and schemaTUI. Not the cause of that run's timeout: the package took 1801s where the last green macOS run took 888s, with the alarm landing on a 5s-old ZCode test (#2191). --- internal/gateway/claude_tui_call_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/gateway/claude_tui_call_test.go b/internal/gateway/claude_tui_call_test.go index fc3d2a8c2..145d0ae02 100644 --- a/internal/gateway/claude_tui_call_test.go +++ b/internal/gateway/claude_tui_call_test.go @@ -1,6 +1,7 @@ package gateway import ( + "context" "encoding/json" "io" "net/http/httptest" @@ -64,6 +65,9 @@ func (c *tuiCalls) write(lines ...string) { func (c *tuiCalls) call(id, args string) { done := make(chan struct{}) c.called[id] = done + // a call the test never answers ends with the test, not the package + ctx, cancel := context.WithCancel(context.Background()) + c.t.Cleanup(func() { cancel(); <-done }) go func() { defer close(done) body := `{"tool_call_id":"` + id + `","name":"Read"` @@ -71,7 +75,7 @@ func (c *tuiCalls) call(id, args string) { body += `,"arguments":` + args } body += `}` - r := httptest.NewRequest("POST", "/", strings.NewReader(body)) + r := httptest.NewRequestWithContext(ctx, "POST", "/", strings.NewReader(body)) r.SetPathValue("token", "run") c.bridge.mcpCall(httptest.NewRecorder(), r) }()