Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

test: harden remote api chat fixture for SSRF validation

liweixinbf514ff68a84
diff --git a/internal/models/chat/remote_api_test.go b/internal/models/chat/remote_api_test.go
index 90b232a44..85a410b81 100644
--- a/internal/models/chat/remote_api_test.go
+++ b/internal/models/chat/remote_api_test.go
@@ -12,19 +12,22 @@ import (
"github.com/stretchr/testify/require"
)
-func newTestRemoteChat() *RemoteAPIChat {
- chat, _ := NewRemoteAPIChat(&ChatConfig{
+func newTestRemoteChat(t *testing.T) *RemoteAPIChat {
+ t.Helper()
+
+ chat, err := NewRemoteAPIChat(&ChatConfig{
Source: types.ModelSourceRemote,
- BaseURL: "https://api.example.com/v1",
+ BaseURL: "https://example.com/v1",
ModelName: "test-model",
APIKey: "test-key",
ModelID: "test-model",
})
+ require.NoError(t, err)
return chat
}
func TestBuildChatCompletionRequest_ParallelToolCalls(t *testing.T) {
- chat := newTestRemoteChat()
+ chat := newTestRemoteChat(t)
messages := []Message{{Role: "user", Content: "hello"}}
t.Run("nil ParallelToolCalls leaves default", func(t *testing.T) {
@@ -65,7 +68,7 @@ func TestBuildChatCompletionRequest_ParallelToolCalls(t *testing.T) {
}
func TestBuildChatCompletionRequest_MCPToolsFormat(t *testing.T) {
- chat := newTestRemoteChat()
+ chat := newTestRemoteChat(t)
messages := []Message{{Role: "user", Content: "查询乙醇的理化性质"}}
mcpTools := []Tool{
@@ -111,7 +114,7 @@ func TestBuildChatCompletionRequest_MCPToolsFormat(t *testing.T) {
}
func TestBuildChatCompletionRequest_ToolChoice(t *testing.T) {
- chat := newTestRemoteChat()
+ chat := newTestRemoteChat(t)
messages := []Message{{Role: "user", Content: "test"}}
t.Run("auto tool choice", func(t *testing.T) {