summaryrefslogtreecommitdiff
path: root/internal/stats/stats_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-16 04:25:26 +0200
committerPaul Buetow <paul@buetow.org>2026-03-16 04:25:26 +0200
commitf55a1e88ea5948582d0e5a33efea0c5d806e1f4b (patch)
treea180dc8c0266c87b0bc8d05a8e9c18d18748d751 /internal/stats/stats_test.go
parent7dd1bfa797b462791dc398690f599a2c5e5d1962 (diff)
Add Snapshot.ScopeReqs/ScopeRPM and simplify 3 callers
Centralizes the provider+model map traversal and window-minutes guard that was duplicated in hexaiaction, hexaicli, and lsp. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/stats/stats_test.go')
-rw-r--r--internal/stats/stats_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/stats/stats_test.go b/internal/stats/stats_test.go
index 45f9e2a..a9b3d22 100644
--- a/internal/stats/stats_test.go
+++ b/internal/stats/stats_test.go
@@ -334,3 +334,50 @@ func TestUpdate_CancelledContext(t *testing.T) {
t.Fatal("expected error from cancelled context, got nil")
}
}
+
+func TestSnapshot_ScopeReqs(t *testing.T) {
+ snap := Snapshot{
+ Providers: map[string]ProviderEntry{
+ "openai": {Models: map[string]Counters{"gpt-5.0": {Reqs: 42}}},
+ },
+ }
+ if got := snap.ScopeReqs("openai", "gpt-5.0"); got != 42 {
+ t.Fatalf("expected 42, got %d", got)
+ }
+ if got := snap.ScopeReqs("openai", "gpt-4.1"); got != 0 {
+ t.Fatalf("expected 0 for missing model, got %d", got)
+ }
+ if got := snap.ScopeReqs("anthropic", "gpt-5.0"); got != 0 {
+ t.Fatalf("expected 0 for missing provider, got %d", got)
+ }
+}
+
+func TestSnapshot_ScopeRPM(t *testing.T) {
+ snap := Snapshot{
+ Providers: map[string]ProviderEntry{
+ "openai": {Models: map[string]Counters{"gpt-5.0": {Reqs: 60}}},
+ },
+ Window: time.Hour,
+ }
+ rpm := snap.ScopeRPM("openai", "gpt-5.0")
+ if rpm != 1.0 {
+ t.Fatalf("expected 1.0 rpm, got %v", rpm)
+ }
+ // Missing model should return 0
+ if rpm := snap.ScopeRPM("openai", "missing"); rpm != 0 {
+ t.Fatalf("expected 0 rpm for missing, got %v", rpm)
+ }
+}
+
+func TestSnapshot_ScopeRPM_ZeroWindow(t *testing.T) {
+ snap := Snapshot{
+ Providers: map[string]ProviderEntry{
+ "openai": {Models: map[string]Counters{"gpt-5.0": {Reqs: 10}}},
+ },
+ Window: 0, // edge case
+ }
+ rpm := snap.ScopeRPM("openai", "gpt-5.0")
+ if rpm <= 0 {
+ t.Fatalf("expected positive rpm even with zero window, got %v", rpm)
+ }
+}