v3.0-genai_keys: GenAI live validations, LLM bridge tests, and portability fix#5423
Conversation
…semantic lifecycle
This commit introduces three new C++ TAP tests that validate ProxySQL's live
GenAI and MCP behaviors using real provider credentials supplied via
environment variables. The goal is to move beyond mock-style checks and verify
actual runtime integration across request transport, tool execution, and
semantic outputs.
High-level scope
- Add a live GenAI embed/rerank validation TAP test.
- Add a live LLM bridge accuracy/error-path TAP test.
- Add a live MCP semantic lifecycle TAP test that combines discovery,
LLM-generated artifacts, upsert, and semantic search.
- Register all three new tests in ai-g1 group mapping.
Files added
- test/tap/tests/genai_live_validation-t.cpp
- test/tap/tests/llm_bridge_accuracy-t.cpp
- test/tap/tests/mcp_semantic_lifecycle-t.cpp
File updated
- test/tap/groups/groups.json
Detailed behavior by test
1) genai_live_validation-t.cpp
- Reads required live env inputs:
TAP_EMBED_URL, TAP_EMBED_TYPE, TAP_EMBED_MODEL, TAP_EMBED_DIMENSION,
TAP_RERANK_URL, TAP_RERANK_MODEL
- Skips (does not fail) when required environment is missing.
- Configures runtime for test stability:
- sets genai-vector_db_path to ./ai_features.db
- enables genai-enabled
- sets embed/rerank endpoints and embedding model
- loads GENAI variables to runtime
- Embedding integrity validation:
- sends GENAI embed request with multiple documents
- verifies row count matches input document count
- verifies each returned embedding dimension matches TAP_EMBED_DIMENSION
- Rerank semantic validation:
- sends query with one intentionally relevant document and irrelevant distractors
- checks highest score maps to the relevant document index
- Stress validation:
- opens 5 client connections
- executes 20 total requests (4 per connection) concurrently
- validates all requests succeed and no failures are reported
- Includes high-verbosity diagnostics for SQL requests and parsed rows.
2) llm_bridge_accuracy-t.cpp
- Reads required live env inputs:
TAP_LLM_PROVIDER, TAP_LLM_URL, TAP_LLM_MODEL, TAP_LLM_KEY
- Skips (does not fail) when required environment is missing.
- Configures LLM bridge runtime:
- sets genai-vector_db_path
- enables genai-enabled and genai-llm_enabled
- sets provider/url/model/key
- loads GENAI variables to runtime
- Special-character prompt handling:
- issues LLM: prompt containing quotes, backslashes, JSON-like text,
and emoji bytes
- verifies request succeeds and response structure is valid
- verifies returned provider column aligns with TAP_LLM_PROVIDER
- Timeout/error-path validation:
- reconfigures provider URL to an unroutable timeout-probe endpoint
- sets genai-llm_timeout_ms=1000 (minimum valid bound in current code)
- verifies client receives an error path with SQLSTATE HY000 and non-empty message
- Captures and restores modified global variables at end of test.
3) mcp_semantic_lifecycle-t.cpp
- Reads required live env inputs:
TAP_LLM_PROVIDER, TAP_LLM_URL, TAP_LLM_MODEL, TAP_LLM_KEY
- Skips (does not fail) when required environment is missing.
- Configures LLM and MCP runtime for end-to-end lifecycle checks:
- enables genai + llm bridge
- configures MCP port/auth endpoint settings
- creates MCP auth and target profiles
- loads MCP variables/profiles to runtime
- End-to-end lifecycle:
- calls discovery.run_static and validates run_id
- lists discovered table objects and selects object_ids
- starts agent run via agent.run_start
- generates summary text through LLM: bridge for two semantic markers
- persists summaries via llm.summary_upsert for two objects
- validates llm.search("customer") finds customer marker
- validates llm.search("index") finds index marker
- finishes run via agent.run_finish
- Cleans up test MCP profiles and restores runtime variables.
Groups registration
- Added to ai-g1 in test/tap/groups/groups.json:
- llm_bridge_accuracy-t
- genai_live_validation-t
- mcp_semantic_lifecycle-t
Implementation notes and constraints reflected in tests
- Tests are intentionally environment-gated and skip when live credentials are
unavailable.
- All tests include verbose diagnostics for outbound requests and parsed
provider/tool responses.
- Runtime variable mutations are restored best-effort to reduce suite side effects.
- llm timeout validation uses 1000ms because current runtime validation enforces
[1000..600000] for genai-llm_timeout_ms.
Build verification performed
- Compiled successfully (as jenkins user):
- genai_live_validation-t
- llm_bridge_accuracy-t
- mcp_semantic_lifecycle-t
This commit intentionally focuses on live integration correctness and transport
behavior under real endpoints, while remaining TAP-friendly for CI environments
that may not provide credentials (skip semantics instead of hard failures).
Add #ifdef __linux__ guard around sys/eventfd.h include to fix compilation on non-Linux platforms.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @renecannao, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the testing infrastructure for GenAI and LLM features, ensuring robustness and correctness across various scenarios. It also addresses a critical portability issue, improving cross-platform compatibility. The new tests cover live validation of GenAI services, accuracy of the LLM bridge, and the end-to-end lifecycle of semantic artifact generation and retrieval within the MCP framework. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces several new TAP tests for GenAI, LLM bridge, and MCP lifecycle, along with a portability fix for Linux. My review focuses on the new test files. I've identified a repeated SQL injection vulnerability in a helper function across all new test files, which should be addressed with high priority. I've also suggested improvements for code readability and exception handling. Overall, the new tests are comprehensive, but the security issue in the test utilities needs to be fixed.
| std::string sql_escape(const std::string& value) { | ||
| std::string out; | ||
| out.reserve(value.size()); | ||
| for (char c : value) { | ||
| out.push_back(c); | ||
| if (c == '\'') { | ||
| out.push_back('\''); | ||
| } | ||
| } | ||
| return out; | ||
| } |
There was a problem hiding this comment.
This custom sql_escape function is vulnerable to SQL injection. It only escapes single quotes (') and does not handle other special characters like backslashes (\\), which can be used to bypass the escaping. This could lead to security vulnerabilities.
It is strongly recommended to use the mysql_real_escape_string() function from the MySQL C API, which is designed for this purpose and handles all necessary character escaping securely. This function requires a MYSQL* connection handle.
For example, you could refactor the function to:
std::string sql_escape(MYSQL* conn, const std::string& value) {
std::string escaped_value;
escaped_value.resize(value.length() * 2 + 1);
unsigned long new_len = mysql_real_escape_string(conn, &escaped_value[0], value.c_str(), value.length());
escaped_value.resize(new_len);
return escaped_value;
}And update call sites accordingly.
Since this utility function is duplicated across multiple new test files, consider creating a shared, secure version in a common utility file.
| std::string sql_escape(const std::string& value) { | ||
| std::string out; | ||
| out.reserve(value.size()); | ||
| for (char c : value) { | ||
| out.push_back(c); | ||
| if (c == '\'') { | ||
| out.push_back('\''); | ||
| } | ||
| } | ||
| return out; | ||
| } |
There was a problem hiding this comment.
This custom sql_escape function is vulnerable to SQL injection as it only escapes single quotes. It does not handle other special characters (e.g., backslashes), which can lead to security vulnerabilities. Please use mysql_real_escape_string() for secure SQL string escaping.
This vulnerable function is present in multiple new test files. It would be best to create a single, secure utility function and use it across all tests.
| std::string sql_escape(const std::string& value) { | ||
| std::string out; | ||
| out.reserve(value.size()); | ||
| for (char c : value) { | ||
| out.push_back(c); | ||
| if (c == '\'') { | ||
| out.push_back('\''); | ||
| } | ||
| } | ||
| return out; | ||
| } |
There was a problem hiding this comment.
This sql_escape function is not safe and is vulnerable to SQL injection. It only handles single quotes and misses other characters that need escaping, such as backslashes. For robust and secure escaping, please use mysql_real_escape_string() from the MySQL C API.
As this function is copied in several test files, it should be refactored into a common, secure utility.
| } catch (...) { | ||
| return default_value; | ||
| } |
There was a problem hiding this comment.
Using catch (...) is generally discouraged as it catches all exceptions, including system-level ones that might be better to propagate. This can hide bugs and make debugging difficult. It's better to catch std::exception or more specific exceptions that you expect std::stoi to throw, such as std::invalid_argument and std::out_of_range.
| } catch (...) { | |
| return default_value; | |
| } | |
| } catch (const std::exception& /* e */) { | |
| return default_value; | |
| } |
| const std::string uniq = std::to_string(static_cast<long long>(time(nullptr))); | ||
| const std::string target_id = "tap_mcp_semantic_target_" + uniq; | ||
| const std::string auth_profile_id = "tap_mcp_semantic_auth_" + uniq; | ||
| const std::string schema_filter = env_or_empty("MYSQL_DATABASE").empty() ? "sysbench" : env_or_empty("MYSQL_DATABASE"); |
There was a problem hiding this comment.
This line calls env_or_empty("MYSQL_DATABASE") twice, which is inefficient and makes the code harder to read. It's better to call it once, store the result in a variable, and then perform the check. For example:
const std::string schema_filter_env = env_or_empty("MYSQL_DATABASE");
const std::string schema_filter = schema_filter_env.empty() ? "sysbench" : schema_filter_env;
|


Summary
This PR adds live TAP validation tests for GenAI, LLM bridge accuracy tests, MCP semantic lifecycle tests, and a Linux portability fix.
Changes
New Test Files
test/tap/tests/genai_live_validation-t.cpp- Live TAP validations for GenAI functionalitytest/tap/tests/llm_bridge_accuracy-t.cpp- LLM bridge accuracy testingtest/tap/tests/mcp_semantic_lifecycle-t.cpp- MCP semantic lifecycle validation (678 lines)Bug Fixes
sys/eventfd.hinclude to be conditional on Linux only (#ifdef __linux__)Modified Files
include/Discovery_Schema.h- Schema discovery updateslib/Admin_FlushVariables.cpp- Admin flush variables updateslib/Discovery_Schema.cpp- Schema discovery implementation updateslib/GenAI_Thread.cpp- Added Linux-only eventfd.h includetest/tap/groups/groups.json- Updated test groupsCommits