Sub2API v1.0 - AI API 网关(二开初始版本,基于上游 Wei-Shaw/sub2api)
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
//go:build unit
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
coderws "github.com/coder/websocket"
|
||||
)
|
||||
|
||||
func TestIsExpectedGrokRealtimeClose(t *testing.T) {
|
||||
for _, status := range []coderws.StatusCode{
|
||||
coderws.StatusNormalClosure,
|
||||
coderws.StatusGoingAway,
|
||||
coderws.StatusNoStatusRcvd,
|
||||
coderws.StatusAbnormalClosure,
|
||||
} {
|
||||
if !isExpectedGrokRealtimeClose(coderws.CloseError{Code: status}) {
|
||||
t.Fatalf("status %v should be treated as an expected session close", status)
|
||||
}
|
||||
}
|
||||
if isExpectedGrokRealtimeClose(coderws.CloseError{Code: coderws.StatusPolicyViolation}) {
|
||||
t.Fatal("policy violations must not be treated as billable normal closes")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGrokRealtimeBillingResultRequiresObservedAudio(t *testing.T) {
|
||||
if grokRealtimeBillingResult("grok-voice-latest", time.Second, false) != nil {
|
||||
t.Fatal("a session without observed audio must not be billed")
|
||||
}
|
||||
if grokRealtimeBillingResult("grok-voice-latest", 0, true) != nil {
|
||||
t.Fatal("zero-duration sessions must not be billed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGrokRealtimeBillingResultUsesForcedUniqueID(t *testing.T) {
|
||||
first := grokRealtimeBillingResult("grok-voice-latest", 90*time.Second, true)
|
||||
second := grokRealtimeBillingResult("grok-voice-latest", 90*time.Second, true)
|
||||
if first == nil || second == nil {
|
||||
t.Fatal("observed audio sessions should be billable")
|
||||
}
|
||||
if first.RequestID == "" {
|
||||
t.Fatalf("unexpected billing request ID %q", first.RequestID)
|
||||
}
|
||||
if first.RequestID == second.RequestID {
|
||||
t.Fatal("independent realtime connections must not share a billing request ID")
|
||||
}
|
||||
if first.AudioUsage == nil || first.AudioUsage.Mode != "realtime" || first.AudioUsage.DurationOrUnits != 1.5 {
|
||||
t.Fatalf("unexpected audio usage: %#v", first.AudioUsage)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user