personal memory agent
at main 151 lines 4.5 kB view raw
1# SPDX-License-Identifier: AGPL-3.0-only 2# Copyright (c) 2026 sol pbc 3 4import os 5 6import pytest 7 8from think.indexer.journal import ( 9 get_entity_intelligence, 10 get_entity_strength, 11 search_entities, 12) 13 14 15@pytest.fixture(autouse=True) 16def fixture_journal(): 17 os.environ["_SOLSTONE_JOURNAL_OVERRIDE"] = "tests/fixtures/journal" 18 yield 19 20 21class TestEntityStrength: 22 def test_returns_ranked_list(self): 23 results = get_entity_strength() 24 assert isinstance(results, list) 25 assert len(results) > 0 26 scores = [r["score"] for r in results] 27 assert scores == sorted(scores, reverse=True) 28 29 def test_has_component_signals(self): 30 results = get_entity_strength() 31 r = results[0] 32 for key in ( 33 "kg_edge_count", 34 "co_occurrence", 35 "appearance", 36 "recency", 37 "facet_breadth", 38 "observation_depth", 39 "score", 40 ): 41 assert key in r 42 43 def test_alice_johnson_has_signals(self): 44 results = get_entity_strength() 45 names = [r.get("entity_id") or r.get("entity_name") for r in results] 46 assert "alice_johnson" in names 47 48 def test_with_facet_filter(self): 49 results = get_entity_strength(facet="work") 50 assert isinstance(results, list) 51 52 def test_with_since_filter(self): 53 results = get_entity_strength(since="20240105") 54 assert isinstance(results, list) 55 56 def test_limit(self): 57 results = get_entity_strength(limit=2) 58 assert len(results) <= 2 59 60 61class TestSearchEntities: 62 def test_by_type_person(self): 63 results = search_entities(entity_type="Person") 64 assert isinstance(results, list) 65 for r in results: 66 assert r["type"] == "Person" 67 68 def test_by_type_company(self): 69 results = search_entities(entity_type="Company") 70 for r in results: 71 assert r["type"] == "Company" 72 73 def test_by_facet(self): 74 results = search_entities(facet="work") 75 assert isinstance(results, list) 76 77 def test_by_query(self): 78 results = search_entities(query="Alice") 79 assert isinstance(results, list) 80 assert any(r["name"] in {"Alice Johnson", "Alice"} for r in results) 81 82 def test_all_entities(self): 83 results = search_entities() 84 assert isinstance(results, list) 85 assert len(results) > 0 86 87 def test_result_structure(self): 88 results = search_entities() 89 if results: 90 r = results[0] 91 assert "entity_id" in r 92 assert "name" in r 93 assert "type" in r 94 95 def test_limit(self): 96 results = search_entities(limit=3) 97 assert len(results) <= 3 98 99 100class TestEntityIntelligence: 101 def test_full_briefing(self): 102 result = get_entity_intelligence("Alice Johnson") 103 assert result is not None 104 for section in ( 105 "identity", 106 "relationships", 107 "observations", 108 "activity", 109 "strength", 110 "network", 111 "facets", 112 ): 113 assert section in result 114 115 def test_identity_section(self): 116 result = get_entity_intelligence("Alice Johnson") 117 assert result["identity"]["entity_id"] == "alice_johnson" 118 assert result["identity"]["name"] == "Alice Johnson" 119 120 def test_activity_section(self): 121 result = get_entity_intelligence("Alice Johnson") 122 assert isinstance(result["activity"], list) 123 assert len(result["activity"]) > 0 124 125 def test_strength_section(self): 126 result = get_entity_intelligence("Alice Johnson") 127 s = result["strength"] 128 assert "score" in s 129 assert s["score"] > 0 130 131 def test_network_section(self): 132 result = get_entity_intelligence("Alice Johnson") 133 assert isinstance(result["network"], dict) 134 135 def test_by_slug(self): 136 result = get_entity_intelligence("alice_johnson") 137 assert result is not None 138 assert result["identity"]["entity_id"] == "alice_johnson" 139 140 def test_unknown_entity(self): 141 result = get_entity_intelligence("Nonexistent Person") 142 assert result is None 143 144 def test_with_facet(self): 145 result = get_entity_intelligence("Alice Johnson", facet="personal") 146 assert result is not None 147 148 def test_bob_smith(self): 149 result = get_entity_intelligence("Bob Smith") 150 assert result is not None 151 assert result["identity"]["entity_id"] == "bob_smith"