-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathtest_disable_permalinks_integration.py
More file actions
138 lines (114 loc) · 5.11 KB
/
test_disable_permalinks_integration.py
File metadata and controls
138 lines (114 loc) · 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""Integration tests for the disable_permalinks configuration."""
import pytest
from basic_memory.config import BasicMemoryConfig
from basic_memory.markdown import EntityParser, MarkdownProcessor
from basic_memory.repository import (
EntityRepository,
ObservationRepository,
RelationRepository,
)
from basic_memory.repository.search_repository import SearchRepository
from basic_memory.schemas import Entity as EntitySchema
from basic_memory.services import FileService
from basic_memory.services.entity_service import EntityService
from basic_memory.services.link_resolver import LinkResolver
from basic_memory.services.search_service import SearchService
from basic_memory.sync.sync_service import SyncService
@pytest.mark.asyncio
async def test_disable_permalinks_create_entity(tmp_path, engine_factory):
"""Test that entities created with disable_permalinks=True don't have permalinks."""
engine, session_maker = engine_factory
# Create app config with disable_permalinks=True
app_config = BasicMemoryConfig(disable_permalinks=True)
# Setup repositories
entity_repository = EntityRepository(session_maker, project_id=1)
observation_repository = ObservationRepository(session_maker, project_id=1)
relation_repository = RelationRepository(session_maker, project_id=1)
search_repository = SearchRepository(session_maker, project_id=1)
# Setup services
entity_parser = EntityParser(tmp_path)
markdown_processor = MarkdownProcessor(entity_parser)
file_service = FileService(tmp_path, markdown_processor)
search_service = SearchService(search_repository, entity_repository, file_service)
await search_service.init_search_index()
link_resolver = LinkResolver(entity_repository, search_service)
entity_service = EntityService(
entity_parser=entity_parser,
entity_repository=entity_repository,
observation_repository=observation_repository,
relation_repository=relation_repository,
file_service=file_service,
link_resolver=link_resolver,
app_config=app_config,
)
# Create entity via API
entity_data = EntitySchema(
title="Test Note",
folder="test",
entity_type="note",
content="Test content",
)
created = await entity_service.create_entity(entity_data)
# Verify entity has no permalink
assert created.permalink is None
# Verify file has no permalink in frontmatter
file_path = tmp_path / "test" / "Test Note.md"
assert file_path.exists()
content = file_path.read_text()
assert "permalink:" not in content
assert "Test content" in content
@pytest.mark.asyncio
async def test_disable_permalinks_sync_workflow(tmp_path, engine_factory):
"""Test full sync workflow with disable_permalinks enabled."""
engine, session_maker = engine_factory
# Create app config with disable_permalinks=True
app_config = BasicMemoryConfig(disable_permalinks=True)
# Create a test markdown file without frontmatter
test_file = tmp_path / "test_note.md"
test_file.write_text("# Test Note\nThis is test content.")
# Setup repositories
entity_repository = EntityRepository(session_maker, project_id=1)
observation_repository = ObservationRepository(session_maker, project_id=1)
relation_repository = RelationRepository(session_maker, project_id=1)
search_repository = SearchRepository(session_maker, project_id=1)
# Setup services
entity_parser = EntityParser(tmp_path)
markdown_processor = MarkdownProcessor(entity_parser)
file_service = FileService(tmp_path, markdown_processor)
search_service = SearchService(search_repository, entity_repository, file_service)
await search_service.init_search_index()
link_resolver = LinkResolver(entity_repository, search_service)
entity_service = EntityService(
entity_parser=entity_parser,
entity_repository=entity_repository,
observation_repository=observation_repository,
relation_repository=relation_repository,
file_service=file_service,
link_resolver=link_resolver,
app_config=app_config,
)
sync_service = SyncService(
app_config=app_config,
entity_service=entity_service,
entity_parser=entity_parser,
entity_repository=entity_repository,
relation_repository=relation_repository,
search_service=search_service,
file_service=file_service,
)
# Run sync
report = await sync_service.scan(tmp_path)
# Note: scan may pick up database files too, so just check our file is there
assert "test_note.md" in report.new
# Sync the file
await sync_service.sync_file("test_note.md", new=True)
# Verify file has no permalink added
content = test_file.read_text()
assert "permalink:" not in content
assert "# Test Note" in content
# Verify entity in database has no permalink
entities = await entity_repository.find_all()
assert len(entities) == 1
assert entities[0].permalink is None
# Title is extracted from filename when no frontmatter, or from frontmatter when present
assert entities[0].title in ("test_note", "Test Note")