The test request was using maxOutputTokens: 1, which caused Google API to generate only 1 token. When decoded, this single token produced "It" as the response, making it look like an error. Changed: - Content: "." → "Test connection" (more meaningful prompt) - MaxTokens: 1 → 10 (enough tokens to verify connection is working) This fixes the issue where account test always showed "It" in the response, which was actually just the truncated output from the single-token generation. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
92 lines
2.6 KiB
Go
92 lines
2.6 KiB
Go
package service
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"testing"
|
||
"time"
|
||
|
||
"github.com/Wei-Shaw/sub2api/internal/pkg/antigravity"
|
||
)
|
||
|
||
// TestDirectUpstreamCall 直接调用真实的 Google API,看返回什么
|
||
func TestDirectUpstreamCall(t *testing.T) {
|
||
t.Log("🔥 直接调用 Google API,观察真实返回值...")
|
||
t.Log("")
|
||
|
||
accessToken := "ya29.a0Aa7MYioHycPKQ7xWQguns0VlftxfCwTqn2OY8zVosNMagLLGd5DXWFXpySKgfroGkqihr4Yrwauy1AXfQyvWB-F_4qt46DiEw1sCmaCNmDwjruUiWK7Km7vh7djBONbgruyL0N9_b3aSLi-Zf3llY5FbWZqcNky13gaVUaW0ioxEDVOZuKxYw82yVXvVEqPRXF7cetjUJbLdzwaCgYKAZwSARMSFQHGX2MiqNlICLPPA-_u6WHPBLiUJQ0213"
|
||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||
defer cancel()
|
||
|
||
// 步骤 1: 创建客户端
|
||
t.Log("步骤 1: 创建 Antigravity 客户端...")
|
||
client, err := antigravity.NewClient("")
|
||
if err != nil {
|
||
t.Fatalf("❌ 创建客户端失败: %v", err)
|
||
}
|
||
t.Log("✅ 客户端创建成功")
|
||
t.Log("")
|
||
|
||
// 步骤 2: 直接调用 LoadCodeAssist
|
||
t.Log("步骤 2: 调用 client.LoadCodeAssist(ctx, accessToken)...")
|
||
t.Logf(" AccessToken: %s... (长度: %d)", accessToken[:30], len(accessToken))
|
||
t.Log("")
|
||
|
||
resp, rawResp, err := client.LoadCodeAssist(ctx, accessToken)
|
||
|
||
// 步骤 3: 分析返回值
|
||
t.Log("步骤 3: 分析返回值...")
|
||
t.Log("")
|
||
|
||
if err != nil {
|
||
t.Logf("❌ 调用失败")
|
||
t.Logf(" 错误类型: %T", err)
|
||
t.Logf(" 错误信息: %v", err)
|
||
t.Logf(" 错误字符串: %s", err.Error())
|
||
t.Logf(" 错误长度: %d 字符", len(err.Error()))
|
||
t.Log("")
|
||
|
||
// 分析错误信息的前几个字符
|
||
errStr := err.Error()
|
||
if len(errStr) >= 2 {
|
||
t.Logf("📊 错误信息的前 5 个字符: '%s'", errStr[:min(5, len(errStr))])
|
||
}
|
||
t.Log("")
|
||
|
||
t.Logf("🎯 这就是导致 'IT' 错误的真实原因!")
|
||
t.Logf(" 错误完整内容: %q", errStr)
|
||
t.Log("")
|
||
|
||
// 尝试找出 "IT" 的来源
|
||
if len(errStr) >= 2 {
|
||
first2 := errStr[:2]
|
||
t.Logf("📌 错误的前两个字符: '%s'", first2)
|
||
if first2 == "IT" {
|
||
t.Logf(" ✓ 确认: 'IT' 就是从这个错误截断来的")
|
||
} else {
|
||
t.Logf(" ⚠️ 前两个字符不是 'IT',可能被其他方式处理了")
|
||
}
|
||
}
|
||
return
|
||
}
|
||
|
||
// 成功的情况
|
||
t.Log("✅ 调用成功!")
|
||
t.Log("")
|
||
|
||
if resp != nil {
|
||
t.Logf("📋 响应信息:")
|
||
t.Logf(" CloudAICompanionProject: %s", resp.CloudAICompanionProject)
|
||
t.Logf(" Response 类型: %T", resp)
|
||
t.Log("")
|
||
|
||
// 打印原始响应
|
||
if rawResp != nil {
|
||
t.Log("📄 原始 API 响应 JSON:")
|
||
jsonBytes, _ := json.MarshalIndent(rawResp, " ", " ")
|
||
t.Logf("%s", string(jsonBytes))
|
||
}
|
||
}
|
||
}
|