Files
magpie/internal/agent/codex_beside_threads_test.go
T
yetone 387b386c84 codex: threads of the provider an older beside wiring took down move to OpenAI (yikelizi9438 on Discord)
yikelizi9438 (Windows, the Codex app): models wouldn't load, "This chat
uses custom, but your current provider is openai. Switch to custom to
continue", and "Model unavailable" in the composer. "custom" is CC
Switch's provider id; magpie never names one so. Before #4347
(e02bc8c49, v0.1.2652) a magpie model picked beside the ChatGPT sign-in
took the user's model_provider down, kept in stash codex.provider for
the Disconnect, leaving Codex on OpenAI by openai_base_url. Codex 0.166
resumes a thread only on the provider it is on now
(modelProviderMismatch), so every thread started on custom was refused.
#4347 stopped new configs reaching that state, and d6e3a36ff moves such
threads only when magpie is Codex's provider, so a config already left
so stayed broken after the update.

Now Sync's bringBeside: with Codex on OpenAI routed by the base URL, no
top-level model_provider, and a provider of the user's in the stash
(not openai, magpie, cc-switch-official or a CC Switch OpenAI mirror,
none a profile names), that provider's threads move to openai as
bringOver moves them onto magpie: in place at OpenAI's length, the last
30 days rewritten with a copy kept otherwise. The ids moved are kept
(codex.brought). The Disconnect, which puts the provider back, returns
exactly those (sessions.MoveCodexThreadIDs, only ones still on openai);
OpenAI's own threads stay. If magpie becomes Codex's provider instead,
they go on to magpie (followBeside), where bringBack returns them at the
Disconnect. A reset forgets the record (Codex stays on OpenAI).

Run: TestCodexBesideBringsTakenProvidersThreads red on origin/main
f280b12e5 ("thread ... on \"custom\", want \"openai\""), green here
(mote-run). Broken by hand: with Unwire's giveBeside("") commented out
the test goes red at the Disconnect ("on \"openai\", want \"custom\"").
mote-run: gofmt -l clean; GOOS=windows and GOOS=linux go vet -tags nogui
of internal/agent and internal/sessions; go test -tags nogui
./internal/agent/ ./internal/sessions/ ./internal/gui/ ok (agent 282s, sessions 31s, gui 95s).
win-run (xiaomi-gpu): TestCodexBeside|TestCodexThreads|
TestMoveRecentCodexThreads|TestMovePackedCodexThreads ok.

Not tried: a real Windows Codex app with the reporter's config (their
magpie version and config.toml are unknown; if CC Switch itself switched
them to its official card, the stash has no provider and nothing moves:
the Sessions page's "Move to openai" does it by hand). The followBeside
path has no test of its own.
2026-11-04 23:16:23 +08:00

68 lines
2.7 KiB
Go

package agent
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/yetone/magpie/internal/edit"
)
// yikelizi9438 on Discord (Windows, the Codex app): "This chat uses
// custom, but your current provider is openai. Switch to custom to
// continue", and "Model unavailable" in the composer. Before #4347
// (v0.1.2652) a magpie model picked beside the ChatGPT sign-in took the
// user's model_provider (CC Switch's "custom") down, keeping it in the
// stash for the Disconnect: Codex went on OpenAI by the base URL, and
// every thread started on custom was refused. Nothing moved them, as
// bringOver moves a provider's threads only onto magpie as Codex's
// provider. Now, beside the sign-in with the user's provider in the
// stash and gone from the top, its threads move to OpenAI, where Codex
// resumes them through magpie, and back to it at the Disconnect, which
// puts the provider back; OpenAI's own threads stay on OpenAI.
func TestCodexBesideBringsTakenProvidersThreads(t *testing.T) {
const (
theirs = "019a0000-0000-7000-8000-0000000000d1"
own = "019a0000-0000-7000-8000-0000000000d2"
)
home, read := codexHome(t, chatGPTAuth, "")
dir := filepath.Join(home, ".codex")
cfgPath := filepath.Join(dir, "config.toml")
// config.toml as the beside wiring before #4347 left it
cfg := "model = \"fake/m1\"\nopenai_base_url = \"" + here(home).codexURL() + "\"\n\n" +
"[model_providers.custom]\nname = \"custom\"\nbase_url = \"https://relay.example/v1\"\nwire_api = \"responses\"\n"
if err := edit.WriteAtomic(cfgPath, []byte(cfg)); err != nil {
t.Fatal(err)
}
stash(map[string]string{"codex.provider": "custom", "codex.model": "gpt-5.5", "codex.beside": "1"})
theirsPath := codexThreadOn(t, dir, theirs, "custom")
codexThreadOn(t, dir, own, "openai")
cx := codex(home)
if err := cx.Sync(); err != nil {
t.Fatal(err)
}
if p, _ := edit.GetTOMLTop(cfgPath, "model_provider"); p != "" {
t.Fatalf("model_provider %q after a sync, want Codex left on OpenAI beside its sign-in:\n%s", p, read())
}
for id, want := range map[string]string{theirs: "openai", own: "openai"} {
if p := codexRowOn(t, dir, id); p != want {
t.Errorf("synced: thread %s on %q, want %q", id, p, want)
}
}
if err := cx.Unwire(); err != nil {
t.Fatal(err)
}
if p, _ := edit.GetTOMLTop(cfgPath, "model_provider"); p != "custom" {
t.Fatalf("model_provider %q after the Disconnect, want custom back:\n%s", p, read())
}
for id, want := range map[string]string{theirs: "custom", own: "openai"} {
if p := codexRowOn(t, dir, id); p != want {
t.Errorf("disconnected: thread %s on %q, want %q", id, p, want)
}
}
if b, _ := os.ReadFile(theirsPath); !strings.Contains(string(b), `"model_provider":"custom"`) {
t.Fatalf("rollout not back on custom:\n%s", b)
}
}