Files
magpie/internal/agent/rescan_test.go
T
yetone 597d16358b gui: the header's refresh reads again what the page shown draws, and no longer looks for a newer magpie (evilgaoshu, #844: 顶部刷新按钮按直觉应该是「刷新当前页面」,检查更新是低频操作,不必占用顶部一个常驻按钮) — the round ↻ refreshed the model lists and checked for an update whatever page was shown. Now on Agents it looks for the agents on this computer again: POST /api/agents/rescan (agent.Rescan forgets the answers kept a while because asking was slow: Cursor Private Inference's apps folder, WSL's distro list and failed probes, Alma's server) and draws the list, Install another agent and the CLI versions afresh, so one just installed or removed, or changed outside magpie, shows at once. On Usage it reads the page now, the allowances too (as its Refresh now); in the panel, Agents rescans, Allowances reads the allowances and Usage the requests; on Providers and every other page it refreshes the model lists as before. Its tooltip says what it reads on the page shown (zh, ja, de strings). A newer magpie is looked for by magpie's own timer and Settings › About's Check, as before. TestRescanLooksAgain (an app installed after magpie looked is found only after the half minute without it) and refresh-page.test.cjs (WebKit, en and zh, window and panel: tooltip per page, Agents rescans and a new agent shows and leaves Install another agent, Usage reads the allowances afresh, Providers syncs, never an update check, no click moves the page) fail on the old code; sync-update.test.cjs, which asserted the old update check, is replaced by it. sync-spin, update-hide, update-check, click-scroll, gui-ja, gui-de, usage-card-refresh and agent-update-all pass on WebKit. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.
2026-10-05 09:26:30 +08:00

72 lines
2.0 KiB
Go

package agent
import (
"os"
"path/filepath"
"runtime"
"testing"
"time"
)
// The Agents page's refresh looks again at once (#844): Cursor Private
// Inference installed after magpie last looked used to wait out the half
// minute its apps folder was kept for, and a WSL distro's agents a minute.
func TestRescanLooksAgain(t *testing.T) {
h := t.TempDir()
t.Setenv("HOME", h)
t.Setenv("USERPROFILE", h)
t.Setenv("LOCALAPPDATA", h)
t.Setenv("ProgramFiles", filepath.Join(h, "none"))
cursorLocalSeen.Lock()
cursorLocalSeen.at = time.Time{}
cursorLocalSeen.Unlock()
t.Cleanup(Rescan)
var res string
switch runtime.GOOS {
case "darwin":
res = filepath.Join(h, "Applications", "Cursor Private Inference.app", "Contents", "Resources", "app")
case "windows":
res = filepath.Join(h, "Programs", "cursor-private", "resources", "app")
default:
res = filepath.Join(h, "Applications", "cursor-private", "resources", "app")
}
if got := cursorLocalApp(); got != "" {
t.Skipf("a Cursor Private Inference is installed here already: %s", got)
}
if err := os.MkdirAll(res, 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(res, "product.json"), []byte(`{"nameShort":"Cursor Private Inference","applicationName":"cursor"}`), 0o644); err != nil {
t.Fatal(err)
}
if got := cursorLocalApp(); got != "" {
t.Fatalf("looked again before the half minute was out: %s", got)
}
Rescan()
if got := cursorLocalApp(); got == "" {
t.Fatal("the refresh didn't look again: Cursor Private Inference just installed isn't found")
}
wsl.Lock()
wsl.at = time.Now()
wsl.failed = map[string]time.Time{"Ubuntu": time.Now()}
wsl.Unlock()
almaRead.Lock()
almaRead.at = map[string]time.Time{"x": time.Now()}
almaRead.Unlock()
Rescan()
wsl.Lock()
at, failed := wsl.at, len(wsl.failed)
wsl.Unlock()
if !at.IsZero() || failed != 0 {
t.Errorf("WSL's distros aren't asked again: at %v, %d failed kept", at, failed)
}
almaRead.Lock()
n := len(almaRead.at)
almaRead.Unlock()
if n != 0 {
t.Errorf("Alma's answers are kept: %d", n)
}
}