gui: a provider's row says its accounts to test on, so "Test on account…" shows (tmr11235 on X)
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).
This commit is contained in:
@@ -294,6 +294,10 @@ type providerJSON struct {
|
||||
// (provider.TestAs), for a relay that serves only them: the chip's
|
||||
// right-click offers each, and says why one can't be when it can't
|
||||
TestsAs map[string]string `json:"testsAs,omitempty"`
|
||||
// TestPicks is the accounts or keys that are on when there are two
|
||||
// or more (provider.TestPicks): the chip's right-click offers a
|
||||
// test on one of them
|
||||
TestPicks []provider.TestPick `json:"testPicks,omitempty"`
|
||||
// DecideTest is set when its decision models can each be sent a
|
||||
// System One question (provider.AsksDecideModels): a mixed
|
||||
// provider's Jev too, beside its conversation models
|
||||
@@ -868,7 +872,7 @@ func providerInfoWith(p provider.Provider, ls provider.Listing, agents []agentUs
|
||||
avail := ls.Available
|
||||
out := providerJSON{
|
||||
ID: p.ID, Name: p.Name, Icon: p.Icon, IconFrom: p.IconFrom, Preset: p.Preset, Host: p.Host(),
|
||||
Chat: p.Chat, Responses: p.Responses, Anthropic: p.Anthropic, Gemini: p.Gemini, Decide: p.Decide, BaseAPI: p.BaseAPI, ModelTest: p.ModelTest(), TestsAs: p.TestClients(), DecideTest: p.AsksDecideModels(), MarksKinds: p.MarksKinds(),
|
||||
Chat: p.Chat, Responses: p.Responses, Anthropic: p.Anthropic, Gemini: p.Gemini, Decide: p.Decide, BaseAPI: p.BaseAPI, ModelTest: p.ModelTest(), TestsAs: p.TestClients(), TestPicks: p.TestPicks(), DecideTest: p.AsksDecideModels(), MarksKinds: p.MarksKinds(),
|
||||
Catalog: p.Catalog, Website: p.Website, KeysURL: p.KeysURL,
|
||||
Proxy: p.Proxy, AccountProxies: p.AccountProxies, AccountModels: p.AccountModels, AccountCaps: p.AccountCaps, AccountWindowCaps: p.AccountWindowCaps, AccountWindowAmounts: p.AccountWindowAmounts, AccountNames: p.AccountNames, Headers: p.Headers, ExtraBody: p.ExtraBody, ReplyHeaders: p.ReplyHeaders, PassHeaders: p.PassHeaders, Searches: p.Searches, Cline: p.ClinePinnable(), PinUpstream: p.PinUpstream, Unredacted: p.Unredacted, CountFree: p.CountFree, Billing: p.Billing, BillingKind: p.BillingKind(), InsecureTLS: p.InsecureTLS, TakesInsecureTLS: p.TakesInsecureTLS(), HTTP1: p.HTTP1, ClientCert: tilde(p.ClientCert), ClientKey: tilde(p.ClientKey), ServerCA: tilde(p.ServerCA), TakesClientCert: p.TakesClientCert(), ServerPin: p.ServerPin, TakesServerPin: p.TakesServerPin(), Socket: p.Socket, TakesSocket: p.TakesSocket(), LimitRestOff: p.LimitRestOff, UpstreamProviders: p.UpstreamProviders, ImageFilesOff: p.ImageFilesOff, TakesImageFiles: p.TakesImageFiles(), NativeCompaction: p.NativeCompaction, CarriesCompaction: p.CarriesCompaction(), PassUserAgent: !p.MagpieUserAgent, OwnClient: p.OwnClient(), PassErrors: p.PassErrors, TakesPassErrors: p.TakesPassErrors(), AuthHeader: p.AuthHeader, BothAuth: p.BothAuth(), BalanceURL: p.BalanceURL, BalancePath: p.BalancePath, BalanceMethod: p.BalanceMethod, NoBalanceProbe: p.NoBalanceProbe, ModelsURL: p.ModelsURL, ListOff: p.ListsOff(), TakesListOff: p.Account == nil && !p.IsPlugin() && !p.DecideOnly(), TakesModelHeaders: p.Account == nil, DecideAPIKind: p.DecideAPIKind(),
|
||||
Ready: p.Ready(), Chosen: p.PicksOf(avail), Agents: make([]providerAgent, 0, len(agents)),
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,14 @@ const base = { icon: "generic", responses: "", anthropic: "", catalog: "", agent
|
||||
const PICKS = [{ id: "k1", name: "Work" }, { id: "k2", name: "Spare" }];
|
||||
const relay = { ...base, id: "relay", name: "Relay", chat: "https://relay.example.com/v1",
|
||||
models: [{ id: "gpt-5.5", name: "gpt-5.5", on: true }], testPicks: PICKS };
|
||||
// tmr11235's: ChatGPT API signed in under two ChatGPT accounts, both on
|
||||
const gpt = { ...base, id: "chatgpt-api", name: "ChatGPT API", chat: "", responses: "https://api.openai.com/v1", key: { set: false, masked: "" },
|
||||
models: [{ id: "gpt-6.1-sol", name: "gpt-6.1-sol", on: true }], testPicks: [{ id: "a@mmuu.mom", name: "a@mmuu.mom" }, { id: "b@tirol.url", name: "b@tirol.url" }] };
|
||||
const plain = { ...base, id: "plain", name: "Plain", chat: "https://plain.example.com/v1",
|
||||
models: [{ id: "model-p", name: "model-p", on: true }] };
|
||||
|
||||
function serve(lang, tests) {
|
||||
const providers = { providers: [relay, plain], presets: [], excluded: [], gateway: { running: true, window: true } };
|
||||
const providers = { providers: [relay, gpt, plain], presets: [], excluded: [], gateway: { running: true, window: true } };
|
||||
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
@@ -100,6 +103,16 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.equal(tests[1].account, undefined, "a plain test names no account");
|
||||
await page.waitForFunction(() => document.querySelector("#status")?.textContent.endsWith(" · Work"));
|
||||
|
||||
// two ChatGPT sign-ins of the ChatGPT API offer it too
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
await page.locator(".row.provider", { hasText: "ChatGPT API" }).click();
|
||||
const sol = page.locator(".editor .mchips .mchip", { hasText: "gpt-6.1-sol" });
|
||||
await sol.waitFor();
|
||||
await rightClick(sol);
|
||||
await menu.getByRole("menuitem", { name: new RegExp("^" + (await tr("Test on account…")).replace(/[.*+?^${}()|[\]\\]/g, "\\$&")) }).click();
|
||||
assert.deepEqual(await page.locator(".pop.proto-menu .pm-name").allTextContents(), ["a@mmuu.mom", "b@tirol.url"]);
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
// a provider with one account has no such entry
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
await page.locator(".row.provider", { hasText: "Plain" }).click();
|
||||
|
||||
Reference in New Issue
Block a user