You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ni...@apache.org on 2026/04/16 16:53:33 UTC
(apisix) 01/01: fix: resolve CI test failures in fixture-converted tests
This is an automated email from the ASF dual-hosted git repository.
nic443 pushed a commit to branch feat/ai-fixture-system
in repository https://gitbox.apache.org/repos/asf/apisix.git
commit 2a8dd4f8916e078cf32b26bbf090577e6f7c3e68
Author: Nic <qi...@api7.ai>
AuthorDate: Fri Apr 17 00:53:05 2026 +0800
fix: resolve CI test failures in fixture-converted tests
- server.lua: v1_chat_completions now has auth-checking + message-echo
fallback when X-AI-Fixture header is absent, restoring behavior needed
by ai-request-rewrite tests (auth validation, message concatenation)
- server.lua: _M.random() returns proper OpenAI JSON format instead of
plain text, matching what ai-request-rewrite.t TEST 8 expects
- ai-proxy.t TEST 12: updated assertion for new /random response format
- ai-proxy2.t TEST 4,8: fixed response_body assertion to allow optional
spaces after colons in JSON (fixture files are pretty-printed)
---
t/lib/server.lua | 37 +++++++++++++++++++++++++++++++++++--
t/plugin/ai-proxy.t | 4 ++--
t/plugin/ai-proxy2.t | 4 ++--
3 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/t/lib/server.lua b/t/lib/server.lua
index ce939463b..c9520fb70 100644
--- a/t/lib/server.lua
+++ b/t/lib/server.lua
@@ -762,7 +762,39 @@ local function ai_fixture_dispatch()
end
function _M.v1_chat_completions()
- ai_fixture_dispatch()
+ -- fixture dispatch takes priority
+ if ngx.req.get_headers()["x-ai-fixture"] then
+ ai_fixture_dispatch()
+ return
+ end
+ -- fallback: auth-checking + message echo (for ai-request-rewrite tests)
+ local header_auth = ngx.req.get_headers()["authorization"]
+ local query_auth = ngx.req.get_uri_args()["api_key"]
+ if header_auth ~= "Bearer token" and query_auth ~= "apikey" then
+ ngx.status = 401
+ ngx.say("Unauthorized")
+ return
+ end
+ ngx.req.read_body()
+ local body = ngx.req.get_body_data()
+ local json = require("cjson.safe")
+ body = json.decode(body)
+ if not body or not body.messages or #body.messages < 1 then
+ ngx.status = 400
+ ngx.say([[{"error":"bad request"}]])
+ return
+ end
+ -- concatenate all message contents (for ai-request-rewrite prompt tests)
+ local parts = {}
+ for _, msg in ipairs(body.messages) do
+ if msg.content then
+ table.insert(parts, msg.content)
+ end
+ end
+ local content = table.concat(parts, " ")
+ ngx.say(json.encode({
+ choices = {{message = {content = content}}}
+ }))
end
function _M.v1_messages()
@@ -788,7 +820,8 @@ function _M.delay_v1_chat_completions()
end
function _M.random()
- ngx.say("path override works")
+ ngx.header["Content-Type"] = "application/json"
+ ngx.print([[{"choices":[{"message":{"content":"return by random endpoint"}}]}]])
end
-- Health check probe endpoint for AI proxy tests.
diff --git a/t/plugin/ai-proxy.t b/t/plugin/ai-proxy.t
index d806c7f74..2359a5bbe 100644
--- a/t/plugin/ai-proxy.t
+++ b/t/plugin/ai-proxy.t
@@ -373,8 +373,8 @@ qr/chat\.completion/
}
}
---- response_body
-path override works
+--- response_body_like
+return by random endpoint
diff --git a/t/plugin/ai-proxy2.t b/t/plugin/ai-proxy2.t
index 9cb5b78d8..5e2614128 100644
--- a/t/plugin/ai-proxy2.t
+++ b/t/plugin/ai-proxy2.t
@@ -147,7 +147,7 @@ POST /anything
X-AI-Fixture: openai/chat-basic.json
--- error_code: 200
--- response_body eval
-qr/"content":"1 \+ 1 = 2\."/
+qr/"content"\s*:\s*"1 \+ 1 = 2\."/
@@ -247,4 +247,4 @@ POST /anything
X-AI-Fixture: openai/chat-basic.json
--- error_code: 200
--- response_body eval
-qr/"content":"1 \+ 1 = 2\."/
+qr/"content"\s*:\s*"1 \+ 1 = 2\."/