superhtoooth (macOS): 保存方案设置了方案名字,但是应用方案没有用这个名字。
menu 里面变成了方案 1,方案 2。而且在应用里面没有显示当前使用的方案.
The bug: the tray panel's Profiles button showed the number of saved
profiles next to its label ("方案" + "2"), which reads as a profile
named 方案 2. Profiles were saved and applied under the typed name all
along; nothing anywhere said which profile was in use.
What changed:
- profile.InUse: a profile is in use while applying it would change
nothing on this computer - every detected agent's saved field is as
the profile has it (compared with the same renamed-ref spelling Apply
writes), its model lists are held (provider.ModelListsHeld, a dry run
of SetModelLists via the extracted putModelLists) and its library
setup is as saved (library.Holds, the mirror of Restore). A profile
that touches no agent here is not in use.
- Why not "last applied": that would stay ticked after the user changes
a model by hand, a tick that lies. With this definition a profile
saved from the current setup is in use at once, a hand change clears
the tick, and applying puts it back. Two identical profiles are both
ticked; the button names the first.
- GUI: /api/state carries inUse. The panel's button names the profile
in use (a pop-up button showing what is picked), else counts them as
before; its chip gets a check mark and aria-current, in panel and
window; the chip's tooltip and its details say "In use" (string
already in every language). CLI `magpie profiles` marks it, the TUI
notes "in use". Docs (reference, start en/zh/ja) say so.
What was run:
- go test ./internal/profile (new TestProfileInUse: save, hand change,
apply, hidden model list, library instructions, absent agents) and
./internal/gui (new TestStateProfileInUse through the HTTP handler),
scratch HOME. Broken by hand: field compare, ModelListsHeld,
library.Holds and state's InUse each turned a test red.
- go test -tags nogui ./... in a scratch HOME (the four slow packages
rerun with -timeout 40m under load ~45).
- GUI: new profile-in-use.test.cjs (reporter's steps in the panel at
360px, every language, plus the window) and panel-profiles,
profile-confirm, profile-details, old-webkit, i18n-keys, gui-zh-tw,
gui-ja, gui-de in chromium and webkit: all pass. Old app.js fails the
new test.
- Real CLI in a sandbox HOME with a codex config: save/use/profiles
show the mark, and it goes after a hand edit.
- gofmt; go vet darwin, linux (nogui), windows.
Not tried: the real tray app with real agents, and Windows/Linux at
runtime.
62 lines
2.0 KiB
Go
62 lines
2.0 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// The page's state says which profile is in use (superhtoooth on X: the
|
|
// panel's button read 方案 1, 方案 2, a count taken for the name, and
|
|
// nothing said which profile was in use). Through the page's own calls: a
|
|
// profile saved under a name is in use at once, another applied is, and a
|
|
// model changed by hand since leaves none in use.
|
|
func TestStateProfileInUse(t *testing.T) {
|
|
home := sandboxHome(t)
|
|
t.Setenv("CODEX_HOME", filepath.Join(home, ".codex"))
|
|
os.MkdirAll(filepath.Join(home, ".codex"), 0o755)
|
|
os.WriteFile(filepath.Join(home, ".codex", "config.toml"), []byte("model = \"relay/m1\"\n"), 0o600)
|
|
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m1", "m2"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
h := Handler(nil, nil)
|
|
call := func(path, body string) []string {
|
|
t.Helper()
|
|
rec := httptest.NewRecorder()
|
|
h.ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(body)))
|
|
if rec.Code != 200 {
|
|
t.Fatalf("%s %d %s", path, rec.Code, rec.Body)
|
|
}
|
|
var s stateJSON
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &s); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var on []string
|
|
for _, p := range s.Profiles {
|
|
if p.InUse {
|
|
on = append(on, p.Name)
|
|
}
|
|
}
|
|
return on
|
|
}
|
|
eq := func(got []string, want ...string) bool { return strings.Join(got, ",") == strings.Join(want, ",") }
|
|
|
|
if got := call("/api/profile/save", `{"name":"工作"}`); !eq(got, "工作") {
|
|
t.Fatalf("saved 工作: in use %v", got)
|
|
}
|
|
if got := call("/api/set", `{"agent":"codex","field":"model","value":"relay/m2"}`); len(got) != 0 {
|
|
t.Fatalf("model changed by hand: in use %v", got)
|
|
}
|
|
if got := call("/api/profile/save", `{"name":"游戏"}`); !eq(got, "游戏") {
|
|
t.Fatalf("saved 游戏: in use %v", got)
|
|
}
|
|
if got := call("/api/profile/use", `{"name":"工作"}`); !eq(got, "工作") {
|
|
t.Fatalf("applied 工作: in use %v", got)
|
|
}
|
|
}
|