From 63b558deec324bc06a6d1b0e23ba08f20da8bbc2 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Tue, 6 Oct 2026 16:36:13 +0530 Subject: [PATCH] test(doctor): pin root's reserved blocks in the cron store free-space check Gate r4 2ab (TOOTHLESS): reverting f56ce2179a left the kept tests green. The doctor rows now stub shutil.disk_usage and os.statvfs instead of free_bytes, pin os.geteuid to the user each row names, and a root row (disk_usage 0 B, statvfs f_bfree 4 GB) must report the store writable; it is red without the root statvfs branch. The ok row stays so the ok path is asserted where os.geteuid is absent and the root row skips. --- tests/hermes_cli/test_doctor.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/hermes_cli/test_doctor.py b/tests/hermes_cli/test_doctor.py index c252f831e6..a124f95448 100644 --- a/tests/hermes_cli/test_doctor.py +++ b/tests/hermes_cli/test_doctor.py @@ -1610,19 +1610,25 @@ class TestMacOSTCCGrants: assert "stable" not in out -@pytest.mark.parametrize("probe_error,free,expected,issues", [ - (None, 50 << 30, "store is writable", []), - (OSError(28, "No space left on device"), 50 << 30, "NOT writable (ENOSPC", ["is not writable"]), - (None, 10 << 20, "free — cron jobs stop when it fills", ["Free disk space"]), +@pytest.mark.parametrize("probe_error,free,root,expected,issues", [ + (None, 50 << 30, False, "store is writable", []), + (OSError(28, "No space left on device"), 50 << 30, False, "NOT writable (ENOSPC", ["is not writable"]), + (None, 10 << 20, False, "free — cron jobs stop when it fills", ["Free disk space"]), + # root may fill the reserved blocks: 0 B for disk_usage, but statvfs f_bfree says 4 GB + pytest.param(None, 0, True, "store is writable", [], id="root-reserved-blocks", + marks=pytest.mark.skipif(not hasattr(os, "geteuid"), reason="no os.geteuid")), ]) def test_cron_store_check_reports_writability_and_low_space( - monkeypatch, tmp_path, capsys, probe_error, free, expected, issues): + monkeypatch, tmp_path, capsys, probe_error, free, root, expected, issues): from cron import store_health (tmp_path / "cron").mkdir() monkeypatch.setattr(doctor, "HERMES_HOME", tmp_path) monkeypatch.setattr(store_health, "probe_store", lambda _d: probe_error) - monkeypatch.setattr(store_health, "free_bytes", lambda _d: free) + monkeypatch.setattr(store_health.shutil, "disk_usage", lambda _d: SimpleNamespace(free=free)) + if hasattr(os, "geteuid"): # rows run as the user they name, whoever runs the suite + monkeypatch.setattr(os, "geteuid", lambda: 0 if root else 1000) + monkeypatch.setattr(os, "statvfs", lambda _d: SimpleNamespace(f_bfree=1 << 20, f_frsize=4096)) finding = doctor_state._check_cron_store(False) assert expected in capsys.readouterr().out assert len(finding.issues) == len(issues) and all(any(s in i for i in finding.issues) for s in issues)