Files
magpie/internal/sessions/file_size_test.go
T
yetone 7c0a103eb1 sessions: a file's modification time is unix nanoseconds, 80 bytes a file (#2278)
A Sessions poll copies every session file's `file` into several slices
(distinctOf, listedRollouts, listCCFiles, distinctCodexFiles), and
rolloutsSeen keeps one of every Codex rollout. Its time.Time was 24 of
its 96 bytes. mod is now a modTime (int64 nanoseconds, 0 for none) with
the few methods the package used; a time.Time going in is modOf(t), one
coming out is .Time(). UnixNano keeps the zero time's own value, so a
parse kept on disk for a file with no time still matches.

Run on mote (M5 Pro, macOS 27), with a copy of the real accounts:
- go vet ./...; GOOS=linux and GOOS=windows go vet ./internal/sessions: ok.
- go test ./internal/sessions ./internal/gui ./internal/usage: ok.
- TestFileFitsEightyBytes (new) holds the size and the round trip of a
  time and of none.
- /api/sessions and /api/sessions/stats?days=30 from a fresh start, real
  history (~23k files): byte-identical to v0.1.3499's code (8,068,574 and
  623,801 bytes).
- 40 /api/sessions polls with X-Magpie-Had: 208 MB allocated before,
  185.5 MB with this.
2026-11-10 10:48:04 +08:00

24 lines
680 B
Go

package sessions
import (
"testing"
"time"
"unsafe"
)
// A Sessions poll copies every session file's file into several slices,
// so its size is held: 80 bytes, a size class of its own (#2278).
func TestFileFitsEightyBytes(t *testing.T) {
if n := unsafe.Sizeof(file{}); n > 80 {
t.Errorf("a file is %d bytes, want 80 at most", n)
}
// a time read back is the one written, and none stays none
at := time.Unix(1790000000, 123456789)
if got := modOf(at).Time(); !got.Equal(at) {
t.Errorf("%v came back %v", at, got)
}
if m := modOf(time.Time{}); m != 0 || !m.Time().IsZero() || m.UnixNano() != (time.Time{}).UnixNano() {
t.Errorf("no time came back as %d", m)
}
}