test
This commit is contained in:
parent
8af744fc97
commit
5dd20d683f
|
|
@ -1,17 +1,15 @@
|
||||||
"""
|
"""
|
||||||
FILE: tests/test_WP22_integration.py
|
FILE: tests/test_WP22_integration.py
|
||||||
DESCRIPTION: Integrationstest für WP-22 (Graph Intelligence).
|
DESCRIPTION: Integrationstest für WP-22 (Graph Intelligence).
|
||||||
Prüft: Registry, Lifecycle Scoring, Router-Logik und Regression.
|
FIX: Nutzt IsolatedAsyncioTestCase und importiert asyncio korrekt.
|
||||||
Mockt Datenbank und LLM, um Logikfehler isoliert zu finden.
|
|
||||||
"""
|
"""
|
||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import json
|
import json
|
||||||
import yaml
|
import yaml
|
||||||
import asyncio # <--- FIX: Hier war der Fehler
|
import asyncio
|
||||||
from unittest.mock import MagicMock, patch, AsyncMock
|
from unittest.mock import MagicMock, patch, AsyncMock
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
# --- Imports der App-Module ---
|
# --- Imports der App-Module ---
|
||||||
from app.models.dto import ChatRequest, QueryRequest, QueryHit
|
from app.models.dto import ChatRequest, QueryRequest, QueryHit
|
||||||
|
|
@ -20,11 +18,12 @@ from app.core.retriever import _compute_total_score, _get_status_multiplier
|
||||||
from app.routers.chat import _classify_intent, get_decision_strategy, chat_endpoint
|
from app.routers.chat import _classify_intent, get_decision_strategy, chat_endpoint
|
||||||
|
|
||||||
# --- Test Suite ---
|
# --- Test Suite ---
|
||||||
class TestWP22Integration(unittest.TestCase):
|
class TestWP22Integration(unittest.IsolatedAsyncioTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Bereitet eine isolierte Test-Umgebung vor."""
|
"""Bereitet eine isolierte Test-Umgebung vor."""
|
||||||
self.test_dir = "tests/temp_integration"
|
self.test_dir = "tests/temp_integration"
|
||||||
|
# Environment Patching: Hier simulieren wir Ihre .env
|
||||||
self.os_env_patch = patch.dict(os.environ, {
|
self.os_env_patch = patch.dict(os.environ, {
|
||||||
"MINDNET_VAULT_ROOT": self.test_dir,
|
"MINDNET_VAULT_ROOT": self.test_dir,
|
||||||
"MINDNET_DECISION_CONFIG": os.path.join(self.test_dir, "config", "decision_engine.yaml"),
|
"MINDNET_DECISION_CONFIG": os.path.join(self.test_dir, "config", "decision_engine.yaml"),
|
||||||
|
|
@ -54,10 +53,13 @@ class TestWP22Integration(unittest.TestCase):
|
||||||
yaml.dump(self.decision_config, f)
|
yaml.dump(self.decision_config, f)
|
||||||
|
|
||||||
# 2. Config: Edge Vocabulary (für Registry)
|
# 2. Config: Edge Vocabulary (für Registry)
|
||||||
with open(os.path.join(self.test_dir, "01_User_Manual", "01_edge_vocabulary.md"), "w") as f:
|
# Wir platzieren die Datei genau dort, wo die Registry sie relativ zu MINDNET_VAULT_ROOT erwartet
|
||||||
|
vocab_path = os.path.join(self.test_dir, "01_User_Manual", "01_edge_vocabulary.md")
|
||||||
|
with open(vocab_path, "w") as f:
|
||||||
f.write("| **caused_by** | ursache_ist, wegen |\n| **part_of** | teil_von |")
|
f.write("| **caused_by** | ursache_ist, wegen |\n| **part_of** | teil_von |")
|
||||||
|
|
||||||
# 3. Registry Reset
|
# 3. Registry Reset
|
||||||
|
# Wir zwingen das Singleton zum Neustart, damit es die neuen ENV-Variablen liest
|
||||||
EdgeRegistry._instance = None
|
EdgeRegistry._instance = None
|
||||||
self.registry = EdgeRegistry(vault_root=self.test_dir)
|
self.registry = EdgeRegistry(vault_root=self.test_dir)
|
||||||
|
|
||||||
|
|
@ -72,6 +74,12 @@ class TestWP22Integration(unittest.TestCase):
|
||||||
# ------------------------------------------------------------------------
|
# ------------------------------------------------------------------------
|
||||||
def test_edge_registry_aliases(self):
|
def test_edge_registry_aliases(self):
|
||||||
print("\n🔵 TEST 1: Edge Registry Resolution")
|
print("\n🔵 TEST 1: Edge Registry Resolution")
|
||||||
|
|
||||||
|
# Prüfung: Hat er die Datei gefunden?
|
||||||
|
# Wenn die Registry leer ist, hat das Laden nicht geklappt.
|
||||||
|
self.assertTrue(len(self.registry.valid_types) > 0,
|
||||||
|
f"Registry ist leer! Pfad war: {self.registry.vault_root}")
|
||||||
|
|
||||||
# Test: Alias Auflösung
|
# Test: Alias Auflösung
|
||||||
resolved = self.registry.resolve("ursache_ist")
|
resolved = self.registry.resolve("ursache_ist")
|
||||||
self.assertEqual(resolved, "caused_by", "Alias 'ursache_ist' sollte zu 'caused_by' werden.")
|
self.assertEqual(resolved, "caused_by", "Alias 'ursache_ist' sollte zu 'caused_by' werden.")
|
||||||
|
|
@ -84,7 +92,7 @@ class TestWP22Integration(unittest.TestCase):
|
||||||
self.assertTrue(os.path.exists(log_path), "Logfile für unbekannte Kanten fehlt.")
|
self.assertTrue(os.path.exists(log_path), "Logfile für unbekannte Kanten fehlt.")
|
||||||
with open(log_path, "r") as f:
|
with open(log_path, "r") as f:
|
||||||
self.assertIn("foobar_link", f.read())
|
self.assertIn("foobar_link", f.read())
|
||||||
print("✅ Registry funktioniert (Alias + Logging).")
|
print("✅ Registry funktioniert (Datei gefunden & Alias gelöst).")
|
||||||
|
|
||||||
# ------------------------------------------------------------------------
|
# ------------------------------------------------------------------------
|
||||||
# TEST 2: Lifecycle Scoring (WP-22 A)
|
# TEST 2: Lifecycle Scoring (WP-22 A)
|
||||||
|
|
@ -119,7 +127,7 @@ class TestWP22Integration(unittest.TestCase):
|
||||||
async def test_router_integration(self):
|
async def test_router_integration(self):
|
||||||
print("\n🔵 TEST 3: Semantic Router Integration")
|
print("\n🔵 TEST 3: Semantic Router Integration")
|
||||||
|
|
||||||
# Mock LLM Service (für Fallback, wird hier aber durch Keywords umgangen)
|
# Mock LLM Service
|
||||||
mock_llm = MagicMock()
|
mock_llm = MagicMock()
|
||||||
mock_llm.prompts = {}
|
mock_llm.prompts = {}
|
||||||
|
|
||||||
|
|
@ -160,8 +168,7 @@ class TestWP22Integration(unittest.TestCase):
|
||||||
# Request: "Warum..."
|
# Request: "Warum..."
|
||||||
req = ChatRequest(message="Warum ist das passiert?", top_k=3)
|
req = ChatRequest(message="Warum ist das passiert?", top_k=3)
|
||||||
|
|
||||||
# EXECUTE Endpoint
|
# Cache Reset für Config (wichtig, damit er unsere Test-Config neu lädt)
|
||||||
# Cache Reset
|
|
||||||
import app.routers.chat
|
import app.routers.chat
|
||||||
app.routers.chat._DECISION_CONFIG_CACHE = None
|
app.routers.chat._DECISION_CONFIG_CACHE = None
|
||||||
|
|
||||||
|
|
@ -212,6 +219,4 @@ class TestWP22Integration(unittest.TestCase):
|
||||||
print("✅ Regression Test bestanden (Standard-Flow intakt).")
|
print("✅ Regression Test bestanden (Standard-Flow intakt).")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
loop = asyncio.new_event_loop()
|
|
||||||
asyncio.set_event_loop(loop)
|
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Loading…
Reference in New Issue
Block a user