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>
251 lines
6.3 KiB
Markdown
251 lines
6.3 KiB
Markdown
# 🎯 Antigravity 账号验证 - 测试执行报告
|
|
|
|
## 执行摘要
|
|
|
|
✅ **所有本地单元测试全部通过**
|
|
|
|
- 基础验证测试: **8/8 通过**
|
|
- 全流程诊断测试: **5/5 通过**
|
|
- 总计: **13/13 通过** (0 失败)
|
|
|
|
---
|
|
|
|
## 📋 测试覆盖范围
|
|
|
|
### 1. 账号凭证完整性验证
|
|
```
|
|
✅ Account ID: 68
|
|
✅ Platform: antigravity
|
|
✅ Type: oauth
|
|
✅ Access Token: 有效 (260 字符)
|
|
✅ Refresh Token: 有效
|
|
✅ Email: priesjosephe139@gmail.com
|
|
✅ Project ID: kinetic-sum-r3tp7
|
|
✅ Token 有效期: 2026-04-11 18:25:54 CST (还有 19+ 分钟)
|
|
```
|
|
|
|
### 2. 模型映射验证
|
|
```
|
|
✅ claude-opus-4-6 - 支持
|
|
✅ claude-sonnet-4-6 - 支持
|
|
✅ gemini-3-pro-preview - 支持
|
|
```
|
|
|
|
### 3. 请求体构建
|
|
```
|
|
✅ JSON 格式正确
|
|
✅ 大小: 124 bytes
|
|
✅ 结构有效
|
|
```
|
|
|
|
### 4. 路由决策验证
|
|
```
|
|
✅ Platform check: antigravity ✓
|
|
✅ Type check: oauth ✓
|
|
✅ 使用路径: OAuth/Upstream (AntigravityGatewayService.TestConnection)
|
|
```
|
|
|
|
---
|
|
|
|
## 🔄 错误处理流程图
|
|
|
|
```
|
|
HTTP Handler
|
|
↓
|
|
accountTestService.TestAccountConnection()
|
|
↓
|
|
routeAntigravityTest()
|
|
├─ Platform: antigravity ✓
|
|
├─ Type: oauth ✓
|
|
└─ 调用: testAntigravityAccountConnection()
|
|
↓
|
|
AntigravityGatewayService.TestConnection()
|
|
├─ 获取 access_token ✓
|
|
├─ 获取 project_id ✓
|
|
├─ 构建请求体 ✓
|
|
└─ 调用 antigravityRetryLoop()
|
|
├─ 执行 HTTP 请求
|
|
├─ 解析响应
|
|
└─ 处理错误
|
|
↓
|
|
sendErrorAndEnd() 或 sendEvent()
|
|
↓
|
|
SSE 响应流
|
|
├─ Content-Type: text/event-stream
|
|
├─ Event: test_start
|
|
├─ Event: content 或 error
|
|
└─ Event: test_complete
|
|
```
|
|
|
|
---
|
|
|
|
## 🔍 "IT" 错误诊断
|
|
|
|
### 可能的根本原因
|
|
|
|
| 场景 | 症状 | 概率 |
|
|
|------|------|------|
|
|
| **错误被截断** | 原文可能是 `INVALID_TOKEN`, `INTERNAL_ERROR` 等 | 🔴 高 |
|
|
| **编码问题** | UTF-8/ASCII 混淆 | 🟡 中 |
|
|
| **SSE 流损坏** | HTTP 响应体不完整 | 🟡 中 |
|
|
| **特殊错误码** | Google API 返回 'IT' 作为错误 | 🟢 低 |
|
|
|
|
---
|
|
|
|
## 📝 建议的代码改进
|
|
|
|
### 1. 在 testAntigravityAccountConnection 中增加日志
|
|
|
|
```go
|
|
result, err := s.antigravityGatewayService.TestConnection(ctx, account, testModelID)
|
|
if err != nil {
|
|
// 添加这一行:捕获完整的错误信息
|
|
log.Printf("[DIAGNOSTIC] TestConnection error: type=%T, msg='%s' (len=%d)",
|
|
err, err.Error(), len(err.Error()))
|
|
return s.sendErrorAndEnd(c, err.Error())
|
|
}
|
|
```
|
|
|
|
**位置**: `backend/internal/service/account_test_service.go` 第 655-657 行
|
|
|
|
### 2. 在 sendErrorAndEnd 中增加详细日志
|
|
|
|
```go
|
|
func (s *AccountTestService) sendErrorAndEnd(c *gin.Context, msg string) error {
|
|
// 添加这些行:记录原始错误信息
|
|
log.Printf("[DIAGNOSTIC] sendErrorAndEnd called")
|
|
log.Printf("[DIAGNOSTIC] error_message='%s'", msg)
|
|
log.Printf("[DIAGNOSTIC] error_length=%d", len(msg))
|
|
log.Printf("[DIAGNOSTIC] error_bytes=%v", []byte(msg))
|
|
|
|
s.sendEvent(c, TestEvent{
|
|
Type: "test_error",
|
|
Error: msg,
|
|
Success: false,
|
|
})
|
|
s.sendEvent(c, TestEvent{Type: "test_complete", Success: false})
|
|
return nil
|
|
}
|
|
```
|
|
|
|
**位置**: `backend/internal/service/account_test_service.go` (搜索 `sendErrorAndEnd` 函数)
|
|
|
|
### 3. 在 TestConnection 中增加诊断日志
|
|
|
|
```go
|
|
func (s *AntigravityGatewayService) TestConnection(ctx context.Context, account *Account, modelID string) (*TestConnectionResult, error) {
|
|
log.Printf("[DIAGNOSTIC] TestConnection start: account=%d, modelID=%s", account.ID, modelID)
|
|
|
|
// ... 现有代码 ...
|
|
|
|
accessToken, err := s.tokenProvider.GetAccessToken(ctx, account)
|
|
if err != nil {
|
|
log.Printf("[DIAGNOSTIC] GetAccessToken error: %v", err)
|
|
return nil, fmt.Errorf("获取 access_token 失败: %w", err)
|
|
}
|
|
|
|
result, err := s.antigravityRetryLoop(p)
|
|
if err != nil {
|
|
log.Printf("[DIAGNOSTIC] antigravityRetryLoop error: type=%T, msg=%v", err, err)
|
|
return nil, err
|
|
}
|
|
|
|
log.Printf("[DIAGNOSTIC] TestConnection success")
|
|
return &TestConnectionResult{Text: text, MappedModel: mappedModel}, nil
|
|
}
|
|
```
|
|
|
|
**位置**: `backend/internal/service/antigravity_gateway_service.go` 第 1114 行
|
|
|
|
---
|
|
|
|
## 🚀 执行下一步的步骤
|
|
|
|
### 步骤 1: 添加诊断日志
|
|
|
|
在上述三个位置添加建议的日志代码。
|
|
|
|
### 步骤 2: 重新编译
|
|
|
|
```bash
|
|
cd backend
|
|
go build -o server ./cmd/server
|
|
```
|
|
|
|
### 步骤 3: 运行测试端点
|
|
|
|
```bash
|
|
curl -v -X POST 'https://temp365.top/api/v1/admin/accounts/68/test' \
|
|
-H 'Content-Type: application/json' \
|
|
-H 'authorization: Bearer YOUR_JWT_TOKEN' \
|
|
-d '{"model_id":"claude-opus-4-6","prompt":""}'
|
|
```
|
|
|
|
### 步骤 4: 查看完整的错误日志
|
|
|
|
```bash
|
|
# Docker 日志
|
|
docker logs <container-id> | grep "DIAGNOSTIC"
|
|
|
|
# 或本地日志
|
|
tail -f /var/log/sub2api/server.log | grep "DIAGNOSTIC"
|
|
```
|
|
|
|
### 步骤 5: 分析并修复
|
|
|
|
基于完整的错误日志,确定真实的错误原因并修复。
|
|
|
|
---
|
|
|
|
## 📊 测试结果统计
|
|
|
|
```
|
|
测试文件:
|
|
✅ antigravity_test_singleton_test.go (8 个测试)
|
|
✅ antigravity_test_full_flow_test.go (5 个测试)
|
|
|
|
执行时间: 0.6 秒
|
|
覆盖范围:
|
|
- 账号凭证验证 ✓
|
|
- 模型映射验证 ✓
|
|
- 请求体构建 ✓
|
|
- Token 有效期 ✓
|
|
- 路由决策 ✓
|
|
- 错误处理流程 ✓
|
|
- 诊断指导 ✓
|
|
|
|
结论: 🎉 所有本地验证已完成,问题根源需在实际环境中诊断
|
|
```
|
|
|
|
---
|
|
|
|
## 📖 参考资源
|
|
|
|
| 资源 | 位置 |
|
|
|------|------|
|
|
| 本地测试指南 | `/LOCAL_TEST_GUIDE.md` |
|
|
| 基础验证测试 | `backend/internal/service/antigravity_test_singleton_test.go` |
|
|
| 全流程诊断测试 | `backend/internal/service/antigravity_test_full_flow_test.go` |
|
|
| 账号处理器 | `backend/internal/handler/admin/account_handler.go` |
|
|
| 账号测试服务 | `backend/internal/service/account_test_service.go` |
|
|
| Antigravity 网关服务 | `backend/internal/service/antigravity_gateway_service.go` |
|
|
|
|
---
|
|
|
|
## ✅ 完成状态
|
|
|
|
- [x] 创建本地单元测试
|
|
- [x] 验证账号凭证
|
|
- [x] 验证请求路径
|
|
- [x] 生成诊断指南
|
|
- [ ] 添加代码日志 (待用户执行)
|
|
- [ ] 重新运行 HTTP 测试 (待用户执行)
|
|
- [ ] 分析完整错误信息 (待用户执行)
|
|
- [ ] 修复根本原因 (待用户执行)
|
|
|
|
---
|
|
|
|
**报告生成时间**: 2026-04-11
|
|
**测试版本**: v1.0
|
|
**状态**: ✅ 就绪,等待下一步行动
|