From 788875632307000e047a97f63c5b206cd022b23f Mon Sep 17 00:00:00 2001 From: Topher Hindman Date: Fri, 9 Oct 2026 16:27:36 -0700 Subject: [PATCH] fix(analytics): hint that an empty session list searched only the last 24 hours --- cmd/lk/analytics.go | 16 +++++++++++++++- cmd/lk/analytics_test.go | 10 ++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cmd/lk/analytics.go b/cmd/lk/analytics.go index f3e0e406..6064c5d6 100644 --- a/cmd/lk/analytics.go +++ b/cmd/lk/analytics.go @@ -739,7 +739,21 @@ func listUserAnalyticsSessions(ctx context.Context, cmd *cli.Command) error { if err != nil { return cloudAPIError(err) } - return render.SessionsPage(out, cmd.Bool("json"), sessions, nextCursor) + asJSON := cmd.Bool("json") + if err := render.SessionsPage(out, asJSON, sessions, nextCursor); err != nil { + return err + } + if len(sessions) == 0 && !asJSON && searchedDefaultWindow(opts) { + out.Statusf("Only the last 24 hours were searched — re-run with %s to look further back", util.Accented("--start YYYY-MM-DD")) + } + return nil +} + +// searchedDefaultWindow reports whether a listing left its window to the +// Public API, which then searches only the last 24 hours. A cursor carries the +// window of the listing it came from. +func searchedDefaultWindow(opts public.SessionListOptions) bool { + return opts.Start.IsZero() && opts.Cursor == "" } // sessionListOptions reads the session list flags for the Public API. --start diff --git a/cmd/lk/analytics_test.go b/cmd/lk/analytics_test.go index 208e2917..3ec0d724 100644 --- a/cmd/lk/analytics_test.go +++ b/cmd/lk/analytics_test.go @@ -296,6 +296,16 @@ func TestSessionListOptions(t *testing.T) { } } +// TestSearchedDefaultWindow checks when an empty listing gets the hint that only +// the last 24 hours were searched: when neither --start nor a cursor set the +// window, so a quiet day doesn't read as a project with no sessions. +func TestSearchedDefaultWindow(t *testing.T) { + assert.True(t, searchedDefaultWindow(public.SessionListOptions{})) + assert.False(t, searchedDefaultWindow(public.SessionListOptions{Start: time.Date(2026, 10, 1, 0, 0, 0, 0, time.UTC)})) + // A cursor carries the window of the listing it came from. + assert.False(t, searchedDefaultWindow(public.SessionListOptions{Cursor: "abc"})) +} + // validateListModeFlags runs analyticsListModeFlags.validate on a command built // from fresh analyticsSessionListFlags plus the --experimental-auth selector, // which production declares on the root.