fix(backend): 修复 CI 失败问题
修复内容: 1. 修复 6 个 golangci-lint 错误 - 3 个 errcheck 错误:在 gateway_request_test.go 中添加类型断言检查 - 3 个 gofmt 格式化问题:修复代码格式 2. 修复 API 契约测试失败 - 在测试中添加缺失的字段:enable_identity_patch 和 identity_patch_prompt 所有测试和 linter 检查现已通过。
This commit is contained in:
@@ -313,7 +313,9 @@ func TestAPIContracts(t *testing.T) {
|
|||||||
"fallback_model_anthropic": "claude-3-5-sonnet-20241022",
|
"fallback_model_anthropic": "claude-3-5-sonnet-20241022",
|
||||||
"fallback_model_antigravity": "gemini-2.5-pro",
|
"fallback_model_antigravity": "gemini-2.5-pro",
|
||||||
"fallback_model_gemini": "gemini-2.5-pro",
|
"fallback_model_gemini": "gemini-2.5-pro",
|
||||||
"fallback_model_openai": "gpt-4o"
|
"fallback_model_openai": "gpt-4o",
|
||||||
|
"enable_identity_patch": true,
|
||||||
|
"identity_patch_prompt": ""
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -176,11 +176,14 @@ func TestFilterThinkingBlocksForRetry_DisablesThinkingAndPreservesAsText(t *test
|
|||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.Len(t, msgs, 2)
|
require.Len(t, msgs, 2)
|
||||||
|
|
||||||
assistant := msgs[1].(map[string]any)
|
assistant, ok := msgs[1].(map[string]any)
|
||||||
content := assistant["content"].([]any)
|
require.True(t, ok)
|
||||||
|
content, ok := assistant["content"].([]any)
|
||||||
|
require.True(t, ok)
|
||||||
require.Len(t, content, 2)
|
require.Len(t, content, 2)
|
||||||
|
|
||||||
first := content[0].(map[string]any)
|
first, ok := content[0].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
require.Equal(t, "text", first["type"])
|
require.Equal(t, "text", first["type"])
|
||||||
require.Equal(t, "Let me think...", first["text"])
|
require.Equal(t, "Let me think...", first["text"])
|
||||||
}
|
}
|
||||||
@@ -221,11 +224,17 @@ func TestFilterThinkingBlocksForRetry_RemovesRedactedThinkingAndKeepsValidConten
|
|||||||
_, hasThinking := req["thinking"]
|
_, hasThinking := req["thinking"]
|
||||||
require.False(t, hasThinking)
|
require.False(t, hasThinking)
|
||||||
|
|
||||||
msgs := req["messages"].([]any)
|
msgs, ok := req["messages"].([]any)
|
||||||
content := msgs[0].(map[string]any)["content"].([]any)
|
require.True(t, ok)
|
||||||
|
msg0, ok := msgs[0].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
content, ok := msg0["content"].([]any)
|
||||||
|
require.True(t, ok)
|
||||||
require.Len(t, content, 1)
|
require.Len(t, content, 1)
|
||||||
require.Equal(t, "text", content[0].(map[string]any)["type"])
|
content0, ok := content[0].(map[string]any)
|
||||||
require.Equal(t, "Visible", content[0].(map[string]any)["text"])
|
require.True(t, ok)
|
||||||
|
require.Equal(t, "text", content0["type"])
|
||||||
|
require.Equal(t, "Visible", content0["text"])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterThinkingBlocksForRetry_EmptyContentGetsPlaceholder(t *testing.T) {
|
func TestFilterThinkingBlocksForRetry_EmptyContentGetsPlaceholder(t *testing.T) {
|
||||||
@@ -240,11 +249,17 @@ func TestFilterThinkingBlocksForRetry_EmptyContentGetsPlaceholder(t *testing.T)
|
|||||||
|
|
||||||
var req map[string]any
|
var req map[string]any
|
||||||
require.NoError(t, json.Unmarshal(out, &req))
|
require.NoError(t, json.Unmarshal(out, &req))
|
||||||
msgs := req["messages"].([]any)
|
msgs, ok := req["messages"].([]any)
|
||||||
content := msgs[0].(map[string]any)["content"].([]any)
|
require.True(t, ok)
|
||||||
|
msg0, ok := msgs[0].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
content, ok := msg0["content"].([]any)
|
||||||
|
require.True(t, ok)
|
||||||
require.Len(t, content, 1)
|
require.Len(t, content, 1)
|
||||||
require.Equal(t, "text", content[0].(map[string]any)["type"])
|
content0, ok := content[0].(map[string]any)
|
||||||
require.NotEmpty(t, content[0].(map[string]any)["text"])
|
require.True(t, ok)
|
||||||
|
require.Equal(t, "text", content0["type"])
|
||||||
|
require.NotEmpty(t, content0["text"])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterSignatureSensitiveBlocksForRetry_DowngradesTools(t *testing.T) {
|
func TestFilterSignatureSensitiveBlocksForRetry_DowngradesTools(t *testing.T) {
|
||||||
@@ -265,11 +280,19 @@ func TestFilterSignatureSensitiveBlocksForRetry_DowngradesTools(t *testing.T) {
|
|||||||
_, hasThinking := req["thinking"]
|
_, hasThinking := req["thinking"]
|
||||||
require.False(t, hasThinking)
|
require.False(t, hasThinking)
|
||||||
|
|
||||||
msgs := req["messages"].([]any)
|
msgs, ok := req["messages"].([]any)
|
||||||
content := msgs[0].(map[string]any)["content"].([]any)
|
require.True(t, ok)
|
||||||
|
msg0, ok := msgs[0].(map[string]any)
|
||||||
|
require.True(t, ok)
|
||||||
|
content, ok := msg0["content"].([]any)
|
||||||
|
require.True(t, ok)
|
||||||
require.Len(t, content, 2)
|
require.Len(t, content, 2)
|
||||||
require.Equal(t, "text", content[0].(map[string]any)["type"])
|
content0, ok := content[0].(map[string]any)
|
||||||
require.Equal(t, "text", content[1].(map[string]any)["type"])
|
require.True(t, ok)
|
||||||
require.Contains(t, content[0].(map[string]any)["text"], "tool_use")
|
content1, ok := content[1].(map[string]any)
|
||||||
require.Contains(t, content[1].(map[string]any)["text"], "tool_result")
|
require.True(t, ok)
|
||||||
|
require.Equal(t, "text", content0["type"])
|
||||||
|
require.Equal(t, "text", content1["type"])
|
||||||
|
require.Contains(t, content0["text"], "tool_use")
|
||||||
|
require.Contains(t, content1["text"], "tool_result")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user