provider: the shared-list tests count Codex's own ask of the list apart (#3854)
TestFetchAsksASharedBaseOnce, TestFetchAsksOneListOnceForTwoBasesOfIt and TestFetchUnionsProtocolListsWithoutChat are red on main since6eb510f78("codex: a relay's own Codex entries reach Codex as it gave them"). Each counts every GET of the models list. For a provider added by its address (no preset, no account) with a Responses base,6eb510f78asks the Responses list once more with client_version (codexEntries), and says so: "fetchOne asks the same URL once more with client_version (codexEntries). Only where the list is fetched (add, key change, Refresh), never per Codex poll." The three tests' providers are such providers, so each counted that ask as the list asked a second time. They weren't seen red then: 6eb510f78's whole internal/provider run crashed in TestUnreadLoginsWriteErrorsKeepCredentials (#3632) first, and after its rebase provider ran with -run Codex. On CI that crash ends the package before them (run 40492644859, ate056779a, names none of the three). The ask is that change's own, and its TestCodexListedEntry counts it, so this keeps it and the three tests count it apart: a request carrying client_version is Codex's, any other is the list. Each still wants the list itself asked exactly once, what it is there for (#1006 for TestFetchAsksOneListOnceForTwoBasesOfIt), and now wants Codex's ask once at most: whether it is made is TestCodexListedEntry's to say. What a Refresh of such a provider asks is unchanged, its Responses list twice, the second time as Codex asks it. If that request isn't wanted, it is codexEntries' to change, and these tests then need nothing. What was run (tree 7e0975fa, on origin/maine056779a, go1.26.8, linux/amd64), outside graftcp, umask 077: - The three, -count=1 -v: red ate056779aas #3854 has them; here 3 PASS. -race -count=20: ok. - Broken by hand (restored after): - the fetch keeping no record of the lists it asked (a nil catalog.Listed, which pays for every list URL again): TestFetchAsksASharedBaseOnce ("asked 2 times, want once") and TestFetchAsksOneListOnceForTwoBasesOfIt ("the one list fetched 2 times, want once", "chat and responses fetched the list 2 times, want once") red; the third's two lists are on two servers, none shared. - codexEntries asking Codex's list twice: all three red ("the list asked as Codex asks 2 times, want once at most", "asked responses as Codex asks 2 times", "asked as Codex asks 2 times"). - internal/provider whole but TestUnreadLoginsWriteErrorsKeepCredentials (#3632's crash), Bun 1.4.2: TestCodexAppServersOnHome alone red (#3906); ate056779a, that and the three. - go test -tags nogui -count=1 -timeout 45m ./... outside graftcp, umask 077, Bun 1.4.2 (log kept): 70 packages ok, 6 red, none in what this changes. internal/provider ends at #3632's crash before the three run, so the run above without that test is their record. The reds: agent TestFolderVarsAreListed (#3884, main's CI red), TestCodexDriftReached (#3398), TestInstalledVersion, TestCursorFolderFromTheEditorIsNotTheCLI, TestCopilotFolderFromAnIDEPluginIsNotTheCLI, TestOmpDetectedWithPiDir and TestZedAppPath (#3141), TestReasonixCLIRequiresSupportedNativeVersion and TestReasonixCLIRecoversAfterProbeTimeout (#3641); edit TestWriteAtomicReadOnlyHardLink and testenv TestProgram (umask 077, #3640); gateway TestPluginToldWhereTheAgentWorks (#3675); gui TestGatewayHeldByAContainer and TestGatewayFixQuitsOnlyAMagpie (#3649); provider TestCodexAppServersOnHome (#3906), then "close of synctest channel from outside bubble" from TestUnreadLoginsWriteErrorsKeepCredentials (#3632), both main's CI red. - gofmt -l clean. go vet -tags nogui and go build -tags nogui for linux, windows and darwin, and go vet and go build for windows without the tag: exit 0 each. go vet and go build without the tag on linux: exit 1 (this box has no GTK or WebKitGTK dev packages). Merged from JoeyWu-tech's branch, cherry-picked onto origin/maind6c459c79with the other of #3906/#3854. Run on mote (macOS) at that tree: - go test ./internal/proc/ ./internal/provider/: ok, both whole (provider's first whole pass since #3632). - the six tests these two touch, -count=20: ok. Each was red on main before. - GOOS=linux and GOOS=windows go vet ./internal/proc/ ./internal/provider/: ok. Not run here: Linux, where #3906 was red; its record is the author's above and the CI run of this push.
This commit is contained in:
@@ -110,8 +110,14 @@ func TestFetchAsksOneListOnceForTwoBasesOfIt(t *testing.T) {
|
||||
asked := map[string]int{}
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
k := r.URL.Path
|
||||
if r.URL.Query().Has("client_version") {
|
||||
// Codex's own ask of the Responses list (codexEntries),
|
||||
// a request of its own
|
||||
k += "?client_version"
|
||||
}
|
||||
mu.Lock()
|
||||
asked[r.URL.Path]++
|
||||
asked[k]++
|
||||
mu.Unlock()
|
||||
if r.URL.Path != "/v1/models" {
|
||||
http.NotFound(w, r)
|
||||
@@ -144,7 +150,8 @@ func TestFetchAsksOneListOnceForTwoBasesOfIt(t *testing.T) {
|
||||
}
|
||||
mu.Unlock()
|
||||
// and the same base as Chat and Responses is one list too, the one
|
||||
// case the base string already covered
|
||||
// case the base string already covered; Codex's own ask of the
|
||||
// Responses list is counted apart (#3854)
|
||||
if err := Save(Provider{ID: "one", Name: "One", Chat: srv.URL + "/v1", Responses: srv.URL + "/v1", Key: "sk-p"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -163,6 +170,9 @@ func TestFetchAsksOneListOnceForTwoBasesOfIt(t *testing.T) {
|
||||
if asked["/v1/models"] != 1 {
|
||||
t.Errorf("chat and responses fetched the list %d times, want once", asked["/v1/models"])
|
||||
}
|
||||
if n := asked["/v1/models?client_version"]; n > 1 {
|
||||
t.Errorf("the list asked as Codex asks %d times, want once at most", n)
|
||||
}
|
||||
}
|
||||
|
||||
// What a base's list refused is reported once (#1006). Chat and Responses
|
||||
|
||||
@@ -111,7 +111,8 @@ func TestFetchUnionsProtocolLists(t *testing.T) {
|
||||
|
||||
// The order the protocols are asked in must not decide which models are
|
||||
// kept: a provider with a Responses base and an Anthropic base and no Chat
|
||||
// one is asked both.
|
||||
// one is asked both, each list once. Codex's own ask of the Responses
|
||||
// list (codexEntries) is counted apart (#3854).
|
||||
func TestFetchUnionsProtocolListsWithoutChat(t *testing.T) {
|
||||
isolate(t)
|
||||
h := t.TempDir()
|
||||
@@ -124,13 +125,17 @@ func TestFetchUnionsProtocolListsWithoutChat(t *testing.T) {
|
||||
t.Setenv(v, "")
|
||||
}
|
||||
|
||||
var responsesHits, anthropicHits atomic.Int32
|
||||
var responsesHits, responsesCodexHits, anthropicHits atomic.Int32
|
||||
responses := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/v1/models" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
responsesHits.Add(1)
|
||||
if r.URL.Query().Has("client_version") {
|
||||
responsesCodexHits.Add(1)
|
||||
} else {
|
||||
responsesHits.Add(1)
|
||||
}
|
||||
w.Write([]byte(`{"data":[{"id":"gpt-a"}]}`))
|
||||
}))
|
||||
defer responses.Close()
|
||||
@@ -167,6 +172,9 @@ func TestFetchUnionsProtocolListsWithoutChat(t *testing.T) {
|
||||
if responsesHits.Load() != 1 || anthropicHits.Load() != 1 {
|
||||
t.Errorf("asked responses %d times, anthropic %d", responsesHits.Load(), anthropicHits.Load())
|
||||
}
|
||||
if responsesCodexHits.Load() > 1 {
|
||||
t.Errorf("asked responses as Codex asks %d times, want once at most", responsesCodexHits.Load())
|
||||
}
|
||||
}
|
||||
|
||||
// One model in two lists is one model: its image capability is merged the
|
||||
@@ -283,7 +291,9 @@ func TestFetchAsksOneProtocolOnce(t *testing.T) {
|
||||
}
|
||||
|
||||
// Chat and Responses at one base ask it once, as they did when the first
|
||||
// answer ended the fetch.
|
||||
// answer ended the fetch. Codex's own ask of the Responses list
|
||||
// (codexEntries, with client_version) is a request of its own, once a
|
||||
// fetch for a provider added by its address, and is counted apart (#3854).
|
||||
func TestFetchAsksASharedBaseOnce(t *testing.T) {
|
||||
isolate(t)
|
||||
h := t.TempDir()
|
||||
@@ -296,13 +306,17 @@ func TestFetchAsksASharedBaseOnce(t *testing.T) {
|
||||
t.Setenv(v, "")
|
||||
}
|
||||
|
||||
var hits atomic.Int32
|
||||
var hits, codexHits atomic.Int32
|
||||
shared := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/v1/models" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
hits.Add(1)
|
||||
if r.URL.Query().Has("client_version") {
|
||||
codexHits.Add(1)
|
||||
} else {
|
||||
hits.Add(1)
|
||||
}
|
||||
w.Write([]byte(`{"data":[{"id":"gpt-a"}]}`))
|
||||
}))
|
||||
defer shared.Close()
|
||||
@@ -326,6 +340,9 @@ func TestFetchAsksASharedBaseOnce(t *testing.T) {
|
||||
if hits.Load() != 1 {
|
||||
t.Errorf("asked %d times, want once", hits.Load())
|
||||
}
|
||||
if codexHits.Load() > 1 {
|
||||
t.Errorf("asked as Codex asks %d times, want once at most", codexHits.Load())
|
||||
}
|
||||
}
|
||||
|
||||
// Where no protocol answers, the error is the one it was: every base asked
|
||||
|
||||
Reference in New Issue
Block a user