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>
197 lines
6.6 KiB
C++
197 lines
6.6 KiB
C++
#include <shared/testing/ITestModule.h>
|
|
#include <grove/JsonDataNode.h>
|
|
#include <grove/IIO.h>
|
|
#include <spdlog/spdlog.h>
|
|
#include <chrono>
|
|
#include <thread>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
namespace aissia::testing {
|
|
|
|
/**
|
|
* @brief Test Storage write via AI tool
|
|
*
|
|
* Workflow:
|
|
* 1. Ask AI to save a note using storage_save_note tool
|
|
* 2. Wait for LLM response confirming save
|
|
* 3. Verify note file was created in data/notes/
|
|
*/
|
|
class IT_007_StorageWrite : public ITestModule {
|
|
public:
|
|
std::string getTestName() const override {
|
|
return "IT_007_StorageWrite";
|
|
}
|
|
|
|
std::string getDescription() const override {
|
|
return "Test Storage write via AI tool";
|
|
}
|
|
|
|
void setConfiguration(const grove::IDataNode& config,
|
|
grove::IIO* io,
|
|
grove::ITaskScheduler* scheduler) override {
|
|
m_io = io;
|
|
m_scheduler = scheduler;
|
|
m_timeout = config.getInt("timeoutMs", 30000);
|
|
|
|
grove::SubscriptionConfig subConfig;
|
|
m_io->subscribe("llm:response", subConfig);
|
|
m_io->subscribe("llm:error", subConfig);
|
|
|
|
spdlog::info("[{}] Configured", getTestName());
|
|
}
|
|
|
|
void process(const grove::IDataNode& input) override {}
|
|
void shutdown() override {}
|
|
|
|
const grove::IDataNode& getConfiguration() override {
|
|
static grove::JsonDataNode config("config");
|
|
return config;
|
|
}
|
|
|
|
std::unique_ptr<grove::IDataNode> getHealthStatus() override {
|
|
auto status = std::make_unique<grove::JsonDataNode>("health");
|
|
status->setString("status", "healthy");
|
|
return status;
|
|
}
|
|
|
|
std::unique_ptr<grove::IDataNode> getState() override {
|
|
return std::make_unique<grove::JsonDataNode>("state");
|
|
}
|
|
|
|
void setState(const grove::IDataNode& state) override {}
|
|
|
|
std::string getType() const override { return "IT_007_StorageWrite"; }
|
|
int getVersion() const override { return 1; }
|
|
bool isIdle() const override { return true; }
|
|
|
|
TestResult execute() override {
|
|
auto start = std::chrono::steady_clock::now();
|
|
TestResult result;
|
|
result.testName = getTestName();
|
|
|
|
const std::string noteContent = "Test IT_007: Integration test storage write";
|
|
|
|
try {
|
|
spdlog::info("[{}] Asking AI to save note...", getTestName());
|
|
|
|
// 1. Ask AI to save a note
|
|
auto request = std::make_unique<grove::JsonDataNode>("request");
|
|
request->setString("query",
|
|
"Utilise le tool storage_save_note pour sauvegarder cette note: '" +
|
|
noteContent + "' avec le titre 'Integration Test IT007'");
|
|
request->setString("conversationId", "it007");
|
|
m_io->publish("ai:query", std::move(request));
|
|
|
|
// 2. Wait for response
|
|
auto response = waitForMessage("llm:response", m_timeout);
|
|
|
|
if (!response) {
|
|
auto error = waitForMessage("llm:error", 1000);
|
|
if (error) {
|
|
result.passed = false;
|
|
result.message = "LLM error: " + error->getString("message", "Unknown");
|
|
} else {
|
|
result.passed = false;
|
|
result.message = "Timeout waiting for llm:response";
|
|
}
|
|
return result;
|
|
}
|
|
|
|
std::string text = response->getString("text", "");
|
|
spdlog::info("[{}] LLM response: {}", getTestName(), text);
|
|
|
|
// 3. Give time for async storage operation
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
|
|
|
// 4. Check if note was saved (look for any .md file with our content)
|
|
bool noteFound = false;
|
|
std::string foundPath;
|
|
|
|
if (fs::exists("data/notes")) {
|
|
for (const auto& entry : fs::recursive_directory_iterator("data/notes")) {
|
|
if (entry.is_regular_file() && entry.path().extension() == ".md") {
|
|
std::ifstream file(entry.path());
|
|
std::string content((std::istreambuf_iterator<char>(file)),
|
|
std::istreambuf_iterator<char>());
|
|
|
|
if (content.find("IT_007") != std::string::npos) {
|
|
noteFound = true;
|
|
foundPath = entry.path().string();
|
|
|
|
// Cleanup
|
|
file.close();
|
|
fs::remove(entry.path());
|
|
break;
|
|
}
|
|
file.close();
|
|
}
|
|
}
|
|
}
|
|
|
|
result.passed = noteFound;
|
|
result.message = noteFound ?
|
|
"Note saved successfully" :
|
|
"Note not found in data/notes/";
|
|
result.details["response"] = text;
|
|
if (noteFound) {
|
|
result.details["notePath"] = foundPath;
|
|
}
|
|
|
|
} catch (const std::exception& e) {
|
|
result.passed = false;
|
|
result.message = std::string("Exception: ") + e.what();
|
|
spdlog::error("[{}] {}", getTestName(), result.message);
|
|
}
|
|
|
|
auto end = std::chrono::steady_clock::now();
|
|
result.durationMs = std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
end - start).count();
|
|
|
|
return result;
|
|
}
|
|
|
|
private:
|
|
std::unique_ptr<grove::IDataNode> waitForMessage(
|
|
const std::string& topic, int timeoutMs) {
|
|
|
|
auto start = std::chrono::steady_clock::now();
|
|
|
|
while (true) {
|
|
if (m_io->hasMessages() > 0) {
|
|
auto msg = m_io->pullMessage();
|
|
if (msg.topic == topic && msg.data) {
|
|
return std::move(msg.data);
|
|
}
|
|
}
|
|
|
|
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
std::chrono::steady_clock::now() - start).count();
|
|
|
|
if (elapsed > timeoutMs) {
|
|
return nullptr;
|
|
}
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
}
|
|
}
|
|
|
|
grove::IIO* m_io = nullptr;
|
|
grove::ITaskScheduler* m_scheduler = nullptr;
|
|
int m_timeout = 30000;
|
|
};
|
|
|
|
} // namespace aissia::testing
|
|
|
|
extern "C" {
|
|
grove::IModule* createModule() {
|
|
return new aissia::testing::IT_007_StorageWrite();
|
|
}
|
|
|
|
void destroyModule(grove::IModule* module) {
|
|
delete module;
|
|
}
|
|
}
|