fix grok usage guard for compatible accounts

This commit is contained in:
Rain committed 2026-08-05 17:59:20 +08:00
1 parent 5c52fa93d5
commit ba92d70422
5 files changed
+113 -2

No files matched your search

@@ -0,0 +1,58 @@
//go:build unit
package service
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestRequiresBillableGrokChatUsage(t *testing.T) {
t.Parallel()
tests := []struct {
name string
account *Account
models []string
want bool
}{
{
name: "grok platform",
account: &Account{Platform: PlatformGrok},
models: []string{"alias"},
want: true,
},
{
name: "OpenAI-compatible requested Grok model",
account: &Account{Platform: PlatformOpenAI},
models: []string{"grok-4.5"},
want: true,
},
{
name: "OpenAI-compatible mapped Grok model",
account: &Account{Platform: PlatformOpenAI},
models: []string{"alias", "grok-4.5"},
want: true,
},
{
name: "xAI-qualified Grok model",
account: &Account{Platform: PlatformOpenAI},
models: []string{"xai/grok-4.5"},
want: true,
},
{
name: "ordinary OpenAI model",
account: &Account{Platform: PlatformOpenAI},
models: []string{"gpt-5.4"},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, tt.want, requiresBillableGrokChatUsage(tt.account, tt.models...))
})
}
}