From 298ab8c017419b9ba42bee42c5fb0ff6024726f0 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 19:40:11 -0600 Subject: [PATCH 01/20] Add website example smoke-test CI workflow --- .github/workflows/website-examples.yaml | 66 +++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/website-examples.yaml diff --git a/.github/workflows/website-examples.yaml b/.github/workflows/website-examples.yaml new file mode 100644 index 00000000..c04ba3bd --- /dev/null +++ b/.github/workflows/website-examples.yaml @@ -0,0 +1,66 @@ +name: website-examples.yaml + +on: + push: + branches: ["main", "rc-*"] + paths: + - "shinywidgets/**/*" + - "js/**/*" + - "website/**/*" + - "tests/**/*" + - "Makefile" + - "pyproject.toml" + - "uv.lock" + - ".github/workflows/website-examples.yaml" + pull_request: + paths: + - "shinywidgets/**/*" + - "js/**/*" + - "website/**/*" + - "tests/**/*" + - "Makefile" + - "pyproject.toml" + - "uv.lock" + - ".github/workflows/website-examples.yaml" + workflow_dispatch: + +permissions: + contents: read + +env: + UV_VERSION: "0.13.x" + +# Smoke-boots every website widget/guide example in a browser. Runs in its own +# workflow (parallel to py-check's jobs) so the repo's ~5-minute CI wall-clock +# is unchanged as long as shards stay within the 10-minute job timeout. +jobs: + py-examples: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + shard: [0, 1, 2, 3, 4, 5] + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install uv + uses: astral-sh/setup-uv@v6.1.0 + with: + version: ${{ env.UV_VERSION }} + enable-cache: true + cache-suffix: examples + + - name: Set up Python 3.12 + run: uv python install 3.12 + + - name: Install dependencies + run: uv sync --python 3.12 --all-groups + + - name: Run website example smoke tests (shard ${{ matrix.shard }}/6) + # Healthy shards should finish in ~5 minutes; kill stragglers quickly + timeout-minutes: 10 + # Retry failures twice, matching the py-playwright job's flake posture + run: make test-examples PYTEST_EXAMPLES_ARGS="--num-shards 6 --shard-id ${{ matrix.shard }} -n 3 --reruns 2 --reruns-delay 5" From 5fe8c397e89df159cf3079937c04e821b1b621db Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 19:40:15 -0600 Subject: [PATCH 02/20] Document website example smoke suite in integration skill and AGENTS.md --- .agents/skills/adding-shinywidgets-integrations/SKILL.md | 1 + AGENTS.md | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.agents/skills/adding-shinywidgets-integrations/SKILL.md b/.agents/skills/adding-shinywidgets-integrations/SKILL.md index bf008501..ae968743 100644 --- a/.agents/skills/adding-shinywidgets-integrations/SKILL.md +++ b/.agents/skills/adding-shinywidgets-integrations/SKILL.md @@ -82,6 +82,7 @@ Turn the guide into `website/widgets//`: `index.md` (front matter: `title` - Add the page to the Widgets sidebar group in `website/_quarto.yml` and the `render_` function to the matching quartodoc `contents:` list; a new sidebar group also needs a matching category card in `website/index.qmd` (`make docs` fails the build when the groups and cards don't match). - `website/_tools/check_docs.py` must report nothing (snippets match example files byte-for-byte; links resolve). Bump the hardcoded sidebar-link count in `website/_tools/check_site.py` (checked by `make docs-check`). +- Every `examples/*.py` you add is booted in a browser by the website-example smoke suite (`tests/examples/`, `make test-examples`) and must render a widget with no browser console errors. An example that can't run in CI (network, credentials, renders no widget) or that logs a known-benign error needs a `tests/examples/manifest.yml` entry — the guardrail in `tests/unit/test_examples_manifest.py` fails the build until every example file is either tested or explained there. - Code blocks name their file: ` ```{.python file="examples/x.py"} `. Reshoot screenshots rather than reusing stale ones. - The bundled agent skill ships a matching reference: add `shinywidgets/.agents/skills/shinywidgets/references/widgets/.md` (end it with a `Written against \`\` N.x.` stamp) and a roster row in that skill's `SKILL.md` Widgets table. `tests/unit/test_agent_skill.py` fails until both exist. diff --git a/AGENTS.md b/AGENTS.md index e2286aad..df67ad0d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -24,6 +24,7 @@ cd js && yarn install && yarn watch - **Unit tests**: `make test` (or `make test-unit`) - **Run a single test**: `uv run pytest tests/unit/test_foo.py::test_name` - **Playwright (browser) tests**: `make test-playwright` +- **Website example smoke tests**: `make test-examples` (boots every `website/{widgets,guide}` example in a browser; overrides in `tests/examples/manifest.yml`) - **All tests**: `make test-all-local` - **Coverage**: `make coverage` - **Build package**: `make dist` @@ -154,5 +155,6 @@ SPLIT=$(git log --format=%H -1 -S'class render_plotly(' -- shinywidgets/_render_ - **Unit tests** (`tests/unit/`): Cover comm transport, serialization, rendering lifecycle, widget coercion, dependencies, reactivity, and layout defaults. Run with `make test-unit`. - **Playwright tests** (`tests/playwright/`): Browser-based integration tests that spin up real Shiny apps from `tests/apps/` fixtures. Run with `make test-playwright`. +- **Example smoke tests** (`tests/examples/`): Browser smoke checks that every website example app boots and renders a widget with a clean console. Discovered automatically from `website/{widgets,guide}/*/examples/*.py`; per-example overrides (skip, no_widget, allowed errors) live in `tests/examples/manifest.yml`, guarded by `tests/unit/test_examples_manifest.py`. Run with `make test-examples`. - Pyright type checking excludes `tests/playwright/` (see `pyproject.toml` `[tool.pyright]` config). - CI runs format, types, and unit tests across Python 3.10-3.14; Playwright tests on 3.12 only. From 65b55f48bf32c26a1c6b186ff8ea3dfc02e85560 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 19:40:32 -0600 Subject: [PATCH 03/20] Add website example discovery module, manifest, and guardrail tests --- tests/examples/discovery.py | 82 ++++++++++++++++++++++++++++ tests/examples/manifest.yml | 12 ++++ tests/unit/test_examples_manifest.py | 64 ++++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 tests/examples/discovery.py create mode 100644 tests/examples/manifest.yml create mode 100644 tests/unit/test_examples_manifest.py diff --git a/tests/examples/discovery.py b/tests/examples/discovery.py new file mode 100644 index 00000000..e7724f98 --- /dev/null +++ b/tests/examples/discovery.py @@ -0,0 +1,82 @@ +"""Discovery of runnable website example apps for the smoke-test suite. + +Shared by the browser suite (`tests/examples/`) and the manifest guardrail +(`tests/unit/test_examples_manifest.py`). A file under an examples/ dir is a +runnable Shiny app when it builds one inline (Express) or constructs one +explicitly (core); everything else must carry a `not_app` manifest entry. +""" + +from __future__ import annotations + +from dataclasses import dataclass +from pathlib import Path + +import yaml + +REPO_ROOT = Path(__file__).resolve().parents[2] +EXAMPLE_GLOBS = ("website/widgets/*/examples/*.py", "website/guide/*/examples/*.py") +MANIFEST_PATH = Path(__file__).parent / "manifest.yml" + +APP_MARKERS = ("from shiny.express", "App(") + +_OVERRIDE_KEYS = {"not_app", "skip", "no_widget", "allowed_errors", "allowed_404s"} + + +@dataclass(frozen=True) +class Override: + # not_app: why this file isn't a runnable app (helper module, script). + # skip: why this app can't run in CI. no_widget: app renders no .lm-Widget. + not_app: str | None = None + skip: str | None = None + no_widget: bool = False + allowed_errors: tuple[str, ...] = () + allowed_404s: tuple[str, ...] = () + + +@dataclass(frozen=True) +class Example: + path: Path # absolute + rel: str # repo-relative POSIX path (manifest key and test id) + override: Override + + +def is_app_source(path: Path) -> bool: + src = path.read_text(encoding="utf-8") + return any(marker in src for marker in APP_MARKERS) + + +def example_files(root: Path = REPO_ROOT) -> list[str]: + files: list[str] = [] + for pattern in EXAMPLE_GLOBS: + files.extend(p.relative_to(root).as_posix() for p in sorted(root.glob(pattern))) + return sorted(files) + + +def load_manifest(path: Path = MANIFEST_PATH) -> dict[str, Override]: + raw = yaml.safe_load(path.read_text(encoding="utf-8")) or {} + overrides: dict[str, Override] = {} + for rel, entry in raw.items(): + unknown = set(entry) - _OVERRIDE_KEYS + if unknown: + raise ValueError(f"{rel}: unknown manifest keys: {sorted(unknown)}") + overrides[rel] = Override( + not_app=entry.get("not_app"), + skip=entry.get("skip"), + no_widget=bool(entry.get("no_widget", False)), + allowed_errors=tuple(entry.get("allowed_errors", ())), + allowed_404s=tuple(entry.get("allowed_404s", ())), + ) + return overrides + + +def discover_examples( + root: Path = REPO_ROOT, manifest_path: Path = MANIFEST_PATH +) -> list[Example]: + overrides = load_manifest(manifest_path) + examples: list[Example] = [] + for rel in example_files(root): + override = overrides.get(rel, Override()) + if override.not_app is not None or not is_app_source(root / rel): + continue + examples.append(Example(path=root / rel, rel=rel, override=override)) + return examples diff --git a/tests/examples/manifest.yml b/tests/examples/manifest.yml new file mode 100644 index 00000000..48996039 --- /dev/null +++ b/tests/examples/manifest.yml @@ -0,0 +1,12 @@ +# Per-example overrides for the website example smoke suite. +# Keys are repo-relative paths of files under website/{widgets,guide}/*/examples/. +# Guardrail: tests/unit/test_examples_manifest.py requires every example file +# to be either discovered as an app or explained here. +"website/guide/any-widget/examples/13_detached_task_context.py": + not_app: standalone script (`python file.py`), not a Shiny app +"website/guide/any-widget/examples/sparkline_widget.py": + not_app: anywidget definition module imported by sibling examples +"website/guide/updating-in-place/examples/globals.py": + not_app: shared-lifetime setup module imported by sibling examples +"website/widgets/pydeck/examples/05_static_iframe.py": + no_widget: true diff --git a/tests/unit/test_examples_manifest.py b/tests/unit/test_examples_manifest.py new file mode 100644 index 00000000..199b1cb3 --- /dev/null +++ b/tests/unit/test_examples_manifest.py @@ -0,0 +1,64 @@ +from __future__ import annotations + +import pytest + +from tests.examples.discovery import ( + REPO_ROOT, + example_files, + is_app_source, + load_manifest, +) + + +def test_every_example_file_is_app_or_manifested() -> None: + overrides = load_manifest() + problems: list[str] = [] + for rel in example_files(): + ov = overrides.get(rel) + app = is_app_source(REPO_ROOT / rel) + if app and ov is not None and ov.not_app is not None: + problems.append(f"{rel}: marked not_app but looks like an app") + if not app and (ov is None or ov.not_app is None): + problems.append(f"{rel}: not an app; add a not_app manifest entry") + if ( + not app + and ov is not None + and (ov.skip or ov.no_widget or ov.allowed_errors or ov.allowed_404s) + ): + problems.append(f"{rel}: app-only override keys on a not_app file") + assert not problems, "\n".join(problems) + + +def test_manifest_entries_reference_existing_files() -> None: + existing = set(example_files()) + stale = [rel for rel in load_manifest() if rel not in existing] + assert not stale, f"manifest entries for missing files: {stale}" + + +def test_manifest_reasons_are_nonempty() -> None: + bad = [ + rel + for rel, ov in load_manifest().items() + if (ov.not_app is not None and not ov.not_app.strip()) + or (ov.skip is not None and not ov.skip.strip()) + ] + assert not bad, f"manifest entries with empty reasons: {bad}" + + +def test_is_app_source(tmp_path) -> None: + express = tmp_path / "express.py" + express.write_text("from shiny.express import ui\n") + core = tmp_path / "core.py" + core.write_text("from shiny import App, ui\napp = App(ui.page_fluid(), None)\n") + helper = tmp_path / "helper.py" + helper.write_text("import traitlets\n\nVALUE = 1\n") + assert is_app_source(express) + assert is_app_source(core) + assert not is_app_source(helper) + + +def test_load_manifest_rejects_unknown_keys(tmp_path) -> None: + manifest = tmp_path / "manifest.yml" + manifest.write_text('"website/widgets/x/examples/a.py":\n bogus: true\n') + with pytest.raises(ValueError, match="bogus"): + load_manifest(manifest) From 3ae9e03e0658cab72ba6c66e7e0a4326970be6f8 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 19:47:49 -0600 Subject: [PATCH 04/20] Add website example smoke-test suite and make target --- Makefile | 7 ++++- pytest.ini | 2 +- tests/examples/conftest.py | 45 ++++++++++++++++++++++++++++++ tests/examples/examples-pytest.ini | 13 +++++++++ tests/examples/test_smoke.py | 27 ++++++++++++++++++ 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 tests/examples/conftest.py create mode 100644 tests/examples/examples-pytest.ini create mode 100644 tests/examples/test_smoke.py diff --git a/Makefile b/Makefile index 6c66ed1c..ea56207d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: help clean clean-build clean-pyc clean-test setup check-format check-types check-tests check check-tox build format coverage check-build test test-unit test-reactable test-playwright test-playwright-reactable test-playwright-coverage test-all-local coverage-ci coverage-combine coverage-html dist install pyright docs docs-preview docs-check +.PHONY: help clean clean-build clean-pyc clean-test setup check-format check-types check-tests check check-tox build format coverage check-build test test-unit test-reactable test-playwright test-playwright-reactable test-playwright-coverage test-examples test-all-local coverage-ci coverage-combine coverage-html dist install pyright docs docs-preview docs-check .DEFAULT_GOAL := help @@ -8,6 +8,7 @@ PYTHON_PATHS := shinywidgets tests PYRIGHT_PATHS := shinywidgets tests/__init__.py tests/unit/test_version_metadata.py PYTEST_UNIT := uv run pytest -c "$(REPO_ROOT)/pytest.ini" --confcutdir "$(REPO_ROOT)" PYTEST_PLAYWRIGHT := uv run pytest -c "$(REPO_ROOT)/tests/playwright/playwright-pytest.ini" --confcutdir "$(REPO_ROOT)/tests/playwright" "$(REPO_ROOT)/tests/playwright" +PYTEST_EXAMPLES := uv run pytest -c "$(REPO_ROOT)/tests/examples/examples-pytest.ini" --confcutdir "$(REPO_ROOT)/tests/examples" "$(REPO_ROOT)/tests/examples" # reactable can't join the shared test/dev groups (importing it builds a # process-global ipyreact Module widget that order-sensitive FakeSession unit # tests don't expect), it imports great_tables without declaring it, and it @@ -96,6 +97,10 @@ test-playwright: ## run Playwright regression tests uv run playwright install chromium $(PYTEST_PLAYWRIGHT) $(PYTEST_PLAYWRIGHT_ARGS) +test-examples: ## smoke-test every website example app in a browser + uv run playwright install chromium + $(PYTEST_EXAMPLES) $(PYTEST_EXAMPLES_ARGS) + test-reactable: ## run reactable unit tests (needs the overlay; see REACTABLE_OVERLAY) $(PYTEST_REACTABLE) diff --git a/pytest.ini b/pytest.ini index 412bfa5c..672607ee 100644 --- a/pytest.ini +++ b/pytest.ini @@ -4,7 +4,7 @@ minversion = 6.0 # Default to fast, deterministic unit tests. Playwright tests are run explicitly # via their own config file under tests/playwright/. testpaths = tests/unit -norecursedirs = tests/playwright +norecursedirs = tests/playwright tests/examples addopts = -ra diff --git a/tests/examples/conftest.py b/tests/examples/conftest.py new file mode 100644 index 00000000..122d0d63 --- /dev/null +++ b/tests/examples/conftest.py @@ -0,0 +1,45 @@ +from __future__ import annotations + +from dataclasses import dataclass + +import pytest +from shiny.run import ShinyAppProc + +# Same private helper shiny's own pytest plugin (create_app_fixture) uses; it +# handles port search, readiness waiting, and subprocess teardown. +from shiny.run._run import shiny_app_gen +from tests.examples.discovery import Example, discover_examples + + +@dataclass(frozen=True) +class RunningExample: + proc: ShinyAppProc + example: Example + + +def _params() -> list: + params = [] + for example in discover_examples(): + marks = ( + [pytest.mark.skip(reason=example.override.skip)] + if example.override.skip + else [] + ) + params.append(pytest.param(example, id=example.rel, marks=marks)) + return params + + +@pytest.fixture(params=_params()) +def running_example(request): + example: Example = request.param + gen = shiny_app_gen( + example.path, + cwd=str(example.path.parent), + timeout_secs=30, + env={"SHINY_TESTMODE": "1"}, + ) + proc = next(gen) + try: + yield RunningExample(proc=proc, example=example) + finally: + proc.close() diff --git a/tests/examples/examples-pytest.ini b/tests/examples/examples-pytest.ini new file mode 100644 index 00000000..909d7d36 --- /dev/null +++ b/tests/examples/examples-pytest.ini @@ -0,0 +1,13 @@ +[pytest] +# -n auto/--dist load: spread the parametrized example tests across xdist +# workers (loadscope would keep the single module on one worker). Shiny gives +# each worker a disjoint app-port range (shiny.run._run.port_search_range). +# Override locally with -n0 to run serially (e.g., for debugging). +addopts = --strict-markers --browser chromium -vv --maxfail=1 -n auto --dist load --durations=10 --durations-min=5.0 +# A hung test must fail quickly rather than stall its CI shard until the job +# timeout. The `thread` method kills the hung xdist worker (which xdist reports +# as a failure of that test); faulthandler dumps every thread's stack to stderr +# just before the kill so the log shows where it hung. +timeout = 180 +timeout_method = thread +faulthandler_timeout = 170 diff --git a/tests/examples/test_smoke.py b/tests/examples/test_smoke.py new file mode 100644 index 00000000..48db649b --- /dev/null +++ b/tests/examples/test_smoke.py @@ -0,0 +1,27 @@ +from __future__ import annotations + +from playwright.sync_api import Page, expect +from tests.examples.conftest import RunningExample +from tests.playwright.conftest import assert_no_unexpected_errors, collect_errors + +# Generous first-paint budget: CI runners under xdist contention are slow, and +# some widgets pull large JS bundles on first load. +WIDGET_TIMEOUT_MS = 30_000 + + +def test_example_boots_and_renders(page: Page, running_example: RunningExample) -> None: + override = running_example.example.override + errors, failed_requests = collect_errors(page) + page.goto(running_example.proc.url) + + if not override.no_widget: + expect(page.locator(".lm-Widget").first).to_be_visible( + timeout=WIDGET_TIMEOUT_MS + ) + + assert_no_unexpected_errors( + errors, + failed_requests, + allowed_404s=override.allowed_404s, + allowed_errors=override.allowed_errors, + ) From 591b6b8327a5e21b09675fd99e308916955a54f6 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 19:51:39 -0600 Subject: [PATCH 05/20] Add mapwidget and ipydeck to test deps for any-widget guide examples --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 629485a1..03e28d05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -282,6 +282,7 @@ test = [ "ipycanvas", "ipycytoscape", "ipydatagrid>=1.2.0", + "ipydeck", "ipyfilechooser", "ipyleaflet>=0.20.0", "ipysigma", @@ -304,6 +305,9 @@ test = [ # Python 3.15+ yet, so lonboard can't be installed there "lonboard; python_version < '3.15'", "maplibre[anywidget]", + # mapwidget and ipydeck aren't shinywidgets integrations (the any-widget + # guide's third-party examples use them via the generic render_widget) + "mapwidget", "mols2grid>=2.2.0,<3", "nglview", "pandas", From 3f61ed7c50d3cbfa50d894bcc3788a8c06f40e61 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 19:51:43 -0600 Subject: [PATCH 06/20] Drop untracked uv.lock from workflow path filters --- .github/workflows/website-examples.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/website-examples.yaml b/.github/workflows/website-examples.yaml index c04ba3bd..711e4266 100644 --- a/.github/workflows/website-examples.yaml +++ b/.github/workflows/website-examples.yaml @@ -10,7 +10,6 @@ on: - "tests/**/*" - "Makefile" - "pyproject.toml" - - "uv.lock" - ".github/workflows/website-examples.yaml" pull_request: paths: @@ -20,7 +19,6 @@ on: - "tests/**/*" - "Makefile" - "pyproject.toml" - - "uv.lock" - ".github/workflows/website-examples.yaml" workflow_dispatch: From aba801529657df2b500fbd56fd6ce703babf943e Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 20:41:52 -0600 Subject: [PATCH 07/20] Fix render_itables accessor misuse in obsplot/lonboard examples table.selected_rows() -> table.selected(): render_itables's named accessor is .selected(); selected_rows is the widget trait. Caught by the website example smoke suite (the apps rendered nothing). --- website/widgets/lonboard/examples/14_table_to_fly_to.py | 2 +- website/widgets/lonboard/index.md | 4 ++-- website/widgets/obsplot/examples/12_table_row_highlight.py | 2 +- .../widgets/obsplot/gallery/showcase_gapminder_dashboard.py | 2 +- website/widgets/obsplot/index.md | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/website/widgets/lonboard/examples/14_table_to_fly_to.py b/website/widgets/lonboard/examples/14_table_to_fly_to.py index 2ea5f35a..0c55a76e 100644 --- a/website/widgets/lonboard/examples/14_table_to_fly_to.py +++ b/website/widgets/lonboard/examples/14_table_to_fly_to.py @@ -35,7 +35,7 @@ def map(): @reactive.effect def _fly_to_selected(): - rows = req(table.selected_rows()) + rows = req(table.selected()) row = cities().iloc[rows[0]] # table drives the map: selecting a row flies the camera there, without # re-sending the 20 points or losing any in-place styling diff --git a/website/widgets/lonboard/index.md b/website/widgets/lonboard/index.md index a26304e7..ea20e6be 100644 --- a/website/widgets/lonboard/index.md +++ b/website/widgets/lonboard/index.md @@ -561,7 +561,7 @@ def _fly_to_city(): ### Table row flies the map -Interaction isn't one-way. An `itables` row selection (`table.selected_rows()`) drives +Interaction isn't one-way. An `itables` row selection (`table.selected()`) drives `map.widget.fly_to(...)` -- the map is the one being updated here, in place, with its existing styling and the other table's selection state untouched. @@ -603,7 +603,7 @@ with ui.layout_columns(col_widths=[5, 7]): @reactive.effect def _fly_to_selected(): - rows = req(table.selected_rows()) + rows = req(table.selected()) row = cities().iloc[rows[0]] # table drives the map: selecting a row flies the camera there, without # re-sending the 20 points or losing any in-place styling diff --git a/website/widgets/obsplot/examples/12_table_row_highlight.py b/website/widgets/obsplot/examples/12_table_row_highlight.py index 6fd0a89d..f0f0dedd 100644 --- a/website/widgets/obsplot/examples/12_table_row_highlight.py +++ b/website/widgets/obsplot/examples/12_table_row_highlight.py @@ -58,6 +58,6 @@ def plot(): @reactive.effect def _(): - rows = table.selected_rows() + rows = table.selected() country = gapminder_2007.iloc[rows[0]]["country"] if rows else None plot.widget.spec = spec(country) diff --git a/website/widgets/obsplot/gallery/showcase_gapminder_dashboard.py b/website/widgets/obsplot/gallery/showcase_gapminder_dashboard.py index 68485826..8c519bf5 100644 --- a/website/widgets/obsplot/gallery/showcase_gapminder_dashboard.py +++ b/website/widgets/obsplot/gallery/showcase_gapminder_dashboard.py @@ -82,7 +82,7 @@ def bubble_spec(data, highlight: str | None = None) -> dict: @render_obsplot def bubble(): data = year_rows() - rows = table.selected_rows() + rows = table.selected() highlight = data.iloc[rows[0]]["country"] if rows else None return Plot.plot(bubble_spec(data, highlight)) diff --git a/website/widgets/obsplot/index.md b/website/widgets/obsplot/index.md index e282134a..eddd2522 100644 --- a/website/widgets/obsplot/index.md +++ b/website/widgets/obsplot/index.md @@ -670,7 +670,7 @@ def _(): ### A table selection highlights a point -`render_itables`'s `.selected_rows()` returns the positions of selected rows (see the +`render_itables`'s `.selected()` returns the positions of selected rows (see the [itables guide](../itables/index.md)). Here, selecting a country in the table draws a second, ringed `Plot.dot` mark on top of the matching bubble: @@ -735,7 +735,7 @@ with ui.layout_columns(): @reactive.effect def _(): - rows = table.selected_rows() + rows = table.selected() country = gapminder_2007.iloc[rows[0]]["country"] if rows else None plot.widget.spec = spec(country) ``` From 23598a212f06631251318b7959502e5931ba03ad Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 20:41:55 -0600 Subject: [PATCH 08/20] Add example-only packages to the test dependency group So the website example smoke suite can boot every example: chatlas, querychat, anthropic (ai-exploration guide), nibabel (niivue), mdtraj (nglview), mocpy (ipyaladin), scikit-learn (k3d/embedding-atlas), bokeh_sampledata (bokeh>=3.8 split), leafmap + rioxarray + mapclassify + localtileserver + scipy (leafmap page). --- pyproject.toml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 03e28d05..a2ec562c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -268,6 +268,23 @@ test = [ # cartopy 0.25 has no Python 3.14 wheels. Drop the pin and the markers once # geoviews supports cartopy>=0.26 (which has 3.14 wheels). "cartopy<0.26; python_version < '3.14'", + "anthropic", + "bokeh_sampledata", + "chatlas", + "querychat", + "nibabel", + "mdtraj", + "mocpy", + "scikit-learn", + # leafmap stays out of the shared group only via its extra because of + # plotlymap's plotly<7 need; the examples don't use plotlymap, so the + # group can carry leafmap with the group's plotly + "leafmap", + "rioxarray", + "mapclassify", + # leafmap[raster] examples (05_raster_cog, 10_drawn_features_zonal) + "localtileserver", + "scipy", "datashader", "drawdata>=0.5", # duckdb (a dependency of embedding-atlas, mosaic-widget, pygwalker, and From 805b3561393493c41e3b130814dee56e014b5df2 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 20:41:55 -0600 Subject: [PATCH 09/20] Triage website example smoke suite to green - Check view attachment via output children, not .lm-Widget (raw-DOM widgets like pythreejs don't carry that class); any output counts, not just the first - Overlay runs (reactable, vizarr) with an env-var skip lift, matching the existing REACTABLE_OVERLAY pattern; leafmap joins the shared group instead since the group's plotly is <7 anyway - Manifest entries: ipyevents.js 404s (leafmap), drawdata svg height console noise, ipydatagrid icon 404s, pydeck widget-less demos, gaia parquet not committed, vitessce draft page, localtileserver's in-process uvicorn suppressing the readiness probe, dead niivue.com/demos/images host --- .github/workflows/website-examples.yaml | 10 ++ Makefile | 13 +- tests/examples/conftest.py | 8 +- tests/examples/manifest.yml | 186 ++++++++++++++++++++++++ tests/examples/test_smoke.py | 16 +- 5 files changed, 227 insertions(+), 6 deletions(-) diff --git a/.github/workflows/website-examples.yaml b/.github/workflows/website-examples.yaml index 711e4266..14fc8635 100644 --- a/.github/workflows/website-examples.yaml +++ b/.github/workflows/website-examples.yaml @@ -62,3 +62,13 @@ jobs: timeout-minutes: 10 # Retry failures twice, matching the py-playwright job's flake posture run: make test-examples PYTEST_EXAMPLES_ARGS="--num-shards 6 --shard-id ${{ matrix.shard }} -n 3 --reruns 2 --reruns-delay 5" + + # reactable and vizarr can't join the shared test group (ipyreact and + # zarr<3 pins respectively), so their examples run with dependency + # overlays, once (shard 0) + - name: Run overlay example smoke tests + if: matrix.shard == 0 + timeout-minutes: 10 + run: | + make test-examples-reactable PYTEST_EXAMPLES_ARGS="-n 3 --reruns 2 --reruns-delay 5" + make test-examples-vizarr PYTEST_EXAMPLES_ARGS="-n 3 --reruns 2 --reruns-delay 5" diff --git a/Makefile b/Makefile index ea56207d..fb43ddb7 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: help clean clean-build clean-pyc clean-test setup check-format check-types check-tests check check-tox build format coverage check-build test test-unit test-reactable test-playwright test-playwright-reactable test-playwright-coverage test-examples test-all-local coverage-ci coverage-combine coverage-html dist install pyright docs docs-preview docs-check +.PHONY: help clean clean-build clean-pyc clean-test setup check-format check-types check-tests check check-tox build format coverage check-build test test-unit test-reactable test-playwright test-playwright-reactable test-playwright-coverage test-examples test-examples-reactable test-examples-vizarr test-all-local coverage-ci coverage-combine coverage-html dist install pyright docs docs-preview docs-check .DEFAULT_GOAL := help @@ -101,6 +101,17 @@ test-examples: ## smoke-test every website example app in a browser uv run playwright install chromium $(PYTEST_EXAMPLES) $(PYTEST_EXAMPLES_ARGS) +# Examples that need a dependency overlay are skipped in the shared run (see +# tests/examples/manifest.yml); the INCLUDE_SKIPPED env var lifts those skips +# for these -k-filtered overlay runs. +test-examples-reactable: ## smoke-test reactable website examples (needs the overlay; see REACTABLE_OVERLAY) + uv run playwright install chromium + SHINYWIDGETS_EXAMPLES_INCLUDE_SKIPPED=1 uv run $(REACTABLE_OVERLAY) pytest -c "$(REPO_ROOT)/tests/examples/examples-pytest.ini" --confcutdir "$(REPO_ROOT)/tests/examples" "$(REPO_ROOT)/tests/examples" -k "reactable or 03_dark_mode" $(PYTEST_EXAMPLES_ARGS) + +test-examples-vizarr: ## smoke-test vizarr website examples (needs the overlay; vizarr pins zarr<3) + uv run playwright install chromium + SHINYWIDGETS_EXAMPLES_INCLUDE_SKIPPED=1 uv run --with vizarr pytest -c "$(REPO_ROOT)/tests/examples/examples-pytest.ini" --confcutdir "$(REPO_ROOT)/tests/examples" "$(REPO_ROOT)/tests/examples" -k vizarr $(PYTEST_EXAMPLES_ARGS) + test-reactable: ## run reactable unit tests (needs the overlay; see REACTABLE_OVERLAY) $(PYTEST_REACTABLE) diff --git a/tests/examples/conftest.py b/tests/examples/conftest.py index 122d0d63..9195d7c2 100644 --- a/tests/examples/conftest.py +++ b/tests/examples/conftest.py @@ -1,5 +1,6 @@ from __future__ import annotations +import os from dataclasses import dataclass import pytest @@ -17,12 +18,17 @@ class RunningExample: example: Example +# Overlay runs (make test-examples-reactable/-leafmap/-vizarr) set this so +# their examples' manifest skips don't apply; the shared run honors them. +_INCLUDE_SKIPPED = os.environ.get("SHINYWIDGETS_EXAMPLES_INCLUDE_SKIPPED") == "1" + + def _params() -> list: params = [] for example in discover_examples(): marks = ( [pytest.mark.skip(reason=example.override.skip)] - if example.override.skip + if example.override.skip and not _INCLUDE_SKIPPED else [] ) params.append(pytest.param(example, id=example.rel, marks=marks)) diff --git a/tests/examples/manifest.yml b/tests/examples/manifest.yml index 48996039..3a4f4150 100644 --- a/tests/examples/manifest.yml +++ b/tests/examples/manifest.yml @@ -8,5 +8,191 @@ not_app: anywidget definition module imported by sibling examples "website/guide/updating-in-place/examples/globals.py": not_app: shared-lifetime setup module imported by sibling examples + +# --- Apps that intentionally render no widget ------------------------------- "website/widgets/pydeck/examples/05_static_iframe.py": no_widget: true +"website/widgets/pydeck/examples/01_deprecation_error.py": + # Demonstrates render_pydeck's deprecation TypeError; the output is the + # error, not a widget + no_widget: true + +# --- Known-benign third-party console noise ---------------------------------- +# drawdata sets svg height="auto", which Chromium logs as a console error +"website/widgets/drawdata/examples/02_live_dataframe.py": + allowed_errors: [" attribute height: Expected length"] +"website/widgets/drawdata/examples/01_quickstart.py": + allowed_errors: [" attribute height: Expected length"] +"website/widgets/drawdata/examples/04_reading_drawn_data.py": + allowed_errors: [" attribute height: Expected length"] +"website/widgets/drawdata/examples/06_clear_and_reset.py": + allowed_errors: [" attribute height: Expected length"] + +# ipydatagrid + plotly in the same app: ipydatagrid's icon .pngs 404 under +# /lib/anywidget-0.0/ (cosmetic; a dependency-resolution quirk in how the +# widget's nbextension base URL is computed -- worth a real fix separately) +"website/widgets/ipydatagrid/examples/06_edited_cell.py": + allowed_404s: ["anywidget-0.0"] +"website/widgets/ipydatagrid/examples/07_visible_data.py": + allowed_404s: ["anywidget-0.0"] + +# --- Examples that need a dependency overlay (skipped in the shared run) ----- +# reactable pins ipyreact<=0.4.1, which conflicts with the test group's +# ipyreact>=0.6 (see REACTABLE_OVERLAY in the Makefile). Covered by +# `make test-examples-reactable` (CI runs it on shard 0). +"website/guide/layout-and-theming/examples/03_dark_mode.py": + # Needs reactable (only runs under the dependency overlay), but also + # ipyleaflet, whose nbextension lookup the overlay breaks -- no environment + # runs both + skip: imports both reactable (needs the overlay) and ipyleaflet (breaks under the overlay) +"website/widgets/altair/examples/13_brush_to_reactable_table.py": + skip: imports reactable, which needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` +"website/widgets/reactable/examples/01_quickstart.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` +"website/widgets/reactable/examples/02_formatting_styling.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` +"website/widgets/reactable/examples/03_grouping.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + # react-table logs this about the aggregate column config on load; the + # table still renders + allowed_errors: ["Invalid column.aggregate option"] +"website/widgets/reactable/examples/04_expandable_details.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` +"website/widgets/reactable/examples/05_custom_cells.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` +"website/widgets/reactable/examples/06_theming.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` +"website/widgets/reactable/examples/07_column_groups_footers.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` +"website/widgets/reactable/examples/08_selected_rows.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` +"website/widgets/reactable/examples/09_page_sorted.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` +"website/widgets/reactable/examples/10_filter_search.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` +"website/widgets/reactable/examples/11_rate_limiting.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` +"website/widgets/reactable/examples/12_inplace_props.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` +"website/widgets/reactable/examples/13_update_data.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` +"website/widgets/reactable/examples/14_selection_to_detail.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` +"website/widgets/reactable/examples/15_search_to_chart.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` +"website/widgets/reactable/examples/16_row_click.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` +"website/widgets/reactable/examples/17_export_selected.py": + skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + + +# vizarr pins zarr<3, so it stays out of the shared test group. Covered by +# `make test-examples-vizarr` (CI runs it on shard 0). +"website/widgets/vizarr/examples/01_quickstart.py": + skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` +"website/widgets/vizarr/examples/02_numpy_array.py": + skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` +"website/widgets/vizarr/examples/03_multichannel_contrast.py": + skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` +"website/widgets/vizarr/examples/04_camera_view_state.py": + skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` +"website/widgets/vizarr/examples/05_add_layer_in_place.py": + skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` +"website/widgets/vizarr/examples/06_channel_toggle_rerender.py": + skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` +"website/widgets/vizarr/examples/07_linked_minimap.py": + skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` +"website/widgets/vizarr/examples/08_linked_histogram.py": + skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` + +# --- Examples that can't run in CI ------------------------------------------- +# vitessce's widget page is a draft until render_vitessce ships (see the repo +# AGENTS.md), so the package isn't in the test group at all. +"website/widgets/vitessce/examples/01_quickstart.py": + skip: widget page is a draft until render_vitessce ships; vitessce isn't installed in the test env +"website/widgets/vitessce/examples/02_build_config.py": + skip: widget page is a draft until render_vitessce ships; vitessce isn't installed in the test env +"website/widgets/vitessce/examples/03_dashboard_with_readout.py": + skip: widget page is a draft until render_vitessce ships; vitessce isn't installed in the test env +"website/widgets/vitessce/examples/04_gene_picker_inplace.py": + skip: widget page is a draft until render_vitessce ships; vitessce isn't installed in the test env +"website/widgets/vitessce/examples/05_gene_picker_noremount.py": + skip: widget page is a draft until render_vitessce ships; vitessce isn't installed in the test env +"website/widgets/vitessce/examples/06_cellset_to_table.py": + skip: widget page is a draft until render_vitessce ships; vitessce isn't installed in the test env + +# --- leafmap: ipyevents 404 -------------------------------------------------- +# leafmap.Map's interaction widget (ipyevents) ships its nbextension inside +# the package, not under share/jupyter/nbextensions, so +# require_dependencies() can't serve it locally and the browser 404s on +# /ipyevents.js before falling back to the CDN (the widget then loads and +# renders fine). Pre-existing resolution gap -- the right fix is local +# serving, tracked separately -- so tolerate the 404 here. +"website/widgets/leafmap/examples/01_quickstart.py": + allowed_404s: ["ipyevents.js"] +"website/widgets/leafmap/examples/02_basemaps.py": + allowed_404s: ["ipyevents.js"] +"website/widgets/leafmap/examples/03_vector_data.py": + allowed_404s: ["ipyevents.js"] +"website/widgets/leafmap/examples/04_choropleth.py": + allowed_404s: ["ipyevents.js"] +"website/widgets/leafmap/examples/05_raster_cog.py": + allowed_404s: ["ipyevents.js"] +"website/widgets/leafmap/examples/06_split_map.py": + allowed_404s: ["ipyevents.js"] +"website/widgets/leafmap/examples/07_bounds_viewport_chart.py": + allowed_404s: ["ipyevents.js"] +"website/widgets/leafmap/examples/08_zoom_center.py": + allowed_404s: ["ipyevents.js"] +"website/widgets/leafmap/examples/09_clicked_detail.py": + allowed_404s: ["ipyevents.js"] +"website/widgets/leafmap/examples/10_drawn_features_zonal.py": + allowed_404s: ["ipyevents.js"] +"website/widgets/leafmap/examples/12_in_place_updates.py": + allowed_404s: ["ipyevents.js"] +"website/widgets/leafmap/examples/13_layout_sizing.py": + allowed_404s: ["ipyevents.js"] +"website/widgets/leafmap/examples/14_read_on_demand.py": + allowed_404s: ["ipyevents.js"] +"website/widgets/drawdata/examples/07_classifier_boundary.py": + allowed_errors: [" attribute height: Expected length"] +"website/widgets/drawdata/examples/08_regression_fit.py": + allowed_errors: [" attribute height: Expected length"] +"website/widgets/drawdata/examples/10_clustering.py": + allowed_errors: [" attribute height: Expected length"] +"website/widgets/drawdata/examples/11_fit_on_demand.py": + allowed_errors: [" attribute height: Expected length"] + +# --- localtileserver ---------------------------------------------------------- +# A TileClient runs its tile server via an in-process uvicorn, which +# reconfigures uvicorn's logging process-wide: the Shiny app then serves fine +# but never emits the "Uvicorn running on" stderr line that shiny_app_gen's +# readiness probe waits for (repro: any app that constructs a TileClient). +# Nothing the suite can wait on -- skip. +"website/widgets/localtileserver/examples/01_quickstart.py": + skip: TileClient's in-process uvicorn suppresses the readiness log line shiny_app_gen waits for +"website/widgets/localtileserver/examples/02_restyle.py": + skip: TileClient's in-process uvicorn suppresses the readiness log line shiny_app_gen waits for +"website/widgets/localtileserver/examples/03_click_sample.py": + skip: TileClient's in-process uvicorn suppresses the readiness log line shiny_app_gen waits for +"website/widgets/localtileserver/examples/04_draw_zonal_stats.py": + skip: TileClient's in-process uvicorn suppresses the readiness log line shiny_app_gen waits for + +# --- Examples that need data not in the repo ---------------------------------- +# The gaia-5m.parquet sample (5M rows) is deliberately not committed (see +# website/guide/linked-views/data/README.md); fetching it per CI shard would +# be slow and flaky. +"website/guide/linked-views/examples/18_datashader_brush_summaries.py": + skip: needs gaia-5m.parquet, which is deliberately not committed (see data/README.md) +"website/guide/linked-views/examples/19_scattergl_lasso_raw_points.py": + skip: needs gaia-5m.parquet, which is deliberately not committed (see data/README.md) +"website/guide/linked-views/examples/20_mosaic_brush_in_widget.py": + skip: needs gaia-5m.parquet, which is deliberately not committed (see data/README.md) + +# The entire niivue.com/demos/images host 404s upstream (every niivue example +# uses it; the others only fetch client-side, so the widget still attaches, +# but their canvases likely render empty -- a page-level content fix is +# needed, tracked separately). This one fetches aal.json server-side at +# import, so the app can't boot at all. +"website/widgets/niivue/examples/09_atlas_label.py": + skip: fetches aal.json from niivue.com/demos/images at import; that host 404s upstream diff --git a/tests/examples/test_smoke.py b/tests/examples/test_smoke.py index 48db649b..7a9aaeae 100644 --- a/tests/examples/test_smoke.py +++ b/tests/examples/test_smoke.py @@ -1,6 +1,6 @@ from __future__ import annotations -from playwright.sync_api import Page, expect +from playwright.sync_api import Page from tests.examples.conftest import RunningExample from tests.playwright.conftest import assert_no_unexpected_errors, collect_errors @@ -8,6 +8,16 @@ # some widgets pull large JS bundles on first load. WIDGET_TIMEOUT_MS = 30_000 +# "A widget rendered" = the output binding attached a view. `.lm-Widget` is +# NOT universal: only lumino-based views carry it, so raw-DOM views (pythreejs, +# drawdata, ...) would never match. The output div always exists in the static +# UI; a child element appears only once a view's `el` is attached. ANY output +# counts: one output can legitimately stay empty while a sibling renders +# (e.g. an itables table gated on a remote fetch next to a map that isn't). +VIEW_ATTACHED_JS = """() => + Array.from(document.querySelectorAll('.shiny-ipywidget-output')) + .some((el) => el.childElementCount > 0)""" + def test_example_boots_and_renders(page: Page, running_example: RunningExample) -> None: override = running_example.example.override @@ -15,9 +25,7 @@ def test_example_boots_and_renders(page: Page, running_example: RunningExample) page.goto(running_example.proc.url) if not override.no_widget: - expect(page.locator(".lm-Widget").first).to_be_visible( - timeout=WIDGET_TIMEOUT_MS - ) + page.wait_for_function(VIEW_ATTACHED_JS, timeout=WIDGET_TIMEOUT_MS) assert_no_unexpected_errors( errors, From d7c76b58c77cb4bf7d02081d6dd856cecb0d302a Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 20:46:17 -0600 Subject: [PATCH 10/20] Limit reactable overlay run to reactable-matching examples 03_dark_mode needs reactable AND ipyleaflet, and the overlay breaks ipyleaflet's nbextension lookup, so no environment runs it; -k reactable already covers every example the overlay can serve. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index fb43ddb7..1016dff2 100644 --- a/Makefile +++ b/Makefile @@ -106,7 +106,7 @@ test-examples: ## smoke-test every website example app in a browser # for these -k-filtered overlay runs. test-examples-reactable: ## smoke-test reactable website examples (needs the overlay; see REACTABLE_OVERLAY) uv run playwright install chromium - SHINYWIDGETS_EXAMPLES_INCLUDE_SKIPPED=1 uv run $(REACTABLE_OVERLAY) pytest -c "$(REPO_ROOT)/tests/examples/examples-pytest.ini" --confcutdir "$(REPO_ROOT)/tests/examples" "$(REPO_ROOT)/tests/examples" -k "reactable or 03_dark_mode" $(PYTEST_EXAMPLES_ARGS) + SHINYWIDGETS_EXAMPLES_INCLUDE_SKIPPED=1 uv run $(REACTABLE_OVERLAY) pytest -c "$(REPO_ROOT)/tests/examples/examples-pytest.ini" --confcutdir "$(REPO_ROOT)/tests/examples" "$(REPO_ROOT)/tests/examples" -k reactable $(PYTEST_EXAMPLES_ARGS) test-examples-vizarr: ## smoke-test vizarr website examples (needs the overlay; vizarr pins zarr<3) uv run playwright install chromium From 5dd89fefd5e424d38793cd21f90d82ff7328ce10 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 20:52:33 -0600 Subject: [PATCH 11/20] Address final review: run guardrail in the workflow, validate manifest types - The manifest guardrail previously only ran under py-check.yaml, whose path filters exclude website/** -- a website-only PR could add an unmanifested helper (or stale entry) unnoticed. Run it on shard 0. - load_manifest rejected unknown keys but not wrong value types: a scalar allowed_errors silently became a tuple of characters (trivially permissive), and a quoted no_widget string was truthy. --- .github/workflows/website-examples.yaml | 7 +++++++ tests/examples/discovery.py | 5 +++++ tests/unit/test_examples_manifest.py | 12 ++++++++++++ 3 files changed, 24 insertions(+) diff --git a/.github/workflows/website-examples.yaml b/.github/workflows/website-examples.yaml index 14fc8635..66869e39 100644 --- a/.github/workflows/website-examples.yaml +++ b/.github/workflows/website-examples.yaml @@ -57,6 +57,13 @@ jobs: - name: Install dependencies run: uv sync --python 3.12 --all-groups + # The guardrail is part of the unit suite, which py-check only runs for + # non-website changes -- run it here too so a website-only PR can't add + # an example file without a manifest entry (or a stale entry) unnoticed + - name: Run manifest guardrail + if: matrix.shard == 0 + run: uv run pytest tests/unit/test_examples_manifest.py -q + - name: Run website example smoke tests (shard ${{ matrix.shard }}/6) # Healthy shards should finish in ~5 minutes; kill stragglers quickly timeout-minutes: 10 diff --git a/tests/examples/discovery.py b/tests/examples/discovery.py index e7724f98..72befcac 100644 --- a/tests/examples/discovery.py +++ b/tests/examples/discovery.py @@ -59,6 +59,11 @@ def load_manifest(path: Path = MANIFEST_PATH) -> dict[str, Override]: unknown = set(entry) - _OVERRIDE_KEYS if unknown: raise ValueError(f"{rel}: unknown manifest keys: {sorted(unknown)}") + for key in ("allowed_errors", "allowed_404s"): + if key in entry and not isinstance(entry[key], list): + raise ValueError(f"{rel}: {key} must be a list") + if "no_widget" in entry and not isinstance(entry["no_widget"], bool): + raise ValueError(f"{rel}: no_widget must be a boolean") overrides[rel] = Override( not_app=entry.get("not_app"), skip=entry.get("skip"), diff --git a/tests/unit/test_examples_manifest.py b/tests/unit/test_examples_manifest.py index 199b1cb3..b3d9c1ff 100644 --- a/tests/unit/test_examples_manifest.py +++ b/tests/unit/test_examples_manifest.py @@ -62,3 +62,15 @@ def test_load_manifest_rejects_unknown_keys(tmp_path) -> None: manifest.write_text('"website/widgets/x/examples/a.py":\n bogus: true\n') with pytest.raises(ValueError, match="bogus"): load_manifest(manifest) + + +def test_load_manifest_rejects_wrong_value_types(tmp_path) -> None: + manifest = tmp_path / "manifest.yml" + # A scalar string would silently become a tuple of characters + manifest.write_text('"website/widgets/x/examples/a.py":\n allowed_errors: oops\n') + with pytest.raises(ValueError, match="allowed_errors"): + load_manifest(manifest) + # A quoted "false" is truthy + manifest.write_text('"website/widgets/x/examples/a.py":\n no_widget: "false"\n') + with pytest.raises(ValueError, match="no_widget"): + load_manifest(manifest) From fe42641f20ba249b7a0fb03c701f5d33c201a7ec Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 20:58:59 -0600 Subject: [PATCH 12/20] Deepen smoke assertions from Copilot review - Capture transport-level request failures (requestfailed), which produce no HTTP response and were invisible to collect_errors - Assert no .shiny-output-error elements: a Python render error shows there (not on the console), and a working sibling widget would let it pass. pydeck's intentional deprecation demo opts out via a new allow_output_error manifest key - no_widget examples waited for nothing, so pydeck's static-iframe demo could pass without rendering; a new wait_selector manifest key waits for the iframe itself - Brief settle after readiness so late async errors land before the assertions --- tests/examples/discovery.py | 24 +++++++++++++++++++--- tests/examples/manifest.yml | 4 +++- tests/examples/test_smoke.py | 40 ++++++++++++++++++++++++++++++++++-- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/tests/examples/discovery.py b/tests/examples/discovery.py index 72befcac..caab97dd 100644 --- a/tests/examples/discovery.py +++ b/tests/examples/discovery.py @@ -19,7 +19,15 @@ APP_MARKERS = ("from shiny.express", "App(") -_OVERRIDE_KEYS = {"not_app", "skip", "no_widget", "allowed_errors", "allowed_404s"} +_OVERRIDE_KEYS = { + "not_app", + "skip", + "no_widget", + "allowed_errors", + "allowed_404s", + "wait_selector", + "allow_output_error", +} @dataclass(frozen=True) @@ -31,6 +39,11 @@ class Override: no_widget: bool = False allowed_errors: tuple[str, ...] = () allowed_404s: tuple[str, ...] = () + # wait_selector: wait for this CSS selector instead of a widget view + # (widget-less apps). allow_output_error: the app intentionally renders a + # .shiny-output-error (e.g. the render_pydeck deprecation demo) + wait_selector: str | None = None + allow_output_error: bool = False @dataclass(frozen=True) @@ -62,14 +75,19 @@ def load_manifest(path: Path = MANIFEST_PATH) -> dict[str, Override]: for key in ("allowed_errors", "allowed_404s"): if key in entry and not isinstance(entry[key], list): raise ValueError(f"{rel}: {key} must be a list") - if "no_widget" in entry and not isinstance(entry["no_widget"], bool): - raise ValueError(f"{rel}: no_widget must be a boolean") + for key in ("no_widget", "allow_output_error"): + if key in entry and not isinstance(entry[key], bool): + raise ValueError(f"{rel}: {key} must be a boolean") + if "wait_selector" in entry and not isinstance(entry["wait_selector"], str): + raise ValueError(f"{rel}: wait_selector must be a string") overrides[rel] = Override( not_app=entry.get("not_app"), skip=entry.get("skip"), no_widget=bool(entry.get("no_widget", False)), allowed_errors=tuple(entry.get("allowed_errors", ())), allowed_404s=tuple(entry.get("allowed_404s", ())), + wait_selector=entry.get("wait_selector"), + allow_output_error=bool(entry.get("allow_output_error", False)), ) return overrides diff --git a/tests/examples/manifest.yml b/tests/examples/manifest.yml index 3a4f4150..e12b1c7a 100644 --- a/tests/examples/manifest.yml +++ b/tests/examples/manifest.yml @@ -11,11 +11,13 @@ # --- Apps that intentionally render no widget ------------------------------- "website/widgets/pydeck/examples/05_static_iframe.py": - no_widget: true + # Renders a static iframe, not a widget -- wait for the iframe itself + wait_selector: "iframe" "website/widgets/pydeck/examples/01_deprecation_error.py": # Demonstrates render_pydeck's deprecation TypeError; the output is the # error, not a widget no_widget: true + allow_output_error: true # --- Known-benign third-party console noise ---------------------------------- # drawdata sets svg height="auto", which Chromium logs as a console error diff --git a/tests/examples/test_smoke.py b/tests/examples/test_smoke.py index 7a9aaeae..e1468a08 100644 --- a/tests/examples/test_smoke.py +++ b/tests/examples/test_smoke.py @@ -1,6 +1,6 @@ from __future__ import annotations -from playwright.sync_api import Page +from playwright.sync_api import Page, expect from tests.examples.conftest import RunningExample from tests.playwright.conftest import assert_no_unexpected_errors, collect_errors @@ -22,14 +22,50 @@ def test_example_boots_and_renders(page: Page, running_example: RunningExample) -> None: override = running_example.example.override errors, failed_requests = collect_errors(page) + + # collect_errors only sees HTTP responses; transport-level failures + # (DNS, connection refused) produce none. ERR_ABORTED is excluded: it + # fires for ordinary cancelled requests (e.g. navigated-away prefetches). + transport_failures: list[str] = [] + page.on( + "requestfailed", + lambda req: ( + transport_failures.append(req.url) + if "ERR_ABORTED" not in (req.failure or "") + else None + ), + ) + page.goto(running_example.proc.url) - if not override.no_widget: + if override.wait_selector is not None: + expect(page.locator(override.wait_selector).first).to_be_visible( + timeout=WIDGET_TIMEOUT_MS + ) + elif not override.no_widget: page.wait_for_function(VIEW_ATTACHED_JS, timeout=WIDGET_TIMEOUT_MS) + # Widget init errors and failed requests can land just after the view + # attaches (or, for no_widget apps, after first paint) + page.wait_for_timeout(1000) + + # A Python render error surfaces as a .shiny-output-error div, not a + # console error, and a working sibling widget would let it pass otherwise + if not override.allow_output_error: + expect(page.locator(".shiny-output-error")).to_have_count(0) + assert_no_unexpected_errors( errors, failed_requests, allowed_404s=override.allowed_404s, allowed_errors=override.allowed_errors, ) + + unexpected_transport = [ + url + for url in transport_failures + if not any(allowed in url for allowed in override.allowed_404s) + ] + assert not unexpected_transport, ( + f"transport-level request failures: {unexpected_transport}" + ) From 61057620f09c4a81f46a25c40677bcf6de9637a8 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 21:04:42 -0600 Subject: [PATCH 13/20] Allow CI-environment console noise the deep suite already tolerates The settle added in fe42641 surfaces errors that land just after view attach; three known classes appear only in CI's headless Linux Chromium: embedding-atlas's WebGPU warnings (filtered identically by the deep suite), lonboard's benign luma.gl re-init message, and anywidget <0.11.1's init failure under CPU contention (the deep suite xfails the same class). --- tests/examples/manifest.yml | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/examples/manifest.yml b/tests/examples/manifest.yml index e12b1c7a..f5730aae 100644 --- a/tests/examples/manifest.yml +++ b/tests/examples/manifest.yml @@ -198,3 +198,46 @@ # import, so the app can't boot at all. "website/widgets/niivue/examples/09_atlas_label.py": skip: fetches aal.json from niivue.com/demos/images at import; that host 404s upstream + +# --- CI-environment console noise -------------------------------------------- +# Chromium's headless Linux build (CI) has no WebGPU, so embedding-atlas's +# embedding view logs these on every load (the deep Playwright suite filters +# the same substring -- see tests/playwright/embedding_atlas_accessors). +"website/guide/performance/examples/16_bigdata_embedding_atlas.py": + allowed_errors: ["WebGPU"] +"website/widgets/embedding-atlas/examples/01_quickstart.py": + allowed_errors: ["WebGPU"] +"website/widgets/embedding-atlas/examples/02_compute_projection.py": + allowed_errors: ["WebGPU"] +"website/widgets/embedding-atlas/examples/03_auto_labels.py": + allowed_errors: ["WebGPU"] +"website/widgets/embedding-atlas/examples/04_images.py": + allowed_errors: ["WebGPU"] +"website/widgets/embedding-atlas/examples/05_predicate_query.py": + allowed_errors: ["WebGPU"] +"website/widgets/embedding-atlas/examples/06_selection_table.py": + allowed_errors: ["WebGPU"] +"website/widgets/embedding-atlas/examples/07_update_in_place.py": + allowed_errors: ["WebGPU"] +"website/widgets/embedding-atlas/examples/08_predicate_to_plotly.py": + allowed_errors: ["WebGPU"] +"website/widgets/embedding-atlas/examples/09_selection_to_cards.py": + allowed_errors: ["WebGPU"] +"website/widgets/embedding-atlas/examples/10_selection_summary_stub.py": + allowed_errors: ["WebGPU"] +"website/widgets/embedding-atlas/examples/11_layout.py": + allowed_errors: ["WebGPU"] +"website/widgets/embedding-atlas/examples/12_export_selection.py": + allowed_errors: ["WebGPU"] + +# lonboard's luma.gl runtime logs this known-benign message intermittently +# under CI CPU contention (same message as KEPLERGL_ALLOWED_ERRORS in +# tests/playwright/conftest.py) +"website/guide/performance/examples/10_ratelimit_lonboard.py": + allowed_errors: ["luma.gl: This version of luma.gl has already been initialized"] + +# lonboard's multi-MB anywidget _esm can fail to initialize under CI CPU +# contention with anywidget <0.11.1 (manzt/anywidget#1032; the deep suite +# xfails the same class of failure via ANYWIDGET_INIT_XFAIL) +"website/guide/linked-views/examples/12_lonboard_plotly_bidirectional.py": + allowed_errors: ["[anywidget] Failed to initialize model"] From 71ebb03b639a1e4cc697ffb7085e0fba375c75f2 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 21:13:27 -0600 Subject: [PATCH 14/20] Skip niivue examples (dead upstream data host), tolerate telemetry noise - niivue.com/demos/images 404s for every file since niivue moved to the mono repo; some assets exist on the replacement GitHub Pages host but aal/BrainMesh/narps don't, so the niivue page needs a data-host migration beyond this PR. Skip all 9 affected examples. - aladin-lite's usage-logger endpoint and pygwalker's CORS-blocked update check are third-party phone-home noise on every init. - maplibre joins lonboard in tolerating the benign luma.gl re-init message under CI contention. --- tests/examples/manifest.yml | 95 ++++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 6 deletions(-) diff --git a/tests/examples/manifest.yml b/tests/examples/manifest.yml index f5730aae..cbce5dc5 100644 --- a/tests/examples/manifest.yml +++ b/tests/examples/manifest.yml @@ -191,13 +191,96 @@ "website/guide/linked-views/examples/20_mosaic_brush_in_widget.py": skip: needs gaia-5m.parquet, which is deliberately not committed (see data/README.md) -# The entire niivue.com/demos/images host 404s upstream (every niivue example -# uses it; the others only fetch client-side, so the widget still attaches, -# but their canvases likely render empty -- a page-level content fix is -# needed, tracked separately). This one fetches aal.json server-side at -# import, so the app can't boot at all. +# --- niivue: upstream demo-data host is dead ---------------------------------- +# Every niivue example loads its volumes from niivue.com/demos/images, which +# 404s for every file (mni152.nii.gz, pcasl.nii.gz, aal.*, BrainMesh.*, +# narps-*) since niivue moved to the mono repo. Some files exist on the +# replacement host (niivue.github.io/niivue-demo-images, e.g. mni152.nii.gz) +# but aal/BrainMesh/narps don't, so the page needs a data-host migration +# beyond this PR. 09 additionally fetches aal.json server-side at import, so +# it can't boot at all. +"website/widgets/niivue/examples/01_quickstart.py": + skip: loads volumes from niivue.com/demos/images, which 404s for every file upstream +"website/widgets/niivue/examples/02_slice_types.py": + skip: loads volumes from niivue.com/demos/images, which 404s for every file upstream +"website/widgets/niivue/examples/03_stat_overlay.py": + skip: loads volumes from niivue.com/demos/images, which 404s for every file upstream +"website/widgets/niivue/examples/04_mesh.py": + skip: loads meshes from niivue.com/demos/images, which 404s for every file upstream +"website/widgets/niivue/examples/06_frame4d.py": + skip: loads volumes from niivue.com/demos/images, which 404s for every file upstream +"website/widgets/niivue/examples/07_location_accessor.py": + skip: loads volumes from niivue.com/demos/images, which 404s for every file upstream +"website/widgets/niivue/examples/08_rate_limiting.py": + skip: loads volumes from niivue.com/demos/images, which 404s for every file upstream "website/widgets/niivue/examples/09_atlas_label.py": - skip: fetches aal.json from niivue.com/demos/images at import; that host 404s upstream + skip: fetches aal.json server-side at import from niivue.com/demos/images, which 404s upstream +"website/widgets/niivue/examples/12_save_location.py": + skip: loads volumes from niivue.com/demos/images, which 404s for every file upstream + +# --- More third-party phone-home/telemetry noise ------------------------------ +# aladin-lite pings a usage logger on every init; the endpoint is flaky (the +# deep suite skips the related HiPS outage class entirely -- +# aladin_hips_outage_as_skip in tests/playwright/conftest.py) + +# pygwalker phones home for an update check on load; the endpoint doesn't +# allow CORS from our origin, logging console errors and failing the request + +"website/widgets/ipyaladin/examples/01_quickstart.py": + allowed_404s: ["AladinLiteLogger"] +"website/widgets/ipyaladin/examples/02_navigate_from_input.py": + allowed_404s: ["AladinLiteLogger"] +"website/widgets/ipyaladin/examples/03_survey_colormap_switch.py": + allowed_404s: ["AladinLiteLogger"] +"website/widgets/ipyaladin/examples/04_catalog_overlay.py": + allowed_404s: ["AladinLiteLogger"] +"website/widgets/ipyaladin/examples/05_footprints_moc.py": + allowed_404s: ["AladinLiteLogger"] +"website/widgets/ipyaladin/examples/06_clicked_object.py": + allowed_404s: ["AladinLiteLogger"] +"website/widgets/ipyaladin/examples/07_selected.py": + allowed_404s: ["AladinLiteLogger"] +"website/widgets/ipyaladin/examples/08_whats_in_view.py": + allowed_404s: ["AladinLiteLogger"] +"website/widgets/ipyaladin/examples/09_rate_limiting.py": + allowed_404s: ["AladinLiteLogger"] +"website/widgets/ipyaladin/examples/10_update_in_place_vs_rerender.py": + allowed_404s: ["AladinLiteLogger"] +"website/widgets/ipyaladin/examples/11_jscatter_stars_on_sky.py": + allowed_404s: ["AladinLiteLogger"] +"website/widgets/ipyaladin/examples/12_layout.py": + allowed_404s: ["AladinLiteLogger"] +"website/widgets/ipyaladin/examples/13_save_view.py": + allowed_404s: ["AladinLiteLogger"] +"website/widgets/pygwalker/examples/01_quickstart.py": + allowed_errors: ["check_updates", "Failed to fetch"] + allowed_404s: ["check_updates"] +"website/widgets/pygwalker/examples/02_build_a_chart.py": + allowed_errors: ["check_updates", "Failed to fetch"] + allowed_404s: ["check_updates"] +"website/widgets/pygwalker/examples/03_save_and_export.py": + allowed_errors: ["check_updates", "Failed to fetch"] + allowed_404s: ["check_updates"] +"website/widgets/pygwalker/examples/04_scale.py": + allowed_errors: ["check_updates", "Failed to fetch"] + allowed_404s: ["check_updates"] +"website/widgets/pygwalker/examples/05_filter_and_persist_spec.py": + allowed_errors: ["check_updates", "Failed to fetch"] + allowed_404s: ["check_updates"] +"website/widgets/pygwalker/examples/06_linked_export_to_plotly.py": + allowed_errors: ["check_updates", "Failed to fetch"] + allowed_404s: ["check_updates"] +"website/widgets/pygwalker/examples/07_layout_sizing.py": + allowed_errors: ["check_updates", "Failed to fetch"] + allowed_404s: ["check_updates"] + +# maplibre's luma.gl runtime logs this known-benign message intermittently +# under CI CPU contention (see KEPLERGL_ALLOWED_ERRORS in +# tests/playwright/conftest.py) +"website/widgets/maplibre/examples/11_rate_limiting.py": + allowed_errors: ["luma.gl: This version of luma.gl has already been initialized"] +"website/widgets/maplibre/examples/17_layout_sizing.py": + allowed_errors: ["luma.gl: This version of luma.gl has already been initialized"] # --- CI-environment console noise -------------------------------------------- # Chromium's headless Linux build (CI) has no WebGPU, so embedding-atlas's From 0fb1301a2aecd0436b4dc71742939f23b5833c92 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 21:14:06 -0600 Subject: [PATCH 15/20] Tolerate pygwalker's generic net::ERR_FAILED console message too --- tests/examples/manifest.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/examples/manifest.yml b/tests/examples/manifest.yml index cbce5dc5..4e476a5a 100644 --- a/tests/examples/manifest.yml +++ b/tests/examples/manifest.yml @@ -253,25 +253,25 @@ "website/widgets/ipyaladin/examples/13_save_view.py": allowed_404s: ["AladinLiteLogger"] "website/widgets/pygwalker/examples/01_quickstart.py": - allowed_errors: ["check_updates", "Failed to fetch"] + allowed_errors: ["check_updates", "Failed to fetch", "net::ERR_FAILED"] allowed_404s: ["check_updates"] "website/widgets/pygwalker/examples/02_build_a_chart.py": - allowed_errors: ["check_updates", "Failed to fetch"] + allowed_errors: ["check_updates", "Failed to fetch", "net::ERR_FAILED"] allowed_404s: ["check_updates"] "website/widgets/pygwalker/examples/03_save_and_export.py": - allowed_errors: ["check_updates", "Failed to fetch"] + allowed_errors: ["check_updates", "Failed to fetch", "net::ERR_FAILED"] allowed_404s: ["check_updates"] "website/widgets/pygwalker/examples/04_scale.py": - allowed_errors: ["check_updates", "Failed to fetch"] + allowed_errors: ["check_updates", "Failed to fetch", "net::ERR_FAILED"] allowed_404s: ["check_updates"] "website/widgets/pygwalker/examples/05_filter_and_persist_spec.py": - allowed_errors: ["check_updates", "Failed to fetch"] + allowed_errors: ["check_updates", "Failed to fetch", "net::ERR_FAILED"] allowed_404s: ["check_updates"] "website/widgets/pygwalker/examples/06_linked_export_to_plotly.py": - allowed_errors: ["check_updates", "Failed to fetch"] + allowed_errors: ["check_updates", "Failed to fetch", "net::ERR_FAILED"] allowed_404s: ["check_updates"] "website/widgets/pygwalker/examples/07_layout_sizing.py": - allowed_errors: ["check_updates", "Failed to fetch"] + allowed_errors: ["check_updates", "Failed to fetch", "net::ERR_FAILED"] allowed_404s: ["check_updates"] # maplibre's luma.gl runtime logs this known-benign message intermittently From ac97758de09384d87f3ee1f3d35d7deacafc96c1 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 21:24:47 -0600 Subject: [PATCH 16/20] Skip vizarr/01 (dead IDR sample dataset), tolerate lonboard/11 anywidget contention --- tests/examples/manifest.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/examples/manifest.yml b/tests/examples/manifest.yml index 4e476a5a..2e2f365c 100644 --- a/tests/examples/manifest.yml +++ b/tests/examples/manifest.yml @@ -91,7 +91,10 @@ # vizarr pins zarr<3, so it stays out of the shared test group. Covered by # `make test-examples-vizarr` (CI runs it on shard 0). "website/widgets/vizarr/examples/01_quickstart.py": - skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` + # vizarr itself needs the overlay, AND this example's sample dataset + # (minio-dev.openmicroscopy.org .../6001240.zarr) 404s upstream -- it needs + # a new data source, not just a smoke-test allowance + skip: overlay-only AND its IDR sample zarr 404s upstream (needs a new dataset) "website/widgets/vizarr/examples/02_numpy_array.py": skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` "website/widgets/vizarr/examples/03_multichannel_contrast.py": @@ -324,3 +327,5 @@ # xfails the same class of failure via ANYWIDGET_INIT_XFAIL) "website/guide/linked-views/examples/12_lonboard_plotly_bidirectional.py": allowed_errors: ["[anywidget] Failed to initialize model"] +"website/widgets/lonboard/examples/11_viewport_to_chart.py": + allowed_errors: ["[anywidget] Failed to initialize model"] From ae116e79d9755fd56fe73d734a473e7dc65e7d95 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 21:41:05 -0600 Subject: [PATCH 17/20] Distinguish overlay skips from permanent skips; xfail anywidget contention Addresses the second Copilot round: - The un-skip env var lifted every manifest skip, so the vizarr overlay re-enabled 01_quickstart, whose IDR dataset is dead upstream. Skips now come in two kinds: an overlay: entry (lifted only by the matching SHINYWIDGETS_EXAMPLES_OVERLAY run) and a plain skip entry (never lifted). vizarr/01 stays skipped in every run; the vizarr overlay run shows 7 passed, 1 skipped. - Whitelisting lonboards anywidget init error would permanently mask real init failures. Mirror the deep suite instead: a version- conditioned, non-strict xfail on lonboard/keplergl examples while anywidget <0.11.1 (manzt/anywidget#1032), lifting itself at 0.11.1. --- Makefile | 8 +-- tests/examples/conftest.py | 35 ++++++++++--- tests/examples/discovery.py | 8 +++ tests/examples/manifest.yml | 76 +++++++++++++--------------- tests/unit/test_examples_manifest.py | 8 ++- 5 files changed, 80 insertions(+), 55 deletions(-) diff --git a/Makefile b/Makefile index 1016dff2..ec6b1822 100644 --- a/Makefile +++ b/Makefile @@ -102,15 +102,15 @@ test-examples: ## smoke-test every website example app in a browser $(PYTEST_EXAMPLES) $(PYTEST_EXAMPLES_ARGS) # Examples that need a dependency overlay are skipped in the shared run (see -# tests/examples/manifest.yml); the INCLUDE_SKIPPED env var lifts those skips -# for these -k-filtered overlay runs. +# tests/examples/manifest.yml); SHINYWIDGETS_EXAMPLES_OVERLAY lifts the skip +# for entries whose `overlay:` names that overlay. test-examples-reactable: ## smoke-test reactable website examples (needs the overlay; see REACTABLE_OVERLAY) uv run playwright install chromium - SHINYWIDGETS_EXAMPLES_INCLUDE_SKIPPED=1 uv run $(REACTABLE_OVERLAY) pytest -c "$(REPO_ROOT)/tests/examples/examples-pytest.ini" --confcutdir "$(REPO_ROOT)/tests/examples" "$(REPO_ROOT)/tests/examples" -k reactable $(PYTEST_EXAMPLES_ARGS) + SHINYWIDGETS_EXAMPLES_OVERLAY=reactable uv run $(REACTABLE_OVERLAY) pytest -c "$(REPO_ROOT)/tests/examples/examples-pytest.ini" --confcutdir "$(REPO_ROOT)/tests/examples" "$(REPO_ROOT)/tests/examples" -k reactable $(PYTEST_EXAMPLES_ARGS) test-examples-vizarr: ## smoke-test vizarr website examples (needs the overlay; vizarr pins zarr<3) uv run playwright install chromium - SHINYWIDGETS_EXAMPLES_INCLUDE_SKIPPED=1 uv run --with vizarr pytest -c "$(REPO_ROOT)/tests/examples/examples-pytest.ini" --confcutdir "$(REPO_ROOT)/tests/examples" "$(REPO_ROOT)/tests/examples" -k vizarr $(PYTEST_EXAMPLES_ARGS) + SHINYWIDGETS_EXAMPLES_OVERLAY=vizarr uv run --with vizarr pytest -c "$(REPO_ROOT)/tests/examples/examples-pytest.ini" --confcutdir "$(REPO_ROOT)/tests/examples" "$(REPO_ROOT)/tests/examples" -k vizarr $(PYTEST_EXAMPLES_ARGS) test-reactable: ## run reactable unit tests (needs the overlay; see REACTABLE_OVERLAY) $(PYTEST_REACTABLE) diff --git a/tests/examples/conftest.py b/tests/examples/conftest.py index 9195d7c2..efdf7067 100644 --- a/tests/examples/conftest.py +++ b/tests/examples/conftest.py @@ -1,9 +1,11 @@ from __future__ import annotations +import importlib.metadata import os from dataclasses import dataclass import pytest +from packaging.version import Version from shiny.run import ShinyAppProc # Same private helper shiny's own pytest plugin (create_app_fixture) uses; it @@ -18,19 +20,36 @@ class RunningExample: example: Example -# Overlay runs (make test-examples-reactable/-leafmap/-vizarr) set this so -# their examples' manifest skips don't apply; the shared run honors them. -_INCLUDE_SKIPPED = os.environ.get("SHINYWIDGETS_EXAMPLES_INCLUDE_SKIPPED") == "1" +# Examples whose package can't join the shared test group carry +# `overlay: ` in the manifest and are skipped unless the matching +# overlay run names it here (see the test-examples-* Makefile targets). +_OVERLAY_ENV = "SHINYWIDGETS_EXAMPLES_OVERLAY" + +# anywidget <0.11.1 rejects a model's init after a hard-coded 2s and then +# drops all subsequent state updates (manzt/anywidget#1030, fixed by +# manzt/anywidget#1032). lonboard's and keplergl's multi-MB inline _esm trip +# that budget under CI-grade CPU contention, intermittently failing widget +# init. Mirrors ANYWIDGET_INIT_XFAIL in tests/playwright/conftest.py: +# non-strict, and lifts itself once anywidget 0.11.1+ is installed. +_BIG_ESM_PACKAGES = ("lonboard", "keplergl") +_ANYWIDGET_INIT_XFAIL = pytest.mark.xfail( + Version(importlib.metadata.version("anywidget")) < Version("0.11.1"), + reason="anywidget <0.11.1 can fail widget init under CPU contention (manzt/anywidget#1032)", + strict=False, +) def _params() -> list: params = [] for example in discover_examples(): - marks = ( - [pytest.mark.skip(reason=example.override.skip)] - if example.override.skip and not _INCLUDE_SKIPPED - else [] - ) + override = example.override + skip_reason = override.skip + if skip_reason is None and override.overlay is not None: + if override.overlay != os.environ.get(_OVERLAY_ENV): + skip_reason = f"needs the {override.overlay} dependency overlay" + marks = [pytest.mark.skip(reason=skip_reason)] if skip_reason else [] + if any(pkg in example.rel for pkg in _BIG_ESM_PACKAGES): + marks.append(_ANYWIDGET_INIT_XFAIL) params.append(pytest.param(example, id=example.rel, marks=marks)) return params diff --git a/tests/examples/discovery.py b/tests/examples/discovery.py index caab97dd..33c0b1d8 100644 --- a/tests/examples/discovery.py +++ b/tests/examples/discovery.py @@ -27,6 +27,7 @@ "allowed_404s", "wait_selector", "allow_output_error", + "overlay", } @@ -44,6 +45,10 @@ class Override: # .shiny-output-error (e.g. the render_pydeck deprecation demo) wait_selector: str | None = None allow_output_error: bool = False + # overlay: name of the dependency overlay this example needs (e.g. + # "reactable"); skipped in the shared run, run by the matching + # SHINYWIDGETS_EXAMPLES_OVERLAY overlay run + overlay: str | None = None @dataclass(frozen=True) @@ -80,6 +85,8 @@ def load_manifest(path: Path = MANIFEST_PATH) -> dict[str, Override]: raise ValueError(f"{rel}: {key} must be a boolean") if "wait_selector" in entry and not isinstance(entry["wait_selector"], str): raise ValueError(f"{rel}: wait_selector must be a string") + if "overlay" in entry and not isinstance(entry["overlay"], str): + raise ValueError(f"{rel}: overlay must be a string") overrides[rel] = Override( not_app=entry.get("not_app"), skip=entry.get("skip"), @@ -88,6 +95,7 @@ def load_manifest(path: Path = MANIFEST_PATH) -> dict[str, Override]: allowed_404s=tuple(entry.get("allowed_404s", ())), wait_selector=entry.get("wait_selector"), allow_output_error=bool(entry.get("allow_output_error", False)), + overlay=entry.get("overlay"), ) return overrides diff --git a/tests/examples/manifest.yml b/tests/examples/manifest.yml index 2e2f365c..fc90e5e0 100644 --- a/tests/examples/manifest.yml +++ b/tests/examples/manifest.yml @@ -39,76 +39,76 @@ allowed_404s: ["anywidget-0.0"] # --- Examples that need a dependency overlay (skipped in the shared run) ----- -# reactable pins ipyreact<=0.4.1, which conflicts with the test group's -# ipyreact>=0.6 (see REACTABLE_OVERLAY in the Makefile). Covered by -# `make test-examples-reactable` (CI runs it on shard 0). +# `overlay: ` skips the example unless SHINYWIDGETS_EXAMPLES_OVERLAY +# names that overlay (see the test-examples-* Makefile targets; CI runs them +# on shard 0). reactable pins ipyreact<=0.4.1, conflicting with the test +# group's ipyreact>=0.6 (see REACTABLE_OVERLAY in the Makefile). "website/guide/layout-and-theming/examples/03_dark_mode.py": # Needs reactable (only runs under the dependency overlay), but also # ipyleaflet, whose nbextension lookup the overlay breaks -- no environment # runs both skip: imports both reactable (needs the overlay) and ipyleaflet (breaks under the overlay) "website/widgets/altair/examples/13_brush_to_reactable_table.py": - skip: imports reactable, which needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable "website/widgets/reactable/examples/01_quickstart.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable "website/widgets/reactable/examples/02_formatting_styling.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable "website/widgets/reactable/examples/03_grouping.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable # react-table logs this about the aggregate column config on load; the # table still renders allowed_errors: ["Invalid column.aggregate option"] "website/widgets/reactable/examples/04_expandable_details.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable "website/widgets/reactable/examples/05_custom_cells.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable "website/widgets/reactable/examples/06_theming.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable "website/widgets/reactable/examples/07_column_groups_footers.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable "website/widgets/reactable/examples/08_selected_rows.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable "website/widgets/reactable/examples/09_page_sorted.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable "website/widgets/reactable/examples/10_filter_search.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable "website/widgets/reactable/examples/11_rate_limiting.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable "website/widgets/reactable/examples/12_inplace_props.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable "website/widgets/reactable/examples/13_update_data.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable "website/widgets/reactable/examples/14_selection_to_detail.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable "website/widgets/reactable/examples/15_search_to_chart.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable "website/widgets/reactable/examples/16_row_click.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable "website/widgets/reactable/examples/17_export_selected.py": - skip: reactable needs the dependency overlay (see REACTABLE_OVERLAY); covered by `make test-examples-reactable` + overlay: reactable -# vizarr pins zarr<3, so it stays out of the shared test group. Covered by -# `make test-examples-vizarr` (CI runs it on shard 0). +# vizarr pins zarr<3, so it stays out of the shared test group. "website/widgets/vizarr/examples/01_quickstart.py": - # vizarr itself needs the overlay, AND this example's sample dataset - # (minio-dev.openmicroscopy.org .../6001240.zarr) 404s upstream -- it needs - # a new data source, not just a smoke-test allowance - skip: overlay-only AND its IDR sample zarr 404s upstream (needs a new dataset) + # The sample dataset (minio-dev.openmicroscopy.org .../6001240.zarr) 404s + # upstream -- the example needs a new data source, not just a smoke-test + # allowance. Not overlay-lifted: it stays skipped in every run. + skip: its IDR sample zarr 404s upstream (needs a new dataset) "website/widgets/vizarr/examples/02_numpy_array.py": - skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` + overlay: vizarr "website/widgets/vizarr/examples/03_multichannel_contrast.py": - skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` + overlay: vizarr "website/widgets/vizarr/examples/04_camera_view_state.py": - skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` + overlay: vizarr "website/widgets/vizarr/examples/05_add_layer_in_place.py": - skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` + overlay: vizarr "website/widgets/vizarr/examples/06_channel_toggle_rerender.py": - skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` + overlay: vizarr "website/widgets/vizarr/examples/07_linked_minimap.py": - skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` + overlay: vizarr "website/widgets/vizarr/examples/08_linked_histogram.py": - skip: vizarr pins zarr<3, so it stays out of the shared test group; covered by `make test-examples-vizarr` + overlay: vizarr # --- Examples that can't run in CI ------------------------------------------- # vitessce's widget page is a draft until render_vitessce ships (see the repo @@ -321,11 +321,3 @@ # tests/playwright/conftest.py) "website/guide/performance/examples/10_ratelimit_lonboard.py": allowed_errors: ["luma.gl: This version of luma.gl has already been initialized"] - -# lonboard's multi-MB anywidget _esm can fail to initialize under CI CPU -# contention with anywidget <0.11.1 (manzt/anywidget#1032; the deep suite -# xfails the same class of failure via ANYWIDGET_INIT_XFAIL) -"website/guide/linked-views/examples/12_lonboard_plotly_bidirectional.py": - allowed_errors: ["[anywidget] Failed to initialize model"] -"website/widgets/lonboard/examples/11_viewport_to_chart.py": - allowed_errors: ["[anywidget] Failed to initialize model"] diff --git a/tests/unit/test_examples_manifest.py b/tests/unit/test_examples_manifest.py index b3d9c1ff..ff8508b4 100644 --- a/tests/unit/test_examples_manifest.py +++ b/tests/unit/test_examples_manifest.py @@ -23,7 +23,13 @@ def test_every_example_file_is_app_or_manifested() -> None: if ( not app and ov is not None - and (ov.skip or ov.no_widget or ov.allowed_errors or ov.allowed_404s) + and ( + ov.skip + or ov.no_widget + or ov.allowed_errors + or ov.allowed_404s + or ov.overlay + ) ): problems.append(f"{rel}: app-only override keys on a not_app file") assert not problems, "\n".join(problems) From fa33d2bacb1a7c6acb5b471b83a37176a24981b6 Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 22:01:25 -0600 Subject: [PATCH 18/20] Recurse example globs; bound the workflow job - The single-level globs silently missed nested examples: the recursive glob finds 2 more apps (guide/performance/examples/lifetimes/08,09, both pass) and 1 more helper (manifested as not_app). Future nested examples can no longer escape the guardrail. - Add a job-level timeout-minutes alongside the step-level ones. --- .github/workflows/website-examples.yaml | 3 +++ tests/examples/discovery.py | 5 ++++- tests/examples/manifest.yml | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/website-examples.yaml b/.github/workflows/website-examples.yaml index 66869e39..d4139769 100644 --- a/.github/workflows/website-examples.yaml +++ b/.github/workflows/website-examples.yaml @@ -34,6 +34,9 @@ env: jobs: py-examples: runs-on: ubuntu-latest + # Shard steps are individually bounded (10 min each); bound the whole + # job too so a stuck install can't hold a runner + timeout-minutes: 25 strategy: fail-fast: false matrix: diff --git a/tests/examples/discovery.py b/tests/examples/discovery.py index 33c0b1d8..96900fb2 100644 --- a/tests/examples/discovery.py +++ b/tests/examples/discovery.py @@ -14,7 +14,10 @@ import yaml REPO_ROOT = Path(__file__).resolve().parents[2] -EXAMPLE_GLOBS = ("website/widgets/*/examples/*.py", "website/guide/*/examples/*.py") +EXAMPLE_GLOBS = ( + "website/widgets/*/examples/**/*.py", + "website/guide/*/examples/**/*.py", +) MANIFEST_PATH = Path(__file__).parent / "manifest.yml" APP_MARKERS = ("from shiny.express", "App(") diff --git a/tests/examples/manifest.yml b/tests/examples/manifest.yml index fc90e5e0..b7f4bea1 100644 --- a/tests/examples/manifest.yml +++ b/tests/examples/manifest.yml @@ -8,6 +8,8 @@ not_app: anywidget definition module imported by sibling examples "website/guide/updating-in-place/examples/globals.py": not_app: shared-lifetime setup module imported by sibling examples +"website/guide/performance/examples/lifetimes/globals.py": + not_app: shared-lifetime setup module imported by sibling examples # --- Apps that intentionally render no widget ------------------------------- "website/widgets/pydeck/examples/05_static_iframe.py": From 7266527001ebbd8d8ba1d5d05664a0c03c91a9db Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 23:39:05 -0600 Subject: [PATCH 19/20] Re-request Copilot review From f4c65adaf06336f2af70c25d33385768c46d956c Mon Sep 17 00:00:00 2001 From: Carson Date: Fri, 4 Dec 2026 23:44:57 -0600 Subject: [PATCH 20/20] Detect big-_esm examples from source, not just paths --- tests/examples/conftest.py | 5 ++--- tests/examples/discovery.py | 21 +++++++++++++++++++++ tests/unit/test_examples_manifest.py | 20 ++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/tests/examples/conftest.py b/tests/examples/conftest.py index efdf7067..8c6f7f00 100644 --- a/tests/examples/conftest.py +++ b/tests/examples/conftest.py @@ -11,7 +11,7 @@ # Same private helper shiny's own pytest plugin (create_app_fixture) uses; it # handles port search, readiness waiting, and subprocess teardown. from shiny.run._run import shiny_app_gen -from tests.examples.discovery import Example, discover_examples +from tests.examples.discovery import Example, discover_examples, uses_big_esm_package @dataclass(frozen=True) @@ -31,7 +31,6 @@ class RunningExample: # that budget under CI-grade CPU contention, intermittently failing widget # init. Mirrors ANYWIDGET_INIT_XFAIL in tests/playwright/conftest.py: # non-strict, and lifts itself once anywidget 0.11.1+ is installed. -_BIG_ESM_PACKAGES = ("lonboard", "keplergl") _ANYWIDGET_INIT_XFAIL = pytest.mark.xfail( Version(importlib.metadata.version("anywidget")) < Version("0.11.1"), reason="anywidget <0.11.1 can fail widget init under CPU contention (manzt/anywidget#1032)", @@ -48,7 +47,7 @@ def _params() -> list: if override.overlay != os.environ.get(_OVERLAY_ENV): skip_reason = f"needs the {override.overlay} dependency overlay" marks = [pytest.mark.skip(reason=skip_reason)] if skip_reason else [] - if any(pkg in example.rel for pkg in _BIG_ESM_PACKAGES): + if uses_big_esm_package(example): marks.append(_ANYWIDGET_INIT_XFAIL) params.append(pytest.param(example, id=example.rel, marks=marks)) return params diff --git a/tests/examples/discovery.py b/tests/examples/discovery.py index 96900fb2..2bca4502 100644 --- a/tests/examples/discovery.py +++ b/tests/examples/discovery.py @@ -8,6 +8,7 @@ from __future__ import annotations +import re from dataclasses import dataclass from pathlib import Path @@ -22,6 +23,26 @@ APP_MARKERS = ("from shiny.express", "App(") +# Widget packages whose multi-MB inline _esm can trip anywidget's init +# budget; tests/examples applies a version-conditioned xfail to examples +# rendering them (see _ANYWIDGET_INIT_XFAIL there). +BIG_ESM_PACKAGES = ("lonboard", "keplergl") + +_PACKAGES_RE = "|".join(BIG_ESM_PACKAGES) +_BIG_ESM_USAGE_RE = re.compile( + rf"(?:from|import)\s+(?:{_PACKAGES_RE})\b|\brender_(?:{_PACKAGES_RE})\b" +) + + +def uses_big_esm_package(example: Example) -> bool: + # Path alone misses examples that render these packages without naming + # them (e.g. lifetimes/08_*.py renders lonboard), so scan the source + # for imports/renderer usage too. + if any(pkg in example.rel for pkg in BIG_ESM_PACKAGES): + return True + return bool(_BIG_ESM_USAGE_RE.search(example.path.read_text(encoding="utf-8"))) + + _OVERRIDE_KEYS = { "not_app", "skip", diff --git a/tests/unit/test_examples_manifest.py b/tests/unit/test_examples_manifest.py index ff8508b4..c844e680 100644 --- a/tests/unit/test_examples_manifest.py +++ b/tests/unit/test_examples_manifest.py @@ -3,10 +3,13 @@ import pytest from tests.examples.discovery import ( + BIG_ESM_PACKAGES, REPO_ROOT, + discover_examples, example_files, is_app_source, load_manifest, + uses_big_esm_package, ) @@ -51,6 +54,23 @@ def test_manifest_reasons_are_nonempty() -> None: assert not bad, f"manifest entries with empty reasons: {bad}" +def test_uses_big_esm_package_detection() -> None: + # lonboard-rendering examples the path check alone would miss must still + # be detected (they need the anywidget-init xfail in tests/examples). + detected = { + ex.rel + for ex in discover_examples() + if uses_big_esm_package(ex) + and not any(pkg in ex.rel for pkg in BIG_ESM_PACKAGES) + } + assert detected == { + "website/guide/choosing-a-widget/examples/03_maps_location_vs_feature_pick.py", + "website/widgets/mosaic/examples/11_linked_map.py", + "website/guide/performance/examples/lifetimes/08_lifetimes_memory_persession.py", + "website/guide/performance/examples/lifetimes/09_lifetimes_memory_shared.py", + } + + def test_is_app_source(tmp_path) -> None: express = tmp_path / "express.py" express.write_text("from shiny.express import ui\n")