From 0e124b94f312b2f9accc6901c7020808496f66bd Mon Sep 17 00:00:00 2001 From: Christian-Sidak <61099993+Christian-Sidak@users.noreply.github.com> Date: Mon, 17 Aug 2026 19:00:52 -0700 Subject: [PATCH] fix(tests): skip SearXNG migration tests on Windows The SearXNG settings migration script uses POSIX-only os.fchown and os.O_DIRECTORY, which CPython does not expose on Windows. The migration runs exclusively inside the Linux SearXNG container, so native Windows contributors should not see failures from the test suite. Add a module-level pytestmark to skip all tests in test_searxng_settings_migration.py on win32, matching the existing convention in test_app_db_permissions.py. Guard os.fchown and the os.O_DIRECTORY directory-fsync path in scripts/migrate_searxng_settings.py behind sys.platform != "win32" checks so the module can be safely imported on Windows without AttributeError. Fixes #6067 Signed-off-by: Christian Sidak Signed-off-by: Christian-Sidak <61099993+Christian-Sidak@users.noreply.github.com> --- scripts/migrate_searxng_settings.py | 18 ++++++++++-------- tests/test_searxng_settings_migration.py | 8 ++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/scripts/migrate_searxng_settings.py b/scripts/migrate_searxng_settings.py index 4b58e2efc..85eb454df 100644 --- a/scripts/migrate_searxng_settings.py +++ b/scripts/migrate_searxng_settings.py @@ -122,22 +122,24 @@ def migrate_settings(path: Path) -> bool: try: # chmod before chown: the Compose cap set is `cap_drop: ALL` plus # CHOWN/SETGID/SETUID/DAC_OVERRIDE, with no FOWNER. Once the temporary - # file belongs to searxng:searxng — which every retained settings file - # does, because searxng's entrypoint chowns /etc/searxng — root can no + # file belongs to searxng:searxng -- which every retained settings file + # does, because searxng's entrypoint chowns /etc/searxng -- root can no # longer chmod it and the migration dies with EPERM. os.fchmod(fd, stat.S_IMODE(source_stat.st_mode)) - os.fchown(fd, source_stat.st_uid, source_stat.st_gid) + if sys.platform != "win32": + os.fchown(fd, source_stat.st_uid, source_stat.st_gid) with os.fdopen(fd, "wb") as handle: fd = -1 handle.write(updated) handle.flush() os.fsync(handle.fileno()) os.replace(temporary, path) - directory_fd = os.open(path.parent, os.O_RDONLY | os.O_DIRECTORY) - try: - os.fsync(directory_fd) - finally: - os.close(directory_fd) + if sys.platform != "win32": + directory_fd = os.open(path.parent, os.O_RDONLY | os.O_DIRECTORY) + try: + os.fsync(directory_fd) + finally: + os.close(directory_fd) finally: if fd >= 0: os.close(fd) diff --git a/tests/test_searxng_settings_migration.py b/tests/test_searxng_settings_migration.py index 75cef7775..f03e34b66 100644 --- a/tests/test_searxng_settings_migration.py +++ b/tests/test_searxng_settings_migration.py @@ -8,6 +8,14 @@ import pytest import yaml +pytestmark = pytest.mark.skipif( + sys.platform == "win32", + reason=( + "SearXNG settings migration relies on POSIX-only os.fchown and " + "os.O_DIRECTORY; the migration script runs only inside the Linux " + "SearXNG container and is not exercised on native Windows." + ), +) ROOT = Path(__file__).resolve().parent.parent MIGRATION = ROOT / "scripts" / "migrate_searxng_settings.py"