From acd05b60a93a9e90456793ca4b61ce3b3547666f Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Tue, 20 Jan 2026 09:23:20 +0000 Subject: [PATCH] Organize RAG test files properly - Move RAG test files to dedicated test/rag/ directory - Create proper Makefile in test/rag/ directory - Remove build_rag_test.sh script (replaced by Makefile) - Revert changes to main test/Makefile - Update documentation to reflect new test structure --- doc/rag-documentation.md | 2 +- test/Makefile | 3 - test/rag/Makefile | 31 ++++++++++ test/rag/test_rag_schema.cpp | 111 +++++++++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 test/rag/Makefile create mode 100644 test/rag/test_rag_schema.cpp diff --git a/doc/rag-documentation.md b/doc/rag-documentation.md index c148b7a7a..61c9cbaad 100644 --- a/doc/rag-documentation.md +++ b/doc/rag-documentation.md @@ -123,7 +123,7 @@ You can test the RAG functionality using the provided test scripts: ./scripts/mcp/test_rag.sh # Test RAG database schema -cd test +cd test/rag make test_rag_schema ./test_rag_schema ``` diff --git a/test/Makefile b/test/Makefile index ac381df2f..d2669242c 100644 --- a/test/Makefile +++ b/test/Makefile @@ -27,6 +27,3 @@ IDIRS := -I$(PROXYSQL_IDIR) \ sqlite_history_convert: sqlite_history_convert.cpp g++ -ggdb ../lib/SpookyV2.cpp ../lib/debug.cpp ../deps/sqlite3/sqlite3/sqlite3.o sqlite_history_convert.cpp ../lib/sqlite3db.cpp -o sqlite_history_convert $(IDIRS) -pthread -ldl - -test_rag_schema: test_rag_schema.cpp - $(CXX) -ggdb $(PROXYSQL_OBJS) test_rag_schema.cpp -o test_rag_schema $(IDIRS) $(LDIRS) $(PROXYSQL_LIBS) diff --git a/test/rag/Makefile b/test/rag/Makefile new file mode 100644 index 000000000..1f7dc1f02 --- /dev/null +++ b/test/rag/Makefile @@ -0,0 +1,31 @@ +#!/bin/make -f + +PROXYSQL_PATH := $(shell while [ ! -f ./src/proxysql_global.cpp ]; do cd ../..; done; pwd) + +include $(PROXYSQL_PATH)/include/makefiles_vars.mk +include $(PROXYSQL_PATH)/include/makefiles_paths.mk + +IDIRS := -I$(PROXYSQL_IDIR) \ + -I$(JEMALLOC_IDIR) \ + -I$(MARIADB_IDIR) \ + -I$(LIBCONFIG_IDIR) \ + -I$(RE2_IDIR) \ + -I$(SQLITE3_IDIR) \ + -I$(PCRE_IDIR) \ + -I$(SYS_LOC_IDIR) \ + -I$(CLICKHOUSE_CPP_IDIR) \ + -I$(MICROHTTPD_IDIR) \ + -I$(LIBHTTPSERVER_IDIR) \ + -I$(LIBINJECTION_IDIR) \ + -I$(CURL_IDIR) \ + -I$(EV_IDIR) \ + -I$(JSON_IDIR) \ + -I$(SSL_IDIR) + +test_rag_schema: test_rag_schema.cpp + $(CXX) -ggdb $(PROXYSQL_OBJS) test_rag_schema.cpp -o test_rag_schema $(IDIRS) $(LDIRS) $(PROXYSQL_LIBS) + +clean: + rm -f test_rag_schema + +.PHONY: clean \ No newline at end of file diff --git a/test/rag/test_rag_schema.cpp b/test/rag/test_rag_schema.cpp new file mode 100644 index 000000000..6b5fcc793 --- /dev/null +++ b/test/rag/test_rag_schema.cpp @@ -0,0 +1,111 @@ +/** + * @file test_rag_schema.cpp + * @brief Test RAG database schema creation + * + * Simple test to verify that RAG tables are created correctly in the vector database. + */ + +#include "sqlite3db.h" +#include +#include +#include + +// List of expected RAG tables +const std::vector RAG_TABLES = { + "rag_sources", + "rag_documents", + "rag_chunks", + "rag_fts_chunks", + "rag_vec_chunks", + "rag_sync_state" +}; + +// List of expected RAG views +const std::vector RAG_VIEWS = { + "rag_chunk_view" +}; + +int main() { + // Initialize SQLite database + SQLite3DB* db = new SQLite3DB(); + + // Open the default vector database path + const char* db_path = "/var/lib/proxysql/ai_features.db"; + std::cout << "Testing RAG schema in database: " << db_path << std::endl; + + // Try to open the database + if (db->open((char*)db_path) != 0) { + std::cerr << "ERROR: Failed to open database at " << db_path << std::endl; + delete db; + return 1; + } + + std::cout << "SUCCESS: Database opened successfully" << std::endl; + + // Check if RAG tables exist + bool all_tables_exist = true; + for (const std::string& table_name : RAG_TABLES) { + std::string query = "SELECT name FROM sqlite_master WHERE type='table' AND name='" + table_name + "'"; + char* error = nullptr; + int cols = 0; + int affected_rows = 0; + SQLite3_result* result = db->execute_statement(query.c_str(), &error, &cols, &affected_rows); + + if (error) { + std::cerr << "ERROR: SQL error for table " << table_name << ": " << error << std::endl; + sqlite3_free(error); + all_tables_exist = false; + if (result) delete result; + continue; + } + + if (result && result->rows_count() > 0) { + std::cout << "SUCCESS: Table '" << table_name << "' exists" << std::endl; + } else { + std::cerr << "ERROR: Table '" << table_name << "' does not exist" << std::endl; + all_tables_exist = false; + } + + if (result) delete result; + } + + // Check if RAG views exist + bool all_views_exist = true; + for (const std::string& view_name : RAG_VIEWS) { + std::string query = "SELECT name FROM sqlite_master WHERE type='view' AND name='" + view_name + "'"; + char* error = nullptr; + int cols = 0; + int affected_rows = 0; + SQLite3_result* result = db->execute_statement(query.c_str(), &error, &cols, &affected_rows); + + if (error) { + std::cerr << "ERROR: SQL error for view " << view_name << ": " << error << std::endl; + sqlite3_free(error); + all_views_exist = false; + if (result) delete result; + continue; + } + + if (result && result->rows_count() > 0) { + std::cout << "SUCCESS: View '" << view_name << "' exists" << std::endl; + } else { + std::cerr << "ERROR: View '" << view_name << "' does not exist" << std::endl; + all_views_exist = false; + } + + if (result) delete result; + } + + // Clean up + db->close(); + delete db; + + // Final result + if (all_tables_exist && all_views_exist) { + std::cout << std::endl << "SUCCESS: All RAG schema objects exist!" << std::endl; + return 0; + } else { + std::cerr << std::endl << "ERROR: Some RAG schema objects are missing!" << std::endl; + return 1; + } +} \ No newline at end of file