Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions tests/hermes_cli/test_doctor_journal_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import re
import sqlite3
from pathlib import Path

import pytest

Expand All @@ -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:
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_run_tests_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import os
import subprocess
import sys
import tempfile
import textwrap
import time
from pathlib import Path
Expand All @@ -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)


Expand Down