Skip to content

v3.0-genai_keys: GenAI live validations, LLM bridge tests, and portability fix#5423

Merged
renecannao merged 2 commits into
v3.0-unified-large-prfrom
v3.0-genai_keys
Feb 25, 2026
Merged

v3.0-genai_keys: GenAI live validations, LLM bridge tests, and portability fix#5423
renecannao merged 2 commits into
v3.0-unified-large-prfrom
v3.0-genai_keys

Conversation

@renecannao

Copy link
Copy Markdown
Contributor

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 functionality
  • test/tap/tests/llm_bridge_accuracy-t.cpp - LLM bridge accuracy testing
  • test/tap/tests/mcp_semantic_lifecycle-t.cpp - MCP semantic lifecycle validation (678 lines)

Bug Fixes

  • Fixed sys/eventfd.h include to be conditional on Linux only (#ifdef __linux__)

Modified Files

  • include/Discovery_Schema.h - Schema discovery updates
  • lib/Admin_FlushVariables.cpp - Admin flush variables updates
  • lib/Discovery_Schema.cpp - Schema discovery implementation updates
  • lib/GenAI_Thread.cpp - Added Linux-only eventfd.h include
  • test/tap/groups/groups.json - Updated test groups

Commits

  • cffd980 - fix: Conditionally include sys/eventfd.h only on Linux
  • bcefd09 - test(genai): add live TAP validations for GenAI, LLM bridge, and MCP semantic lifecycle

…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.
@coderabbitai

coderabbitai Bot commented Feb 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch v3.0-genai_keys

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @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

  • GenAI Live Validations: Added comprehensive TAP validation tests for GenAI's embedding and reranking asynchronous pipeline, including checks for vector integrity, semantic correctness, and concurrency stress.
  • LLM Bridge Accuracy Tests: Introduced tests to verify the LLM bridge's behavior, ensuring correct handling of special characters in prompts and proper MySQL error reporting for timeout scenarios.
  • MCP Semantic Lifecycle Tests: Implemented end-to-end tests for the MCP framework's semantic lifecycle, validating the process from data discovery and LLM-generated summary creation to persistence and retrieval.
  • Linux Portability Fix: Resolved a portability issue by making the inclusion of the sys/eventfd.h header conditional, ensuring it is only compiled on Linux systems.

🧠 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
  • lib/GenAI_Thread.cpp
    • Wrapped the sys/eventfd.h include within a #ifdef __linux__ block to ensure it's only compiled on Linux.
  • test/tap/groups/groups.json
    • Added llm_bridge_accuracy-t to the ai-g1 test group.
    • Added genai_live_validation-t to the ai-g1 test group.
    • Added mcp_semantic_lifecycle-t to the ai-g1 test group.
  • test/tap/tests/genai_live_validation-t.cpp
    • Added a new TAP test file to validate GenAI embed/rerank async pipeline, including vector integrity, semantic correctness, and concurrency stress.
  • test/tap/tests/llm_bridge_accuracy-t.cpp
    • Added a new TAP test file to validate LLM bridge behavior, including special character handling and proper MySQL error reporting for timeouts.
  • test/tap/tests/mcp_semantic_lifecycle-t.cpp
    • Added a new TAP test file to validate the MCP discovery and LLM semantic artifact lifecycle, covering target registration, discovery, LLM summary generation, persistence, and retrieval.
Activity
  • renecannao fixed the conditional inclusion of sys/eventfd.h for Linux portability.
  • renecannao added comprehensive live TAP validation tests for GenAI, LLM bridge accuracy, and MCP semantic lifecycle.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +49 to +59
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;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

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.

Comment on lines +43 to +53
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;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

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.

Comment on lines +48 to +58
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;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

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.

Comment on lines +306 to +308
} catch (...) {
return default_value;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
} 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");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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;

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
Image 6 Security Hotspots

See analysis details on SonarQube Cloud

@renecannao
renecannao merged commit 148dfb2 into v3.0-unified-large-pr Feb 25, 2026
12 of 15 checks passed
@renecannao
renecannao deleted the v3.0-genai_keys branch April 17, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant