mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
fix imports for sync
This commit is contained in:
@@ -15,7 +15,7 @@ from basic_memory.config import config
|
||||
from basic_memory.db import DatabaseType
|
||||
from basic_memory.repository import DocumentRepository, EntityRepository
|
||||
from basic_memory.services import FileChangeScanner
|
||||
from basic_memory.services.utils import SyncReport, FileState
|
||||
from basic_memory.services.sync.utils import SyncReport, FileState
|
||||
|
||||
# Create rich console
|
||||
console = Console()
|
||||
|
||||
@@ -6,7 +6,7 @@ from loguru import logger
|
||||
|
||||
from basic_memory.services import DocumentService
|
||||
from basic_memory.services import FileChangeScanner
|
||||
from basic_memory.services.utils import SyncReport
|
||||
from basic_memory.services.sync. utils import SyncReport
|
||||
|
||||
|
||||
class DocumentSyncService:
|
||||
|
||||
@@ -7,7 +7,7 @@ from loguru import logger
|
||||
|
||||
from basic_memory.repository.document_repository import DocumentRepository
|
||||
from basic_memory.repository.entity_repository import EntityRepository
|
||||
from basic_memory.services.utils import FileState, SyncReport
|
||||
from basic_memory.services.sync.utils import FileState, SyncReport
|
||||
from basic_memory.utils.file_utils import compute_checksum
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ from pathlib import Path
|
||||
|
||||
from basic_memory.markdown import KnowledgeParser
|
||||
from basic_memory.services import FileChangeScanner, KnowledgeService
|
||||
from basic_memory.services.utils import FileState, SyncReport
|
||||
from basic_memory.services.sync.utils import FileState, SyncReport
|
||||
|
||||
|
||||
class KnowledgeSyncService:
|
||||
|
||||
+33
-55
@@ -1,12 +1,11 @@
|
||||
"""Test status command functionality."""
|
||||
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
from rich.console import Console
|
||||
from io import StringIO
|
||||
|
||||
from basic_memory.cli.commands.status import display_changes, run_status
|
||||
from basic_memory.services.file_sync_service import SyncReport, FileState
|
||||
from basic_memory.services.sync.utils import SyncReport, FileState
|
||||
from basic_memory.utils.file_utils import compute_checksum
|
||||
|
||||
|
||||
@@ -34,15 +33,13 @@ async def test_display_compact_changes(console):
|
||||
deleted={"old/deleted.md"},
|
||||
moved={
|
||||
"new/location.md": FileState(
|
||||
path="new/location.md",
|
||||
checksum="abc123",
|
||||
moved_from="old/location.md"
|
||||
path="new/location.md", checksum="abc123", moved_from="old/location.md"
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
display_changes("Test Files", changes, verbose=False)
|
||||
output_text = output.getvalue()
|
||||
|
||||
|
||||
# Check directory summaries
|
||||
assert "docs/ +1 new" in output_text.replace(" ", " ")
|
||||
assert "docs/ ~1 modified" in output_text.replace(" ", " ")
|
||||
@@ -61,23 +58,23 @@ async def test_display_verbose_changes(console):
|
||||
"new/location.md": FileState(
|
||||
path="new/location.md",
|
||||
checksum="abc123def", # 8 chars for display
|
||||
moved_from="old/location.md"
|
||||
moved_from="old/location.md",
|
||||
)
|
||||
},
|
||||
checksums={
|
||||
"docs/new.md": "def456789abcdef",
|
||||
"docs/mod.md": "ghi789abcdef123",
|
||||
}
|
||||
},
|
||||
)
|
||||
display_changes("Test Files", changes, verbose=True)
|
||||
output_text = output.getvalue()
|
||||
|
||||
|
||||
# Verify sections
|
||||
assert "New Files" in output_text
|
||||
assert "Modified" in output_text
|
||||
assert "Deleted" in output_text
|
||||
assert "Moved" in output_text
|
||||
|
||||
|
||||
# Check file listings with checksums
|
||||
assert "new.md (def45678)" in output_text
|
||||
assert "mod.md (ghi78789)" in output_text
|
||||
@@ -85,46 +82,41 @@ async def test_display_verbose_changes(console):
|
||||
|
||||
|
||||
async def test_end_to_end_status(
|
||||
file_change_scanner,
|
||||
test_config,
|
||||
document_repository,
|
||||
entity_repository
|
||||
file_change_scanner, test_config, document_repository, entity_repository
|
||||
):
|
||||
"""Test complete status command with real files."""
|
||||
# Create test files in both knowledge and documents directories
|
||||
docs_dir = test_config.documents_dir
|
||||
knowledge_dir = test_config.knowledge_dir
|
||||
|
||||
|
||||
# Create some test files
|
||||
docs_dir.mkdir(parents=True, exist_ok=True)
|
||||
knowledge_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
# Create documents
|
||||
doc_path = docs_dir / "test.md"
|
||||
doc_path.write_text("test document")
|
||||
doc_checksum = await compute_checksum("test document")
|
||||
|
||||
|
||||
nested_dir = docs_dir / "subdir"
|
||||
nested_dir.mkdir(exist_ok=True)
|
||||
nested_path = nested_dir / "nested.md"
|
||||
nested_path.write_text("nested document")
|
||||
|
||||
|
||||
# Create knowledge files
|
||||
component_dir = knowledge_dir / "component"
|
||||
component_dir.mkdir(exist_ok=True)
|
||||
component_path = component_dir / "test.md"
|
||||
component_path.write_text("test component")
|
||||
|
||||
|
||||
# Add some files to DB with different paths to test moves
|
||||
await document_repository.create({
|
||||
"path_id": "old/doc.md",
|
||||
"file_path": "old/doc.md",
|
||||
"checksum": "abc123"
|
||||
})
|
||||
await document_repository.create(
|
||||
{"path_id": "old/doc.md", "file_path": "old/doc.md", "checksum": "abc123"}
|
||||
)
|
||||
|
||||
# Run status check
|
||||
await run_status(file_change_scanner, verbose=True)
|
||||
|
||||
|
||||
# Verify changes through sync service directly
|
||||
doc_changes = await file_change_scanner.find_document_changes(docs_dir)
|
||||
assert len(doc_changes.new) == 2 # test.md and nested.md
|
||||
@@ -137,32 +129,26 @@ async def test_end_to_end_status(
|
||||
assert "component/test.md" in knowledge_changes.new
|
||||
|
||||
|
||||
async def test_status_with_case_changes(
|
||||
file_change_scanner,
|
||||
test_config,
|
||||
document_repository
|
||||
):
|
||||
async def test_status_with_case_changes(file_change_scanner, test_config, document_repository):
|
||||
"""Test status detection with case-sensitive path changes."""
|
||||
docs_dir = test_config.documents_dir
|
||||
docs_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
# Create file with initial case
|
||||
content = "test content"
|
||||
original_path = "Test.md"
|
||||
orig_file = docs_dir / original_path
|
||||
orig_file.write_text(content)
|
||||
checksum = await compute_checksum(content)
|
||||
|
||||
|
||||
# Add to DB
|
||||
await document_repository.create({
|
||||
"path_id": original_path,
|
||||
"file_path": original_path,
|
||||
"checksum": checksum
|
||||
})
|
||||
|
||||
await document_repository.create(
|
||||
{"path_id": original_path, "file_path": original_path, "checksum": checksum}
|
||||
)
|
||||
|
||||
# Simulate case change in filesystem
|
||||
orig_file.rename(docs_dir / "test.md")
|
||||
|
||||
|
||||
# Check changes
|
||||
changes = await file_change_scanner.find_document_changes(docs_dir)
|
||||
assert len(changes.moved) == 1
|
||||
@@ -170,32 +156,24 @@ async def test_status_with_case_changes(
|
||||
assert changes.moved["test.md"].moved_from == original_path
|
||||
|
||||
|
||||
async def test_status_with_spaces(
|
||||
file_change_scanner,
|
||||
test_config,
|
||||
document_repository
|
||||
):
|
||||
async def test_status_with_spaces(file_change_scanner, test_config, document_repository):
|
||||
"""Test status handling files with spaces and special characters."""
|
||||
docs_dir = test_config.documents_dir
|
||||
docs_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
# Create file with spaces
|
||||
content = "test content"
|
||||
path = "My Document.md"
|
||||
file_path = docs_dir / path
|
||||
file_path.write_text(content)
|
||||
checksum = await compute_checksum(content)
|
||||
|
||||
|
||||
# Add to DB with same path
|
||||
await document_repository.create({
|
||||
"path_id": path,
|
||||
"file_path": path,
|
||||
"checksum": checksum
|
||||
})
|
||||
|
||||
await document_repository.create({"path_id": path, "file_path": path, "checksum": checksum})
|
||||
|
||||
# Check changes
|
||||
changes = await file_change_scanner.find_document_changes(docs_dir)
|
||||
assert not changes.modified # File unchanged
|
||||
assert not changes.moved # Path matches exactly
|
||||
assert not changes.moved # Path matches exactly
|
||||
assert not changes.deleted
|
||||
assert not changes.new
|
||||
assert not changes.new
|
||||
|
||||
+1
-1
@@ -147,7 +147,7 @@ def knowledge_parser():
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
def file_sync_service(document_repository, entity_repository) -> FileChangeScanner:
|
||||
def file_change_scanner(document_repository, entity_repository) -> FileChangeScanner:
|
||||
"""Create FileChangeScanner instance."""
|
||||
return FileChangeScanner(document_repository, entity_repository)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user