Repository navigation
fix(shared): let ArchivedMemories create its own table, and stop the test leaking - #86
Merged
Merged
Conversation
…test leaking `test_archived_memories` failed with `no such table: archived_memories` when run alone, and passed when another test had migrated the shared session database first. A test that needs a neighbour to pass is testing the neighbour, not the class. Two separate defects, one on each side. **The test wrote to the real memory directory.** It built `ArchivedMemories()` with no connection manager, so it used the global one — and before `hermetic_global_db` existed (90c9149, 2026-08-24) that was the live data dir. The evidence is still there: `~/.mcp-ariel-memory/memory.db` holds 32 rows with `user_id='test_sh'`, all of them from 2026-08-24, the day the fixture landed. It now takes its own manager on `tmp_path`, like its neighbour `test_connection.py` already did. `test_dream_buffer` and `test_embedding_cache` are given the same treatment: neither ever checked a global property, and the leak date names `test_sh` as the marker for both. **The class assumed its table already existed.** `archive()` and `get_archived()` went straight to `SELECT`, while the table is created by `_init_db()` — and in production by the Alembic migration. On a migrated database it worked, which is what hid this. `DreamBuffer` solved the identical problem already, with an idempotent `ensure()` guarded by `_ready` and called from each method that touches the table; `ArchivedMemories` now does the same, with the same shape and for the same reason. The schema in `_init_db` matches the migration's definition exactly, so no new migration is needed. Four production call sites construct `ArchivedMemories` and never run migrations — `core/episodic.py`, `lifecycle/forgetting.py`, `rag/conflict.py` and `mcp_server/tools/primitives/forget.py` — so this was reachable outside tests, not just inside them. Two others (`features/compression.py`, `forget.py`) called `_init_db()` by hand before `archive()`; those calls stay, they are now simply redundant rather than load-bearing. Tests: each of the six in the file passes alone (was: one failed alone); one new test covers the class on an already-migrated database. Full suite: 2087 passed. The real memory directory was verified untouched — still 32 rows and the same mtime.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
test_archived_memoriesfailed withno such table: archived_memorieswhen run alone, and passed when another test had migrated the shared session database first. A test that needs a neighbour to pass is testing the neighbour, not the class.Two separate defects, one on each side.
The test wrote to the real memory directory
It built
ArchivedMemories()with no connection manager, so it used the global one — and beforehermetic_global_dbexisted (90c9149, 2026-08-24) that was the live data dir.The evidence is still on disk:
~/.mcp-ariel-memory/memory.dbholds 32 rows withuser_id='test_sh', all of them from 2026-08-24 — the day the fixture landed. The fixture stopped further writes; it did not clean up the ones already there.The test now takes its own manager on
tmp_path, like its neighbourtests/test_shared/test_connection.pyalready did.test_dream_bufferandtest_embedding_cacheare given the same treatment: neither of them ever checked a global property either, andtest_shis the marker both of them use.The class assumed its table already existed
archive()andget_archived()went straight toSELECT, while the table is created by_init_db()— and in production by the Alembic migration. On a migrated database it worked, which is exactly what hid the problem.DreamBuffersolved the identical problem already, with an idempotentensure()guarded by_readyand called from each method that touches the table.ArchivedMemoriesnow does the same, with the same shape and for the same reason. The schema in_init_dbmatches the migration's definition exactly, so no new migration is needed.This was reachable outside tests, not just inside them: four production call sites construct
ArchivedMemoriesand never run migrations —core/episodic.py,lifecycle/forgetting.py,rag/conflict.py,mcp_server/tools/primitives/forget.py. Two others (features/compression.py,forget.py) called_init_db()by hand beforearchive(); those calls stay, now simply redundant rather than load-bearing.Tests
2026-08-24 14:09:12, mtime unchanged.