Each range statsFor keeps (all days, and 30, warmed at start) holds a Summary for every session, and each had four maps (tools, skills, skillLast, perDay) plus a tools map in every day. Most hold one or two names, and a Go map of one is a few hundred bytes. They are now counts (name, calls, a skill's last date) in the names' order, and perDay a slice of days in order; the build still sums into maps and hands those over once. Run at this head (8ab4fd612+ this change), in a sandbox HOME with the real ~/.codex and ~/.claude sessions (15,921 files), warm start, two alternating runs each, 40 s after settling: before: footprint 174 / 178 MB, live heap 104 / 104 MB after: footprint 165 / 170 MB, live heap 97 / 96 MB Both builds side by side on the same files, /api/sessions/overview at days 30, 0, 30&agent=codex and 0&agent=claude, and /api/sessions/stats at 30: stats identical; the overviews differ only in the title length8ab4fd612changed and in today's counts of the Claude sessions being written between the two reads (codex-only: titles alone). go test ./internal/sessions ./internal/gui ok; ./internal/usage red once on TestUsageReadAfterAppendHashesNothingOnAFineClock's whole-second case (#3511, #3551, untouched here), 5 of 5 ok rerun. gofmt clean; GOOS=linux and GOOS=windows go vet -tags nogui ./internal/sessions ok.
19 lines
800 B
Go
19 lines
800 B
Go
package sessions
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestGatewayStatsRebaseNativeCalendar(t *testing.T) {
|
|
native := Stats{From: "2026-10-06", To: "2026-10-07", Sessions: []Summary{{Agent: "claude", ID: "native", Days: []int{0}, perDay: []summaryDay{{day: 0, output: 4}}}}}
|
|
merged := MergeExternalStats(native, []ExternalDayUsage{{Date: "2026-10-04", Agent: "opencode"}}, nil)
|
|
view := merged.Overview("claude", "", "", 8)
|
|
if !reflect.DeepEqual(view.Days, []int{0, 0, 1, 0}) || !reflect.DeepEqual(view.Output, []int{0, 0, 4, 0}) {
|
|
t.Fatalf("native calendar shifted when gateway history extended range: days=%v output=%v", view.Days, view.Output)
|
|
}
|
|
if native.Sessions[0].Days[0] != 0 || native.Sessions[0].perDay[0].output != 4 {
|
|
t.Fatal("merge mutated the original native snapshot")
|
|
}
|
|
}
|