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
84ced1c4
Unverified
Commit
84ced1c4
authored
Feb 10, 2026
by
Wesley Liddick
Committed by
GitHub
Feb 10, 2026
Browse files
Merge pull request #543 from slovx2/upstream_main
feat(antigravity): 转发与测试支持 daily/prod 单 URL 切换
parents
5dd83d3c
b1613121
Changes
2
Show whitespace changes
Inline
Side-by-side
backend/internal/service/antigravity_gateway_service.go
View file @
84ced1c4
...
...
@@ -70,6 +70,7 @@ var antigravityPassthroughErrorMessages = []string{
const
(
antigravityBillingModelEnv
=
"GATEWAY_ANTIGRAVITY_BILL_WITH_MAPPED_MODEL"
antigravityForwardBaseURLEnv
=
"GATEWAY_ANTIGRAVITY_FORWARD_BASE_URL"
antigravityFallbackSecondsEnv
=
"GATEWAY_ANTIGRAVITY_FALLBACK_COOLDOWN_SECONDS"
)
...
...
@@ -131,6 +132,20 @@ type antigravityRetryLoopResult struct {
resp
*
http
.
Response
}
// resolveAntigravityForwardBaseURL 解析转发用 base URL。
// 默认使用 daily(ForwardBaseURLs 的首个地址);当环境变量为 prod 时使用第二个地址。
func
resolveAntigravityForwardBaseURL
()
string
{
baseURLs
:=
antigravity
.
ForwardBaseURLs
()
if
len
(
baseURLs
)
==
0
{
return
""
}
mode
:=
strings
.
ToLower
(
strings
.
TrimSpace
(
os
.
Getenv
(
antigravityForwardBaseURLEnv
)))
if
mode
==
"prod"
&&
len
(
baseURLs
)
>
1
{
return
baseURLs
[
1
]
}
return
baseURLs
[
0
]
}
// smartRetryAction 智能重试的处理结果
type
smartRetryAction
int
...
...
@@ -466,10 +481,11 @@ func (s *AntigravityGatewayService) antigravityRetryLoop(p antigravityRetryLoopP
}
}
availabl
eURL
s
:=
a
ntigravity
.
DefaultURLAvailability
.
GetAvailabl
eURL
s
()
if
len
(
availabl
eURL
s
)
==
0
{
availableURLs
=
antigravity
.
BaseURLs
bas
eURL
:=
resolveA
ntigravity
ForwardBas
eURL
()
if
bas
eURL
==
""
{
return
nil
,
errors
.
New
(
"no antigravity forward base url configured"
)
}
availableURLs
:=
[]
string
{
baseURL
}
var
resp
*
http
.
Response
var
usedBaseURL
string
...
...
@@ -907,11 +923,11 @@ func (s *AntigravityGatewayService) TestConnection(ctx context.Context, account
proxyURL
=
account
.
Proxy
.
URL
()
}
// URL fallback 循环
availableURLs
:=
antigravity
.
DefaultURLAvailability
.
GetAvailableURLs
()
if
len
(
availableURLs
)
==
0
{
availableURLs
=
antigravity
.
BaseURLs
// 所有 URL 都不可用时,重试所有
baseURL
:=
resolveAntigravityForwardBaseURL
()
if
baseURL
==
""
{
return
nil
,
errors
.
New
(
"no antigravity forward base url configured"
)
}
availableURLs
:=
[]
string
{
baseURL
}
var
lastErr
error
for
urlIdx
,
baseURL
:=
range
availableURLs
{
...
...
backend/internal/service/antigravity_rate_limit_test.go
View file @
84ced1c4
...
...
@@ -86,7 +86,9 @@ func (s *stubAntigravityAccountRepo) SetModelRateLimit(ctx context.Context, id i
return
nil
}
func
TestAntigravityRetryLoop_URLFallback_UsesLatestSuccess
(
t
*
testing
.
T
)
{
func
TestAntigravityRetryLoop_NoURLFallback_UsesConfiguredBaseURL
(
t
*
testing
.
T
)
{
t
.
Setenv
(
antigravityForwardBaseURLEnv
,
""
)
oldBaseURLs
:=
append
([]
string
(
nil
),
antigravity
.
BaseURLs
...
)
oldAvailability
:=
antigravity
.
DefaultURLAvailability
defer
func
()
{
...
...
@@ -131,15 +133,16 @@ func TestAntigravityRetryLoop_URLFallback_UsesLatestSuccess(t *testing.T) {
require
.
NotNil
(
t
,
result
)
require
.
NotNil
(
t
,
result
.
resp
)
defer
func
()
{
_
=
result
.
resp
.
Body
.
Close
()
}()
require
.
Equal
(
t
,
http
.
StatusOK
,
result
.
resp
.
StatusCode
)
require
.
False
(
t
,
handleErrorCalled
)
require
.
Len
(
t
,
upstream
.
calls
,
2
)
require
.
True
(
t
,
strings
.
HasPrefix
(
upstream
.
calls
[
0
],
base1
))
require
.
True
(
t
,
strings
.
HasPrefix
(
upstream
.
calls
[
1
],
base2
))
require
.
Equal
(
t
,
http
.
StatusTooManyRequests
,
result
.
resp
.
StatusCode
)
require
.
True
(
t
,
handleErrorCalled
)
require
.
Len
(
t
,
upstream
.
calls
,
antigravityMaxRetries
)
for
_
,
callURL
:=
range
upstream
.
calls
{
require
.
True
(
t
,
strings
.
HasPrefix
(
callURL
,
base1
))
}
available
:=
antigravity
.
DefaultURLAvailability
.
GetAvailableURLs
()
require
.
NotEmpty
(
t
,
available
)
require
.
Equal
(
t
,
base
2
,
available
[
0
])
require
.
Equal
(
t
,
base
1
,
available
[
0
])
}
// TestHandleUpstreamError_429_ModelRateLimit 测试 429 模型限流场景
...
...
@@ -915,6 +918,22 @@ func TestIsAntigravityAccountSwitchError(t *testing.T) {
}
}
func
TestResolveAntigravityForwardBaseURL_DefaultDaily
(
t
*
testing
.
T
)
{
t
.
Setenv
(
antigravityForwardBaseURLEnv
,
""
)
oldBaseURLs
:=
append
([]
string
(
nil
),
antigravity
.
BaseURLs
...
)
defer
func
()
{
antigravity
.
BaseURLs
=
oldBaseURLs
}()
prodURL
:=
"https://prod.test"
dailyURL
:=
"https://daily.test"
antigravity
.
BaseURLs
=
[]
string
{
dailyURL
,
prodURL
}
resolved
:=
resolveAntigravityForwardBaseURL
()
require
.
Equal
(
t
,
dailyURL
,
resolved
)
}
func
TestAntigravityAccountSwitchError_Error
(
t
*
testing
.
T
)
{
err
:=
&
AntigravityAccountSwitchError
{
OriginalAccountID
:
789
,
...
...
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