From a4937f8ff9fb9050b79d619bb4a46fcd01ed2da3 Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 14 Nov 2026 11:59:40 +0800 Subject: [PATCH] gateway: the effort tests' fake upstream answers only the turns TestEffortUpdateRefused went red on macOS CI at eb1b83000: "effort_update_test.go:158: upstream body: unexpected end of JSON input". The fake records the last request's body in f.got, and the Codex account's model list (provider/codex_models.go, a GET to CodexBase + "/models" with no body) can reach the same server after the turn. When it lands between the post and sentShape, f.got is empty. effortCodexAccount now hands only paths ending in /responses to the fake and answers anything else 404, which is what the model list got in effect before (an SSE body it couldn't parse). Run: with a GET to /models injected after the turn, the old helper fails with CI's exact message and the new one passes (mica). go vet and go test -tags nogui -count=20 -run Effort ./internal/gateway pass on mica; gofmt clean. Not run: the full suite (test file only). --- internal/gateway/effort_update_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/gateway/effort_update_test.go b/internal/gateway/effort_update_test.go index ced84fc62..b0cfd82f6 100644 --- a/internal/gateway/effort_update_test.go +++ b/internal/gateway/effort_update_test.go @@ -4,6 +4,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "net/http" "net/http/httptest" "os" "path/filepath" @@ -72,7 +73,15 @@ func effortCodexAccount(t *testing.T, f *fake) { auth := fmt.Sprintf(`{"auth_mode":"chatgpt","tokens":{"id_token":%q,"access_token":%q,"refresh_token":"r","account_id":"acct-1"}}`, claims(map[string]any{"email": "me@example.com"}), claims(map[string]any{"exp": time.Now().Add(time.Hour).Unix()})) os.WriteFile(filepath.Join(home, ".codex", "auth.json"), []byte(auth), 0o600) - up := httptest.NewServer(f) + // Only the turns reach f: the account's model list (a GET, no body) + // is fetched in the background and would overwrite what f got. + up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if !strings.HasSuffix(r.URL.Path, "/responses") { + http.NotFound(w, r) + return + } + f.ServeHTTP(w, r) + })) t.Cleanup(up.Close) old := provider.CodexBase provider.CodexBase = up.URL + "/backend-api/codex"