From 23b13dd78f4f48862d77b2251668c473b73266ac Mon Sep 17 00:00:00 2001 From: Omer Bektas Date: Tue, 11 Aug 2026 22:21:16 +0300 Subject: [PATCH] fix(tests): make Windows collection portable --- tests/hermes_cli/test_doctor_journal_modes.py | 13 ++++++++++--- tests/test_run_tests_parallel.py | 5 +++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/hermes_cli/test_doctor_journal_modes.py b/tests/hermes_cli/test_doctor_journal_modes.py index acc56ff0ea2a..3e564375d06c 100644 --- a/tests/hermes_cli/test_doctor_journal_modes.py +++ b/tests/hermes_cli/test_doctor_journal_modes.py @@ -10,6 +10,7 @@ import os import re import sqlite3 +from pathlib import Path import pytest @@ -21,6 +22,11 @@ EXPOSED_TEXT = "exposed to the WAL-reset bug" +def _running_as_root() -> bool: + geteuid = getattr(os, "geteuid", None) + return geteuid is not None and geteuid() == 0 + + def _make_db(path, journal_mode=None): conn = sqlite3.connect(path) try: @@ -114,7 +120,7 @@ def test_locked_database_is_still_readable(self, tmp_path): holder.close() @pytest.mark.skipif(os.name == "nt", reason="chmod is a no-op on Windows") - @pytest.mark.skipif(os.geteuid() == 0, reason="root ignores file permissions") + @pytest.mark.skipif(_running_as_root(), reason="root ignores file permissions") def test_read_only_directory_is_still_readable(self, tmp_path): db = tmp_path / "state.db" _make_db(db, journal_mode="WAL") @@ -185,7 +191,8 @@ def test_lists_every_managed_database(self, tmp_path, capsys): assert "state.db is in WAL mode" in out assert "projects.db: rollback journal mode" in out assert "kanban.db: rollback journal mode" in out - assert "kanban/boards/myboard/kanban.db is in WAL mode" in out + nested_db = str(Path("kanban") / "boards" / "myboard" / "kanban.db") + assert f"{nested_db} is in WAL mode" in out def test_missing_databases_are_skipped(self, tmp_path, capsys): doctor._report_database_journal_modes(tmp_path, VULNERABLE) @@ -209,7 +216,7 @@ def test_locked_database_does_not_crash_or_block(self, tmp_path, capsys): assert "state.db: rollback journal mode" in out @pytest.mark.skipif(os.name == "nt", reason="chmod is a no-op on Windows") - @pytest.mark.skipif(os.geteuid() == 0, reason="root ignores file permissions") + @pytest.mark.skipif(_running_as_root(), reason="root ignores file permissions") def test_unreadable_database_does_not_crash(self, tmp_path, capsys): db = tmp_path / "state.db" _make_db(db) diff --git a/tests/test_run_tests_parallel.py b/tests/test_run_tests_parallel.py index f83e9a55634f..48c6e38d2099 100644 --- a/tests/test_run_tests_parallel.py +++ b/tests/test_run_tests_parallel.py @@ -24,6 +24,7 @@ import os import subprocess import sys +import tempfile import textwrap import time from pathlib import Path @@ -32,9 +33,9 @@ # Both tests share the same handoff file: the leaker writes here, the -# verifier reads here. We park it in $TMPDIR with a unique-per-run name +# verifier reads here. We park it in the platform temp directory with a unique-per-run name # so concurrent invocations of the suite don't clobber each other. -_HANDOFF_DIR = Path(os.environ.get("TMPDIR", "/tmp")) / "hermes-isolation-probe" +_HANDOFF_DIR = Path(tempfile.gettempdir()) / "hermes-isolation-probe" _HANDOFF_DIR.mkdir(exist_ok=True)