From 3c815245b47203cb69e17a298998185320adf4a8 Mon Sep 17 00:00:00 2001 From: lrnselfreliance <33263708+lrnselfreliance@users.noreply.github.com> Date: Tue, 27 Oct 2026 18:58:52 -0600 Subject: [PATCH] An archive detects a browser when the configured one is not installed (#895) A configured browser_executable was used without checking it exists. A config on the media drive can outlive the OS it was written on: Raspberry Pi OS's /usr/bin/chromium-browser is /usr/bin/chromium on Debian. The wrapper discards the browser's stderr, so its failed exec only showed as single-file's "Connection refused ... Child process has already terminated", and every archive failed. Now a missing configured browser is logged and one is detected, as when none is configured. Co-authored-by: Claude Opus 5.5 --- modules/archive/__init__.py | 15 ++++++---- .../archive/test/test_archive_downloader.py | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/modules/archive/__init__.py b/modules/archive/__init__.py index 21bde1e2..573882db 100644 --- a/modules/archive/__init__.py +++ b/modules/archive/__init__.py @@ -9,7 +9,7 @@ from typing import Callable, List, Optional, Tuple from sqlalchemy import text from sqlalchemy.orm import Session -from wrolpi.cmd import SINGLE_FILE_BIN, CHROMIUM, FIREFOX, DENO_BIN, SINGLE_FILE_DENO_SCRIPT +from wrolpi.cmd import SINGLE_FILE_BIN, CHROMIUM, FIREFOX, DENO_BIN, SINGLE_FILE_DENO_SCRIPT, which from wrolpi.collections import Collection from wrolpi.common import logger, register_modeler, register_refresh_cleanup, limit_concurrent, split_lines_by_length, \ slow_logger, get_title_from_html, strip_surrogates, TRACE_LEVEL @@ -137,11 +137,14 @@ class ArchiveDownloader(Downloader, ABC): config = lib.get_archive_downloader_config() # Determine browser executable - browser_executable = config.browser_executable - if browser_executable: - # Use configured browser path - browser = browser_executable - else: + browser = None + if browser_executable := config.browser_executable: + # Use the configured browser, if it is installed. A config can outlive the OS it was written on (e.g. + # Raspberry Pi OS names Chromium "chromium-browser"). + if not (browser := which(browser_executable)): + logger.warning(f'Configured browser_executable is not installed, detecting a browser instead:' + f' {browser_executable}') + if not browser: # Auto-detect: prefer Chromium, fallback to Firefox browser = CHROMIUM or FIREFOX if not browser: diff --git a/modules/archive/test/test_archive_downloader.py b/modules/archive/test/test_archive_downloader.py index 8825ede8..c7171703 100644 --- a/modules/archive/test/test_archive_downloader.py +++ b/modules/archive/test/test_archive_downloader.py @@ -238,3 +238,31 @@ async def test_finalize_adds_tags(async_client, test_session, test_directory, ta assert len(archives) == 1 archive_tag_names = [tf.tag.name for tf in archives[0].file_group.tag_files] assert tag.name in archive_tag_names + + +@pytest.mark.asyncio +@pytest.mark.parametrize('configured, expected', [ + # A config can outlive the OS it was written on: Raspberry Pi OS names Chromium "chromium-browser". + ('/nonexistent/chromium-browser', '/usr/bin/chromium'), + (None, '/usr/bin/chromium'), + ('/bin/sh', '/bin/sh'), +]) +async def test_do_singlefile_configured_browser(test_session, test_directory, monkeypatch, configured, expected): + """The configured browser is used when it is installed; otherwise one is detected.""" + from types import SimpleNamespace + import modules.archive + singlefile = b'' + process_runner, calls = make_process_runner_recorder(singlefile) + monkeypatch.setattr(modules.archive, 'DENO_BIN', '/usr/local/bin/deno') + monkeypatch.setattr(modules.archive, 'SINGLE_FILE_DENO_SCRIPT', + '/usr/local/lib/node_modules/single-file-cli/single-file') + monkeypatch.setattr(modules.archive, 'CHROMIUM', '/usr/bin/chromium') + monkeypatch.setattr(archive_downloader, 'process_runner', process_runner) + monkeypatch.setattr(modules.archive.lib, 'get_archive_downloader_config', + lambda: SimpleNamespace(browser_executable=configured, browser_args=None, user_agent=None)) + + prepared = PreparedArchive(url='https://example.com', destination=None, settings={}) + await archive_downloader.do_singlefile(prepared, make_test_ctx()) + + capture, = calls + assert capture['env']['WROLPI_BROWSER'] == expected