Codex wired by its profile alone (codex -p magpie) kept offering the models of a provider that was deleted. The profile's model was one of that provider's, so it no longer resolved as a magpie model, wired() was false, and the profile's Sync returned before it wrote magpie-models.json again. The old list stayed, new providers' models never reached it. The Sync now writes the list again whenever the profile names magpie as provider and its list, even when the model it was set to is gone. All-of-Codex scope already did this (asProvider and ownCatalog), as did the models_cache.json staling. Found by syncing a sandbox HOME in both scopes after a provider edit and a provider delete: only profile scope plus delete left the old list. TestCodexProfileListDropsADeletedProvider is red on the old code (listed added/m2 and added/m3 after the delete) and green now. Run on mote: internal/agent package, go vet darwin, linux nogui, windows. Not tried: a real Codex CLI reading the list; the viaBase models_cache.json path (covered by existing tests, not changed).
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
package agent
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// Codex wired by its profile alone (codex -p magpie) keeps offering the
|
|
// models of a provider that was deleted: the profile's model was one of
|
|
// that provider's, so it no longer counted as magpie's and the sync left
|
|
// magpie-models.json as it was (JNDliuliuM on X).
|
|
func TestCodexProfileListDropsADeletedProvider(t *testing.T) {
|
|
home := syncHome(t)
|
|
stash(map[string]string{codexScopeKey: "profile"})
|
|
if err := provider.Save(provider.Provider{ID: "added", Name: "Added", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m2", "m3"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := provider.Save(provider.Provider{ID: "kept", Name: "Kept", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"k1"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := codex(home).Fields[0].Set("added/m2"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
list := filepath.Join(home, ".codex", "magpie-models.json")
|
|
if !strings.Contains(readFile(list), "added/m3") {
|
|
t.Fatalf("not listed to begin with:\n%s", readFile(list))
|
|
}
|
|
if err := provider.Delete("added"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
SyncCatalog()
|
|
got := readFile(list)
|
|
if strings.Contains(got, "added/") {
|
|
t.Errorf("the deleted provider's models are still listed:\n%s", got)
|
|
}
|
|
if !strings.Contains(got, "kept/k1") {
|
|
t.Errorf("the list was not written again:\n%s", got)
|
|
}
|
|
}
|