From 16cd3837e4321c047549950a79101f2d126cccb2 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Thu, 4 Jun 2026 23:38:56 -0700 Subject: [PATCH] use archivebox installs in browser security tests --- archivebox/tests/conftest.py | 27 +++---------------- archivebox/tests/test_hooks.py | 6 ++--- .../tests/test_server_security_browser.py | 27 ++++++++++++++----- 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/archivebox/tests/conftest.py b/archivebox/tests/conftest.py index 7f2a97a8..ee840541 100644 --- a/archivebox/tests/conftest.py +++ b/archivebox/tests/conftest.py @@ -59,9 +59,10 @@ def _assert_safe_runtime_paths(*, cwd: Path | None = None, env: dict[str, str] | def _test_source_pythonpath() -> str: entries: list[str] = [] for repo_name in ("abxpkg", "abx-plugins", "abx-dl"): - repo_path = WORKSPACE_ROOT / repo_name - if repo_path.exists(): - entries.append(str(repo_path.resolve(strict=False))) + for repo_path in (WORKSPACE_ROOT / repo_name, REPO_ROOT / repo_name): + if repo_path.exists(): + entries.append(str(repo_path.resolve(strict=False))) + break return os.pathsep.join(entries) @@ -1427,26 +1428,6 @@ def _find_system_browser() -> Path | None: return None -def _ensure_puppeteer(shared_lib: Path) -> None: - pnpm_prefix = shared_lib / "pnpm" / "packages" / "chrome" - node_modules = pnpm_prefix / "node_modules" - puppeteer_dir = node_modules / "puppeteer" - if puppeteer_dir.exists(): - return - pnpm_prefix.mkdir(parents=True, exist_ok=True) - env = os.environ.copy() - env["PUPPETEER_SKIP_DOWNLOAD"] = "1" - subprocess.run( - ["pnpm", "add", "--dir", str(pnpm_prefix), "puppeteer"], - cwd=str(pnpm_prefix), - env=env, - check=True, - capture_output=True, - text=True, - timeout=600, - ) - - @pytest.fixture(scope="class") def real_archive_with_example(tmp_path_factory, request): """ diff --git a/archivebox/tests/test_hooks.py b/archivebox/tests/test_hooks.py index 6d2817a8..ee614fc8 100755 --- a/archivebox/tests/test_hooks.py +++ b/archivebox/tests/test_hooks.py @@ -106,9 +106,9 @@ def test_cli_env_does_not_emit_relative_pythonpath_entries(): os.environ["PYTHONPATH"] = old_pythonpath pythonpath_entries = env["PYTHONPATH"].split(os.pathsep) - assert str((WORKSPACE_ROOT / "abxpkg").resolve(strict=False)) in pythonpath_entries - assert str((WORKSPACE_ROOT / "abx-plugins").resolve(strict=False)) in pythonpath_entries - assert str((WORKSPACE_ROOT / "abx-dl").resolve(strict=False)) in pythonpath_entries + for repo_name in ("abxpkg", "abx-plugins", "abx-dl"): + repo_path = next(path for path in (WORKSPACE_ROOT / repo_name, REPO_ROOT / repo_name) if path.exists()) + assert str(repo_path.resolve(strict=False)) in pythonpath_entries assert all(Path(entry).is_absolute() for entry in pythonpath_entries) assert not any(entry.startswith("..") for entry in pythonpath_entries) diff --git a/archivebox/tests/test_server_security_browser.py b/archivebox/tests/test_server_security_browser.py index 771766e7..342d0ca0 100644 --- a/archivebox/tests/test_server_security_browser.py +++ b/archivebox/tests/test_server_security_browser.py @@ -14,7 +14,7 @@ from urllib.parse import urlencode import pytest -from .conftest import _ensure_puppeteer, _find_cached_chrome, _find_system_browser, run_python_cwd +from .conftest import _find_cached_chrome, _find_system_browser, run_python_cwd from .conftest import ( cli_env, get_free_port, @@ -289,13 +289,28 @@ def _resolve_browser(shared_lib: Path) -> Path | None: return None -@pytest.fixture(scope="session") -def browser_runtime(tmp_path_factory): +@pytest.fixture +def browser_runtime(initialized_archive: Path): assert shutil.which("node") is not None, "Node.js is required for browser security tests" - assert shutil.which("pnpm") is not None, "pnpm is required for browser security tests" - shared_lib = tmp_path_factory.mktemp("archivebox_browser_lib") - _ensure_puppeteer(shared_lib) + shared_lib = initialized_archive / "lib" + env = cli_env( + ABXPKG_INSTALL_TIMEOUT="900", + ABXPKG_MIN_RELEASE_AGE="0", + LIB_DIR=str(shared_lib), + ABXPKG_LIB_DIR=str(shared_lib), + CHROME_HEADLESS="True", + CHROME_SANDBOX="False", + CHROME_ISOLATION="snapshot", + ) + env.pop("CHROME_BINARY", None) + install_result = run_archivebox_cmd( + ["install", "chrome"], + cwd=initialized_archive, + env=env, + timeout=900, + ) + assert install_result.returncode == 0, install_result.stderr or install_result.stdout browser = _resolve_browser(shared_lib) assert browser, "No Chrome/Chromium binary available for browser security tests"