personal memory agent
0
fork

Configure Feed

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

Merge branch 'hopper-qav75euw-stream-discovery-hardening'

+86 -4
+19
tests/test_cluster.py
··· 191 191 assert "This insight should NOT appear" not in result 192 192 193 193 194 + def test_load_entries_from_toplevel_segment(tmp_path, monkeypatch): 195 + """_load_entries_from_segment resolves the day for top-level segment dirs.""" 196 + monkeypatch.setenv("_SOLSTONE_JOURNAL_OVERRIDE", str(tmp_path)) 197 + day_dir = day_path("20240101") 198 + segment = day_dir / "100000_300" 199 + segment.mkdir() 200 + 201 + mod = importlib.import_module("think.cluster") 202 + 203 + entries = mod._load_entries_from_segment( 204 + str(segment), 205 + transcripts=True, 206 + percepts=False, 207 + agents=False, 208 + ) 209 + 210 + assert entries == [] 211 + 212 + 194 213 def test_cluster_range_with_agents(tmp_path, monkeypatch): 195 214 """Test cluster_range with agents source loads all *.md files.""" 196 215 monkeypatch.setenv("_SOLSTONE_JOURNAL_OVERRIDE", str(tmp_path))
+56 -1
tests/test_think_utils.py
··· 13 13 import pytest 14 14 15 15 from think.entities import load_entity_names 16 - from think.utils import day_from_path, segment_key, setup_cli 16 + from think.utils import ( 17 + DEFAULT_STREAM, 18 + day_from_path, 19 + iter_segments, 20 + segment_key, 21 + setup_cli, 22 + ) 17 23 18 24 19 25 class TestDayFromPath: ··· 811 817 # Now it should exist 812 818 assert health_dir.exists() 813 819 assert (health_dir / "new_service.port").read_text() == "9999" 820 + 821 + 822 + class TestIterSegments: 823 + def test_skips_health_directory(self, tmp_path): 824 + """iter_segments does not return segments from health/ dirs.""" 825 + day_dir = tmp_path / "20240101" 826 + day_dir.mkdir() 827 + health_seg = day_dir / "health" / "120000_300" 828 + health_seg.mkdir(parents=True) 829 + normal_seg = day_dir / "default" / "130000_300" 830 + normal_seg.mkdir(parents=True) 831 + 832 + results = iter_segments(day_dir) 833 + stream_names = [r[0] for r in results] 834 + assert "health" not in stream_names 835 + assert "default" in stream_names 836 + 837 + def test_toplevel_segments_as_default_stream(self, tmp_path): 838 + """Top-level segment dirs are returned with _default stream name.""" 839 + day_dir = tmp_path / "20240101" 840 + day_dir.mkdir() 841 + toplevel_seg = day_dir / "143022_300" 842 + toplevel_seg.mkdir() 843 + normal_seg = day_dir / "default" / "150000_300" 844 + normal_seg.mkdir(parents=True) 845 + 846 + results = iter_segments(day_dir) 847 + assert len(results) == 2 848 + default_results = [(s, k, p) for s, k, p in results if s == DEFAULT_STREAM] 849 + assert len(default_results) == 1 850 + assert default_results[0][1] == "143022_300" 851 + normal_results = [(s, k, p) for s, k, p in results if s == "default"] 852 + assert len(normal_results) == 1 853 + 854 + def test_normal_stream_discovery_unchanged(self, tmp_path): 855 + """Normal stream/segment discovery still works correctly.""" 856 + day_dir = tmp_path / "20240101" 857 + day_dir.mkdir() 858 + (day_dir / "default" / "100000_300").mkdir(parents=True) 859 + (day_dir / "default" / "110000_300").mkdir(parents=True) 860 + (day_dir / "import.apple" / "120000_600").mkdir(parents=True) 861 + 862 + results = iter_segments(day_dir) 863 + assert len(results) == 3 864 + assert results[0][1] == "100000_300" 865 + assert results[1][1] == "110000_300" 866 + assert results[2][1] == "120000_600" 867 + assert results[0][0] == "default" 868 + assert results[2][0] == "import.apple"
+5 -3
think/cluster.py
··· 12 12 from observe.screen import format_screen_text 13 13 14 14 from .streams import read_segment_stream 15 - from .utils import day_path 15 + from .utils import day_from_path, day_path 16 16 17 17 18 18 def _date_str(day_dir: str) -> str: ··· 645 645 List of entry dicts with timestamp, prefix, content, etc. 646 646 """ 647 647 segment_path_obj = Path(segment_dir) 648 - # Parent is stream dir; grandparent is day dir 649 - date_str = _date_str(str(segment_path_obj.parent.parent)) 648 + day_str = day_from_path(segment_path_obj) 649 + if day_str is None: 650 + raise ValueError(f"Cannot determine day from segment path: {segment_dir}") 651 + date_str = day_str 650 652 entries = _process_segment( 651 653 segment_path_obj, date_str, transcripts, percepts, agents 652 654 )
+6
think/utils.py
··· 27 27 from media import MIME_TYPES 28 28 29 29 DATE_RE = re.compile(r"\d{8}") 30 + DEFAULT_STREAM = "_default" 30 31 31 32 32 33 def now_ms() -> int: ··· 275 276 results = [] 276 277 for entry in day_dir.iterdir(): 277 278 if not entry.is_dir(): 279 + continue 280 + if segment_key(entry.name) is not None: 281 + results.append((DEFAULT_STREAM, entry.name, entry)) 282 + continue 283 + if entry.name == "health": 278 284 continue 279 285 stream_name = entry.name 280 286 for seg_entry in entry.iterdir():