Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
95
backend/sdk/cliproxy/auth/conductor_recent_requests_test.go
Normal file
95
backend/sdk/cliproxy/auth/conductor_recent_requests_test.go
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestManagerMarkResultRecordsRecentRequests(t *testing.T) {
|
||||
mgr := NewManager(nil, nil, nil)
|
||||
auth := &Auth{
|
||||
ID: "auth-1",
|
||||
Provider: "antigravity",
|
||||
Attributes: map[string]string{
|
||||
"runtime_only": "true",
|
||||
},
|
||||
Metadata: map[string]any{
|
||||
"type": "antigravity",
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := mgr.Register(WithSkipPersist(context.Background()), auth); err != nil {
|
||||
t.Fatalf("Register returned error: %v", err)
|
||||
}
|
||||
|
||||
mgr.MarkResult(context.Background(), Result{AuthID: "auth-1", Provider: "antigravity", Model: "gpt-5", Success: true})
|
||||
mgr.MarkResult(context.Background(), Result{AuthID: "auth-1", Provider: "antigravity", Model: "gpt-5", Success: false})
|
||||
|
||||
gotAuth, ok := mgr.GetByID("auth-1")
|
||||
if !ok || gotAuth == nil {
|
||||
t.Fatalf("GetByID returned ok=%v auth=%v", ok, gotAuth)
|
||||
}
|
||||
|
||||
if gotAuth.Success != 1 || gotAuth.Failed != 1 {
|
||||
t.Fatalf("auth totals = success=%d failed=%d, want 1/1", gotAuth.Success, gotAuth.Failed)
|
||||
}
|
||||
|
||||
snapshot := gotAuth.RecentRequestsSnapshot(time.Now())
|
||||
var successTotal int64
|
||||
var failedTotal int64
|
||||
for _, bucket := range snapshot {
|
||||
successTotal += bucket.Success
|
||||
failedTotal += bucket.Failed
|
||||
}
|
||||
if successTotal != 1 || failedTotal != 1 {
|
||||
t.Fatalf("totals = success=%d failed=%d, want 1/1", successTotal, failedTotal)
|
||||
}
|
||||
}
|
||||
|
||||
func TestManagerUpdatePreservesRecentRequestsAndTotals(t *testing.T) {
|
||||
mgr := NewManager(nil, nil, nil)
|
||||
auth := &Auth{
|
||||
ID: "auth-1",
|
||||
Provider: "antigravity",
|
||||
Metadata: map[string]any{
|
||||
"type": "antigravity",
|
||||
},
|
||||
}
|
||||
if _, err := mgr.Register(WithSkipPersist(context.Background()), auth); err != nil {
|
||||
t.Fatalf("Register returned error: %v", err)
|
||||
}
|
||||
|
||||
mgr.MarkResult(context.Background(), Result{AuthID: "auth-1", Provider: "antigravity", Model: "gpt-5", Success: true})
|
||||
|
||||
updated := &Auth{
|
||||
ID: "auth-1",
|
||||
Provider: "antigravity",
|
||||
Metadata: map[string]any{
|
||||
"type": "antigravity",
|
||||
"note": "updated",
|
||||
},
|
||||
}
|
||||
if _, err := mgr.Update(WithSkipPersist(context.Background()), updated); err != nil {
|
||||
t.Fatalf("Update returned error: %v", err)
|
||||
}
|
||||
|
||||
gotAuth, ok := mgr.GetByID("auth-1")
|
||||
if !ok || gotAuth == nil {
|
||||
t.Fatalf("GetByID returned ok=%v auth=%v", ok, gotAuth)
|
||||
}
|
||||
if gotAuth.Success != 1 || gotAuth.Failed != 0 {
|
||||
t.Fatalf("auth totals = success=%d failed=%d, want 1/0", gotAuth.Success, gotAuth.Failed)
|
||||
}
|
||||
|
||||
snapshot := gotAuth.RecentRequestsSnapshot(time.Now())
|
||||
var successTotal int64
|
||||
var failedTotal int64
|
||||
for _, bucket := range snapshot {
|
||||
successTotal += bucket.Success
|
||||
failedTotal += bucket.Failed
|
||||
}
|
||||
if successTotal != 1 || failedTotal != 0 {
|
||||
t.Fatalf("bucket totals = success=%d failed=%d, want 1/0", successTotal, failedTotal)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue