JiangLiuer222 on X: after Disconnect the Codex app kept sending to 127.0.0.1:3425, now and then. The app's app-server reads config.toml only as it starts, so one started while Codex was connected kept the gateway's base URL until the user quit the app. Now the gateway's watcher (KeepCodexAppOnItsProvider, from8b0132b3d) ends the app's own app-server whenever what it reads at start and magpie writes changes: model_provider, openai_base_url, model_catalog_json, the magpie table's base_url and the used-up takeover (codexAppRoute, through the provider.CodexAppRoute hook, which replaces CodexAppOnMagpie). Same guards as before: never while a Codex request is in flight or ended in the last 10s, never with a turn open, only on magpie's Codex home, a clean exit. At its first look only a used-up account's app-servers are ended, as before. Also checked: after Disconnect nothing writes the base URL back. Failover and the stale-model rewire skip a disconnected Codex, and the takeover paths in Sync need Codex joined or on magpie. Run at this tree (on origin/main32ea16c5a), private GOCACHE, sandbox HOME: - gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows (internal/agent, internal/provider); go build darwin, windows, linux nogui. - go test -count=1 -run Codex ./internal/provider ./internal/agent: ok (at47175a68f); -run CodexApp again at32ea16c5a: ok. - Broken by hand: comparing only the takeover flag (the old condition) made TestCodexAppServerRestartedOnDisconnect red ("disconnected, idle: ended [], want [60]"). - Real app: ChatGPT.app 26.1013 under a sandbox HOME (CFFIXED_USER_HOME), this build's magpie serve on 3492, Codex connected to a custom provider by magpie codex fakeai/fake-1. magpie codex default: the app's app-server 76497 ended within 5s, the app started 77343 and logged "Codex CLI process exited classifiedAsExpected=true code=0"; window kept. Connect again: 77343 -> 79138. The owner's own app-server (1902, HOME=~) was untouched. Not tried: Windows and Linux real apps, a turn running during the switch (unit-tested only), a signed-in sandbox app (it was signed out, so no turn was sent to see the new route used).
50 lines
1.5 KiB
Go
50 lines
1.5 KiB
Go
package agent
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/edit"
|
|
)
|
|
|
|
// The route the Codex app's app-server is restarted on (codex_app_server.go)
|
|
// changes when Codex is connected beside its ChatGPT sign-in and when it is
|
|
// disconnected (JiangLiuer222 on X: the app kept sending to 127.0.0.1:3425
|
|
// after Disconnect), and not when the Codex app writes a model pick of its
|
|
// own, which would restart it on every pick.
|
|
func TestCodexAppRouteFollowsConnectAndDisconnect(t *testing.T) {
|
|
home, read := codexHome(t, `{"tokens":{"access_token":"x","id_token":"x.e30.x"}}`, "model = \"gpt-5.5\"\n")
|
|
cx := codex(home)
|
|
route := func() string {
|
|
t.Helper()
|
|
r, _, known := codexAppRoute()
|
|
if !known {
|
|
t.Fatal("route not known")
|
|
}
|
|
return r
|
|
}
|
|
before := route()
|
|
if _, err := cx.ConnectHow(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
connected := route()
|
|
if connected == before {
|
|
t.Fatalf("connect left the route as it was:\n%s", read())
|
|
}
|
|
// the Codex app writes its own pick: no restart for that
|
|
if err := edit.SetTOMLTop(filepath.Join(home, ".codex", "config.toml"), edit.KV{Path: "model", Value: "gpt-6.1-sol"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if route() != connected {
|
|
t.Fatalf("a model pick changed the route:\n%s", read())
|
|
}
|
|
if err := cx.Disconnect(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// the [model_providers.magpie] table stays, for the threads started
|
|
// on it; openai_base_url goes
|
|
if r := route(); r == connected {
|
|
t.Fatalf("disconnect left the route as it was: %q\n%s", r, read())
|
|
}
|
|
}
|