agent: Codex thread tables are written only for ids magpie can own
JsonParser (X) found [model_providers.openai_token_sharing] in
~/.codex/config.toml, written by magpie, and Codex refusing to start:
"provider auth cannot be combined with experimental_bearer_token". The
id is T3 Code's: T3 starts Codex with -c model_providers.
openai_token_sharing={..., auth={command=...}}, its threads name that
id, and putThreadTables (#1372) wrote a magpie table (name, base_url,
wire_api, experimental_bearer_token) for every provider a thread named
that config.toml lacked. Codex merges T3's -c over it, and the merged
table has both auth and a bearer token.
putThreadTables now writes a table only for a CC Switch id
(ccSwitchProvider) or an id config.toml itself once held, recorded per
Codex home in the stash (codex.filed_tables) whenever magpie reads the
file. A table an older magpie wrote for any other id, recognised by its
exact shape (four keys, name == id, wire_api responses, magpie's own
gateway key), is taken out at Sync, at Disconnect (uninstall and quit
restore) and in TakeLeftovers, unless a profile or model_provider names
it or it has sub-tables. The user's own tables, other apps' tables and
tables with any other key are left alone.
Known tradeoff: a magpie-written table for a card-named CC Switch id
that config.toml lost before this release, and magpie never recorded,
is removed once and not written again. CC Switch's own ids still are.
Run (mote): go test ./internal/agent -count=1 -timeout 45m ok (421s);
gofmt -l clean; go vet ./internal/agent for darwin, linux and windows
ok. Real codex 0.165.0 in a sandbox CODEX_HOME: magpie's stray table
plus T3's -c override reproduces the exact error; without the table
Codex loads.
Tests: TestCodexLeavesOtherAppsProviders (threads name
openai_token_sharing, custom and a relay config.toml once held: no table
for T3's id, the other two written back), TestCodexDropsStrayThreadTables
(wired and unwired; another app's table, a profile-named one and the
user's own key stay), TestCodexSyncDropsStrayThreadTable.
Broken by hand: without the threadTableFor guard and the tidy calls,
TestCodexLeavesOtherAppsProviders and TestCodexDropsStrayThreadTables
went red; without only the Disconnect tidy, TestCodexDropsStrayThreadTables
went red; without only the Sync tidy, TestCodexSyncDropsStrayThreadTable
went red.
Not tried: the TakeLeftovers tidy was not broken by hand on its own;
T3 Code itself was not run, only codex with its -c override.
This commit is contained in:
@@ -21,7 +21,7 @@ something else shows up as drift.
|
||||
| What came before | The stash (`stash.json`) remembers what the config said before magpie pointed it at the gateway, so Disconnect restores it rather than guessing. | [`stash.go`](../../internal/agent/stash.go) |
|
||||
| Restore on quit | By default a connected agent keeps magpie as the app quits. With Settings › General › Put agents back when quitting on, `RestoreOnQuit` runs `Disconnect` on each agent that is `Wired` and not `Disconnected()`, drops the `.disconnected` mark that Disconnect left, and stashes the ids (`quit.restored`); `RewireOnStart` connects those again at the next start, once, skipping any the user disconnected or connected since. See the gui-shell page, "A Quit asks while agents go through magpie". | [`quitrestore.go`](../../internal/agent/quitrestore.go) |
|
||||
| Disconnect and preview | `Disconnect` runs `Unwire`, then returns each field still on magpie to its default. Last it runs `Restore`: Pi and its kin (`piLike`: Pi, OmO, Prime Agent, mu; and MothX, its one `settings.json`) copy `settings.json` and `models.json` aside (`*.before-magpie`, `beforeMagpie`) before magpie's first write, and put that copy back byte for byte where what Disconnect left is the same JSON; a file that wasn't there goes again when only empty objects are left in it. `DisconnectPreview` runs the real Disconnect on a copy under a temporary home, in a subprocess (`DryRunArg`), and diffs the files. The preview is never a second account of what Disconnect does. | [`applied.go`](../../internal/agent/applied.go), [`preview.go`](../../internal/agent/preview.go) |
|
||||
| Uninstall | `magpie uninstall` and Settings › About › Uninstall magpie take magpie off this computer, because deleting magpie's folders by hand left Codex's `openai_base_url` on a gateway that was gone, and every turn failed with a 502 (Jevik_AI on X). `Run` goes in this order. `System` removes the service, opening at login, the Start menu shortcut, `magpie://` links and the privacy model's helper. `Agents` ends Codex's account failover, runs each connected agent's `Disconnect`, or its offline disconnect for a closed app, so the restore keeps what the user changed by hand since. It then takes Codex's leftovers (`TakeCodexLeftovers`): an `openai_base_url` at magpie's gateway, or magpie as Codex's provider, goes by the gates a Disconnect uses even when magpie's notes are gone and Codex reads as not connected (#3866); magpie's provider table stays for the threads that name it. It then ports Codex's rollouts and restarts the Codex app's app-server. `Data` deletes magpie's folders, but keeps the Library while it holds skills, servers or hooks. The executable stays where the user put it. The CLI refuses while another magpie runs, and asks first unless given `--yes`. On Windows magpie is listed in Settings › Apps › Installed apps: `shortcut.Ensure` writes `HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\magpie` at every installed start, and `System` takes it out with the Start menu shortcut. Its Uninstall runs `magpie uninstall --window` with no console, which opens the app's window (or the running app's) on Settings › About with the question asked (`uninstallView`, `shortcut.UninstallArgs`). Deleting the app by hand still runs no code. The app runs `System` and `Agents` from `POST /api/uninstall`. If anything failed, nothing else is removed. Otherwise `POST /api/uninstall/finish` starts a detached `magpie uninstall --data-after <pid>`, which deletes the files once the app has quit, since WebView2 holds its folder open until then. magpie web refuses both routes (`TestUninstall*`, `uninstall-settings.test.cjs`). Every line magpie writes into a TOML, YAML or env config has a `# magpie:` note above it saying how to undo it, so a config left behind still names magpie (`edit.Mark`, `TestMarkedLinesEveryAgent`). | [`uninstall.go`](../../internal/uninstall/uninstall.go), [`uninstall_cli.go`](../../internal/cli/uninstall_cli.go), [`gui/uninstall.go`](../../internal/gui/uninstall.go) |
|
||||
| Uninstall | `magpie uninstall` and Settings › About › Uninstall magpie take magpie off this computer, because deleting magpie's folders by hand left Codex's `openai_base_url` on a gateway that was gone, and every turn failed with a 502 (Jevik_AI on X). `Run` goes in this order. `System` removes the service, opening at login, the Start menu shortcut, `magpie://` links and the privacy model's helper. `Agents` ends Codex's account failover, runs each connected agent's `Disconnect`, or its offline disconnect for a closed app, so the restore keeps what the user changed by hand since. It then takes Codex's leftovers (`TakeCodexLeftovers`): an `openai_base_url` at magpie's gateway, or magpie as Codex's provider, goes by the gates a Disconnect uses even when magpie's notes are gone and Codex reads as not connected (#3866); magpie's provider table stays for the threads that name it. A table magpie writes for a provider a Codex thread names that config.toml lost (`putThreadTables`, #1372) is written only for CC Switch's ids and an id config.toml has had a table of (stash `codex.filed_tables`): another app can give Codex a provider on its command line (T3 Code's `openai_token_sharing` with `auth = {command}`), and magpie's table merged with it made Codex refuse its config ("provider auth cannot be combined with experimental_bearer_token"). One an older magpie wrote so goes at a Sync, a Disconnect and here (`tidyTables`, `TestCodexLeavesOtherAppsProviders`, `TestCodexDropsStrayThreadTables`). It then ports Codex's rollouts and restarts the Codex app's app-server. `Data` deletes magpie's folders, but keeps the Library while it holds skills, servers or hooks. The executable stays where the user put it. The CLI refuses while another magpie runs, and asks first unless given `--yes`. On Windows magpie is listed in Settings › Apps › Installed apps: `shortcut.Ensure` writes `HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\magpie` at every installed start, and `System` takes it out with the Start menu shortcut. Its Uninstall runs `magpie uninstall --window` with no console, which opens the app's window (or the running app's) on Settings › About with the question asked (`uninstallView`, `shortcut.UninstallArgs`). Deleting the app by hand still runs no code. The app runs `System` and `Agents` from `POST /api/uninstall`. If anything failed, nothing else is removed. Otherwise `POST /api/uninstall/finish` starts a detached `magpie uninstall --data-after <pid>`, which deletes the files once the app has quit, since WebView2 holds its folder open until then. magpie web refuses both routes (`TestUninstall*`, `uninstall-settings.test.cjs`). Every line magpie writes into a TOML, YAML or env config has a `# magpie:` note above it saying how to undo it, so a config left behind still names magpie (`edit.Mark`, `TestMarkedLinesEveryAgent`). | [`uninstall.go`](../../internal/uninstall/uninstall.go), [`uninstall_cli.go`](../../internal/cli/uninstall_cli.go), [`gui/uninstall.go`](../../internal/gui/uninstall.go) |
|
||||
| Keeping configs current | `Reseat` moves agents off a model magpie no longer serves (#200). `OnGateway` and `Rewire` write the new gateway address into every connected agent when the port changes. `Source` and `Stale` say what an unconnected agent runs on, and whether running copies still use the old list. For Codex that is where its config sends it and which models its lists hold (`listedModels`, slug and visibility), not every byte of each entry: the Codex app's list carries the ChatGPT backend's entries as sent, asked for each hour, and a rewrite with the same models told the user to reopen the app several times a day (Qyburn3 on X). A digest an older magpie stashed over the same files is kept (`readsBefore`). | [`reseat.go`](../../internal/agent/reseat.go), [`rewire.go`](../../internal/agent/rewire.go), [`connectinfo.go`](../../internal/agent/connectinfo.go) |
|
||||
| Restarting a desktop app | Claude Desktop, WorkBuddy (WorkBuddy AI on macOS), OpenMausBot and ZCode (`ZCode.app`, `ZCode.exe`; `zcodePart`: magpie's provider without its key and magpie's rules in `provider_config.json`, Flandern1211 on X, #5662) read magpie's settings only as they start (微雨南山 and stones on Discord). `AppBehind` names one running here that started more than a second before magpie last changed what it reads (`changedAt`, which puts a change no file's time shows, such as Claude Desktop's gateway model list, at when it is first seen); only for an agent connected in magpie or disconnected in it. The row's Restart asks first in magpie's own dialog (`confirmRestart`), then `POST /api/agents/restart/{id}` runs `RestartApp`. On macOS (`restartApps`, the bundle found by id under `appFolders`, its `CFBundleExecutable` matched in `pgrep`) it quits as ⌘Q does and waits for every process of the bundle (`reopenBundle`), but a script run on the app's own executable (`runsScript`: a `.js` argument or an absolute path as its first argument), which the running check skips too. WorkBuddy starts its sidecar (`sidecar-entry.js`) and its `codebuddy` CLIs that way, detached; the sidecar outlives a quit, so counting it kept the row behind after every restart and made Restart wait it out and never open the app (Northes on Discord, 11-04, #3700). On Windows the same check reads each process's command line (`proc.CommandLine`); one still open after `appQuitWait` (a "Save?" question) is left as it is and not opened again (`noticeRestartStillOpen`). On Windows (`claude.exe` under `AnthropicClaude` or its Store package, `WorkBuddy.exe` outside the WorkBuddy AI folder) its processes are asked to close (`taskkill` without `/F`); one that has hidden every window and still runs after `appTrayGrace` (1s) is in the tray and has its tree ended at once (`waitClosed`, `winShown`: Claude Desktop hides its window in ~0.6s and keeps all its processes, so waiting the whole `appCloseWait` made a Restart ~12s where quitting by hand takes ~2s, CyberCaius on Discord, 10-29); one still showing a window (a question) gets `appCloseWait` before it is ended, and it is opened again through its Store id or Squirrel's stub. The Codex app's own Restart (`ReopenCodexApp`) asks first too, then ends only the app-server that app runs for itself (`provider.RestartCodexApp`: under its bundle, never a `--listen` one), as a switch does; the app starts another and keeps its window. Quitting and opening it, as before, opened a new window (yoshi037070 on Discord, 10-27). Codex on Windows, WorkBuddy AI on Windows and Linux aren't restarted: their process names aren't known. | [`apprestart.go`](../../internal/agent/apprestart.go), [`apprestart_windows.go`](../../internal/agent/apprestart_windows.go), [`connectinfo.go`](../../internal/agent/connectinfo.go) |
|
||||
| Codex background compaction | Long conversations' Codex background compaction, in Codex's opened row on the Agents page (`CodexAsyncCompact`, `CodexAsyncCompactPercent`, #2490) writes `[features.async_compaction]` `enabled = true` and `model_async_compact_threshold_percent` (Codex 0.163 reads it only in that table) into each Codex config magpie routes, on every `Sync`. The table is written only when every Codex that reads the config is 0.163.0-alpha.8 or later (`codexReaders`: the CLI on PATH, the Mac app's bundled `codex-cli/codex-package.json`, the Windows Store app and an editor's `openai.chatgpt` extension, whose versions aren't known, a WSL distro's CLI): an older Codex takes every unknown `[features]` entry for a bool and won't load a config with the table ("invalid type: map, expected a boolean"). Otherwise, or with no Codex found, magpie writes the bare `[features]` `async_compaction = true`, which every Codex loads, and no threshold; a table magpie wrote before is taken out on the next `Sync`, and Settings' row names the Codex that held it (`CodexAsyncHeld`). Codex starts a background compaction only on a provider whose `capabilities.remote_compaction` is `"v2"`, which it gives OpenAI and Azure alone, so `[model_providers.magpie]` gets `capabilities = { remote_compaction = "v2" }` too, also when the user turned the feature on by hand (#2493); `putProvider` carries the table's capabilities over when it writes it again. What magpie wrote is in the stash under `codex.async`: a value the user set, or changed since, is never written over and stays when the switch goes off; a bare `async_compaction = true` the stash doesn't name as magpie's (`bool`), an inline or dotted table is the user's as written. | [`codex_async.go`](../../internal/agent/codex_async.go) |
|
||||
|
||||
+110
-2
@@ -1123,6 +1123,80 @@ func codexIn(at place) *Agent {
|
||||
}
|
||||
return out
|
||||
}
|
||||
// filedTables is the provider ids config.toml has had a table of
|
||||
// that magpie didn't write (noteTables), kept in the stash
|
||||
filedTables := func() []string {
|
||||
var ids []string
|
||||
json.Unmarshal([]byte(stashShared()[at.key("codex.filed_tables")]), &ids)
|
||||
return ids
|
||||
}
|
||||
// noteTables records the provider tables config.toml has now that
|
||||
// aren't putThreadTables', for putThreadTables to tell a table that
|
||||
// was in the file and is gone from one that never was
|
||||
noteTables := func(providers map[string]any) {
|
||||
ids := filedTables()
|
||||
n := len(ids)
|
||||
for id, v := range providers {
|
||||
if id == magpieID || codexBuiltinProvider[id] || codexThreadTableOurs(id, v) || slices.Contains(ids, id) {
|
||||
continue
|
||||
}
|
||||
ids = append(ids, id)
|
||||
}
|
||||
if len(ids) == n {
|
||||
return
|
||||
}
|
||||
slices.Sort(ids)
|
||||
b, _ := json.Marshal(ids)
|
||||
stash(map[string]string{at.key("codex.filed_tables"): string(b)})
|
||||
}
|
||||
// threadTableFor says whether putThreadTables may write a table for
|
||||
// the provider id a thread names: CC Switch's own ids, and one
|
||||
// config.toml had a table of. Another app can start Codex with a
|
||||
// provider of its own on the command line (T3 Code's
|
||||
// openai_token_sharing, `-c model_providers.openai_token_sharing=
|
||||
// {…, auth = {command = …}}`), and its threads name that id while
|
||||
// config.toml never had it. A table magpie wrote for it was merged
|
||||
// with the app's -c one, and Codex refused the config: "provider auth
|
||||
// cannot be combined with experimental_bearer_token" (JsonParser on
|
||||
// X). Such an id is the app's, never magpie's to write.
|
||||
threadTableFor := func(id string) bool {
|
||||
return ccSwitchProvider.MatchString(id) || slices.Contains(filedTables(), id)
|
||||
}
|
||||
// dropStrayTables takes out a table putThreadTables wrote, by an
|
||||
// older magpie, for an id threadTableFor no longer gives one: as
|
||||
// written, with magpie's key, nothing of the user's in it
|
||||
dropStrayTables := func(providers map[string]any) error {
|
||||
names, _ := edit.TOMLTables(path)
|
||||
named := profileNamed(names)
|
||||
for id, v := range providers {
|
||||
// one Codex or a profile is on is the user's, however made
|
||||
if threadTableFor(id) || !codexThreadTableOurs(id, v) || !slices.Contains(names, "model_providers."+id) || named[id] || get("model_provider") == id {
|
||||
continue
|
||||
}
|
||||
if slices.ContainsFunc(names, func(n string) bool { return strings.HasPrefix(n, "model_providers."+id+".") }) {
|
||||
continue
|
||||
}
|
||||
if err := edit.DelTOMLTable(path, "model_providers."+id); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf("codex: took out [model_providers.%s], written by an older magpie for threads another app starts on its own provider", id)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// tidyTables notes config.toml's provider tables and drops the stray
|
||||
// ones; a config that doesn't parse is left alone
|
||||
tidyTables := func() error {
|
||||
doc, err := codexTopOf(path)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
providers, _ := doc.ModelProviders.(map[string]any)
|
||||
if len(providers) == 0 {
|
||||
return nil
|
||||
}
|
||||
noteTables(providers)
|
||||
return dropStrayTables(providers)
|
||||
}
|
||||
// putThreadTables writes a table for each provider a Codex thread was
|
||||
// started on that config.toml has none of, pointed at magpie. The
|
||||
// Codex app resumes a thread on its own provider, and without that
|
||||
@@ -1130,8 +1204,13 @@ func codexIn(at place) *Agent {
|
||||
// a thread started through CC Switch reopened after CC Switch rewrote
|
||||
// config.toml without its table (#1372). Codex's built-in providers
|
||||
// need none, and magpie's own is putProvider's. A table written so
|
||||
// stays, as magpie's own does, for the threads that name it.
|
||||
// stays, as magpie's own does, for the threads that name it. Only for
|
||||
// a table config.toml lost (threadTableFor): an id another app gives
|
||||
// Codex on its command line is that app's.
|
||||
putThreadTables := func() error {
|
||||
if err := tidyTables(); err != nil {
|
||||
return err
|
||||
}
|
||||
// the providers config.toml has, however spelled (a table, inline,
|
||||
// dotted keys); one that doesn't parse is left alone
|
||||
doc, err := codexTopOf(path)
|
||||
@@ -1143,7 +1222,7 @@ func codexIn(at place) *Agent {
|
||||
return nil
|
||||
}
|
||||
for _, id := range sessions.CodexThreadProviders(dir) {
|
||||
if _, ok := providers[id]; ok || id == magpieID || codexBuiltinProvider[id] {
|
||||
if _, ok := providers[id]; ok || id == magpieID || codexBuiltinProvider[id] || !threadTableFor(id) {
|
||||
continue
|
||||
}
|
||||
if err := edit.SetTOMLTable(path, "model_providers."+id,
|
||||
@@ -1661,6 +1740,11 @@ func codexIn(at place) *Agent {
|
||||
}
|
||||
set := func(v string) error {
|
||||
if v == "" {
|
||||
// a stray table of an older magpie's goes with a Disconnect
|
||||
// too, an uninstall's or a quit's: no Sync may come after
|
||||
if err := tidyTables(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := dropSubagent(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1938,6 +2022,10 @@ func codexIn(at place) *Agent {
|
||||
// itself goes, by the same gates a Disconnect takes them by
|
||||
TakeLeftovers: func() (bool, error) {
|
||||
took := false
|
||||
// a table an older magpie wrote for another app's provider
|
||||
if err := tidyTables(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if viaBase() {
|
||||
if err := dropBase(); err != nil {
|
||||
return false, err
|
||||
@@ -1960,6 +2048,11 @@ func codexIn(at place) *Agent {
|
||||
return ""
|
||||
},
|
||||
Sync: func() error {
|
||||
// a table an older magpie wrote for another app's provider
|
||||
// goes, wired or not: Codex refuses its config with it
|
||||
if err := tidyTables(); err != nil {
|
||||
return err
|
||||
}
|
||||
// after the sync, which may have put Codex back beside its
|
||||
// sign-in or made magpie its provider, and whatever it failed at
|
||||
defer lendOwn()
|
||||
@@ -2481,6 +2574,21 @@ const packedSince = 30 * 24 * time.Hour
|
||||
|
||||
var packedBudget int64 = 128 << 20
|
||||
|
||||
// codexThreadTableOurs says whether config.toml's provider id, decoded as
|
||||
// v, is the table putThreadTables writes: name, base_url, wire_api
|
||||
// "responses" and magpie's key, and nothing else.
|
||||
func codexThreadTableOurs(id string, v any) bool {
|
||||
t, ok := v.(map[string]any)
|
||||
if !ok || len(t) != 4 {
|
||||
return false
|
||||
}
|
||||
name, _ := t["name"].(string)
|
||||
wire, _ := t["wire_api"].(string)
|
||||
key, _ := t["experimental_bearer_token"].(string)
|
||||
_, url := t["base_url"].(string)
|
||||
return name == id && wire == "responses" && url && ourKey(key)
|
||||
}
|
||||
|
||||
// ccSwitchProvider matches the ids of the provider tables CC Switch writes
|
||||
// into Codex's config: "custom", and "cc-switch", "cc-switch-2"… from its
|
||||
// older versions. Its "cc-switch-official" is its own proxy to OpenAI.
|
||||
|
||||
@@ -164,3 +164,112 @@ func TestCodexTakesThreadTables(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// JsonParser on X: T3 Code starts Codex with a provider of its own on the
|
||||
// command line (`-c model_providers.openai_token_sharing={…, auth =
|
||||
// {command = …}}`), so its threads name openai_token_sharing while
|
||||
// config.toml never had that table. magpie wrote one for them, pointed at
|
||||
// itself with experimental_bearer_token, Codex merged it with T3's -c, and
|
||||
// refused the whole config: "model_providers.openai_token_sharing: provider
|
||||
// auth cannot be combined with experimental_bearer_token". An id
|
||||
// config.toml never had is the other app's: magpie writes no table for it,
|
||||
// and takes out the one an older magpie wrote, wired or not. CC Switch's
|
||||
// ids, and a table of the user's that config.toml lost, are still written
|
||||
// (#1372).
|
||||
func TestCodexLeavesOtherAppsProviders(t *testing.T) {
|
||||
for _, auth := range []string{`{"tokens":{"access_token":"x","id_token":"x.e30.x"}}`, ""} {
|
||||
conf := "model = \"gpt-5.4\"\n\n" +
|
||||
"[model_providers.relay]\nname = \"relay\"\nbase_url = \"https://relay.example/v1\"\nexperimental_bearer_token = \"sk-relay\"\n"
|
||||
home, read := codexHome(t, auth, conf)
|
||||
dir := filepath.Join(home, ".codex")
|
||||
codexThreads(t, dir, "openai_token_sharing", "custom", "relay")
|
||||
path := filepath.Join(dir, "config.toml")
|
||||
cx := codex(home)
|
||||
// seen once, then lost, as CC Switch's rewrite loses a table
|
||||
if err := cx.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := edit.DelTOMLTable(path, "model_providers.relay"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := cx.Fields[0].Set("fake/m1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := cx.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(read(), "openai_token_sharing") {
|
||||
t.Fatalf("auth %q: wrote another app's provider:\n%s", auth, read())
|
||||
}
|
||||
v1 := here(home).v1()
|
||||
for _, id := range []string{"custom", "relay"} {
|
||||
if tb, _ := edit.GetTOMLTable(path, "model_providers."+id); tb["base_url"] != v1 {
|
||||
t.Fatalf("auth %q: %s's table not written back:\n%s", auth, id, read())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The table an older magpie wrote for T3 Code's provider is taken out at
|
||||
// the next sync or Disconnect, connected or not; one the user made, one with keys of
|
||||
// theirs added, and one Codex is on stay.
|
||||
func TestCodexDropsStrayThreadTables(t *testing.T) {
|
||||
for _, wire := range []bool{true, false} {
|
||||
home, read := codexHome(t, "", "model = \"gpt-5.4\"\n")
|
||||
dir := filepath.Join(home, ".codex")
|
||||
codexThreads(t, dir, "openai_token_sharing", "other_app", "kept")
|
||||
path := filepath.Join(dir, "config.toml")
|
||||
cx := codex(home)
|
||||
if wire {
|
||||
if err := cx.Fields[0].Set("fake/m1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
at := here(home)
|
||||
stray := func(id string) string {
|
||||
return "\n[model_providers." + id + "]\nname = \"" + id + "\"\nbase_url = \"" + at.v1() + "\"\nwire_api = \"responses\"\nexperimental_bearer_token = \"" + at.gwKey() + "\"\n"
|
||||
}
|
||||
raw, err := edit.Read(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conf := string(raw) + stray("openai_token_sharing") + stray("other_app") + "env_key = \"MINE\"\n" + stray("kept") +
|
||||
"\n[model_providers.mine]\nname = \"mine\"\nbase_url = \"https://mine.example/v1\"\nwire_api = \"responses\"\nexperimental_bearer_token = \"sk-mine\"\n" +
|
||||
"\n[profiles.k]\nmodel_provider = \"kept\"\n"
|
||||
if err := edit.WriteAtomic(path, []byte(conf)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// a Disconnect (an uninstall's, a quit's) with no Sync before it
|
||||
// takes it out too, wired or not
|
||||
if err := cx.Fields[0].Set(""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := read()
|
||||
if strings.Contains(got, "openai_token_sharing") {
|
||||
t.Fatalf("wired %v: stray table kept:\n%s", wire, got)
|
||||
}
|
||||
for _, id := range []string{"other_app", "kept", "mine"} {
|
||||
if !strings.Contains(got, "[model_providers."+id+"]") {
|
||||
t.Fatalf("wired %v: %s taken out:\n%s", wire, id, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The same stray table goes at the next Sync with nothing else to do.
|
||||
func TestCodexSyncDropsStrayThreadTable(t *testing.T) {
|
||||
home, read := codexHome(t, "", "model = \"gpt-5.4\"\n")
|
||||
codexThreads(t, filepath.Join(home, ".codex"), "openai_token_sharing")
|
||||
at := here(home)
|
||||
path := filepath.Join(home, ".codex", "config.toml")
|
||||
conf := "model = \"gpt-5.4\"\n\n[model_providers.openai_token_sharing]\nname = \"openai_token_sharing\"\nbase_url = \"" + at.v1() + "\"\nwire_api = \"responses\"\nexperimental_bearer_token = \"" + at.gwKey() + "\"\n"
|
||||
if err := edit.WriteAtomic(path, []byte(conf)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := codex(home).Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(read(), "openai_token_sharing") {
|
||||
t.Fatalf("\n%s", read())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user