d96403141 added "Test on account…" to a model chip's right-click, shown
when the provider row has testPicks, and added provider.TestPicks. The
row the GUI is sent (providerJSON in internal/gui/providers.go) never set
the field, so the entry never showed for any provider: tmr11235's ChatGPT
API with two ChatGPT sign-ins on v0.1.3884 has only Test this model, Copy
model ID and the image toggle. The GUI test fed a hand-made testPicks and
the provider tests called TestPicks directly, so nothing joined them.
providerJSON now carries TestPicks (p.TestPicks()).
Account kinds checked (TestPicks reads AccountsOn for any signed-in
provider, KeyList otherwise): API keys (first key and saved keys, off ones
left out); signed-in accounts and their also-on accounts of every sign-in
that AlsoOn lists: ChatGPT API's ChatGPT sign-ins, Codex and Claude logins,
Copilot, Gemini and Antigravity, plugin accounts. Read, not each signed in:
only keys are run as a row (new test); plugin accounts are covered by
TestModelTestPinnedToAnAccount; the ChatGPT API shape is in the GUI test.
Run on mote (load ~107 at the time, mica 128): go test ./internal/gui
./internal/provider ok; model-test-account (now with a ChatGPT API
provider with two accounts) and i18n-keys 14 of 14, chromium and webkit,
en zh zh-TW ja de; gofmt clean; go vet darwin, windows, linux nogui.
Broken by hand: with TestPicks left out of the row,
TestProviderInfoSaysTestPicks fails ("two keys on: testPicks []").
Not tried: the live app with two real ChatGPT sign-ins. The GUI test serves
a fixed /api/providers, so it is not red on the old code; the Go row test
is the guard. The other model-* and provider-* GUI files not rerun (a Go
field the page already reads).
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// tmr11235 on X: "Test on account…" was in the GUI and the provider
|
|
// package, but the row the GUI is sent never carried testPicks, so a
|
|
// provider with two accounts or keys on offered no such entry. The row
|
|
// says the picks, and says none for a provider with one.
|
|
func TestProviderInfoSaysTestPicks(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
|
|
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
|
|
row := func(p provider.Provider) map[string]any {
|
|
t.Helper()
|
|
b, err := json.Marshal(providerInfo(p, nil))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var m map[string]any
|
|
if err := json.Unmarshal(b, &m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return m
|
|
}
|
|
two := provider.Provider{ID: "relay", Name: "Relay", Chat: "http://127.0.0.1:1/v1", Key: "sk-a", KeyName: "first",
|
|
Keys: []provider.KeyAccount{{Name: "second", Key: "sk-b"}, {Name: "off", Key: "sk-c", Off: true}}}
|
|
picks, _ := row(two)["testPicks"].([]any)
|
|
if len(picks) != 2 {
|
|
t.Fatalf("two keys on: testPicks %v", picks)
|
|
}
|
|
one := provider.Provider{ID: "solo", Name: "Solo", Chat: "http://127.0.0.1:1/v1", Key: "sk-a"}
|
|
if _, ok := row(one)["testPicks"]; ok {
|
|
t.Fatal("one key: testPicks sent")
|
|
}
|
|
}
|