@@ -146,6 +146,20 @@ var azureInvalidConfigMissingToken = func() json.RawMessage {
146146 return data
147147}()
148148
149+ // 测试配置:Azure OpenAI Response API配置
150+ var azureResponseAPIConfig = func () json.RawMessage {
151+ data , _ := json .Marshal (map [string ]interface {}{
152+ "provider" : map [string ]interface {}{
153+ "type" : "azure" ,
154+ "apiTokens" : []string {
155+ "sk-azure-multi" ,
156+ },
157+ "azureServiceUrl" : "https://multi-resource.openai.azure.com/openai/responses?api-version=2025-04-01-preview" ,
158+ },
159+ })
160+ return data
161+ }()
162+
149163func RunAzureParseConfigTests (t * testing.T ) {
150164 test .RunGoTest (t , func (t * testing.T ) {
151165 // 测试基本Azure OpenAI配置解析
@@ -203,6 +217,17 @@ func RunAzureParseConfigTests(t *testing.T) {
203217 require .NotNil (t , config )
204218 })
205219
220+ // 测试Azure Response API 配置解析
221+ t .Run ("azure response api config" , func (t * testing.T ) {
222+ host , status := test .NewTestHost (azureResponseAPIConfig )
223+ defer host .Reset ()
224+ require .Equal (t , types .OnPluginStartStatusOK , status )
225+
226+ config , err := host .GetMatchConfig ()
227+ require .NoError (t , err )
228+ require .NotNil (t , config )
229+ })
230+
206231 // 测试Azure OpenAI无效配置(缺少azureServiceUrl)
207232 t .Run ("azure invalid config missing url" , func (t * testing.T ) {
208233 host , status := test .NewTestHost (azureInvalidConfigMissingUrl )
@@ -411,6 +436,61 @@ func RunAzureOnHttpRequestBodyTests(t *testing.T) {
411436 require .Equal (t , "gpt-4" , model , "Model should be mapped correctly" )
412437 })
413438
439+ // 测试Azure OpenAI Response API 处理
440+ t .Run ("azure response api request body" , func (t * testing.T ) {
441+ host , status := test .NewTestHost (azureResponseAPIConfig )
442+ defer host .Reset ()
443+ require .Equal (t , types .OnPluginStartStatusOK , status )
444+
445+ // 设置请求头
446+ action := host .CallOnHttpRequestHeaders ([][2 ]string {
447+ {":authority" , "example.com" },
448+ {":path" , "/responses/v1/responses" },
449+ {":method" , "POST" },
450+ {"Content-Type" , "application/json" },
451+ })
452+ require .Equal (t , types .HeaderStopIteration , action )
453+
454+ // 设置请求体
455+ requestBody := `{
456+ "input": [
457+ {
458+ "role": "user",
459+ "content": [
460+ {
461+ "type": "input_text",
462+ "text": "Explain quantum computing"
463+ }
464+ ]
465+ }
466+ ],
467+ "model": "gpt-5",
468+ "reasoning": {
469+ "effort": "medium"
470+ }
471+ }`
472+ action = host .CallOnHttpRequestBody ([]byte (requestBody ))
473+ require .Equal (t , types .ActionContinue , action )
474+
475+ // 验证请求体是否被正确处理
476+ transformedBody := host .GetRequestBody ()
477+ require .NotNil (t , transformedBody )
478+
479+ var bodyMap map [string ]interface {}
480+ err := json .Unmarshal (transformedBody , & bodyMap )
481+ require .NoError (t , err )
482+
483+ model , exists := bodyMap ["model" ]
484+ require .True (t , exists , "Model should exist in request body" )
485+ require .Equal (t , "gpt-5" , model , "Model should be mapped correctly" )
486+
487+ // 验证请求路径是否被正确转换
488+ requestHeaders := host .GetRequestHeaders ()
489+ pathValue , hasPath := test .GetHeaderValue (requestHeaders , ":path" )
490+ require .True (t , hasPath , "Path header should exist" )
491+ require .Equal (t , pathValue , "/openai/responses?api-version=2025-04-01-preview" , "Path should not equal Azure response api path" )
492+ })
493+
414494 // 测试Azure OpenAI请求体处理(仅部署配置)
415495 t .Run ("azure deployment only request body" , func (t * testing.T ) {
416496 host , status := test .NewTestHost (azureDeploymentOnlyConfig )
@@ -566,6 +646,10 @@ func RunAzureOnHttpResponseBodyTests(t *testing.T) {
566646 }
567647 ]
568648 }`
649+ action = host .CallOnHttpResponseHeaders ([][2 ]string {
650+ {"Content-Type" , "application/json" },
651+ })
652+ require .Equal (t , types .ActionContinue , action )
569653 action = host .CallOnHttpRequestBody ([]byte (requestBody ))
570654 require .Equal (t , types .ActionContinue , action )
571655
0 commit comments