Skip to content

Commit e01820f

Browse files
jope-bmclaude
andcommitted
fix: Fix failing watch service edge case tests
- Fix tests to pass absolute paths to handle_changes instead of relative paths - Add directory filtering to deletion processing to skip directories without entities - All watch service edge case tests now pass 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Joe P <joe@basicmemory.com>
1 parent 27feda9 commit e01820f

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

src/basic_memory/sync/watch_service.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,16 @@ async def handle_changes(self, project: Project, changes: Set[FileChange]) -> No
296296
processed.add(path)
297297
modify_count += 1
298298
else:
299+
# Check if this was a directory - skip if so
300+
# (we can't tell if the deleted path was a directory since it no longer exists,
301+
# so we check if there's an entity in the database for it)
302+
entity = await sync_service.entity_repository.get_by_file_path(path)
303+
if entity is None:
304+
# No entity means this was likely a directory - skip it
305+
logger.debug(f"Skipping deleted path with no entity (likely directory), path={path}")
306+
processed.add(path)
307+
continue
308+
299309
# File truly deleted
300310
logger.debug("Processing deleted file", path=path)
301311
await sync_service.handle_delete(path)

tests/sync/test_watch_service_edge_cases.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Test edge cases in the WatchService."""
22

3-
from pathlib import Path
43
from unittest.mock import patch
54

65
import pytest
@@ -103,9 +102,8 @@ async def test_handle_vim_atomic_write_delete_still_exists(watch_service, projec
103102
test_file.write_text(modified_content)
104103

105104
# Setup DELETE event even though file still exists (vim's atomic write behavior)
106-
# Use relative path like the real watch service would
107-
relative_path = str(test_file.relative_to(project_dir))
108-
changes = {(Change.deleted, relative_path)}
105+
# Use absolute path like the real watch service would
106+
changes = {(Change.deleted, str(test_file))}
109107

110108
# Handle the change
111109
await watch_service.handle_changes(test_project, changes)
@@ -155,12 +153,10 @@ async def test_handle_true_deletion_vs_vim_atomic(watch_service, project_config,
155153
delete_file.unlink()
156154

157155
# Setup DELETE events for both files
158-
# Use relative paths like the real watch service would
159-
atomic_relative = str(atomic_file.relative_to(project_dir))
160-
delete_relative = str(delete_file.relative_to(project_dir))
156+
# Use absolute paths like the real watch service would
161157
changes = {
162-
(Change.deleted, atomic_relative), # File still exists - atomic write
163-
(Change.deleted, delete_relative), # File deleted - true deletion
158+
(Change.deleted, str(atomic_file)), # File still exists - atomic write
159+
(Change.deleted, str(delete_file)), # File deleted - true deletion
164160
}
165161

166162
# Handle the changes
@@ -235,9 +231,8 @@ async def test_handle_vim_atomic_write_markdown_with_relations(watch_service, pr
235231
main_file.write_text(modified_content)
236232

237233
# Setup DELETE event (vim atomic write)
238-
# Use relative path like the real watch service would
239-
relative_path = str(main_file.relative_to(project_dir))
240-
changes = {(Change.deleted, relative_path)}
234+
# Use absolute path like the real watch service would
235+
changes = {(Change.deleted, str(main_file))}
241236

242237
# Handle the change
243238
await watch_service.handle_changes(test_project, changes)
@@ -267,9 +262,8 @@ async def test_handle_vim_atomic_write_directory_path_ignored(watch_service, pro
267262
test_dir.mkdir()
268263

269264
# Setup DELETE event for directory (should be ignored)
270-
# Use relative path like the real watch service would
271-
relative_path = str(test_dir.relative_to(project_dir))
272-
changes = {(Change.deleted, relative_path)}
265+
# Use absolute path like the real watch service would
266+
changes = {(Change.deleted, str(test_dir))}
273267

274268
# Handle the change - should not cause errors
275269
await watch_service.handle_changes(test_project, changes)

0 commit comments

Comments
 (0)