TestCodexOwnModelUnreached went red on ubuntu CI at0ddcf28a1(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 as9a852ae9dandd0ccbbebc. 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.
31 lines
1.1 KiB
Go
31 lines
1.1 KiB
Go
package gateway
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// One of Codex's own models, when OpenAI can't be reached, fails saying so
|
|
// and what to do, not with the dial error alone (#322).
|
|
func TestCodexOwnModelUnreached(t *testing.T) {
|
|
setup(t, provider.Chat, &fake{t: t})
|
|
// 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 = "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}`))
|
|
req.Header.Set("Authorization", "Bearer sk-relay-key")
|
|
New().Handler().ServeHTTP(rec, req)
|
|
body := rec.Body.String()
|
|
if rec.Code != 502 || !strings.Contains(body, "OpenAI can't be reached") || !strings.Contains(body, "gpt-5.5 is one of Codex's own models") ||
|
|
!strings.Contains(body, "pick one of magpie's models") {
|
|
t.Fatalf("%d %s", rec.Code, body)
|
|
}
|
|
}
|