Skip to content

Commit 7c7ce9a

Browse files
committed
fix(sync): use configured reload interval for empty-project sleep
The guard added in b38823b slept a hardcoded 30 s when no projects were selected, which broke test_run_handles_no_projects and three sibling reload tests: - test_run_handles_no_projects expects the sleep to match config.watch_project_reload_interval (the existing project-reload cadence), not a new magic number. - test_run_reloads_projects_each_cycle, test_run_continues_after_cycle_error, and test_timer_task_cancelled_properly hung because they created Projects whose names weren't registered in app_config.projects. get_project_mode() treats unknown names as CLOUD, so _select_projects_to_watch() filtered them all out, the guard's sleep+continue fired every iteration, and the stubbed _watch_projects_cycle never got called. Two fixes: 1. Sleep watch_project_reload_interval instead of 30 s, matching the existing reload-loop cadence and honoring the existing test contract. 2. Register the test projects as local-mode in app_config.projects so they survive the cloud filter. This aligns the reload tests with test_run_filters_cloud_only_projects_each_cycle, which already does this. Signed-off-by: phernandez <paul@basicmachines.co>
1 parent b38823b commit 7c7ce9a

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

src/basic_memory/sync/watch_service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,14 @@ async def run(self): # pragma: no cover
216216
# Why: watchfiles.awatch() requires at least one path. Calling it
217217
# with an empty list raises ValueError, which the outer handler
218218
# catches with a 5s sleep — producing a tight error-log loop.
219-
# Outcome: sleep longer and retry, giving the project list a chance
220-
# to populate (e.g. after a project is added).
219+
# Outcome: sleep the configured reload interval before retrying, so
220+
# newly added projects get picked up on the next cycle.
221221
if not projects:
222222
logger.warning(
223223
"No projects to watch; sleeping before retry "
224224
f"(constrained_project={self.constrained_project!r})"
225225
)
226-
await asyncio.sleep(30)
226+
await asyncio.sleep(self.app_config.watch_project_reload_interval)
227227
continue
228228

229229
project_paths = [project.path for project in projects]

tests/sync/test_watch_service_reload.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,16 @@ async def fake_write_status():
117117

118118
@pytest.mark.asyncio
119119
async def test_run_reloads_projects_each_cycle(monkeypatch, tmp_path):
120-
config = BasicMemoryConfig(watch_project_reload_interval=1)
120+
# Projects must be registered in app_config.projects as local-mode, otherwise
121+
# _select_projects_to_watch() treats unknown names as CLOUD and filters them
122+
# out, which would short-circuit through the empty-projects guard in run().
123+
config = BasicMemoryConfig(
124+
watch_project_reload_interval=1,
125+
projects={
126+
"project1": {"path": str(tmp_path / "p1"), "mode": "local"},
127+
"project2": {"path": str(tmp_path / "p2"), "mode": "local"},
128+
},
129+
)
121130
repo = _Repo(
122131
projects_side_effect=[
123132
[Project(id=1, name="project1", path=str(tmp_path / "p1"), permalink="project1")],
@@ -229,7 +238,9 @@ async def fake_write_status():
229238

230239
@pytest.mark.asyncio
231240
async def test_run_continues_after_cycle_error(monkeypatch, tmp_path):
232-
config = BasicMemoryConfig()
241+
config = BasicMemoryConfig(
242+
projects={"test": {"path": str(tmp_path / "test"), "mode": "local"}},
243+
)
233244
repo = _Repo(
234245
projects_return=[Project(id=1, name="test", path=str(tmp_path / "test"), permalink="test")]
235246
)
@@ -264,7 +275,9 @@ async def fake_write_status():
264275

265276
@pytest.mark.asyncio
266277
async def test_timer_task_cancelled_properly(monkeypatch, tmp_path):
267-
config = BasicMemoryConfig()
278+
config = BasicMemoryConfig(
279+
projects={"test": {"path": str(tmp_path / "test"), "mode": "local"}},
280+
)
268281
repo = _Repo(
269282
projects_return=[Project(id=1, name="test", path=str(tmp_path / "test"), permalink="test")]
270283
)

0 commit comments

Comments
 (0)