Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
7cb5444d
Commit
7cb5444d
authored
Feb 03, 2026
by
song
Browse files
fix: update tests for group fallback
parent
3bede6e6
Changes
6
Hide whitespace changes
Inline
Side-by-side
backend/internal/handler/auth_handler.go
View file @
7cb5444d
...
@@ -409,6 +409,7 @@ func (h *AuthHandler) ValidateInvitationCode(c *gin.Context) {
...
@@ -409,6 +409,7 @@ func (h *AuthHandler) ValidateInvitationCode(c *gin.Context) {
Valid
:
true
,
Valid
:
true
,
})
})
}
}
// ForgotPasswordRequest 忘记密码请求
// ForgotPasswordRequest 忘记密码请求
type
ForgotPasswordRequest
struct
{
type
ForgotPasswordRequest
struct
{
Email
string
`json:"email" binding:"required,email"`
Email
string
`json:"email" binding:"required,email"`
...
...
backend/internal/handler/dto/mappers.go
View file @
7cb5444d
...
@@ -105,12 +105,12 @@ func GroupFromServiceAdmin(g *service.Group) *AdminGroup {
...
@@ -105,12 +105,12 @@ func GroupFromServiceAdmin(g *service.Group) *AdminGroup {
return
nil
return
nil
}
}
out
:=
&
AdminGroup
{
out
:=
&
AdminGroup
{
Group
:
groupFromServiceBase
(
g
),
Group
:
groupFromServiceBase
(
g
),
ModelRouting
:
g
.
ModelRouting
,
ModelRouting
:
g
.
ModelRouting
,
ModelRoutingEnabled
:
g
.
ModelRoutingEnabled
,
ModelRoutingEnabled
:
g
.
ModelRoutingEnabled
,
MCPXMLInject
:
g
.
MCPXMLInject
,
MCPXMLInject
:
g
.
MCPXMLInject
,
SupportedModelScopes
:
g
.
SupportedModelScopes
,
SupportedModelScopes
:
g
.
SupportedModelScopes
,
AccountCount
:
g
.
AccountCount
,
AccountCount
:
g
.
AccountCount
,
}
}
if
len
(
g
.
AccountGroups
)
>
0
{
if
len
(
g
.
AccountGroups
)
>
0
{
out
.
AccountGroups
=
make
([]
AccountGroup
,
0
,
len
(
g
.
AccountGroups
))
out
.
AccountGroups
=
make
([]
AccountGroup
,
0
,
len
(
g
.
AccountGroups
))
...
@@ -142,8 +142,8 @@ func groupFromServiceBase(g *service.Group) Group {
...
@@ -142,8 +142,8 @@ func groupFromServiceBase(g *service.Group) Group {
FallbackGroupID
:
g
.
FallbackGroupID
,
FallbackGroupID
:
g
.
FallbackGroupID
,
// 无效请求兜底分组
// 无效请求兜底分组
FallbackGroupIDOnInvalidRequest
:
g
.
FallbackGroupIDOnInvalidRequest
,
FallbackGroupIDOnInvalidRequest
:
g
.
FallbackGroupIDOnInvalidRequest
,
CreatedAt
:
g
.
CreatedAt
,
CreatedAt
:
g
.
CreatedAt
,
UpdatedAt
:
g
.
UpdatedAt
,
UpdatedAt
:
g
.
UpdatedAt
,
}
}
}
}
...
...
backend/internal/handler/dto/types.go
View file @
7cb5444d
...
@@ -89,9 +89,9 @@ type AdminGroup struct {
...
@@ -89,9 +89,9 @@ type AdminGroup struct {
MCPXMLInject
bool
`json:"mcp_xml_inject"`
MCPXMLInject
bool
`json:"mcp_xml_inject"`
// 支持的模型系列(仅 antigravity 平台使用)
// 支持的模型系列(仅 antigravity 平台使用)
SupportedModelScopes
[]
string
`json:"supported_model_scopes"`
SupportedModelScopes
[]
string
`json:"supported_model_scopes"`
AccountGroups
[]
AccountGroup
`json:"account_groups,omitempty"`
AccountGroups
[]
AccountGroup
`json:"account_groups,omitempty"`
AccountCount
int64
`json:"account_count,omitempty"`
AccountCount
int64
`json:"account_count,omitempty"`
}
}
type
Account
struct
{
type
Account
struct
{
...
...
backend/internal/server/api_contract_test.go
View file @
7cb5444d
...
@@ -180,6 +180,7 @@ func TestAPIContracts(t *testing.T) {
...
@@ -180,6 +180,7 @@ func TestAPIContracts(t *testing.T) {
"image_price_4k": null,
"image_price_4k": null,
"claude_code_only": false,
"claude_code_only": false,
"fallback_group_id": null,
"fallback_group_id": null,
"fallback_group_id_on_invalid_request": null,
"created_at": "2025-01-02T03:04:05Z",
"created_at": "2025-01-02T03:04:05Z",
"updated_at": "2025-01-02T03:04:05Z"
"updated_at": "2025-01-02T03:04:05Z"
}
}
...
@@ -600,8 +601,8 @@ func newContractDeps(t *testing.T) *contractDeps {
...
@@ -600,8 +601,8 @@ func newContractDeps(t *testing.T) *contractDeps {
settingRepo
:=
newStubSettingRepo
()
settingRepo
:=
newStubSettingRepo
()
settingService
:=
service
.
NewSettingService
(
settingRepo
,
cfg
)
settingService
:=
service
.
NewSettingService
(
settingRepo
,
cfg
)
adminService
:=
service
.
NewAdminService
(
userRepo
,
groupRepo
,
&
accountRepo
,
proxyRepo
,
apiKeyRepo
,
redeemRepo
,
nil
,
nil
,
nil
,
nil
)
adminService
:=
service
.
NewAdminService
(
userRepo
,
groupRepo
,
&
accountRepo
,
proxyRepo
,
apiKeyRepo
,
redeemRepo
,
nil
,
nil
,
nil
,
nil
)
authHandler
:=
handler
.
NewAuthHandler
(
cfg
,
nil
,
userService
,
settingService
,
nil
,
redeemService
,
nil
)
authHandler
:=
handler
.
NewAuthHandler
(
cfg
,
nil
,
userService
,
settingService
,
nil
,
redeemService
,
nil
)
apiKeyHandler
:=
handler
.
NewAPIKeyHandler
(
apiKeyService
)
apiKeyHandler
:=
handler
.
NewAPIKeyHandler
(
apiKeyService
)
usageHandler
:=
handler
.
NewUsageHandler
(
usageService
,
apiKeyService
)
usageHandler
:=
handler
.
NewUsageHandler
(
usageService
,
apiKeyService
)
adminSettingHandler
:=
adminhandler
.
NewSettingHandler
(
settingService
,
nil
,
nil
,
nil
)
adminSettingHandler
:=
adminhandler
.
NewSettingHandler
(
settingService
,
nil
,
nil
,
nil
)
...
...
backend/internal/service/admin_service_group_test.go
View file @
7cb5444d
...
@@ -458,6 +458,14 @@ func (s *groupRepoStubForInvalidRequestFallback) DeleteAccountGroupsByGroupID(_
...
@@ -458,6 +458,14 @@ func (s *groupRepoStubForInvalidRequestFallback) DeleteAccountGroupsByGroupID(_
panic
(
"unexpected DeleteAccountGroupsByGroupID call"
)
panic
(
"unexpected DeleteAccountGroupsByGroupID call"
)
}
}
func
(
s
*
groupRepoStubForInvalidRequestFallback
)
GetAccountIDsByGroupIDs
(
_
context
.
Context
,
_
[]
int64
)
([]
int64
,
error
)
{
panic
(
"unexpected GetAccountIDsByGroupIDs call"
)
}
func
(
s
*
groupRepoStubForInvalidRequestFallback
)
BindAccountsToGroup
(
_
context
.
Context
,
_
int64
,
_
[]
int64
)
error
{
panic
(
"unexpected BindAccountsToGroup call"
)
}
func
TestAdminService_CreateGroup_InvalidRequestFallbackRejectsUnsupportedPlatform
(
t
*
testing
.
T
)
{
func
TestAdminService_CreateGroup_InvalidRequestFallbackRejectsUnsupportedPlatform
(
t
*
testing
.
T
)
{
fallbackID
:=
int64
(
10
)
fallbackID
:=
int64
(
10
)
repo
:=
&
groupRepoStubForInvalidRequestFallback
{
repo
:=
&
groupRepoStubForInvalidRequestFallback
{
...
@@ -764,4 +772,4 @@ func TestAdminService_UpdateGroup_InvalidRequestFallbackAllowsAntigravity(t *tes
...
@@ -764,4 +772,4 @@ func TestAdminService_UpdateGroup_InvalidRequestFallbackAllowsAntigravity(t *tes
require
.
NotNil
(
t
,
group
)
require
.
NotNil
(
t
,
group
)
require
.
NotNil
(
t
,
repo
.
updated
)
require
.
NotNil
(
t
,
repo
.
updated
)
require
.
Equal
(
t
,
fallbackID
,
*
repo
.
updated
.
FallbackGroupIDOnInvalidRequest
)
require
.
Equal
(
t
,
fallbackID
,
*
repo
.
updated
.
FallbackGroupIDOnInvalidRequest
)
}
}
backend/internal/service/antigravity_gateway_service.go
View file @
7cb5444d
...
@@ -2046,6 +2046,9 @@ func (s *AntigravityGatewayService) handleUpstreamError(ctx context.Context, pre
...
@@ -2046,6 +2046,9 @@ func (s *AntigravityGatewayService) handleUpstreamError(ctx context.Context, pre
fallbackMinutes
=
s
.
settingService
.
cfg
.
Gateway
.
AntigravityFallbackCooldownMinutes
fallbackMinutes
=
s
.
settingService
.
cfg
.
Gateway
.
AntigravityFallbackCooldownMinutes
}
}
defaultDur
:=
time
.
Duration
(
fallbackMinutes
)
*
time
.
Minute
defaultDur
:=
time
.
Duration
(
fallbackMinutes
)
*
time
.
Minute
if
fallbackDur
,
ok
:=
antigravityFallbackCooldownSeconds
();
ok
{
defaultDur
=
fallbackDur
}
ra
:=
time
.
Now
()
.
Add
(
defaultDur
)
ra
:=
time
.
Now
()
.
Add
(
defaultDur
)
if
useScopeLimit
{
if
useScopeLimit
{
log
.
Printf
(
"%s status=429 rate_limited scope=%s reset_in=%v (fallback)"
,
prefix
,
quotaScope
,
defaultDur
)
log
.
Printf
(
"%s status=429 rate_limited scope=%s reset_in=%v (fallback)"
,
prefix
,
quotaScope
,
defaultDur
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment