- Extract the duplicated `_document_is_searchable`/`_note_is_searchable` helpers into a shared, Playwright-free `tests/integration/_search_helpers.py` (`document_is_searchable`), used by both the plotly and sampling tests. - Resolve the sampling Medium finding: `wait_for_vector_sync` now triggers the searchability path on `search_term` alone (matching the plotly variant) instead of requiring both `search_term` and `note_id`, removing the silent fall-through to the unreliable gauge-delta path. - Tighten `_get_with_retry`'s `last_exc` annotation to `httpx.TransportError`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
"""Shared helpers for asserting vector-sync visibility in integration tests.
|
|
|
|
Kept dependency-light (no Playwright) so both the multi-user-basic UI tests and
|
|
the single-user sampling tests can import it.
|
|
"""
|
|
|
|
import json
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def document_is_searchable(
|
|
mcp_client, search_term: str, note_id: int | None = None
|
|
) -> bool:
|
|
"""Return True once a freshly-created document is retrievable.
|
|
|
|
Polls ``nc_semantic_search`` (hybrid: an exact unique term reliably matches
|
|
on the keyword side) and matches by ``note_id`` when provided, otherwise by
|
|
the term appearing in a result's title/excerpt. Transient errors return
|
|
False so callers can keep polling.
|
|
"""
|
|
try:
|
|
search = await mcp_client.call_tool(
|
|
"nc_semantic_search",
|
|
arguments={"query": search_term, "limit": 10, "score_threshold": 0.0},
|
|
)
|
|
except Exception as e: # transient transport/availability blip — keep polling
|
|
logger.debug("Semantic search poll failed: %s", e)
|
|
return False
|
|
if search.isError:
|
|
logger.debug("Semantic search poll error: %s", search)
|
|
return False
|
|
|
|
results = json.loads(search.content[0].text).get("results", [])
|
|
needle = search_term.lower()
|
|
for r in results:
|
|
if note_id is not None:
|
|
if r.get("id") == note_id and r.get("doc_type") == "note":
|
|
return True
|
|
elif needle in f"{r.get('title', '')} {r.get('excerpt', '')}".lower():
|
|
return True
|
|
return False
|