v0.1.4108 kept the drift poll's "is this value magpie's" answers. After it, real accounts on mote (acgui6, w75, the window open) showed the poll's cost had moved into Pi's Values: piOffered on every Drift, every 15s. Each call walked the agent's model list and built the model's whole models.json entry, which reads settings again under GroupHasNative. That was 23 MB of the window's three minutes. piOffered is now kept per agent and model in a stampedLists, as sharedModels is: built again when provider.StampNow moves, or a minute after it was. Its callers (Pi-like Values, their effort options, Aside) only read it. Run: TestPiOfferedKeptPerStamp (new), TestThinkingWithoutLevels* and the Pi tests on mica. Broken by hand (the kept entry dropped on every call): red, "built again while nothing changed". Suite on mica at this commit: gofmt clean; go vet internal/agent for darwin, linux and windows; go test ./internal/agent ok (281.1s).
56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// Pi's Values asks piOffered on every Drift of the window's poll: it is
|
|
// built once while provider.StampNow stays the same, and again after a
|
|
// change, which reaches the answer.
|
|
func TestPiOfferedKeptPerStamp(t *testing.T) {
|
|
syncHome(t)
|
|
thinks := func(reasoning string) {
|
|
t.Helper()
|
|
if err := os.WriteFile(catalog.CachePath(), []byte(`{
|
|
"moonshotai": {"models": {"kimi-k3-max": {"id":"kimi-k3-max","name":"Kimi-K3-Max","reasoning":`+reasoning+`,"limit":{"context":262144}}}}
|
|
}`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
catalog.Reset()
|
|
}
|
|
thinks("true")
|
|
if err := provider.Save(provider.Provider{ID: "trae-cn", Name: "Trae CN", Key: "k", Chat: "http://127.0.0.1:1/v1",
|
|
Catalog: "moonshotai", Models: []string{"kimi-k3-max"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
const model = "magpie/trae-cn/kimi-k3-max"
|
|
built := func() int64 {
|
|
builtOffered.Lock()
|
|
defer builtOffered.Unlock()
|
|
return builtOffered.m["pi\x00trae-cn/kimi-k3-max"].at.UnixNano()
|
|
}
|
|
want := []string{"off", "minimal", "low", "medium", "high"}
|
|
if got := piOffered("pi", model); !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("Pi offers %v, want %v", got, want)
|
|
}
|
|
first := built()
|
|
for range 5 {
|
|
piOffered("pi", model)
|
|
}
|
|
if built() != first {
|
|
t.Fatal("built again while nothing changed")
|
|
}
|
|
if got := piOffered("pi", "magpie/trae-cn/none"); got != nil {
|
|
t.Fatalf("a model magpie doesn't have: %v", got)
|
|
}
|
|
thinks("false")
|
|
if got := piOffered("pi", model); !reflect.DeepEqual(got, []string{"off"}) {
|
|
t.Fatalf("after the catalog said it doesn't think, Pi offers %v, want off alone", got)
|
|
}
|
|
}
|