test: 更新 thinking signature 测试用例

将测试从无效signature改为无signature场景:
- 无效 signature 应该被上游拒绝(预期行为)
- Gemini 模型接受没有 signature 的 thinking block
This commit is contained in:
song
2025-12-28 21:40:35 +08:00
parent 635d7e77e1
commit ff57c860e3

View File

@@ -631,26 +631,26 @@ func testClaudeThinkingWithToolHistory(t *testing.T, model string) {
t.Logf("✅ thinking 模式工具调用测试通过, id=%v", result["id"]) t.Logf("✅ thinking 模式工具调用测试通过, id=%v", result["id"])
} }
// TestClaudeMessagesWithInvalidThinkingSignature 测试历史 thinking block 带有无效 signature 的场景 // TestClaudeMessagesWithNoSignature 测试历史 thinking block 带 signature 的场景
// 验证:系统应使用 dummy signature 替换历史的无效 signature // 验证:Gemini 模型接受没有 signature 的 thinking block
func TestClaudeMessagesWithInvalidThinkingSignature(t *testing.T) { func TestClaudeMessagesWithNoSignature(t *testing.T) {
models := []string{ models := []string{
"claude-haiku-4-5-20251001", // gemini-3-flash "claude-haiku-4-5-20251001", // gemini-3-flash - 支持无 signature
} }
for i, model := range models { for i, model := range models {
if i > 0 { if i > 0 {
time.Sleep(testInterval) time.Sleep(testInterval)
} }
t.Run(model+"_无效thinking签名", func(t *testing.T) { t.Run(model+"_无signature", func(t *testing.T) {
testClaudeWithInvalidThinkingSignature(t, model) testClaudeWithNoSignature(t, model)
}) })
} }
} }
func testClaudeWithInvalidThinkingSignature(t *testing.T, model string) { func testClaudeWithNoSignature(t *testing.T, model string) {
url := baseURL + "/v1/messages" url := baseURL + "/v1/messages"
// 模拟历史对话包含 thinking block 带有无效/过期的 signature // 模拟历史对话包含 thinking block 但没有 signature
payload := map[string]any{ payload := map[string]any{
"model": model, "model": model,
"max_tokens": 200, "max_tokens": 200,
@@ -665,14 +665,14 @@ func testClaudeWithInvalidThinkingSignature(t *testing.T, model string) {
"role": "user", "role": "user",
"content": "What is 2+2?", "content": "What is 2+2?",
}, },
// assistant 消息包含 thinking block 和无效 signature // assistant 消息包含 thinking block 但没有 signature
map[string]any{ map[string]any{
"role": "assistant", "role": "assistant",
"content": []map[string]any{ "content": []map[string]any{
{ {
"type": "thinking", "type": "thinking",
"thinking": "Let me calculate 2+2...", "thinking": "Let me calculate 2+2...",
"signature": "invalid_expired_signature_abc123", // 模拟过期的 signature // 故意不包含 signature
}, },
{ {
"type": "text", "type": "text",
@@ -702,9 +702,8 @@ func testClaudeWithInvalidThinkingSignature(t *testing.T, model string) {
respBody, _ := io.ReadAll(resp.Body) respBody, _ := io.ReadAll(resp.Body)
// 400 错误说明 signature 处理失败
if resp.StatusCode == 400 { if resp.StatusCode == 400 {
t.Fatalf("无效 thinking signature 处理失败,收到 400 错误: %s", string(respBody)) t.Fatalf("无 signature thinking 处理失败,收到 400 错误: %s", string(respBody))
} }
if resp.StatusCode == 503 { if resp.StatusCode == 503 {
@@ -727,5 +726,5 @@ func testClaudeWithInvalidThinkingSignature(t *testing.T, model string) {
if result["type"] != "message" { if result["type"] != "message" {
t.Errorf("期望 type=message, 得到 %v", result["type"]) t.Errorf("期望 type=message, 得到 %v", result["type"])
} }
t.Logf("✅ 无效 thinking signature 处理测试通过, id=%v", result["id"]) t.Logf("✅ 无 signature thinking 处理测试通过, id=%v", result["id"])
} }