TestShowSessionProgress verifies that in-session hub-edit statistics are reported accurately, exposing hub churn as a context-bloat signal.
(t *testing.T)
| 980 | // TestShowSessionProgress verifies that in-session hub-edit statistics are |
| 981 | // reported accurately, exposing hub churn as a context-bloat signal. |
| 982 | func TestShowSessionProgress(t *testing.T) { |
| 983 | t.Run("no daemon state produces no output", func(t *testing.T) { |
| 984 | out := captureOutput(func() { showSessionProgress(t.TempDir()) }) |
| 985 | if out != "" { |
| 986 | t.Errorf("expected no output with no state, got %q", out) |
| 987 | } |
| 988 | }) |
| 989 | |
| 990 | t.Run("state with no events produces no output", func(t *testing.T) { |
| 991 | root := t.TempDir() |
| 992 | writeWatchState(t, root, watch.State{ |
| 993 | UpdatedAt: time.Now(), |
| 994 | FileCount: 5, |
| 995 | }) |
| 996 | out := captureOutput(func() { showSessionProgress(root) }) |
| 997 | if out != "" { |
| 998 | t.Errorf("expected no output for state with no events, got %q", out) |
| 999 | } |
| 1000 | }) |
| 1001 | |
| 1002 | t.Run("shows files-edited count", func(t *testing.T) { |
| 1003 | root := t.TempDir() |
| 1004 | writeWatchState(t, root, watch.State{ |
| 1005 | UpdatedAt: time.Now(), |
| 1006 | FileCount: 10, |
| 1007 | RecentEvents: []watch.Event{ |
| 1008 | {Path: "main.go", Op: "WRITE"}, |
| 1009 | {Path: "utils.go", Op: "WRITE"}, |
| 1010 | {Path: "main.go", Op: "WRITE"}, // duplicate — same file |
| 1011 | }, |
| 1012 | }) |
| 1013 | out := captureOutput(func() { showSessionProgress(root) }) |
| 1014 | if !strings.Contains(out, "2 files edited") { |
| 1015 | t.Errorf("expected '2 files edited', got %q", out) |
| 1016 | } |
| 1017 | }) |
| 1018 | |
| 1019 | t.Run("reports hub-edit count to surface risky churn", func(t *testing.T) { |
| 1020 | root := t.TempDir() |
| 1021 | writeWatchState(t, root, watch.State{ |
| 1022 | UpdatedAt: time.Now(), |
| 1023 | FileCount: 10, |
| 1024 | RecentEvents: []watch.Event{ |
| 1025 | {Path: "types.go", Op: "WRITE", IsHub: true}, |
| 1026 | {Path: "utils.go", Op: "WRITE", IsHub: false}, |
| 1027 | {Path: "types.go", Op: "WRITE", IsHub: true}, |
| 1028 | }, |
| 1029 | }) |
| 1030 | out := captureOutput(func() { showSessionProgress(root) }) |
| 1031 | if !strings.Contains(out, "1 hub edits") { |
| 1032 | t.Errorf("expected '1 hub edits' (unique hub files, not events), got %q", out) |
| 1033 | } |
| 1034 | if !strings.Contains(out, "2 files edited") { |
| 1035 | t.Errorf("expected '2 files edited', got %q", out) |
| 1036 | } |
| 1037 | }) |
| 1038 | |
| 1039 | t.Run("omits hub-edit label when there are none", func(t *testing.T) { |
nothing calls this directly
no test coverage detected