A provider with two or more accounts or keys that are on now offers
"Test on account..." in a model chip's right-click, an app menu (never a
native select) of those accounts' or keys' names. The pick is posted as
`account` with provider/test and pins the test (provider.TestOn,
accountNamed / keyNamed; an unknown or switched-off one is an error row,
not a silent fallback). Every result now names the account or key it went
to (Result.Account, set in probe), and the status line ends " - <name>"
for such a provider, whether the test was pinned or routing picked.
Test models and the CLI still test with routing's pick.
Core script budget raised 1,263,333 -> 1,263,700 (+367): the model chip
menu is core code and there is no page to move it to; the PLAY icon
literal was folded into one constant and the status call tightened first.
Run: gofmt clean; mote-run go test ./internal/gui ./internal/provider ok
(new TestModelTestPinnedToAKey, TestTestPicksNeedSeveral,
TestModelTestPinnedToAnAccount); model-test-account.test.cjs 10 of 10
(chromium and webkit, en zh zh-TW ja de) on mica. Broken by hand: with
the menu entry disabled the GUI test is 0 of 10. GUI batch model-*,
provider-*, i18n-*, gui-*: reds are the same on origin/main 2e92d71aa
(model-chip-steady, model-copy-id, provider-fetch-again, provider-max-
output, provider-many-keys, provider-mask, provider-typed, gui-de/ja),
all already filed (#4388, #4621, #3292, #6209, #5109, #4673, #5475).
Not tried: a real multi-account provider end to end; the CLI and the bulk
Test models button (unchanged); vet on windows/linux not rerun beyond the
earlier builds.
79 lines
2.9 KiB
Go
79 lines
2.9 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// A model's test can be pinned to one of a provider's keys (tmr11235 on
|
|
// X), and its result names the key that was asked: without the pick,
|
|
// routing sends m to the first key that serves it and the others are
|
|
// never tried.
|
|
func TestModelTestPinnedToAKey(t *testing.T) {
|
|
probeHome(t)
|
|
srv, asked := askingRelay(t, "sk-b", "m")
|
|
if err := Save(Provider{ID: "relay", Name: "Relay", Chat: srv.URL + "/v1",
|
|
Key: "sk-a", KeyName: "first", Keys: []KeyAccount{{Name: "second", Key: "sk-b"}}, Models: []string{"m"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p, err := Find("relay")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
picks := p.TestPicks()
|
|
if len(picks) != 2 || picks[0].Name != "first" || picks[1].Name != "second" || picks[1].ID != keyID("sk-b") {
|
|
t.Fatalf("the picks: %+v", picks)
|
|
}
|
|
// the key asked: sk-b answers m, sk-a is turned away, and each result says who was asked
|
|
rs := p.TestModels(TestOn(context.Background(), keyID("sk-b")), []string{"m"})
|
|
if len(rs) != 1 || !rs[0].OK || rs[0].Account != "second" {
|
|
t.Fatalf("pinned to the second key: %+v (asked %v)", rs, asked())
|
|
}
|
|
rs = p.TestModels(TestOn(context.Background(), keyID("sk-a")), []string{"m"})
|
|
if len(rs) != 1 || rs[0].OK || rs[0].Account != "first" {
|
|
t.Fatalf("pinned to the first key: %+v (asked %v)", rs, asked())
|
|
}
|
|
// nothing pinned: routing's pick, still named
|
|
rs = p.TestModels(context.Background(), []string{"m"})
|
|
if len(rs) != 1 || rs[0].Account == "" {
|
|
t.Fatalf("unpinned: %+v", rs)
|
|
}
|
|
// a key that isn't there is said, not swapped for another
|
|
rs = p.TestModels(TestOn(context.Background(), "nope"), []string{"m"})
|
|
if len(rs) != 1 || rs[0].OK || rs[0].Error == "" {
|
|
t.Fatalf("a key that is not there: %+v", rs)
|
|
}
|
|
}
|
|
|
|
// One key is nothing to pick from.
|
|
func TestTestPicksNeedSeveral(t *testing.T) {
|
|
if got := (Provider{ID: "x", Key: "sk-a"}).TestPicks(); got != nil {
|
|
t.Fatalf("one key: %+v", got)
|
|
}
|
|
}
|
|
|
|
// A pool's test pinned to its second account asks it, though the first
|
|
// is the one routing takes, and names it (twoAccountPlugin's fake vendor
|
|
// answers b@fake alone).
|
|
func TestModelTestPinnedToAnAccount(t *testing.T) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
|
defer cancel()
|
|
p, wrong := twoAccountPlugin(t, ctx, nil)
|
|
if got := p.TestPicks(); len(got) != 2 || got[0].ID != "a@fake" || got[1].ID != "b@fake" {
|
|
t.Fatalf("the picks: %+v", got)
|
|
}
|
|
rs := p.TestModels(TestOn(ctx, "b@fake"), []string{"fake-1"})
|
|
if len(rs) != 1 || !rs[0].OK || rs[0].Account != "b@fake" {
|
|
t.Fatalf("pinned to b@fake: %+v (others asked %v)", rs, wrong())
|
|
}
|
|
rs = p.TestModels(TestOn(ctx, "a@fake"), []string{"fake-1"})
|
|
if len(rs) != 1 || rs[0].OK || rs[0].Account != "a@fake" {
|
|
t.Fatalf("pinned to a@fake, which the vendor turns away: %+v", rs)
|
|
}
|
|
rs = p.TestModels(TestOn(ctx, "c@fake"), []string{"fake-1"})
|
|
if len(rs) != 1 || rs[0].OK || rs[0].Error == "" {
|
|
t.Fatalf("an account that isn't there: %+v", rs)
|
|
}
|
|
}
|