Uninstalling disconnected only the agents that read as connected. A
Codex whose config still had openai_base_url at magpie's gateway (or
model_provider = "magpie") but whose notes in magpie's folder were gone
(the folder deleted by hand, a fresh install beside an old config, a
magpie older than the notes) read as not connected, so the uninstall
left it pointing at a port nothing answers: every Codex turn then failed
with a connection error that never names magpie.
Uninstall's Agents step now ends with Codex's leftovers pass
(agent.TakeCodexLeftovers, the Agent's TakeLeftovers): the base URL goes
by viaBase()/dropBase and magpie as provider by asProvider()/dropProvider,
the same gates and drops a Disconnect uses, notes or not. Codex's own
model, its own provider and keys stay, and so does
[model_providers.magpie], which threads started on magpie name. Taking
anything shows "Codex's leftover settings" in the report and restarts
the Codex app's app-server. docs/subsystems/agent-wiring.md says so.
Not changed: deleting magpie.exe by hand runs no code, so the reporter's
Windows case is covered only through Settings > About > Uninstall magpie
or `magpie uninstall`. The pass is this machine's Codex only, like
EndCodexFailover; a WSL distro's config is left as it was. viaBase
matches any loopback port with /backend-api/codex, as Disconnect does.
Run on mote, base origin/main 4e7661adc:
- gofmt -l on the touched files: nothing
- go vet -tags nogui ./internal/agent/ ./internal/uninstall/,
GOOS=linux go vet -tags nogui, GOOS=windows go vet: clean
- go test -tags nogui -count=1 ./internal/uninstall/: ok
- go test -tags nogui -run 'Uninstall|Run|Keep|Data' ./internal/cli/: ok
- go test -tags nogui -run Codex ./internal/agent/: ok (44s)
Broken by hand: TakeLeftovers returning false at once and Agents not
calling endLeftovers: TestCodexLeftoversGoAtUninstallWithoutTheMarks and
TestCodexProviderLeftovers... FAIL "took false, err <nil>"; TestRunOrder,
TestKeepData and TestRunTakesCodexLeftovers FAIL (no "leftovers" step,
the Codex app not restarted, a failed pass not reported).
Not tried: a real `magpie uninstall` (it removes the login service, which
a sandbox HOME doesn't isolate), the Codex app, Windows.
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
86 lines
3.7 KiB
Go
86 lines
3.7 KiB
Go
package agent
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/edit"
|
|
)
|
|
|
|
// Uninstalling takes magpie's dead addresses out of Codex's config even
|
|
// where no Disconnect could name them (#3866): the marks magpie keeps its
|
|
// writes by are gone (magpie's folder deleted by hand, a fresh install
|
|
// beside an old config, a magpie from before the marks), so Codex reads as
|
|
// not connected, and the base URL at magpie's gateway sends every turn to
|
|
// a port nothing answers any more. Codex's own model and provider stay,
|
|
// and so does magpie's provider table, whose threads name it.
|
|
func TestCodexLeftoversGoAtUninstallWithoutTheMarks(t *testing.T) {
|
|
home, read := codexHome(t, `{"tokens":{"access_token":"x","id_token":"x.e30.x"}}`,
|
|
"model = \"gpt-5.4\"\nopenai_base_url = \""+codexGatewayURL()+"\"\n\n"+
|
|
"[model_providers.magpie]\nname = \"magpie\"\nbase_url = \""+codexGatewayURL()+"\"\nwire_api = \"responses\"\n")
|
|
cx := codex(home)
|
|
if cx.Wired() {
|
|
t.Fatalf("read as connected with no marks of magpie's:\n%s", read())
|
|
}
|
|
took, err := TakeCodexLeftovers()
|
|
if err != nil || !took {
|
|
t.Fatalf("took %v, err %v", took, err)
|
|
}
|
|
cfg := read()
|
|
if strings.Contains(cfg, "openai_base_url") {
|
|
t.Fatalf("magpie's base URL left for a gateway that is gone:\n%s", cfg)
|
|
}
|
|
if !strings.Contains(cfg, `model = "gpt-5.4"`) || strings.Contains(cfg, "model_provider =") || strings.Contains(cfg, "model_catalog_json") {
|
|
t.Fatalf("Codex's own pick disturbed:\n%s", cfg)
|
|
}
|
|
if !strings.Contains(cfg, "[model_providers.magpie]") {
|
|
t.Fatal("magpie's provider table taken: threads started on it name it")
|
|
}
|
|
// nothing of magpie's the second time
|
|
if took, err := TakeCodexLeftovers(); err != nil || took {
|
|
t.Fatalf("took again: %v, %v", took, err)
|
|
}
|
|
}
|
|
|
|
// magpie its provider with the marks gone: the pick and the name of
|
|
// magpie's model list go with it, or Codex is left on a provider of a dead
|
|
// gateway (and loading no config at all once its list file is gone).
|
|
func TestCodexProviderLeftoversGoAtUninstallWithoutTheMarks(t *testing.T) {
|
|
home, read := codexHome(t, "",
|
|
"model = \"gpt-5.4\"\nmodel_provider = \"magpie\"\nopenai_base_url = \""+codexGatewayURL()+"\"\n\n"+
|
|
"[model_providers.magpie]\nname = \"magpie\"\nbase_url = \""+codexGatewayURL()+"\"\nwire_api = \"responses\"\n\n[projects.\"/x\"]\ntrust_level = \"trusted\"\n")
|
|
path := filepath.Join(home, ".codex", "config.toml")
|
|
// the list magpie wrote for its provider, named as Codex reads it
|
|
if err := edit.SetTOMLTop(path, edit.KV{Path: "model_catalog_json", Value: filepath.Join(home, ".codex", "magpie-models.json")}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cx := codex(home)
|
|
if cx.Wired() {
|
|
t.Fatalf("read as connected with no marks of magpie's:\n%s", read())
|
|
}
|
|
if took, err := TakeCodexLeftovers(); err != nil || !took {
|
|
t.Fatalf("took %v, err %v", took, err)
|
|
}
|
|
cfg := read()
|
|
if strings.Contains(cfg, "openai_base_url") || strings.Contains(cfg, `model_provider = "magpie"`) || strings.Contains(cfg, "model_catalog_json") {
|
|
t.Fatalf("magpie's provider pick left:\n%s", cfg)
|
|
}
|
|
if !strings.Contains(cfg, `model = "gpt-5.4"`) || !strings.Contains(cfg, `trust_level = "trusted"`) {
|
|
t.Fatalf("Codex's own keys disturbed:\n%s", cfg)
|
|
}
|
|
}
|
|
|
|
// The user's own addresses stay, and nothing of theirs is taken.
|
|
func TestCodexLeftoversLeaveTheUsersOwn(t *testing.T) {
|
|
const config = "model = \"gpt-5.4\"\nopenai_base_url = \"https://api.openai.com/v1\"\nmodel_provider = \"mine\"\n\n" +
|
|
"[model_providers.mine]\nname = \"mine\"\nbase_url = \"https://mine.example/v1\"\n"
|
|
_, read := codexHome(t, "", config)
|
|
if took, err := TakeCodexLeftovers(); err != nil || took {
|
|
t.Fatalf("took %v, err %v", took, err)
|
|
}
|
|
if cfg := read(); cfg != config {
|
|
t.Fatalf("the user's own config changed:\n%s", cfg)
|
|
}
|
|
}
|