Entry.Provider was a Provider value, 1,328 of an Entry's 1,760 bytes, copied into every model of every provider each time a catalog, an agent's list or a routing group's entries were built. It is now a *Provider: entriesOf and decide's list give every model of one provider the same one (sharedEntry), and a group's entry points at its first member's. It is read only; every place that hands it on as a value (Resolve, CanFast, ownAgent, modelAllowed, …) dereferences it, so what they get is a copy as before. entryFor keeps its signature for the one model ServedEntryOf builds; offEntries' entries now carry their provider too. Measured on mote with the owner's real accounts (acctp sandbox, page open for 2m32s, w40 = before, w41 = this, alternating): - catalogOf's allocations 106 MB -> 67 MB, providerEntries' 88 -> 78 MB - CPU at the page's settle mark 3.42/3.33 s -> 3.18/3.30 s - live heap unchanged (76.3/76.1 -> 76.7/75.9 MB): the lists are rebuilt, not kept, so the copies were churn for the GC, not held Run: go build and go vet ./... and the tests compiled (go test -run ^$) on mote; the full suite at this tree (d1e823d5f) on mica: 99 packages ok, 0 FAIL (agent 317s, gateway 972s, gui 188s, provider 220s, usage 56s).
34 lines
1.2 KiB
Go
34 lines
1.2 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// #1839: a model a subscription account serves says so to the Routing page,
|
|
// which tells beside a classifier set to it that every turn starts with a
|
|
// request to that subscription; a key's model says nothing of it.
|
|
func TestServedRefSaysASubscription(t *testing.T) {
|
|
sub := servedRef(provider.Entry{ID: "codex/gpt-5-mini", Name: "gpt-5-mini", Model: "gpt-5-mini",
|
|
Provider: &provider.Provider{ID: "codex", Name: "Codex", Account: &provider.Account{Agent: "codex", User: "a@x.y"}}}, settings.Settings{})
|
|
if !sub.Sub {
|
|
t.Fatalf("a subscription's model: %+v", sub)
|
|
}
|
|
key := servedRef(provider.Entry{ID: "or/flash", Name: "flash", Model: "flash", Provider: &provider.Provider{ID: "or", Name: "OpenRouter", Key: "k"}}, settings.Settings{})
|
|
if key.Sub {
|
|
t.Fatalf("a key's model: %+v", key)
|
|
}
|
|
b, _ := json.Marshal(key)
|
|
if strings.Contains(string(b), `"sub"`) {
|
|
t.Fatalf("a key's model sends no sub: %s", b)
|
|
}
|
|
b, _ = json.Marshal(sub)
|
|
if !strings.Contains(string(b), `"sub":true`) {
|
|
t.Fatalf("%s", b)
|
|
}
|
|
}
|