gateway tests: each test's Codex pool starts from no Codex client seen (#4807)

TestCodexPoolSaysTheClientsVersion was red in full internal/gateway runs
on mote and passed alone: the pool signed its request as
codex_cli_rs/0.165.0 where the client said 0.161.0. 0.165.0 wasn't mote's
installed Codex (none is on mote's PATH, and the package's TestMain puts
an inert codex stand-in first anyway). It was another test's client:
provider.codexSeen keeps the newest version any Codex client sent through
CodexPath for the process's life, and
TestRemoteMagpieCodexModelKeepsLiteOnCodexPath sends
"codex/0.165.0 (Mac OS 27.2; arm64)" with an originator there. Any later
test then had its pool say 0.165.0. codexVersionCache (the installed and
models_cache version, kept ten minutes) is the same kind of state, read
in whichever test's HOME asked first.

provider.ForgetCodexClientsForTest clears both, and the package's fresh()
(which codexSignedIn and the other pool tests start with) calls it, as it
already clears Copilot's and the cards' caches. The test's assertion is
unchanged.

Run on mote at this tree:
- old code: go test ./internal/gateway -run
  '^(TestRemoteMagpieCodexModelKeepsLiteOnCodexPath|TestCodexPoolSaysTheClientsVersion)$'
  red every time, "request 0: User-Agent codex_cli_rs/0.165.0 (Mac OS
  27.2.0; arm64) Apple_Terminal/455", as in the issue's comments.
- new code: the same pair -count=3, 3 of 3 ok.
- go test -tags nogui ./internal/gateway -run
  "Draw|Drawing|Relay|Codex|UpBytes|TrysSecondAsk|OneAuth|TestClaude|TestWorkDir|Lite"
  (the set a comment on #4807 found red): ok, 183s.
- go test ./internal/provider -run Codex: ok.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet of provider and
  gateway ok.

Not run: the full internal/gateway package. Three other sessions' full
gateway suites were running on mote, and one suite runs per machine.
This commit is contained in:
yetone
2026-11-03 13:12:01 +08:00
parent 2c214ce252
commit 17f2387e10
2 changed files with 16 additions and 0 deletions
+1
View File
@@ -64,6 +64,7 @@ func fresh(t *testing.T) {
provider.ForgetCopilotForTest()
provider.ForgetRemoteCardsForTest()
provider.ForgetKeptCardsForTest()
provider.ForgetCodexClientsForTest()
remoteRefreshes.Lock()
remoteRefreshes.at = map[string]time.Time{}
remoteRefreshes.Unlock()
+15
View File
@@ -208,6 +208,21 @@ func SawCodexClient(h http.Header) {
codexSeen.saw(v)
}
// ForgetCodexClientsForTest forgets the Codex version the gateway saw a
// client say it was and the one it found installed, for a test that asks
// what the pool says it is: both are kept for the process's life (the
// installed one for ten minutes, read in whichever test's HOME asked
// first), so an earlier test's Codex 0.165.0 spoke for the next test's
// 0.161.0 (#4807).
func ForgetCodexClientsForTest() {
codexSeen.Lock()
codexSeen.v = ""
codexSeen.Unlock()
codexVersionCache.Lock()
codexVersionCache.v, codexVersionCache.at = "", time.Time{}
codexVersionCache.Unlock()
}
// codexExecutable finds the codex CLI; a var so tests can fake it. Beyond
// PATH it looks where npm, nvm, bun, volta, pnpm, mise and the standalone
// installer put it, which a desktop app's PATH lacks.