import pytest
from pulse.daemons.consolidation import deep_consolidation


def test_deep_consolidation_cycle(monkeypatch):
    """Mock brain_db.get_conn (imported locally inside the function body)."""
    class MockCursor:
        rowcount = 5

    class MockConn:
        def __enter__(self): return self
        def __exit__(self, exc_type, exc_val, exc_tb): pass
        def execute(self, query, params=None):
            return MockCursor()

    # get_conn is imported inside stage_deep_consolidation from pulse.core.brain_db
    monkeypatch.setattr("pulse.core.brain_db.get_conn", lambda: MockConn())

    stats = deep_consolidation.deep_consolidation_cycle()

    # 5 tables * 5 rows each for permanent and archived
    assert stats["permanent"] == 25
    assert stats["archived"] == 25