aissia/tests/CMakeLists.txt
StillHammer d5cbf3b994 feat: Add modular integration test system with 8 tests
Implémentation complète d'un système de tests d'intégration modulaire
pour valider AISSIA en conditions réelles.

Architecture "Un module = Un test":
- Chaque test est un module GroveEngine (.so) chargé dynamiquement
- TestRunnerModule orchestre l'exécution de tous les tests
- Rapports console + JSON avec détails complets
- Exit codes appropriés pour CI/CD (0=success, 1=failure)

Infrastructure:
- ITestModule: Interface de base pour tous les tests
- TestRunnerModule: Orchestrateur qui découvre/charge/exécute les tests
- Configuration globale: config/test_runner.json
- Flag --run-tests pour lancer les tests

Tests implémentés (8/8 passing):

Phase 1 - Tests MCP:
 IT_001_GetCurrentTime: Test tool get_current_time via AI
 IT_002_FileSystemWrite: Test tool filesystem_write
 IT_003_FileSystemRead: Test tool filesystem_read
 IT_004_MCPToolsList: Vérification inventaire tools (≥5)

Phase 2 - Tests Flux:
 IT_005_VoiceToAI: Communication Voice → AI
 IT_006_AIToLLM: Requête AI → Claude API (réelle)
 IT_007_StorageWrite: AI → Storage (sauvegarde note)
 IT_008_StorageRead: AI → Storage (lecture note)

Avantages:
🔥 Hot-reload ready: Tests modifiables sans recompiler
🌐 Conditions réelles: Vraies requêtes Claude API, vrais fichiers
🎯 Isolation: Chaque test indépendant, cleanup automatique
📊 Rapports complets: Console + JSON avec détails par test
 CI/CD ready: Exit codes, JSON output, automation-friendly

Usage:
  cmake --build build --target integration_tests
  cd build && ./aissia --run-tests

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 19:37:59 +08:00

168 lines
5.2 KiB
CMake

# ============================================================================
# AISSIA Integration Tests
# ============================================================================
# Fetch Catch2
include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0
)
FetchContent_MakeAvailable(Catch2)
# ============================================================================
# Test executable
# ============================================================================
add_executable(aissia_tests
main.cpp
# Mocks
mocks/MockIO.cpp
# Module sources (needed for testing)
${CMAKE_SOURCE_DIR}/src/modules/SchedulerModule.cpp
${CMAKE_SOURCE_DIR}/src/modules/NotificationModule.cpp
${CMAKE_SOURCE_DIR}/src/modules/MonitoringModule.cpp
${CMAKE_SOURCE_DIR}/src/modules/AIModule.cpp
${CMAKE_SOURCE_DIR}/src/modules/VoiceModule.cpp
${CMAKE_SOURCE_DIR}/src/modules/StorageModule.cpp
${CMAKE_SOURCE_DIR}/src/modules/WebModule.cpp
# Module tests (70 TI)
modules/SchedulerModuleTests.cpp
modules/NotificationModuleTests.cpp
modules/MonitoringModuleTests.cpp
modules/AIModuleTests.cpp
modules/VoiceModuleTests.cpp
modules/StorageModuleTests.cpp
modules/WebModuleTests.cpp
# MCP tests (50 TI)
mcp/MCPTypesTests.cpp
mcp/StdioTransportTests.cpp
mcp/MCPClientTests.cpp
)
target_link_libraries(aissia_tests PRIVATE
Catch2::Catch2WithMain
GroveEngine::impl
AissiaTools
spdlog::spdlog
)
# WebModule needs httplib and OpenSSL
target_include_directories(aissia_tests PRIVATE
${httplib_SOURCE_DIR}
)
if(OPENSSL_FOUND)
target_link_libraries(aissia_tests PRIVATE OpenSSL::SSL OpenSSL::Crypto)
target_compile_definitions(aissia_tests PRIVATE CPPHTTPLIB_OPENSSL_SUPPORT)
endif()
# Disable module factory functions during testing
target_compile_definitions(aissia_tests PRIVATE AISSIA_TEST_BUILD)
target_include_directories(aissia_tests PRIVATE
${CMAKE_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}
)
# ============================================================================
# Copy test fixtures to build directory
# ============================================================================
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/fixtures/
DESTINATION ${CMAKE_BINARY_DIR}/tests/fixtures)
# ============================================================================
# CTest integration
# ============================================================================
include(CTest)
# Note: catch_discover_tests requires running the exe at build time
# which can fail due to missing DLLs. Use manual test registration instead.
add_test(NAME aissia_tests COMMAND aissia_tests)
# ============================================================================
# Custom targets
# ============================================================================
# Run all tests
add_custom_target(test_all
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
DEPENDS aissia_tests
COMMENT "Running all integration tests"
)
# Run module tests only
add_custom_target(test_modules
COMMAND $<TARGET_FILE:aissia_tests> "[scheduler],[notification],[monitoring],[ai],[voice],[storage],[web]"
DEPENDS aissia_tests
COMMENT "Running module integration tests"
)
# Run MCP tests only
add_custom_target(test_mcp
COMMAND $<TARGET_FILE:aissia_tests> "[mcp]"
DEPENDS aissia_tests
COMMENT "Running MCP integration tests"
)
# ============================================================================
# Integration Test Modules (Dynamic .so files)
# ============================================================================
# Helper macro to create integration test modules
macro(add_integration_test TEST_NAME)
add_library(${TEST_NAME} SHARED
integration/${TEST_NAME}.cpp
)
target_include_directories(${TEST_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/src
)
target_link_libraries(${TEST_NAME} PRIVATE
GroveEngine::impl
spdlog::spdlog
)
set_target_properties(${TEST_NAME} PROPERTIES
PREFIX ""
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests/integration
)
endmacro()
# Individual integration test modules (will be added as we create them)
# Phase 2: MCP Tests
add_integration_test(IT_001_GetCurrentTime)
add_integration_test(IT_002_FileSystemWrite)
add_integration_test(IT_003_FileSystemRead)
add_integration_test(IT_004_MCPToolsList)
# Phase 3: Flow Tests
add_integration_test(IT_005_VoiceToAI)
add_integration_test(IT_006_AIToLLM)
add_integration_test(IT_007_StorageWrite)
add_integration_test(IT_008_StorageRead)
# Phase 4: End-to-End Test
# add_integration_test(IT_009_FullConversationLoop)
# Phase 5: Module Tests
# add_integration_test(IT_010_SchedulerHyperfocus)
# add_integration_test(IT_011_NotificationAlert)
# add_integration_test(IT_012_MonitoringActivity)
# add_integration_test(IT_013_WebRequest)
# Custom target to build all integration tests
add_custom_target(integration_tests
DEPENDS
IT_001_GetCurrentTime
IT_002_FileSystemWrite
IT_003_FileSystemRead
IT_004_MCPToolsList
IT_005_VoiceToAI
IT_006_AIToLLM
IT_007_StorageWrite
IT_008_StorageRead
COMMENT "Building all integration test modules"
)