An open source, non-profit web search engine
Super Search: weekly live smoke tests for YAML recipes
Daoud Clarke1ad5184bdcbd
diff --git a/.github/workflows/super-search-smoke.yml b/.github/workflows/super-search-smoke.ymlnew file mode 100644index 0000000..b7f5ac5--- /dev/null+++ b/.github/workflows/super-search-smoke.yml@@ -0,0 +1,55 @@+name: Super Search smoke (live)++# Runs the Super Search recipe smoke tests against the REAL external endpoints+# (Wiktionary, archive.org, Project Gutenberg) to catch sites changing their+# response format or blocking us. These tests are marked `live` and excluded+# from the normal CI run, so they only execute here (weekly) and on demand.++on:+ schedule:+ - cron: "0 6 * * 1" # 06:00 UTC every Monday+ workflow_dispatch:++jobs:+ smoke:+ runs-on: ubuntu-latest++ services:+ postgres:+ image: postgres:15+ env:+ POSTGRES_PASSWORD: postgres+ POSTGRES_DB: test_mwmbl+ options: >-+ --health-cmd pg_isready+ --health-interval 10s+ --health-timeout 5s+ --health-retries 5+ ports:+ - 5432:5432++ steps:+ - name: Check out repository+ uses: actions/checkout@v3+ - name: Set up python+ uses: actions/setup-python@v4+ with:+ python-version: '3.11.12'+ - name: Install uv+ uses: astral-sh/setup-uv@v5+ with:+ enable-cache: true+ cache-dependency-glob: "uv.lock"+ - name: Install Rust toolchain+ uses: dtolnay/rust-toolchain@stable+ - name: Install dependencies+ run: uv sync --group dev+ - name: Install project with maturin+ run: uv run maturin develop+ - name: Create test directories and files+ run: mkdir -p /tmp/test_mwmbl_data+ - name: Run live smoke tests+ env:+ DATABASE_URL: postgres://postgres:postgres@localhost:5432/test_mwmbl+ DJANGO_SETTINGS_MODULE: mwmbl.settings_test+ run: uv run pytest -m live test/test_super_search_smoke.pydiff --git a/pyproject.toml b/pyproject.tomlindex 3a286dc..a579ab7 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -92,5 +92,8 @@ log_cli = truelog_cli_level = "INFO"DJANGO_SETTINGS_MODULE = "mwmbl.settings_test"python_files = ["tests.py", "test_*.py", "*_tests.py"]-addopts = "--reuse-db"+addopts = "--reuse-db -m 'not live'"asyncio_mode = "auto"+markers = [+ "live: hits real external endpoints; excluded from the default run. Run with -m live (used by the weekly Super Search smoke workflow).",+]diff --git a/test/test_super_search_smoke.py b/test/test_super_search_smoke.pynew file mode 100644index 0000000..4c459db--- /dev/null+++ b/test/test_super_search_smoke.py@@ -0,0 +1,55 @@+"""Live smoke tests for the Super Search YAML recipes.++Unlike test_super_search_recipes.py (which mocks HTTP), these hit the REAL+external endpoints to catch sites changing their response format or blocking+us. They are marked ``live`` and excluded from the default test run; the+weekly "Super Search smoke" GitHub Actions workflow runs them.++Run locally with:++ uv run pytest -m live test/test_super_search_smoke.py++search_with_recipe swallows transport/parse errors and returns [], so a+blocked or reformatted site surfaces here as an empty result list — which the+assertions below turn into a clear failure.+"""+import httpx+import pytest++from mwmbl.tinysearchengine.super_search_sources.recipe import load_recipes, search_with_recipe++pytestmark = pytest.mark.live++QUERY = "frankenstein"+USER_AGENT = "mwmbl-super-search/0.1 (+https://mwmbl.org)"++RECIPES = load_recipes()+++def _client() -> httpx.AsyncClient:+ return httpx.AsyncClient(timeout=20.0, headers={"User-Agent": USER_AGENT})+++def _assert_usable(docs, expected_url_substr: str):+ assert docs, "recipe returned no results — the site may have changed its format or blocked us"+ top = docs[0]+ assert top.url and expected_url_substr in top.url, f"unexpected result URL: {top.url!r}"+ assert top.title, "top result has an empty title"+++async def test_wiktionary_live():+ async with _client() as client:+ docs = await search_with_recipe(client, RECIPES["wiktionary"], QUERY, 5)+ _assert_usable(docs, "en.wiktionary.org/wiki/")+++async def test_archive_org_live():+ async with _client() as client:+ docs = await search_with_recipe(client, RECIPES["archive_org"], QUERY, 5)+ _assert_usable(docs, "archive.org/details/")+++async def test_gutenberg_live():+ async with _client() as client:+ docs = await search_with_recipe(client, RECIPES["gutenberg"], QUERY, 5)+ _assert_usable(docs, "gutenberg.org/ebooks/")