Skip to content

Commit 7930ddb

Browse files
fix: [BUG] Some notes never exit "modified" status (#77)
1 parent 1844e58 commit 7930ddb

File tree

2 files changed

+73
-4
lines changed

2 files changed

+73
-4
lines changed

src/basic_memory/sync/sync_service.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,18 +362,25 @@ async def sync_markdown_file(self, path: str, new: bool = True) -> Tuple[Optiona
362362
# Update relations and search index
363363
entity = await self.entity_service.update_entity_relations(path, entity_markdown)
364364

365+
# After updating relations, we need to compute the checksum again
366+
# This is necessary for files with wikilinks to ensure consistent checksums
367+
# after relation processing is complete
368+
final_checksum = await self.file_service.compute_checksum(path)
369+
365370
# set checksum
366-
await self.entity_repository.update(entity.id, {"checksum": checksum})
367-
371+
await self.entity_repository.update(entity.id, {"checksum": final_checksum})
372+
368373
logger.debug(
369374
"Markdown sync completed",
370375
path=path,
371376
entity_id=entity.id,
372377
observation_count=len(entity.observations),
373378
relation_count=len(entity.relations),
379+
checksum=final_checksum,
374380
)
375-
376-
return entity, checksum
381+
382+
# Return the final checksum to ensure everything is consistent
383+
return entity, final_checksum
377384

378385
async def sync_regular_file(self, path: str, new: bool = True) -> Tuple[Optional[Entity], str]:
379386
"""Sync a non-markdown file with basic tracking.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""Test for issue #72 - notes with wikilinks staying in modified status."""
2+
3+
import pytest
4+
from pathlib import Path
5+
6+
from basic_memory.sync.sync_service import SyncService
7+
8+
9+
async def create_test_file(path: Path, content: str) -> None:
10+
"""Create a test file with given content."""
11+
path.parent.mkdir(parents=True, exist_ok=True)
12+
path.write_text(content)
13+
14+
15+
@pytest.mark.asyncio
16+
async def test_wikilink_modified_status_issue(sync_service: SyncService, test_config):
17+
"""Test that files with wikilinks don't remain in modified status after sync."""
18+
project_dir = test_config.home
19+
20+
# Create a file with a wikilink
21+
content = """---
22+
title: Test Wikilink
23+
type: note
24+
---
25+
# Test File
26+
27+
This file contains a wikilink to [[another-file]].
28+
"""
29+
test_file_path = project_dir / "test_wikilink.md"
30+
await create_test_file(test_file_path, content)
31+
32+
# Initial sync
33+
report1 = await sync_service.sync(test_config.home, show_progress=False)
34+
assert "test_wikilink.md" in report1.new
35+
assert "test_wikilink.md" not in report1.modified
36+
37+
# Sync again without changing the file - should not be modified
38+
report2 = await sync_service.sync(test_config.home, show_progress=False)
39+
assert "test_wikilink.md" not in report2.new
40+
assert "test_wikilink.md" not in report2.modified
41+
42+
# Create the target file
43+
target_content = """---
44+
title: Another File
45+
type: note
46+
---
47+
# Another File
48+
49+
This is the target file.
50+
"""
51+
target_file_path = project_dir / "another_file.md"
52+
await create_test_file(target_file_path, content)
53+
54+
# Sync again after adding target file
55+
report3 = await sync_service.sync(test_config.home, show_progress=False)
56+
assert "another_file.md" in report3.new
57+
assert "test_wikilink.md" not in report3.modified
58+
59+
# Sync one more time - both files should now be stable
60+
report4 = await sync_service.sync(test_config.home, show_progress=False)
61+
assert "test_wikilink.md" not in report4.modified
62+
assert "another_file.md" not in report4.modified

0 commit comments

Comments
 (0)