From a9e512d1dc220b691bbb9486b0832c7007bf4ee7 Mon Sep 17 00:00:00 2001 From: Chris Coutinho Date: Wed, 17 Jun 2026 23:24:06 +0200 Subject: [PATCH] =?UTF-8?q?test(integration):=20address=20round-8=20review?= =?UTF-8?q?=20=E2=80=94=20sampling=20wait-loop=20robustness?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Guard the status parse in test_sampling's wait_for_vector_sync with try/except (AttributeError, IndexError, ValueError) -> {} and read status fields via .get() with safe defaults (pending defaults to 1 = "not done"), so a transient empty/error status response keeps polling instead of raising and an empty dict never triggers a false break. - Document the idle-signal else branch: idle + pending==0 is also the initial empty state, so prefer passing search_term. Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/integration/test_sampling.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/integration/test_sampling.py b/tests/integration/test_sampling.py index 78340996..4a103d9e 100644 --- a/tests/integration/test_sampling.py +++ b/tests/integration/test_sampling.py @@ -59,7 +59,12 @@ async def wait_for_vector_sync( sync_status = await nc_mcp_client.call_tool( "nc_get_vector_sync_status", arguments={} ) - status_data = json.loads(sync_status.content[0].text) + try: + status_data = json.loads(sync_status.content[0].text) + except (AttributeError, IndexError, ValueError): + # transient empty/error response — keep polling. .get() defaults + # below also keep an empty dict from triggering a false break. + status_data = {} if search_term is not None: # Robust signal: wait for the specific document to be retrievable @@ -68,13 +73,18 @@ async def wait_for_vector_sync( elif initial_indexed_count is not None: # Legacy: wait for new document(s) to be indexed (gauge delta) if ( - status_data["indexed_count"] > initial_indexed_count - and status_data["pending_count"] == 0 + status_data.get("indexed_count", 0) > initial_indexed_count + and status_data.get("pending_count", 1) == 0 ): break else: - # Wait for all pending work to complete - if status_data["status"] == "idle" and status_data["pending_count"] == 0: + # NOTE: idle + pending==0 is also the *initial empty* state, so this + # can break before a caller's work is even enqueued — prefer passing + # search_term. Kept only for callers that just need a settled corpus. + if ( + status_data.get("status") == "idle" + and status_data.get("pending_count", 1) == 0 + ): break await anyio.sleep(wait_interval)