Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /als-apg_osprey /tests /interfaces /test_load_smokes.py
| """Per-interface "loads clean in a real browser" smoke suite. | |
| Boots each OSPREY interface ``create_app()`` factory on a real uvicorn server | |
| (see ``_run_app_server`` in ``conftest.py``) and drives a real Chromium page | |
| against ``GET /``, asserting via :func:`assert_page_loads_clean` that the page | |
| loaded without an uncaught JS exception or a failed same-origin | |
| script/stylesheet fetch. This is the negative-space complement to | |
| ``test_app_setup_parametrized.py`` (which only inspects the assembled FastAPI | |
| app object, never a live page): here the browser is the oracle. | |
| Two targets additionally assert their DOM actually rendered, since a page can | |
| load "clean" by the above signals while its JS silently no-ops before building | |
| any UI: Web Terminal checks the hub shell's artifacts tab button, and the | |
| graph-mode Channel Finder checks that the explore view's class tree drew nodes. | |
| Run: | |
| uv run pytest tests/interfaces/test_load_smokes.py -v | |
| Skips cleanly when the chromium headless binary is not installed. | |
| """ | |
| from __future__ import annotations | |
| import re | |
| from contextlib import contextmanager | |
| from pathlib import Path | |
| from typing import TYPE_CHECKING | |
| from unittest.mock import patch | |
| import pytest | |
| from tests.interfaces._browser import assert_page_loads_clean | |
| from tests.interfaces._panel_launch import publish_artifact_url | |
| from tests.interfaces.conftest import _run_app_server, launch_graph_channel_finder | |
| if TYPE_CHECKING: | |
| from collections.abc import Iterator | |
| from playwright.sync_api import Browser | |
| try: | |
| from playwright.sync_api import expect | |
| _PLAYWRIGHT_AVAILABLE = True | |
| except ImportError: # pragma: no cover | |
| _PLAYWRIGHT_AVAILABLE = False | |
| pytestmark = [pytest.mark.browser, pytest.mark.slow] | |
| # --------------------------------------------------------------------------- | |
| # Per-interface launchers | |
| # --------------------------------------------------------------------------- | |
| # Each is a @contextmanager yielding a live base_url, isolating cwd to | |
| # tmp_path first (matters for ariel's config lookup and artifacts' index | |
| # dir) and building the app with the same signature the interface's own | |
| # tests use (see test_app_setup_parametrized.py). | |
| def _launch_web_terminal(tmp_path, monkeypatch) -> Iterator[str]: | |
| monkeypatch.chdir(tmp_path) | |
| # Patch trio bypasses companion-backend spawn; must stay active while the | |
| # lifespan runs (i.e. across both create_app() and _run_app_server). | |
| with ( | |
| patch( | |
| "osprey.interfaces.web_terminal.app._load_web_config", | |
| return_value={"watch_dir": str(tmp_path)}, | |
| ), | |
| patch( | |
| "osprey.interfaces.web_terminal.app._load_panel_config", | |
| return_value=({"artifacts"}, [], None), | |
| ), | |
| patch( | |
| "osprey.interfaces.web_terminal.app._launch_panel_server", | |
| side_effect=publish_artifact_url(), | |
| ), | |
| ): | |
| from osprey.interfaces.web_terminal.app import create_app | |
| app = create_app(shell_command=["echo", "hello"]) | |
| with _run_app_server(app) as base_url: | |
| yield base_url | |
| def _launch_artifacts(tmp_path, monkeypatch) -> Iterator[str]: | |
| monkeypatch.chdir(tmp_path) | |
| from osprey.interfaces.artifacts.app import create_app | |
| app = create_app(workspace_root=tmp_path) | |
| with _run_app_server(app) as base_url: | |
| yield base_url | |
| def _launch_ariel(tmp_path, monkeypatch) -> Iterator[str]: | |
| monkeypatch.chdir(tmp_path) | |
| from osprey.interfaces.ariel.app import create_app | |
| app = create_app() | |
| with _run_app_server(app) as base_url: | |
| yield base_url | |
| def _launch_channel_finder(tmp_path, monkeypatch) -> Iterator[str]: | |
| monkeypatch.chdir(tmp_path) | |
| from osprey.interfaces.channel_finder.app import create_app | |
| app = create_app(project_cwd=str(tmp_path)) | |
| with _run_app_server(app) as base_url: | |
| yield base_url | |
| def _launch_channel_finder_graph(tmp_path, monkeypatch) -> Iterator[str]: | |
| # Same interface, second paradigm: the graph mode serves a different | |
| # explore view off the same factory, so it gets its own target. The | |
| # launcher (shared with the visual lane) writes the graph config and | |
| # points the app's store seam at the demo corpus -- no database is dialled. | |
| with launch_graph_channel_finder(tmp_path, monkeypatch) as base_url: | |
| yield base_url | |
| def _launch_lattice_dashboard(tmp_path, monkeypatch) -> Iterator[str]: | |
| monkeypatch.chdir(tmp_path) | |
| from osprey.interfaces.lattice_dashboard.app import create_app | |
| app = create_app(workspace_root=tmp_path) | |
| with _run_app_server(app) as base_url: | |
| yield base_url | |
| def _launch_okf_panel(tmp_path, monkeypatch) -> Iterator[str]: | |
| monkeypatch.chdir(tmp_path) | |
| from osprey.interfaces.okf_panel.app import create_app | |
| # Build over the shared on-disk fixture bundle the panel's own unit tests use | |
| # (tests/interfaces/okf_panel/fixtures/bundle) so GET / renders real content. | |
| bundle = Path(__file__).parent / "okf_panel" / "fixtures" / "bundle" | |
| app = create_app(bundle_path=str(bundle)) | |
| with _run_app_server(app) as base_url: | |
| yield base_url | |
| # --------------------------------------------------------------------------- | |
| # Allowlists | |
| # --------------------------------------------------------------------------- | |
| # Empty (None) unless a real interface turns out to have benign vendored-lib | |
| # noise; keep entries narrow and documented with the benign source. | |
| _ALLOWLISTS: dict[str, object] = { | |
| "web_terminal": None, | |
| "artifacts": None, | |
| "ariel": None, | |
| "channel_finder": None, | |
| "channel_finder_graph": None, | |
| "lattice_dashboard": None, | |
| "okf_panel": None, | |
| "web_terminal_session": None, | |
| } | |
| INTERFACE_LAUNCHERS = [ | |
| ("web_terminal", _launch_web_terminal), | |
| ("artifacts", _launch_artifacts), | |
| ("ariel", _launch_ariel), | |
| ("channel_finder", _launch_channel_finder), | |
| ("channel_finder_graph", _launch_channel_finder_graph), | |
| ("lattice_dashboard", _launch_lattice_dashboard), | |
| ("okf_panel", _launch_okf_panel), | |
| ] | |
| def test_interface_loads_clean( | |
| name: str, | |
| launcher, | |
| tmp_path, | |
| monkeypatch, | |
| chromium_browser: Browser, | |
| ) -> None: | |
| """Each interface's ``GET /`` loads with no uncaught error or failed asset.""" | |
| with launcher(tmp_path, monkeypatch) as base_url: | |
| page = chromium_browser.new_page() | |
| assert_page_loads_clean(page, base_url, allowlist=_ALLOWLISTS[name]) | |
| if name == "web_terminal": | |
| if not _PLAYWRIGHT_AVAILABLE: # pragma: no cover - guarded above too | |
| pytest.skip("playwright package not installed") | |
| # Hub shell DOM check: the artifacts tab button is always present | |
| # (artifacts is always-enabled, see _open_page in | |
| # test_panels_browser.py) once panel-manager.js finishes its | |
| # async init (fetch /api/panels, then per-panel config). | |
| expect(page.locator('button[data-panel-id="artifacts"]')).to_be_visible(timeout=10_000) | |
| if name == "channel_finder_graph": | |
| # Explore is the default route (no hash), and its finder renders | |
| # result rows only after /api/graph/search answers -- so a result | |
| # row is the DOM proof the page did more than load. | |
| row = "#graph-finder-table .result-table tbody tr[data-pv]:first-child" | |
| page.wait_for_selector(row, timeout=10_000) | |
| assert page.locator(row).count() >= 1 | |
| page.close() | |
| # --------------------------------------------------------------------------- | |
| # Web-terminal static pages (session.html) -- CC-11 | |
| # --------------------------------------------------------------------------- | |
| # A static asset under the hub's own /static mount (configure_interface_app | |
| # mounts the whole static/ dir), not a second app -- a path-override on the | |
| # same _launch_web_terminal hub server above, mirroring test_visual.py's | |
| # _web_terminal_static_page_server (which likewise reuses its hub server | |
| # unchanged and only varies the VisualTarget's `path`). | |
| _WEB_TERMINAL_STATIC_PAGES = [ | |
| ("web_terminal_session", "/static/session.html"), | |
| ] | |
| def test_web_terminal_static_page_loads_clean( | |
| name: str, | |
| path: str, | |
| tmp_path, | |
| monkeypatch, | |
| chromium_browser: Browser, | |
| ) -> None: | |
| """session.html loads with no uncaught error or failed asset.""" | |
| with _launch_web_terminal(tmp_path, monkeypatch) as base_url: | |
| page = chromium_browser.new_page() | |
| assert_page_loads_clean(page, f"{base_url}{path}", allowlist=_ALLOWLISTS[name]) | |
| page.close() | |
| # --------------------------------------------------------------------------- | |
| # Web-terminal status readouts | |
| # --------------------------------------------------------------------------- | |
| def test_web_terminal_status_readouts_are_live( | |
| tmp_path, | |
| monkeypatch, | |
| chromium_browser: Browser, | |
| ) -> None: | |
| """The status bar's clock still says something on a live page. | |
| It used to be a hardcoded ``#status-clock`` node written by an | |
| ``initStatusBar()`` that no longer exists: it is a bar item now, built by | |
| ``bar-items.js`` into a shell the server emits from the effective layout. Every step of that hand-over is | |
| unit-tested, and none of those unit tests can tell whether the chain | |
| actually closes on a live page — a broken link anywhere in it leaves | |
| empty boxes in the corner of the screen and no failing test anywhere, | |
| because an empty box is what an item that never built looks like. | |
| So this asserts the VALUES, not the elements. A present-but-blank readout | |
| is the failure being guarded against, which is why the clock is matched | |
| against its shape rather than merely located: it reads a real ``HH:MM``. | |
| """ | |
| if not _PLAYWRIGHT_AVAILABLE: # pragma: no cover - guarded by the fixture too | |
| pytest.skip("playwright package not installed") | |
| from osprey.interfaces.web_terminal.app import DEFAULT_BAR_LAYOUT | |
| places_clock = { | |
| **DEFAULT_BAR_LAYOUT, | |
| "status": [ | |
| {"type": "space"}, | |
| {"type": "clock"}, | |
| ], | |
| } | |
| with ( | |
| patch( | |
| "osprey.interfaces.web_terminal.app._load_bar_items", | |
| return_value=places_clock, | |
| ), | |
| _launch_web_terminal(tmp_path, monkeypatch) as base_url, | |
| ): | |
| page = chromium_browser.new_page() | |
| page.goto(base_url) | |
| bar = page.locator('footer.status-bar[data-bar-host="status"]') | |
| expect(bar.locator(".bar-clock-time")).to_have_text( | |
| re.compile(r"^\d{1,2}:\d{2}$"), timeout=15_000 | |
| ) | |
| page.close() | |
Xet Storage Details
- Size:
- 11 kB
- Xet hash:
- c4183d3e537e7e7d310ecaec743604ed1de7a972d9922f47a9958564b1568532
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.