From 86254d4049cb6be4a2ccdab02edf0bd59860c603 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 22 Oct 2026 16:27:54 +0800 Subject: [PATCH] tests: an unreachable upstream is 127.0.0.1:1, not a closed server's port TestCodexOwnModelUnreached went red on ubuntu CI at 0ddcf28a1 (run 39742463965, shard 2): it closed an httptest server and pointed codexAPIBase at its URL, Linux handed that port to another test's server at once, and its fake answered "pong" with 200 instead of the dial error the test is about. The same class as 9a852ae9d and d0ccbbebc. Both tests that took a dead URL from a closed server now use http://127.0.0.1:1: refused at once on every OS, and no test can listen on it (privileged on Linux and macOS, unused on Windows). The sibling is TestMirrorFailuresAreTheMirrors in internal/update, whose "gone" mirror had the same race. Run at this tree: go test -count=3 -run 'TestCodexOwnModelUnreached|TestMirrorFailuresAreTheMirrors' ./internal/gateway ./internal/update: ok; go test ./internal/update: ok; gofmt -l none; go vet for darwin, linux, windows: ok. The reuse itself wasn't injected; the CI log's 200 "pong" body is the evidence. --- internal/gateway/codex_unreached_test.go | 8 ++++---- internal/update/mirror_test.go | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/gateway/codex_unreached_test.go b/internal/gateway/codex_unreached_test.go index f0b181f2d..869d41a4a 100644 --- a/internal/gateway/codex_unreached_test.go +++ b/internal/gateway/codex_unreached_test.go @@ -1,7 +1,6 @@ package gateway import ( - "net/http" "net/http/httptest" "strings" "testing" @@ -13,10 +12,11 @@ import ( // and what to do, not with the dial error alone (#322). func TestCodexOwnModelUnreached(t *testing.T) { setup(t, provider.Chat, &fake{t: t}) - up := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})) - up.Close() + // port 1: refused at once, and no test can listen on it. A closed + // server's port was handed to another test's server on Linux CI, whose + // fake answered "pong" with 200. was := codexAPIBase - codexAPIBase = up.URL + codexAPIBase = "http://127.0.0.1:1" t.Cleanup(func() { codexAPIBase = was }) rec := httptest.NewRecorder() req := httptest.NewRequest("POST", CodexPath+"/responses", strings.NewReader(`{"model":"gpt-5.5","input":"hi","stream":true}`)) diff --git a/internal/update/mirror_test.go b/internal/update/mirror_test.go index 9c45fc6f4..5b8b648c5 100644 --- a/internal/update/mirror_test.go +++ b/internal/update/mirror_test.go @@ -206,9 +206,10 @@ func TestMirrorFailuresAreTheMirrors(t *testing.T) { defer tampered.Close() missing := httptest.NewServer(http.NotFoundHandler()) defer missing.Close() - gone := httptest.NewServer(http.NotFoundHandler()) - gone.Close() - for _, m := range []string{tampered.URL + "/", missing.URL + "/", gone.URL + "/"} { + // port 1 is refused at once and no test can listen on it, where a + // closed server's port can be handed to the next server at once + gone := "http://127.0.0.1:1/" + for _, m := range []string{tampered.URL + "/", missing.URL + "/", gone} { path := filepath.Join(t.TempDir(), "magpie.new") err := fetch(WithMirror(context.Background(), m), asset, path) if err == nil || MirrorOf(err) != m || !strings.Contains(err.Error(), strings.TrimSuffix(m, "/")) {