Skip to content
Closed
125 changes: 0 additions & 125 deletions tests/test_all.py

This file was deleted.

147 changes: 2 additions & 145 deletions tests/test_auth_backup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
Tests for auth, backup, import/export, and MCP auto-start.
Tests for auth, MCP metadata, and config — unique tests only.
Backup/audit/rate_limiter/import_export are tested in test_integration.py.
"""

import pytest
import os


# ═══════════════════════════════════════════════════════════════
Expand Down Expand Up @@ -79,147 +79,6 @@ async def test_bearer_rotate():
assert ba.verify("Bearer " + new_token) is True


# ═══════════════════════════════════════════════════════════════
# BACKUP TESTS
# ═══════════════════════════════════════════════════════════════


@pytest.mark.asyncio
async def test_backup_create():
from features.backup import BackupManager

bm = BackupManager()
path = await bm.backup(label="test_backup")
assert path is not None
assert os.path.exists(path)


@pytest.mark.asyncio
async def test_backup_list():
from features.backup import BackupManager

bm = BackupManager()
await bm.backup(label="test_list")
backups = bm.list_backups()
assert len(backups) >= 1


@pytest.mark.asyncio
async def test_backup_restore():
from features.backup import BackupManager

bm = BackupManager()
path = await bm.backup(label="test_restore")
backup_name = os.path.basename(path)
result = await bm.restore(backup_name)
assert "restored" in result


@pytest.mark.asyncio
async def test_backup_cleanup():
from features.backup import BackupManager

bm = BackupManager()
removed = bm.cleanup_old()
assert isinstance(removed, int)


# ═══════════════════════════════════════════════════════════════
# IMPORT/EXPORT TESTS
# ═══════════════════════════════════════════════════════════════


@pytest.mark.asyncio
async def test_export_import():
from features.import_export import ImportExport
from core import memory_manager

# Create some data
user = memory_manager.user_memory("export_test")
await user.remember("key1", "value1", 0.8)

ie = ImportExport()

# Export
export_path = await ie.export_user("export_test")
assert export_path is not None
assert os.path.exists(export_path)

# List exports
exports = ie.list_exports()
assert len(exports) >= 1


# ═══════════════════════════════════════════════════════════════
# AUDIT TRAIL TESTS
# ═══════════════════════════════════════════════════════════════


@pytest.mark.asyncio
async def test_audit_log():
from features.audit_trail import AuditTrail

at = AuditTrail()
await at._init_db()
await at.log("audit_test", "test_action", "user", "target_1", {"key": "value"})
history = await at.get_history("audit_test")
assert len(history) >= 1
assert history[0]["action"] == "test_action"


@pytest.mark.asyncio
async def test_audit_count():
from features.audit_trail import AuditTrail

at = AuditTrail()
await at._init_db()
await at.log("count_test", "action1")
await at.log("count_test", "action2")
count = await at.count("count_test")
assert count >= 2


@pytest.mark.asyncio
async def test_audit_cleanup():
from features.audit_trail import AuditTrail

at = AuditTrail()
await at._init_db()
removed = await at.cleanup_old(retention_days=0)
assert isinstance(removed, int)


# ═══════════════════════════════════════════════════════════════
# RATE LIMITER TESTS
# ═══════════════════════════════════════════════════════════════


@pytest.mark.asyncio
async def test_rate_limiter():
from features.rate_limiting import RateLimiter

rl = RateLimiter()
result = await rl.check("rate_test")
assert "allowed" in result
assert result["allowed"] is True


@pytest.mark.asyncio
async def test_rate_limiter_stats(tmp_path):
from features.rate_limiting import RateLimiter
from shared.connection import AsyncConnectionManager

cm = AsyncConnectionManager(base_dir=str(tmp_path))
await cm.execute_script(
"memory.db",
"CREATE TABLE IF NOT EXISTS rate_limits (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id TEXT NOT NULL, timestamp REAL NOT NULL);",
)
rl = RateLimiter(cm=cm)
await rl.check("stats_test")
stats = await rl.get_stats("stats_test")
assert "requests_last_minute" in stats


# ═══════════════════════════════════════════════════════════════
# MCP AUTO-START TESTS
# ═══════════════════════════════════════════════════════════════
Expand Down Expand Up @@ -290,14 +149,12 @@ def test_config_get():
from config import Config

config = Config()
# Default values should work
assert config.get("layers", "user", "enabled", default=True) is True


def test_config_hooks():
from config import Config

config = Config()
# Should not crash
result = config.is_hook_enabled("user", "message_received")
assert isinstance(result, bool)
76 changes: 2 additions & 74 deletions tests/test_core/test_core.py
Original file line number Diff line number Diff line change
@@ -1,83 +1,11 @@
"""Tests for core/ module (L1-L4) — async."""
"""Tests for core/ module — unique tests only."""

import asyncio
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.parent.parent))


def test_user_remember_recall():
from core import memory_manager

async def t():
await memory_manager.user_memory("test_core").remember("lang", "Python", 0.8)
results = await memory_manager.user_memory("test_core").recall("lang")
assert len(results) > 0
assert results[0]["key"] == "lang"

asyncio.run(t())


def test_agent_remember_recall():
from core import memory_manager

async def t():
await memory_manager.agent_memory("test_core").remember("rule", "YAGNI", 0.9)
results = await memory_manager.agent_memory("test_core").recall("rule")
assert len(results) > 0

asyncio.run(t())
from core.reflex import ReflexBuffer


def test_reflex_buffer():
from core.reflex import ReflexBuffer

buf = ReflexBuffer(max_size=5)
buf.add(role="user", content="Hello", tokens=5)
buf.add(role="assistant", content="Hi", tokens=3)
assert buf.size() == 2
assert buf.get_recent(1)[0].content == "Hi"


def test_session_store():
from core.session import SessionStore

async def t():
ss = SessionStore()
sid = await ss.create_session("test_core")
assert sid is not None
await ss.close_session(sid, summary="Test session")
assert await ss.count_sessions("test_core") >= 1

asyncio.run(t())


def test_episodic_memory():
from core.episodic import EpisodicMemory

async def t():
ep = EpisodicMemory()
eid = await ep.save("test_core", "Test episode", 0.8, ["tag1"])
assert eid > 0
episodes = await ep.search_by_tag("test_core", "tag1")
assert len(episodes) >= 1

asyncio.run(t())


def test_core_memory():
from core.memory import CoreMemory

async def t():
cm = CoreMemory()
await cm.save("test_core", "key1", "value1", 0.9)
entry = await cm.get("test_core", "key1")
assert entry is not None
assert entry.value == "value1"
results = await cm.search("test_core", "value1")
assert len(results) > 0
assert await cm.delete("test_core", "key1")
assert await cm.get("test_core", "key1") is None

asyncio.run(t())
Loading
Loading