Files
leocrm/tests/test_audit_connections.py
T

103 lines
4.7 KiB
Python
Raw Normal View History

"""Integration tests for the 10 audit connection points.
Tests that the previously unconnected modules are now actually imported
and called by the real code paths (agent_runner, engine, agent_routes).
"""
from __future__ import annotations
import pytest
class TestAuditConnections:
"""Verify that the 10 audit points are now wired up."""
def test_punkt1_context_builder_imported_in_agent_runner(self):
"""Punkt 1: context_builder.build_agent_context is imported in agent_runner."""
import inspect
from app.plugins.builtins.automation import agent_runner
source = inspect.getsource(agent_runner)
assert "from app.ai.context_builder import build_agent_context" in source
def test_punkt2_agent_permissions_imported_in_agent_runner(self):
"""Punkt 2: agent_permissions.resolve_agent_permissions is imported in agent_runner."""
import inspect
from app.plugins.builtins.automation import agent_runner
source = inspect.getsource(agent_runner)
assert "from app.ai.agent_permissions import resolve_agent_permissions" in source
def test_punkt3_agent_tools_imported_in_agent_runner(self):
"""Punkt 3: agent_tools.get_agent_tools is imported in agent_runner."""
import inspect
from app.plugins.builtins.automation import agent_runner
source = inspect.getsource(agent_runner)
assert "from app.ai.agent_tools import get_agent_tools" in source
def test_punkt4_data_policy_imported_in_agent_runner(self):
"""Punkt 4: data_policy.enforce_data_policy is imported in agent_runner."""
import inspect
from app.plugins.builtins.automation import agent_runner
source = inspect.getsource(agent_runner)
assert "from app.ai.data_policy import enforce_data_policy" in source
def test_punkt5_oversight_imported_in_agent_runner(self):
"""Punkt 5: oversight.create_decision_record is imported in agent_runner."""
import inspect
from app.plugins.builtins.automation import agent_runner
source = inspect.getsource(agent_runner)
assert "from app.ai.oversight import DecisionRecord, create_decision_record" in source
def test_punkt6_transparency_imported_in_agent_runner(self):
"""Punkt 6: transparency.mark_as_ai_generated is imported in agent_runner."""
import inspect
from app.plugins.builtins.automation import agent_runner
source = inspect.getsource(agent_runner)
assert "from app.ai.transparency import mark_as_ai_generated" in source
def test_punkt7_agent_stream_imported_in_agent_routes(self):
"""Punkt 7: agent_stream.stream_react_loop is imported in agent_routes."""
import inspect
from app.plugins.builtins.automation import agent_routes
source = inspect.getsource(agent_routes)
assert "from app.ai.agent_stream import stream_react_loop" in source
def test_punkt8_agent_memory_ai_module_deleted(self):
"""Punkt 8: app/ai/agent_memory.py is deleted (dup with plugin)."""
import os
assert not os.path.exists("app/ai/agent_memory.py")
def test_punkt9_decision_guard_imported_in_engine(self):
"""Punkt 9: decision_guard.check_decision_guard is imported in engine.py."""
import inspect
from app.workflows import engine
source = inspect.getsource(engine)
assert "from app.workflows.decision_guard import check_decision_guard" in source
def test_punkt10_require_approval_passed_in_agent_runner(self):
"""Punkt 10: require_approval is passed to run_react_loop in agent_runner."""
import inspect
from app.plugins.builtins.automation import agent_runner
source = inspect.getsource(agent_runner)
assert "require_approval=" in source
assert "approval_tools=" in source
def test_oversight_table_exists_in_db(self):
"""Punkt 5: ai_decision_records table exists in test DB."""
import os
os.environ.setdefault("MIGRATION_DATABASE_URL", "postgresql+asyncpg://leocrm:leocrm@localhost:5432/leocrm_test")
import asyncio
from sqlalchemy import text
from sqlalchemy.ext.asyncio import create_async_engine
async def check():
engine = create_async_engine(os.environ["MIGRATION_DATABASE_URL"])
async with engine.connect() as conn:
result = await conn.execute(
text("SELECT EXISTS (SELECT FROM pg_tables WHERE tablename = 'ai_decision_records')")
)
exists = result.scalar()
await engine.dispose()
return exists
exists = asyncio.get_event_loop().run_until_complete(check())
assert exists is True