The Sessions page polls its list and its stats every 15s, the Usage page its clients, and each asked agent.Clients() only for each agent's id, name and icon. Clients() builds every agent (30+ constructors): 2.5 ms, 378 KB and 3411 allocations a call on the Windows box with discovery's real 2s look window, mostly os.Stat, filepath.Join and Getenv. On the real-account run (t69, 4 min) agent.All under the sessions handler was 22 MB of 210 MB allocated. agent.Looks keeps that id/name/shared-name/icon list for 30s, built again at once when the plugins' agents change (agentplug's set) or the Agents page's refresh (Rescan). A new omp or QwenPaw profile shows by its id for up to 30s. Nothing is kept in a test binary unless a test says, so tests that add an agent read it at once. The GUI's sessions list, stats, one session, markdown export, trash, manage and reads views, and usageapi.Clients, read Looks. Tests: TestLooksBuiltOnceAWhile — six asks build once, the list equals Clients(), a plugin agent switched on and off shows at once, Rescan builds again. Broken by hand (memo check made false): "six asks built the agents 6 times; want once". Run on the Windows box: go test ./internal/agent ./internal/gui ./internal/usageapi at the pre-rebase base0cc91af3d: usageapi ok, agent and gui with 38 reds. Those tests, run at8aae124b0with and without this change: the same 37 fail on both (#6068). TestLooks/TestPlugged/TestRescan ok and go vet ok at8aae124b0. mote (macOS) refused ssh all session, so no macOS run and no real-account measurement yet. Rebased on156861b3aafter the runs; its new commits touch library, plugin and site only.
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package agent
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/agentplug"
|
|
)
|
|
|
|
// The pages that only name and draw rows by agent poll Looks, which builds
|
|
// every agent once for a while, not on each ask; a plugin's agent coming
|
|
// or going, and the Agents page's refresh, build it again at once.
|
|
func TestLooksBuiltOnceAWhile(t *testing.T) {
|
|
pluggedHome(t)
|
|
old := looksFresh
|
|
looksFresh = looksFreshInApp
|
|
t.Cleanup(func() { looksFresh = old; forgetLooks() })
|
|
forgetLooks()
|
|
|
|
has := func(id string) bool {
|
|
return slices.ContainsFunc(Looks(), func(l Look) bool { return l.ID == id })
|
|
}
|
|
before := looksBuilt()
|
|
first := Looks()
|
|
for range 5 {
|
|
Looks()
|
|
}
|
|
if n := looksBuilt() - before; n != 1 {
|
|
t.Fatalf("six asks built the agents %d times; want once", n)
|
|
}
|
|
cs := Clients()
|
|
if len(first) != len(cs) {
|
|
t.Fatalf("%d looks, %d clients", len(first), len(cs))
|
|
}
|
|
for i, a := range cs {
|
|
if l := first[i]; l != (Look{a.ID, a.Name, a.SharedName(), a.Icon}) {
|
|
t.Fatalf("look %d = %+v, client %s %q %q %q", i, l, a.ID, a.Name, a.SharedName(), a.Icon)
|
|
}
|
|
}
|
|
if has("aider") {
|
|
t.Fatal("aider looked before its plugin is on")
|
|
}
|
|
|
|
pluggedHome(t, aiderSrc)
|
|
if !has("aider") {
|
|
t.Fatal("a plugin's agent switched on isn't looked until the memo runs out")
|
|
}
|
|
pluggedHome(t)
|
|
agentplug.Reload()
|
|
if has("aider") {
|
|
t.Fatal("a plugin's agent switched off is still looked")
|
|
}
|
|
|
|
before = looksBuilt()
|
|
Rescan()
|
|
Looks()
|
|
if looksBuilt() == before {
|
|
t.Fatal("the Agents page's refresh didn't build the looks again")
|
|
}
|
|
}
|