Self-hosted AI workspace.
Python
ci: provision browser dependencies for pytest
Alexandre Teixeira83088f88116c
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex a276fdb1d..5e2231bc3 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -140,6 +140,15 @@ jobs:cache: pip- run: pip install -r requirements.txtif: steps.docs-check.outputs.docs_only != 'true'+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0+ if: steps.docs-check.outputs.docs_only != 'true'+ with:+ node-version: "20"+ cache: npm+ - run: npm ci+ if: steps.docs-check.outputs.docs_only != 'true'+ - run: npx playwright install --with-deps chromium+ if: steps.docs-check.outputs.docs_only != 'true'- run: mkdir -p data # sqlite DB lives at ./data/app.dbif: steps.docs-check.outputs.docs_only != 'true'- run: python -m pytest -qdiff --git a/tests/conftest.py b/tests/conftest.pyindex 2f6defa1c..0e8faebde 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -4,6 +4,7 @@ import osimport typesimport importlib.utilfrom unittest.mock import MagicMock+import pytestsys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))@@ -93,3 +94,52 @@ def pytest_collection_modifyitems(config, items):path = getattr(item, "path", None) or item.fspathfor marker_name in markers_for_path(path):item.add_marker(getattr(pytest.mark, marker_name))++[email protected](scope="session", autouse=True)+def _serve_test_static():+ """Ensure static assets are available on loopback port 7011 for browser integration tests."""+ import socket+ import threading+ import http.server+ import socketserver+ from pathlib import Path++ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)+ try:+ is_bound = (sock.connect_ex(("127.0.0.1", 7011)) == 0)+ finally:+ sock.close()++ if is_bound:+ yield+ return++ root_dir = Path(__file__).resolve().parent.parent++ class _Handler(http.server.SimpleHTTPRequestHandler):+ def __init__(self, *args, **kwargs):+ super().__init__(*args, directory=str(root_dir), **kwargs)++ def log_message(self, format, *args):+ pass++ def guess_type(self, path):+ if path.endswith(".js") or path.endswith(".mjs"):+ return "application/javascript"+ if path.endswith(".css"):+ return "text/css"+ return super().guess_type(path)++ class _Server(socketserver.TCPServer):+ allow_reuse_address = True++ try:+ server = _Server(("127.0.0.1", 7011), _Handler)+ thread = threading.Thread(target=server.serve_forever, daemon=True)+ thread.start()+ yield+ server.shutdown()+ server.server_close()+ except Exception:+ yield