personal memory agent
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

tests: stabilize api-baseline harness under freezegun + heavy-module stubs

The baseline suite's module-scoped freeze_time ran before the autouse
heavy-module stub fixture, causing freezegun to traverse real
pandas/sklearn/torch and crash on pristine main. Extract the stub install
into a helper, invoke it at module scope for this suite, and pass the
heavy libs as freezegun ignore prefixes.

Reproduces and fixes a test failure that predates the chat-refactor
follow-ups lode.

Co-Authored-By: OpenAI Codex <codex@openai.com>

+110 -84
+87 -83
tests/conftest.py
··· 14 14 if str(ROOT) not in sys.path: 15 15 sys.path.insert(0, str(ROOT)) 16 16 17 - from convey.chat import stop_all_chat_runtime 18 - from tests._baseline_harness import copytree_tracked 19 - from think.entities.journal import clear_journal_entity_cache 20 - from think.entities.loading import clear_entity_loading_cache 21 - from think.entities.observations import clear_observation_cache 22 - from think.entities.relationships import clear_relationship_caches 23 - from think.push.runtime import stop_all_push_runtime 24 - from think.utils import now_ms 25 - from think.voice import brain as voice_brain 26 - from think.voice.runtime import stop_all_voice_runtime 27 17 28 - 29 - @pytest.fixture(autouse=True) 30 - def set_test_journal_path(request, monkeypatch): 31 - """Set _SOLSTONE_JOURNAL_OVERRIDE to tests/fixtures/journal for all unit tests. 32 - 33 - This ensures all tests have a valid _SOLSTONE_JOURNAL_OVERRIDE without needing 34 - to explicitly set it in each test. Integration tests are excluded. 35 - """ 36 - # Skip for integration tests - they may have different requirements 37 - if "integration" in request.node.keywords: 38 - return 39 - 40 - # Set _SOLSTONE_JOURNAL_OVERRIDE to tests/fixtures/journal for all unit tests 41 - monkeypatch.setenv( 42 - "_SOLSTONE_JOURNAL_OVERRIDE", 43 - str(Path("tests/fixtures/journal").resolve()), 44 - ) 45 - monkeypatch.setenv("SOL_SKIP_SUPERVISOR_CHECK", "1") 46 - 47 - 48 - @pytest.fixture(autouse=True) 49 - def _clear_entity_caches(request): 50 - """Clear all entity caches before/after each test.""" 51 - if "integration" in request.node.keywords: 52 - yield 53 - return 54 - clear_entity_loading_cache() 55 - clear_journal_entity_cache() 56 - clear_relationship_caches() 57 - clear_observation_cache() 58 - yield 59 - clear_entity_loading_cache() 60 - clear_journal_entity_cache() 61 - clear_relationship_caches() 62 - clear_observation_cache() 63 - 64 - 65 - @pytest.fixture(autouse=True) 66 - def _cleanup_voice_runtime(): 67 - yield 68 - stop_all_voice_runtime() 69 - voice_brain.clear_brain_state() 70 - 71 - 72 - @pytest.fixture(autouse=True) 73 - def _cleanup_push_runtime(): 74 - yield 75 - stop_all_push_runtime() 76 - 77 - 78 - @pytest.fixture(autouse=True) 79 - def _cleanup_chat_runtime(): 80 - yield 81 - stop_all_chat_runtime() 82 - 83 - 84 - @pytest.fixture 85 - def journal_copy(tmp_path, monkeypatch): 86 - """Copy git-tracked fixture files to tmp_path for mutation tests.""" 87 - src = Path(__file__).resolve().parent / "fixtures" / "journal" 88 - dst = tmp_path / "journal" 89 - copytree_tracked(src, dst) 90 - monkeypatch.setenv("_SOLSTONE_JOURNAL_OVERRIDE", str(dst.resolve())) 91 - return dst 92 - 93 - 94 - @pytest.fixture(autouse=True) 95 - def add_module_stubs(request, monkeypatch): 96 - # Skip stubbing for integration tests 97 - if "integration" in request.node.keywords: 98 - return 99 - 100 - # stub heavy modules used by think.indexer 18 + def _install_heavy_module_stubs(): 101 19 if "usearch.index" not in sys.modules: 102 20 usearch = types.ModuleType("usearch") 103 21 index_mod = types.ModuleType("usearch.index") ··· 198 116 dotenv_mod.load_dotenv = load_dotenv 199 117 dotenv_mod.dotenv_values = dotenv_values 200 118 sys.modules["dotenv"] = dotenv_mod 119 + 120 + 121 + from convey.chat import stop_all_chat_runtime 122 + from tests._baseline_harness import copytree_tracked 123 + from think.entities.journal import clear_journal_entity_cache 124 + from think.entities.loading import clear_entity_loading_cache 125 + from think.entities.observations import clear_observation_cache 126 + from think.entities.relationships import clear_relationship_caches 127 + from think.push.runtime import stop_all_push_runtime 128 + from think.utils import now_ms 129 + from think.voice import brain as voice_brain 130 + from think.voice.runtime import stop_all_voice_runtime 131 + 132 + 133 + @pytest.fixture(autouse=True) 134 + def set_test_journal_path(request, monkeypatch): 135 + """Set _SOLSTONE_JOURNAL_OVERRIDE to tests/fixtures/journal for all unit tests. 136 + 137 + This ensures all tests have a valid _SOLSTONE_JOURNAL_OVERRIDE without needing 138 + to explicitly set it in each test. Integration tests are excluded. 139 + """ 140 + # Skip for integration tests - they may have different requirements 141 + if "integration" in request.node.keywords: 142 + return 143 + 144 + # Set _SOLSTONE_JOURNAL_OVERRIDE to tests/fixtures/journal for all unit tests 145 + monkeypatch.setenv( 146 + "_SOLSTONE_JOURNAL_OVERRIDE", 147 + str(Path("tests/fixtures/journal").resolve()), 148 + ) 149 + monkeypatch.setenv("SOL_SKIP_SUPERVISOR_CHECK", "1") 150 + 151 + 152 + @pytest.fixture(autouse=True) 153 + def _clear_entity_caches(request): 154 + """Clear all entity caches before/after each test.""" 155 + if "integration" in request.node.keywords: 156 + yield 157 + return 158 + clear_entity_loading_cache() 159 + clear_journal_entity_cache() 160 + clear_relationship_caches() 161 + clear_observation_cache() 162 + yield 163 + clear_entity_loading_cache() 164 + clear_journal_entity_cache() 165 + clear_relationship_caches() 166 + clear_observation_cache() 167 + 168 + 169 + @pytest.fixture(autouse=True) 170 + def _cleanup_voice_runtime(): 171 + yield 172 + stop_all_voice_runtime() 173 + voice_brain.clear_brain_state() 174 + 175 + 176 + @pytest.fixture(autouse=True) 177 + def _cleanup_push_runtime(): 178 + yield 179 + stop_all_push_runtime() 180 + 181 + 182 + @pytest.fixture(autouse=True) 183 + def _cleanup_chat_runtime(): 184 + yield 185 + stop_all_chat_runtime() 186 + 187 + 188 + @pytest.fixture 189 + def journal_copy(tmp_path, monkeypatch): 190 + """Copy git-tracked fixture files to tmp_path for mutation tests.""" 191 + src = Path(__file__).resolve().parent / "fixtures" / "journal" 192 + dst = tmp_path / "journal" 193 + copytree_tracked(src, dst) 194 + monkeypatch.setenv("_SOLSTONE_JOURNAL_OVERRIDE", str(dst.resolve())) 195 + return dst 196 + 197 + 198 + @pytest.fixture(autouse=True) 199 + def add_module_stubs(request, monkeypatch): 200 + # Skip stubbing for integration tests 201 + if "integration" in request.node.keywords: 202 + return 203 + 204 + _install_heavy_module_stubs() 201 205 # Import real observe package first to avoid shadowing with stubs 202 206 if "observe" not in sys.modules: 203 207 importlib.import_module("observe")
+23 -1
tests/test_api_baselines.py
··· 17 17 make_logged_in_test_client, 18 18 prepare_isolated_journal, 19 19 ) 20 + from tests.conftest import _install_heavy_module_stubs 20 21 from tests.verify_api import ENDPOINTS, baseline_path, fetch_endpoint, normalize 21 22 23 + FREEZEGUN_IGNORE = [ 24 + "librosa", 25 + "numba", 26 + "pandas", 27 + "pyarrow", 28 + "scipy", 29 + "sentencepiece", 30 + "sklearn", 31 + "torch", 32 + "transformers", 33 + ] 34 + 35 + 36 + @pytest.fixture(scope="module", autouse=True) 37 + def _install_stubs(): 38 + _install_heavy_module_stubs() 39 + 22 40 23 41 @pytest.fixture(scope="module", autouse=True) 24 42 def _freeze_time(): 25 - with freeze_time(FROZEN_DATE, tz_offset=FROZEN_TZ_OFFSET): 43 + with freeze_time( 44 + FROZEN_DATE, 45 + tz_offset=FROZEN_TZ_OFFSET, 46 + ignore=FREEZEGUN_IGNORE, 47 + ): 26 48 yield 27 49 28 50