Skip to content

Commit b038eae

Browse files
committed
fix tests
Signed-off-by: phernandez <paul@basicmachines.co>
1 parent e4d20dd commit b038eae

3 files changed

Lines changed: 18 additions & 11 deletions

File tree

src/basic_memory/services/initialization.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ async def migrate_legacy_project_data(project: Project, legacy_dir: Path) -> boo
119119
async def initialize_file_sync(
120120
app_config: BasicMemoryConfig,
121121
):
122-
"""Initialize file synchronization services.
122+
"""Initialize file synchronization services. This function starts the watch service and does not return
123123
124124
Args:
125125
app_config: The Basic Memory project configuration
@@ -157,15 +157,15 @@ async def initialize_file_sync(
157157
sync_dir = Path(project.path)
158158

159159
try:
160-
#await sync_service.sync(sync_dir)
160+
await sync_service.sync(sync_dir)
161161
logger.info(f"Sync completed successfully for project: {project.name}")
162162
except Exception as e: # pragma: no cover
163163
logger.error(f"Error syncing project {project.name}: {e}")
164164
# Continue with other projects even if one fails
165165

166166
# Then start the watch service in the background
167167
logger.info("Starting watch service for all projects")
168-
# Create a background task for the watch service
168+
# run the watch service
169169
try:
170170
await watch_service.run()
171171
logger.info("Watch service started")
@@ -215,5 +215,4 @@ def ensure_initialization(app_config: BasicMemoryConfig) -> None:
215215
logger.exception(f"Error during initialization: {e}")
216216
# Continue execution even if initialization fails
217217
# The command might still work, or will fail with a
218-
# more specific error message
219-
218+
# more specific error message

tests/mcp/test_tool_utils.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ async def test_call_get_error(mock_response):
5252
async def test_call_post_success(mock_response):
5353
"""Test successful POST request."""
5454
client = AsyncClient()
55-
client.post = lambda *args, **kwargs: AsyncMock(return_value=mock_response())()
55+
response = mock_response()
56+
response.json = lambda: {"test": "data"}
57+
client.post = lambda *args, **kwargs: AsyncMock(return_value=response)()
5658

5759
response = await call_post(client, "http://test.com", json={"test": "data"})
5860
assert response.status_code == 200
@@ -62,7 +64,10 @@ async def test_call_post_success(mock_response):
6264
async def test_call_post_error(mock_response):
6365
"""Test POST request with error."""
6466
client = AsyncClient()
65-
client.post = lambda *args, **kwargs: AsyncMock(return_value=mock_response(500))()
67+
response = mock_response(500)
68+
response.json = lambda: {"test": "error"}
69+
70+
client.post = lambda *args, **kwargs: AsyncMock(return_value=response)()
6671

6772
with pytest.raises(ToolError) as exc:
6873
await call_post(client, "http://test.com", json={"test": "data"})
@@ -159,12 +164,15 @@ async def test_get_error_message():
159164
async def test_call_post_with_json(mock_response):
160165
"""Test POST request with JSON payload."""
161166
client = AsyncClient()
162-
mock_post = AsyncMock(return_value=mock_response())
167+
response = mock_response()
168+
response.json = lambda: {"test": "data"}
169+
170+
mock_post = AsyncMock(return_value=response)
163171
client.post = mock_post
164172

165173
json_data = {"key": "value", "nested": {"test": "data"}}
166174
await call_post(client, "http://test.com", json=json_data)
167175

168176
mock_post.assert_called_once()
169177
call_kwargs = mock_post.call_args[1]
170-
assert call_kwargs["json"] == json_data
178+
assert call_kwargs["json"] == json_data

tests/services/test_initialization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async def test_initialize_app(
5353
mock_initialize_database.assert_called_once_with(app_config)
5454
mock_reconcile_projects.assert_called_once_with(app_config)
5555
mock_migrate_legacy_projects.assert_called_once_with(app_config)
56-
mock_initialize_file_sync.assert_called_once_with(app_config)
56+
mock_initialize_file_sync.assert_not_called()
5757
assert result is None
5858

5959

@@ -352,4 +352,4 @@ async def test_initialize_file_sync_sequential(
352352
mock_watch_service.run.assert_called_once()
353353

354354
# Should return None
355-
assert result is None
355+
assert result is None

0 commit comments

Comments
 (0)