fix(executor): identify Grok CLI OAuth requests

This commit is contained in:
1502538344
2026-07-12 16:40:08 +08:00
parent 6fc4f0c4ef
commit 1a0bbe09c6
2 changed files with 10 additions and 0 deletions
@@ -1028,6 +1028,7 @@ func applyXAIChatHeaders(r *http.Request, auth *cliproxyauth.Auth, token string,
if xaiIsCLIChatProxyBaseURL(xaiChatBaseURL(auth)) {
r.Header.Set(xaiTokenAuthHeader, xaiTokenAuthValue)
r.Header.Set(xaiClientVersionHeader, xaiClientVersionValue)
r.Header.Set("User-Agent", "xai-grok-workspace/"+xaiClientVersionValue)
}
applyXAICustomHeaders(r, auth)
}
@@ -1733,6 +1733,9 @@ func TestApplyXAIChatHeaders(t *testing.T) {
if got := req.Header.Get(xaiClientVersionHeader); got != "" {
t.Fatalf("%s = %q, want empty for official API", xaiClientVersionHeader, got)
}
if got := req.Header.Get("User-Agent"); got != "" {
t.Fatalf("User-Agent = %q, want empty for official API", got)
}
})
t.Run("OAuth defaults to cli chat proxy headers", func(t *testing.T) {
@@ -1757,6 +1760,9 @@ func TestApplyXAIChatHeaders(t *testing.T) {
if got := req.Header.Get(xaiClientVersionHeader); got != xaiClientVersionValue {
t.Fatalf("%s = %q, want %q", xaiClientVersionHeader, got, xaiClientVersionValue)
}
if got := req.Header.Get("User-Agent"); got != "xai-grok-workspace/"+xaiClientVersionValue {
t.Fatalf("User-Agent = %q, want xai-grok-workspace/%s", got, xaiClientVersionValue)
}
})
t.Run("no cli headers on custom gateway with using_api false", func(t *testing.T) {
@@ -1775,6 +1781,9 @@ func TestApplyXAIChatHeaders(t *testing.T) {
if got := req.Header.Get(xaiClientVersionHeader); got != "" {
t.Fatalf("%s = %q, want empty for custom gateway", xaiClientVersionHeader, got)
}
if got := req.Header.Get("User-Agent"); got != "" {
t.Fatalf("User-Agent = %q, want empty for custom gateway", got)
}
})
t.Run("custom headers override cli chat proxy defaults", func(t *testing.T) {