Repository navigation
test(hygiene): stop the suite writing to the operator's real data dir - #87
Merged
Merged
Conversation
Several modules resolve their data directory ONCE, at import time, from MCP_MEMORY_DATA_DIR: `shared/saga/impl/storage.py` (SAGA_DIR), `shared/read_only.py` (which builds the module-level `read_only_replica` singleton on import) and `features/auth/__init__.py`. Importing any of them while the real value was in place was enough to write to the live directory — no test body had to do anything wrong, and `hermetic_global_db` could not help because by the time a fixture runs those constants are already resolved. Measured on the operator's `~/.mcp-ariel-memory` before this change: | path | what the suite left behind | |---|---| | `replica/memory.db` | 14 MB, rewritten on every run by the lifespan | | `sagas/` | 15875 state files, 63 MB | | `<repo>/data/auth/keys.enc` | 704 KB, +~860 B per run | `tests/conftest.py` now publishes a session temp dir as MCP_MEMORY_DATA_DIR before pytest imports the first test module, and the session fixture removes it and restores the operator's value on teardown. After the change a full run leaves all three paths byte-identical: same mtime, same size, same file count. Two tests were relying on the variable being unset and had to stop: - `test_backup_saga_success` patched `pathlib.Path.home` to fake a data dir, which only worked while MCP_MEMORY_DATA_DIR was unset and the fallback was reachable. It now names its own dir through the variable, which is what the saga actually reads. - `test_backup_saga_compensation` passed vacuously: with no source database the first step reported `skipped_no_source`, so `backup_path` was absent and the assertion that the backup was removed never ran. It now requires the backup to have existed, and it finds one. `test_auth_backup.py` also constructed `APIKeyAuth()` / `BearerAuth()` bare, which fall back to the CWD-relative `data/auth/*.enc` — a fallback no environment variable can redirect, hence the separate fix there. Each test now passes its own `tmp_path`, and `test_api_key_list` asserts `== 2` instead of `>= 2`: it was being satisfied by the accumulated history rather than by itself. Full suite: 2087 passed. Not addressed here, and reported instead: the same scratch dir holds 1.6 GB of `tmp*` directories left by tests that call `tempfile.mkdtemp()` without cleaning up, and `data/auth/keys.enc` from earlier runs is still on disk (gitignored, nothing was ever committed).
|
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.
Several modules resolve their data directory once, at import time, from
MCP_MEMORY_DATA_DIR:shared/saga/impl/storage.py(SAGA_DIR),shared/read_only.py(which builds the module-levelread_only_replicasingleton on import) andfeatures/auth/__init__.py. Importing any of them while the real value was in place was enough to write to the live directory — no test body had to do anything wrong, andhermetic_global_dbcould not help, because by the time a fixture runs those constants are already resolved.What the suite was leaving behind
Measured on
~/.mcp-ariel-memorybefore this change:replica/memory.dbsagas/<repo>/data/auth/keys.encThe fix
tests/conftest.pynow publishes a session temp dir asMCP_MEMORY_DATA_DIRbefore pytest imports the first test module, and the session fixture removes it and restores the operator's value on teardown.hermetic_global_dbreuses that directory instead of making its own.After the change, a full run leaves all three paths byte-identical: same mtime, same size, same file count.
Two tests were relying on the variable being unset
test_backup_saga_successpatchedpathlib.Path.hometo fake a data dir. That only worked whileMCP_MEMORY_DATA_DIRwas unset and the fallback was reachable; the variable wins. It now names its own dir through the variable the saga actually reads.test_backup_saga_compensationpassed vacuously: with no source database the first step reportedskipped_no_source, sobackup_pathwas absent and the assertion that the backup was removed never ran. It now requires the backup to have existed — and finds one.test_auth_backup.pyalso constructedAPIKeyAuth()/BearerAuth()bare, falling back to the CWD-relativedata/auth/*.enc, which no environment variable can redirect — hence the separate fix there. Each test passes its owntmp_path, andtest_api_key_listasserts== 2rather than>= 2: it was being satisfied by the accumulated history, not by itself.Tests
Full suite: 2087 passed.
Not addressed here, reported instead
tmp*directories left by tests that calltempfile.mkdtemp()without cleaning up. Different mechanism, own PR.data/auth/keys.encfrom earlier runs is still on disk. It is gitignored (*.enc), so nothing was ever committed.