Files
magpie/internal/sessions/uuid_set_test.go
T
yetone 0bb991b0da sessions: Claude Code's copied-session ids are kept as 16 bytes, and folder listings go with the idle parses
On a real history (~15k Claude Code sessions), the idle heap after one
visit to the Sessions page still held two things:

- ccUUIDMemo's set of message uuids per file, as map[string]bool with
  the strings gjson copied out: ~5.1 MB. It is now a uuidSet,
  map[[16]byte]struct{}: an 8-4-4-4-12 uuid (any case) is parsed into
  its 16 bytes, anything else is hashed with FNV-128a.
- ccListed, every Claude Code folder's last listing (path and key per
  file): ~2 MB, kept for the life of the process. dropIdleCache now
  clears it with the other memos it lets go; the next listing builds it
  again from the folder.

Run on mote (go1.26.8):
- go test -count=1 ./internal/catalog ./internal/sessions
  ./internal/provider ./internal/agent ./internal/codexcat: ok
  (before the ccListed line); ./internal/sessions again after: ok.
- gofmt -l, go vet and GOOS=windows go vet for internal/sessions: clean.
- Broken by hand: with ccListed.Clear() commented out,
  TestIdleParsesLetGoAndComeBackFromDisk fails ("3 Claude Code
  listings kept").

Not tried: the real-account idle measurement of this change alone; it
runs with the catalog change's measurement.
2026-11-11 05:58:14 +08:00

36 lines
883 B
Go

package sessions
import (
"fmt"
"strings"
"testing"
)
// A uuid is kept by its bytes, so it is found again in any case and no
// other id is taken for it; an id that is not a uuid is kept too.
func TestUUIDSetHoldsWhatWasAdded(t *testing.T) {
s := uuidSet{}
var ids []string
for i := range 2000 {
ids = append(ids, fmt.Sprintf("%08x-%04x-4%03x-a%03x-%012x", i*7919, i, i%4096, i%4096, i*104729))
}
for _, id := range ids[:1000] {
s.add(id)
}
s.add("msg_01-not-a-uuid")
for i, id := range ids {
if got := s.has(id); got != (i < 1000) {
t.Fatalf("has(%s) = %v", id, got)
}
}
if !s.has(strings.ToUpper(ids[3])) {
t.Fatal("a uuid isn't found in upper case")
}
if !s.has("msg_01-not-a-uuid") || s.has("msg_02-not-a-uuid") || s.has("") {
t.Fatal("an id that isn't a uuid is kept wrong")
}
if len(s) != 1001 {
t.Fatalf("%d kept, want 1001", len(s))
}
}