personal memory agent
0
fork

Configure Feed

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

test: lock in load-after-save cache invalidation regression

Add two regression tests to tests/test_entities.py covering both save_entities
paths (detected with day, attached with day=None). Each test loads to populate
the loading cache, saves new entities, then loads again and asserts fresh data
is returned. Both fail without the clear_entity_loading_cache() calls in
saving.py (fix landed in a907ce41).

Verifies VPE request req_hc5flgx4 — conftest.py autouse fixture and saving.py
invalidation already landed in a907ce41; this adds the missing regression
coverage so future reverts fail loudly.

+55
+55
tests/test_entities.py
··· 287 287 assert "beta_corp" in journal_ids 288 288 289 289 290 + def test_save_entities_detected_invalidates_loading_cache(fixture_journal, tmp_path): 291 + """Regression: save_entities must invalidate the loading cache so load-after-save returns fresh data. 292 + 293 + The autouse _clear_entity_caches fixture only clears between tests, so within 294 + a single test the cache persists across calls. Before the fix, the first load 295 + populated the cache and a subsequent save did not invalidate it — the second 296 + load returned stale data from the cache rather than re-reading disk. 297 + """ 298 + os.environ["_SOLSTONE_JOURNAL_OVERRIDE"] = str(tmp_path) 299 + (tmp_path / "facets" / "test_facet" / "entities").mkdir(parents=True) 300 + 301 + save_entities( 302 + "test_facet", 303 + [{"type": "Person", "name": "Alice", "description": "First"}], 304 + "20250101", 305 + ) 306 + 307 + loaded_first = load_entities("test_facet", "20250101") 308 + assert [e["name"] for e in loaded_first] == ["Alice"] 309 + 310 + save_entities( 311 + "test_facet", 312 + [ 313 + {"type": "Person", "name": "Alice", "description": "First"}, 314 + {"type": "Person", "name": "Bob", "description": "Second"}, 315 + ], 316 + "20250101", 317 + ) 318 + 319 + loaded_second = load_entities("test_facet", "20250101") 320 + assert {e["name"] for e in loaded_second} == {"Alice", "Bob"} 321 + 322 + 323 + def test_save_entities_attached_invalidates_loading_cache(fixture_journal, tmp_path): 324 + """Regression: save_entities (attached path, day=None) must invalidate the loading cache.""" 325 + os.environ["_SOLSTONE_JOURNAL_OVERRIDE"] = str(tmp_path) 326 + (tmp_path / "facets" / "test_facet").mkdir(parents=True) 327 + 328 + save_entities( 329 + "test_facet", 330 + [{"type": "Person", "name": "Alice", "description": "First"}], 331 + ) 332 + 333 + loaded_first = load_entities("test_facet") 334 + assert [e["name"] for e in loaded_first] == ["Alice"] 335 + 336 + save_entities( 337 + "test_facet", 338 + [{"type": "Person", "name": "Bob", "description": "Second"}], 339 + ) 340 + 341 + loaded_second = load_entities("test_facet") 342 + assert {e["name"] for e in loaded_second} == {"Alice", "Bob"} 343 + 344 + 290 345 def test_save_detected_entity_basic(fixture_journal, tmp_path): 291 346 """Test save_detected_entity adds an entity with locking.""" 292 347 os.environ["_SOLSTONE_JOURNAL_OVERRIDE"] = str(tmp_path)