Files
Geniusia_v2/test_orchestrator_integration.py
2026-03-05 00:20:25 +01:00

161 lines
5.4 KiB
Python

#!/usr/bin/env python3
"""
Test de l'intégration de l'EnhancedWorkflowMatcher dans l'Orchestrator.
"""
import sys
import numpy as np
from datetime import datetime
from pathlib import Path
# Ajouter le répertoire parent au path
sys.path.insert(0, str(Path(__file__).parent))
from geniusia2.core.logger import Logger
from geniusia2.core.orchestrator import Orchestrator
from geniusia2.core.learning_manager import LearningManager
from geniusia2.core.utils.vision_utils import VisionUtils
from geniusia2.core.llm_manager import LLMManager
from geniusia2.core.config import get_config
print('Test de l\'intégration EnhancedWorkflowMatcher dans Orchestrator')
print('='*70)
# Créer les composants nécessaires
print('\n1. Initialisation des composants...')
logger = Logger(log_dir='test_logs')
config = get_config()
# Créer les managers
learning_manager = LearningManager(logger=logger, config=config)
vision_utils = VisionUtils(logger=logger)
llm_manager = LLMManager(logger=logger, config=config)
print(' ✓ Composants créés')
# Créer l'Orchestrator
print('\n2. Création de l\'Orchestrator...')
try:
orchestrator = Orchestrator(
learning_manager=learning_manager,
vision_utils=vision_utils,
llm_manager=llm_manager,
logger=logger,
config=config
)
print(' ✓ Orchestrator créé')
except Exception as e:
print(f' ✗ Erreur lors de la création: {e}')
import traceback
traceback.print_exc()
sys.exit(1)
# Vérifier que l'EnhancedWorkflowMatcher est bien initialisé
print('\n3. Vérification de l\'EnhancedWorkflowMatcher...')
if hasattr(orchestrator, 'enhanced_matcher'):
print(' ✓ enhanced_matcher présent')
print(f' ✓ Type: {type(orchestrator.enhanced_matcher).__name__}')
print(f' ✓ Screen weight: {orchestrator.enhanced_matcher.screen_weight}')
print(f' ✓ Elements weight: {orchestrator.enhanced_matcher.elements_weight}')
else:
print(' ✗ enhanced_matcher non trouvé!')
sys.exit(1)
# Vérifier que le MultiModalEmbeddingManager est bien initialisé
print('\n4. Vérification du MultiModalEmbeddingManager...')
if hasattr(orchestrator, 'multimodal_manager'):
print(' ✓ multimodal_manager présent')
print(f' ✓ Type: {type(orchestrator.multimodal_manager).__name__}')
else:
print(' ✗ multimodal_manager non trouvé!')
sys.exit(1)
# Vérifier que la méthode find_matching_workflows_enhanced existe
print('\n5. Vérification de la méthode find_matching_workflows_enhanced...')
if hasattr(orchestrator, 'find_matching_workflows_enhanced'):
print(' ✓ Méthode find_matching_workflows_enhanced présente')
# Tester l'appel (sans workflows, devrait retourner une liste vide)
print('\n6. Test de la méthode (sans workflows)...')
try:
matches = orchestrator.find_matching_workflows_enhanced(top_k=5)
print(f' ✓ Méthode appelée avec succès')
print(f' ✓ Matches retournés: {len(matches)}')
print(f' ✓ Type de retour: {type(matches).__name__}')
except Exception as e:
print(f' ✗ Erreur lors de l\'appel: {e}')
import traceback
traceback.print_exc()
else:
print(' ✗ Méthode find_matching_workflows_enhanced non trouvée!')
sys.exit(1)
# Test avec un workflow simulé
print('\n7. Test avec un workflow simulé...')
try:
from geniusia2.core.workflow_detector import Workflow, WorkflowStep
# Créer un workflow de test
step1 = WorkflowStep(
step_id=1,
action_type='click',
target_description='submit button',
position=(100, 200),
window='TestApp',
embedding=np.random.rand(512)
)
workflow = Workflow(
workflow_id='test_workflow_001',
name='Test Workflow',
steps=[step1],
repetitions=5,
confidence=0.9,
last_seen=datetime.now()
)
# Ajouter le workflow au detector
orchestrator.workflow_detector.workflows.append(workflow)
print(f' ✓ Workflow de test ajouté')
print(f' ✓ Workflows disponibles: {len(orchestrator.workflow_detector.workflows)}')
# Tester le matching avec le workflow
print('\n8. Test du matching avec workflow...')
matches = orchestrator.find_matching_workflows_enhanced(top_k=5)
print(f' ✓ Matching effectué')
print(f' ✓ Matches trouvés: {len(matches)}')
if matches:
match = matches[0]
print(f'\n 📊 Meilleur match:')
print(f' Workflow: {match.workflow_name}')
print(f' Score composite: {match.composite_score:.3f}')
print(f' Confiance: {match.confidence:.3f}')
print(f' Similarité écran: {match.screen_similarity:.3f}')
print(f' Matches d\'éléments: {len(match.element_matches)}')
if match.differences:
print(f' Différences détectées: {len(match.differences)}')
print(f'\n 📋 Feedback:')
feedback = match.get_feedback_summary()
for line in feedback.split('\n')[:10]: # Limiter à 10 lignes
print(f' {line}')
except Exception as e:
print(f' ✗ Erreur: {e}')
import traceback
traceback.print_exc()
print('\n' + '='*70)
print('✅ Test d\'intégration complété avec succès!')
print('='*70)
# Nettoyage
import shutil
if Path('test_logs').exists():
shutil.rmtree('test_logs')
if Path('data').exists():
shutil.rmtree('data')
print('\n✓ Nettoyage effectué')