Files
magpie/internal/gateway/vision_cache_unix_test.go
T
yetoneandMYCF711 df7c94bdf5 gateway: inline image descriptions survive a restart (#5121)
The vision description cache (Server.sights) was in memory only, so a
restart, update or handover described every image of a long conversation
again (62 calls in 2.5 minutes in the report). Completed descriptions of
inline images are now appended to vision-cache.jsonl (0600) in the config
dir before their waiters are released, and New restores them under the
same 2048-entry LRU. URL images stay in memory (their bytes can change);
failures are never written. Appends and compaction go through a file lock,
a corrupt or truncated line is skipped (and backed up before compaction),
and shutdown waits for pending saves within the drain window.

Patch by MYCF711, applied clean on main. One change: the Unix permission
test now makes the config folder before it pre-creates the file (it failed
on a fresh sandbox, where the folder doesn't exist yet).

Run (mote, at this tree): go test ./internal/gateway filtered to the
vision/sight/cache tests, ok; gofmt -l clean; go vet ./internal/gateway
for linux and windows, clean. Broken by hand: saveSight call removed from
see(), TestDescriptionSurvivesGatewayRestart red (2 descriptions, want 1),
green again with it back. Windows: the same filtered tests on xiaomi-gpu
via win-run. Not tried: full go test ./..., go vet ./... for linux (wails
cgo doesn't build off-platform on mote), a real process kill or a real
handover, a real gateway with a real vision model.

Co-authored-by: MYCF711 <323101370+MYCF711@users.noreply.github.com>
2026-11-04 07:57:43 +08:00

33 lines
647 B
Go

//go:build !windows
package gateway
import (
"fmt"
"os"
"path/filepath"
"testing"
)
func TestSightAppendTightensExistingPermissions(t *testing.T) {
fresh(t)
s := New()
if err := os.MkdirAll(filepath.Dir(s.sightFile), 0o700); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(s.sightFile, nil, 0o644); err != nil {
t.Fatal(err)
}
if err := os.Chmod(s.sightFile, 0o644); err != nil {
t.Fatal(err)
}
s.saveSight(fmt.Sprintf("%064x", 88), "private", "probe/eye")
st, err := os.Stat(s.sightFile)
if err != nil {
t.Fatal(err)
}
if got := st.Mode().Perm(); got != 0o600 {
t.Fatalf("cache mode = %04o, want 0600", got)
}
}