fix(service): normalize user agent for gemini session reuse
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -52,10 +52,11 @@ func BuildGeminiDigestChain(req *antigravity.GeminiRequest) string {
|
|||||||
// 返回 16 字符的 Base64 编码的 SHA256 前缀
|
// 返回 16 字符的 Base64 编码的 SHA256 前缀
|
||||||
func GenerateGeminiPrefixHash(userID, apiKeyID int64, ip, userAgent, platform, model string) string {
|
func GenerateGeminiPrefixHash(userID, apiKeyID int64, ip, userAgent, platform, model string) string {
|
||||||
// 组合所有标识符
|
// 组合所有标识符
|
||||||
|
normalizedUserAgent := NormalizeSessionUserAgent(userAgent)
|
||||||
combined := strconv.FormatInt(userID, 10) + ":" +
|
combined := strconv.FormatInt(userID, 10) + ":" +
|
||||||
strconv.FormatInt(apiKeyID, 10) + ":" +
|
strconv.FormatInt(apiKeyID, 10) + ":" +
|
||||||
ip + ":" +
|
ip + ":" +
|
||||||
userAgent + ":" +
|
normalizedUserAgent + ":" +
|
||||||
platform + ":" +
|
platform + ":" +
|
||||||
model
|
model
|
||||||
|
|
||||||
|
|||||||
@@ -152,6 +152,24 @@ func TestGenerateGeminiPrefixHash(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGenerateGeminiPrefixHash_IgnoresUserAgentVersionNoise(t *testing.T) {
|
||||||
|
hash1 := GenerateGeminiPrefixHash(1, 100, "192.168.1.1", "Mozilla/5.0 codex_cli_rs/0.1.0", "antigravity", "gemini-2.5-pro")
|
||||||
|
hash2 := GenerateGeminiPrefixHash(1, 100, "192.168.1.1", "Mozilla/5.0 codex_cli_rs/0.1.1", "antigravity", "gemini-2.5-pro")
|
||||||
|
|
||||||
|
if hash1 != hash2 {
|
||||||
|
t.Fatalf("version-only User-Agent changes should not perturb Gemini prefix hash: %s vs %s", hash1, hash2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGenerateGeminiPrefixHash_IgnoresFreeformUserAgentVersionNoise(t *testing.T) {
|
||||||
|
hash1 := GenerateGeminiPrefixHash(1, 100, "192.168.1.1", "Codex CLI 0.1.0", "antigravity", "gemini-2.5-pro")
|
||||||
|
hash2 := GenerateGeminiPrefixHash(1, 100, "192.168.1.1", "Codex CLI 0.1.1", "antigravity", "gemini-2.5-pro")
|
||||||
|
|
||||||
|
if hash1 != hash2 {
|
||||||
|
t.Fatalf("free-form version-only User-Agent changes should not perturb Gemini prefix hash: %s vs %s", hash1, hash2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseGeminiSessionValue(t *testing.T) {
|
func TestParseGeminiSessionValue(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
Reference in New Issue
Block a user