personal memory agent
0

Configure Feed

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

solstone / tests / test_maint_001_migrate_to_journal_entities.py
2.3 kB 76 lines
1# SPDX-License-Identifier: AGPL-3.0-only 2# Copyright (c) 2026 sol pbc 3 4from __future__ import annotations 5 6import importlib 7import json 8from pathlib import Path 9 10mod = importlib.import_module( 11 "solstone.apps.entities.maint.001_migrate_to_journal_entities" 12) 13 14 15def test_load_all_legacy_entities_no_facets_dir(tmp_path: Path) -> None: 16 """Fresh journal with no facets/ dir must return (empty list, 0) — not bare [].""" 17 journal = tmp_path / "journal" 18 journal.mkdir() 19 20 entities, skipped = mod.load_all_legacy_entities(journal) 21 22 assert entities == [] 23 assert skipped == 0 24 25 26def test_migrate_entities_fresh_journal_no_crash(tmp_path: Path) -> None: 27 """Fresh-install path: running the migration against a journal with no facets/ 28 must complete cleanly. Regression guard for the ValueError (expected 2, got 0) 29 that crashed Ramon's install on 2026-04-22.""" 30 journal = tmp_path / "journal" 31 journal.mkdir() 32 33 summary = mod.migrate_entities(journal, dry_run=False) 34 35 assert summary == {"loaded": 0, "canonicals": 0, "merges": 0, "relationships": 0} 36 37 38def test_load_all_legacy_entities_with_facets(tmp_path: Path) -> None: 39 """Normal path: journal with facets/ directory still returns (entities, skipped).""" 40 journal = tmp_path / "journal" 41 facet_dir = journal / "facets" / "work" 42 facet_dir.mkdir(parents=True) 43 44 entities_file = facet_dir / "entities.jsonl" 45 entities_file.write_text( 46 json.dumps( 47 { 48 "name": "Acme Corp", 49 "type": "organization", 50 "description": "A company.", 51 "aka": ["Acme"], 52 "is_principal": False, 53 "detached": False, 54 } 55 ) 56 + "\n" 57 + json.dumps( 58 { 59 "name": "Ghost Entity", 60 "type": "person", 61 "description": "Soft-deleted.", 62 "aka": [], 63 "is_principal": False, 64 "detached": True, 65 } 66 ) 67 + "\n", 68 encoding="utf-8", 69 ) 70 71 entities, skipped = mod.load_all_legacy_entities(journal) 72 73 assert len(entities) == 1 74 assert entities[0].name == "Acme Corp" 75 assert entities[0].facet == "work" 76 assert skipped == 1