Files
magpie/internal/agent/codex_desk_slash_test.go
T
yetone 6cc70b2b3c agent: deskCatalog cleans an absolute /-spelled path too (#4785)
Dopetaiga's 3751d6cb3 made ownCatalog clean an absolute catalog path, so
a /-spelled one names magpie's list on Windows. deskCatalog, the same
predicate for the Codex app's list, still joined dir onto an absolute
path and never matched one. With the app gone, Sync left
model_catalog_json naming a list it had removed. It now has the same
shape; the WSL spelling keeps its branch.

Run on Windows 11 (xiaomi-gpu, win-run, -tags nogui):
TestCodexSyncMendsGoneCatalog, TestCodexDesktopListSlashSpelled (new),
TestCodexOwnCatalogGoneNotPutBack and TestCodexDesktopList.* are ok at
this tree. With main's codex.go, not_the_provider and the new test are
red. With 3751d6cb3's codex.go (ownCatalog fixed, deskCatalog not), only
the new test is red. On macOS the bug is not visible (/ is the native
spelling there).

Batch record (ggbdpq's five patches #3254 #3356 #4258 #6391 #4785 and
the two follow-ups), on mica through suite.lock:
- At 8c58d9b0b (base 7b002b6be): gofmt -l clean; go vet ./... on darwin,
  windows and linux (nogui) ok; builds ok;
  go test -tags nogui -count=1 -timeout 45m ./... exit 0, 99 packages ok.
- Rebased onto 27c998aba (12 commits, no file in common) at 0806a4fe8:
  vet on all three OSes ok, and internal/agent, internal/provider and
  internal/davsync are ok. Rebased again onto aba6aeac2 (a provider
  balance-history commit, no file in common): at this tree, go vet
  ./internal/... (plus windows for agent, provider and davsync) is ok,
  and internal/provider, internal/agent and internal/davsync are ok.
- Ablations: each new test is red with its product file reverted to main.
  The Windows ones ran on xiaomi-gpu.
Not tried: a real two-process forget, and a real WebDAV server.
2026-11-14 13:14:36 +08:00

51 lines
1.6 KiB
Go

package agent
import (
"os"
"path/filepath"
"strings"
"testing"
)
// #4785's sibling: the Codex app's list named by an absolute path spelled
// with / is still magpie's on Windows. With the app gone the list is taken
// out, and the key naming it goes with it, or Codex loads no config.
func TestCodexDesktopListSlashSpelled(t *testing.T) {
home, read := codexHome(t, `{"tokens":{"access_token":"x","id_token":"x.e30.x"}}`, `model = "gpt-5.5"`+"\n")
cfgPath := filepath.Join(home, ".codex", "config.toml")
desk := filepath.Join(home, ".codex", "magpie-desktop-models.json")
app := true
codexAppReads(t, &app)
list := `{"models":[{"slug":"gpt-6-sol"}]}`
deskListIs(t, &list)
cx := codex(home)
if ok, err := cx.Join(); err != nil || !ok {
t.Fatalf("join: %v %v", ok, err)
}
cfg := read()
if !strings.Contains(cfg, "magpie-desktop-models.json") {
t.Fatalf("the app installed:\n%s", cfg)
}
// as an older magpie, or the user, spelled it: absolute, with /
var out []string
for _, l := range strings.Split(cfg, "\n") {
if strings.HasPrefix(l, "model_catalog_json") {
l = `model_catalog_json = "` + filepath.ToSlash(desk) + `"`
}
out = append(out, l)
}
if err := os.WriteFile(cfgPath, []byte(strings.Join(out, "\n")), 0o644); err != nil {
t.Fatal(err)
}
app = false
if err := cx.Sync(); err != nil {
t.Fatal(err)
}
if cfg := read(); strings.Contains(cfg, "model_catalog_json") {
t.Fatalf("the app gone: the key still names magpie's list:\n%s", cfg)
}
if _, err := os.Stat(desk); !os.IsNotExist(err) {
t.Fatalf("the app gone: the list stays: %v", err)
}
}