Private
Public Access
0
0
Files
manual_slop/tests/test_summary_cache.py
T
ed 63e91198ac test(sandbox): update v3 paths-aware tests for FR1+FR3 invariants
- test_paths.py: explicit initialize_paths(<empty_config>) instead of
  SLOP_CONFIG env var (v3 design); add restore_paths fixture so other
  tests keep their conftest workspace init.
- test_summary_cache.py: use tmp_path (under ./tests/) instead of
  hardcoded Path('.test_cache') that FR1 blocks.
- test_orchestrator_pm_history.py: use tempfile.mkdtemp() instead of
  writing to project-root 'test_conductor/' that FR1 blocks.
- test_gui_paths.py::test_save_paths: mock src.paths.initialize_paths
  instead of src.paths.reset_paths (v3 entry point).

All 12 tests pass in the Tier 2 clone after these fixes.
2026-06-19 12:36:21 -04:00

67 lines
2.1 KiB
Python

import os
import shutil
from pathlib import Path
from src.summary_cache import SummaryCache, get_file_hash
def test_get_file_hash():
content = "hello world"
# sha256 of "hello world"
expected = "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
assert get_file_hash(content) == expected
def test_summary_cache(tmp_path):
# v3 paths.py: use tmp_path (which is under ./tests/) instead of
# hardcoded project-root paths that the FR1 guard blocks.
cache_file = tmp_path / "cache.json"
cache = SummaryCache(str(cache_file))
file_path = "test.py"
content = "print('hello')"
content_hash = get_file_hash(content)
summary = "**Python** - 1 lines"
# Test empty cache
assert cache.get_summary(file_path, content_hash) is None
# Test set and get
cache.set_summary(file_path, content_hash, summary)
assert cache.get_summary(file_path, content_hash) == summary
# Test cache invalidation
assert cache.get_summary(file_path, "different_hash") is None
# Test persistence
cache2 = SummaryCache(str(cache_file))
assert cache2.get_summary(file_path, content_hash) == summary
def test_summary_cache_lru(tmp_path):
# v3 paths.py: use tmp_path instead of hardcoded project-root paths.
cache_file = tmp_path / "cache.json"
# Create cache with max 2 entries
cache = SummaryCache(str(cache_file), max_entries=2)
cache.set_summary("file1.py", "hash1", "summary1")
cache.set_summary("file2.py", "hash2", "summary2")
cache.set_summary("file3.py", "hash3", "summary3") # This should evict file1.py
assert cache.get_summary("file1.py", "hash1") is None
assert cache.get_summary("file2.py", "hash2") == "summary2"
assert cache.get_summary("file3.py", "hash3") == "summary3"
# Access file2.py, then add file4.py. file3.py should be evicted
cache.get_summary("file2.py", "hash2")
cache.set_summary("file4.py", "hash4", "summary4")
assert cache.get_summary("file3.py", "hash3") is None
assert cache.get_summary("file2.py", "hash2") == "summary2"
assert cache.get_summary("file4.py", "hash4") == "summary4"
if __name__ == "__main__":
test_get_file_hash()
test_summary_cache()
test_summary_cache_lru()
print("Tests passed!")