Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

test(watches): wait for a retry inside one watch run, not any second cycle

cyh36253441913d
diff --git a/tests/test_watches.py b/tests/test_watches.py
index 544a3dcb2..35d17332b 100644
--- a/tests/test_watches.py
+++ b/tests/test_watches.py
@@ -929,7 +929,10 @@ def test_managed_watch_service_forever_timeout_disables_and_enqueues_failure(tmp
assert saved.last_exit_code == 124
-def test_managed_watch_service_forever_timeout_retries_when_explicitly_allowed(tmp_path: Path) -> None:
+def test_managed_watch_service_forever_timeout_retries_when_explicitly_allowed(
+ tmp_path: Path,
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
store = ManagedWatchStore(tmp_path / "watches.json")
request_store = TaskExecutionStore(tmp_path / "task_requests")
runtime_store = WatchRuntimeStateStore(tmp_path / "watch_runtime.json")
@@ -955,20 +958,44 @@ def test_managed_watch_service_forever_timeout_retries_when_explicitly_allowed(t
runtime_store=runtime_store,
)
+ cycles = 0
+ watch_runs = 0
+ run_cycle = service._run_cycle
+ run_watch = service._run_watch
+
+ async def counting_run_cycle(*args, **kwargs):
+ nonlocal cycles
+ cycles += 1
+ return await run_cycle(*args, **kwargs)
+
+ async def counting_run_watch(*args, **kwargs):
+ nonlocal watch_runs
+ watch_runs += 1
+ return await run_watch(*args, **kwargs)
+
+ monkeypatch.setattr(service, "_run_cycle", counting_run_cycle)
+ monkeypatch.setattr(service, "_run_watch", counting_run_watch)
+
async def _run() -> None:
await _start_watch_service(service)
# A fixed sleep bets that a real interpreter spawn, its 50ms deadline and
# the write-back all land inside one window; on a contended runner they do
# not, and the assertion samples ``last_exit_code`` while it is still None.
- # Wait for the recorded outcome instead, so a genuinely wrong code still fails.
+ #
+ # Wait for the retry this test is named for instead, and name it as the
+ # invariant that separates one from a restart: a *second waiter inside the
+ # same watch run*. A watch that recorded the retryable timeout and then
+ # returned would be started again by reconciliation and reach two waiters
+ # too, so the second waiter alone does not distinguish the two.
try:
- for _ in range(250):
- recorded = store.get_watch(watch.id)
- if recorded is not None and recorded.last_exit_code is not None:
+ for _ in range(500):
+ if cycles >= 2 and watch_runs == 1:
break
await asyncio.sleep(0.02)
else:
- raise AssertionError("waiter timeout outcome was never recorded")
+ raise AssertionError(
+ f"waiter never retried inside one watch run (cycles={cycles}, runs={watch_runs})"
+ )
finally:
await service.stop()
@@ -976,6 +1003,7 @@ def test_managed_watch_service_forever_timeout_retries_when_explicitly_allowed(t
saved = store.get_watch(watch.id)
assert saved is not None
+ assert watch_runs == 1
assert saved.enabled is True
assert saved.last_exit_code == 124
assert request_store.list_pending() == []