f99010fae1
CI / lint (push) Failing after 1s
CI / frontend (push) Failing after 1s
CI / scripts (push) Failing after 1s
CI / Go Test (ubuntu-latest) (push) Failing after 0s
CI / frontend-node-25 (push) Failing after 1s
CI / docs (push) Failing after 0s
CI / coverage (push) Failing after 0s
CI / e2e (push) Failing after 0s
Docker / build-and-push (push) Failing after 1s
CI / integration (push) Failing after 4m43s
CI / Go Test (windows-latest) (push) Has been cancelled
CI / Desktop Unit Tests (Windows) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Windows) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Has been cancelled
70 lines
2.1 KiB
Go
70 lines
2.1 KiB
Go
package db
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestComputeSessionCoverageUpdates(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
candidates []SessionCoverageCandidate
|
|
msgCoverage map[string][2]bool
|
|
want []SessionCoverageUpdate
|
|
}{
|
|
{
|
|
name: "basic: three candidates with mixed updates",
|
|
candidates: []SessionCoverageCandidate{
|
|
// gets both flags from message coverage
|
|
{ID: "a", TotalOutputTokens: 0, PeakContextTokens: 0,
|
|
HasTotal: false, HasPeak: false},
|
|
// gets hasTotal from non-zero total tokens
|
|
{ID: "b", TotalOutputTokens: 100, PeakContextTokens: 0,
|
|
HasTotal: false, HasPeak: false},
|
|
// already has both flags — no update needed
|
|
{ID: "c", TotalOutputTokens: 50, PeakContextTokens: 200,
|
|
HasTotal: true, HasPeak: true},
|
|
},
|
|
msgCoverage: map[string][2]bool{
|
|
"a": {true, true}, // hasContext=true, hasOutput=true
|
|
},
|
|
want: []SessionCoverageUpdate{
|
|
{ID: "a", HasTotal: true, HasPeak: true},
|
|
{ID: "b", HasTotal: true, HasPeak: false},
|
|
},
|
|
},
|
|
{
|
|
name: "empty: nil candidates and nil coverage returns empty",
|
|
candidates: nil,
|
|
msgCoverage: nil,
|
|
want: []SessionCoverageUpdate{},
|
|
},
|
|
{
|
|
name: "no updates needed: all candidates already correct",
|
|
candidates: []SessionCoverageCandidate{
|
|
{ID: "x", TotalOutputTokens: 10, PeakContextTokens: 20,
|
|
HasTotal: true, HasPeak: true},
|
|
{ID: "y", TotalOutputTokens: 0, PeakContextTokens: 0,
|
|
HasTotal: false, HasPeak: false},
|
|
},
|
|
msgCoverage: map[string][2]bool{},
|
|
want: []SessionCoverageUpdate{},
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := ComputeSessionCoverageUpdates(tc.candidates, tc.msgCoverage)
|
|
|
|
require.Len(t, got, len(tc.want), "len mismatch; got = %v", got)
|
|
for i, w := range tc.want {
|
|
assert.Equal(t, w.ID, got[i].ID, "[%d] ID", i)
|
|
assert.Equal(t, w.HasTotal, got[i].HasTotal, "[%d] HasTotal", i)
|
|
assert.Equal(t, w.HasPeak, got[i].HasPeak, "[%d] HasPeak", i)
|
|
}
|
|
})
|
|
}
|
|
}
|