Split session time into on/off/unclassified buckets

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-01 20:58:16 -04:00
parent 6b99804132
commit 7eb2b5dc58
3 changed files with 72 additions and 10 deletions
+32
View File
@@ -1376,3 +1376,35 @@ func TestEnforcementLevelPersists(t *testing.T) {
t.Fatalf("enforcement level not restored: got %q want %q", got, domain.EnforcementBlock)
}
}
func TestCreditLockedSplitsByDriftStatus(t *testing.T) {
c, _ := newTestController(t)
c.stats = &EvidenceStats{
Buckets: map[bucketKey]time.Duration{},
OnTask: map[bucketKey]time.Duration{},
OffTask: map[bucketKey]time.Duration{},
}
k := bucketKey{Class: "code", Title: "main.go"}
c.driftStatus = driftOnTask
c.creditLocked(k, 10*time.Second)
c.driftStatus = driftDrifting
c.creditLocked(k, 5*time.Second)
c.driftStatus = driftIdle
c.creditLocked(k, 3*time.Second)
c.driftStatus = driftPending
c.creditLocked(k, 2*time.Second)
if got := c.stats.OnTask[k]; got != 10*time.Second {
t.Errorf("OnTask = %v, want 10s", got)
}
if got := c.stats.OffTask[k]; got != 5*time.Second {
t.Errorf("OffTask = %v, want 5s", got)
}
if got := c.stats.unclassified; got != 5*time.Second { // 3s idle + 2s pending
t.Errorf("unclassified = %v, want 5s", got)
}
if got := c.stats.Buckets[k]; got != 20*time.Second { // total of all four
t.Errorf("Buckets total = %v, want 20s", got)
}
}