mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
add tests for document sync
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
"""Test sync service."""
|
||||
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
|
||||
@@ -39,3 +39,75 @@ async def test_sync_documents(
|
||||
paths = {d.path_id for d in documents}
|
||||
assert "new.md" in paths
|
||||
assert "modified.md" in paths
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_new_document_adds_frontmatter(
|
||||
test_config: ProjectConfig,
|
||||
sync_service: SyncService
|
||||
):
|
||||
"""Test that syncing a new document adds appropriate frontmatter."""
|
||||
|
||||
# Create document without frontmatter
|
||||
doc_path = test_config.documents_dir / "test.md"
|
||||
original_content = "# Test Document\n\nThis is a test."
|
||||
doc_path.write_text(original_content)
|
||||
|
||||
# Sync
|
||||
await sync_service.sync(test_config.home)
|
||||
|
||||
# Read updated file
|
||||
content = doc_path.read_text()
|
||||
|
||||
# Verify frontmatter was added
|
||||
assert "---" in content
|
||||
assert "id: test.md" in content
|
||||
assert "created:" in content
|
||||
assert "modified:" in content
|
||||
|
||||
# Original content preserved
|
||||
assert original_content in content
|
||||
|
||||
# Verify document in DB
|
||||
doc = await sync_service.document_service.repository.find_by_path_id("test.md")
|
||||
assert doc is not None
|
||||
assert doc.checksum is not None
|
||||
assert doc.created_at is not None
|
||||
assert doc.updated_at is not None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_modified_document_updates_frontmatter(
|
||||
test_config: ProjectConfig,
|
||||
sync_service: SyncService
|
||||
):
|
||||
"""Test that modifying a document updates frontmatter properly."""
|
||||
|
||||
# First create and sync a document
|
||||
doc_path = test_config.documents_dir / "test.md"
|
||||
original_content = "# Test Document\n\nOriginal content."
|
||||
doc_path.write_text(original_content)
|
||||
await sync_service.sync(test_config.home)
|
||||
|
||||
# Get original timestamps
|
||||
doc = await sync_service.document_service.repository.find_by_path_id("test.md")
|
||||
original_created = doc.created_at
|
||||
original_modified = doc.updated_at
|
||||
|
||||
await asyncio.sleep(1)
|
||||
|
||||
# Modify document
|
||||
new_content = "# Test Document\n\nUpdated content."
|
||||
doc_path.write_text(new_content)
|
||||
await sync_service.sync(test_config.home)
|
||||
|
||||
# Verify document in DB
|
||||
updated_doc = await sync_service.document_service.repository.find_by_path_id("test.md")
|
||||
assert updated_doc.created_at == original_created # Should not change
|
||||
assert updated_doc.updated_at > original_modified # Should be updated
|
||||
|
||||
# Check file content
|
||||
content = doc_path.read_text()
|
||||
assert "Updated content" in content
|
||||
assert "created:" in content
|
||||
assert "modified:" in content
|
||||
Reference in New Issue
Block a user