Skip to content

The agent that grows with you

refactor(doctor): reuse backup's size formatter for database listings

kshitijdf0a5c3ee4d6
diff --git a/hermes_cli/doctor.py b/hermes_cli/doctor.py
index 3e35b67b6e9..b6dd56c8780 100644
--- a/hermes_cli/doctor.py
+++ b/hermes_cli/doctor.py
@@ -142,11 +142,15 @@ def _read_journal_mode(db_path: Path) -> tuple[str | None, str | None]:
def _format_db_size(db_path: Path) -> str:
+ # backup.py owns human-readable size formatting; reuse it (as with
+ # _QUICK_STATE_FILES above) and keep only the stat-failure wrap here.
+ from hermes_cli.backup import _format_size
+
try:
- mb = db_path.stat().st_size / 1_048_576
+ nbytes = db_path.stat().st_size
except OSError:
return "size unknown"
- return f"{mb:.1f} MB" if mb >= 0.1 else "<0.1 MB"
+ return _format_size(nbytes)
def _report_database_journal_modes(
diff --git a/tests/hermes_cli/test_doctor_journal_modes.py b/tests/hermes_cli/test_doctor_journal_modes.py
index 674d7023fec..acc56ff0ea2 100644
--- a/tests/hermes_cli/test_doctor_journal_modes.py
+++ b/tests/hermes_cli/test_doctor_journal_modes.py
@@ -8,6 +8,7 @@ read-only engine open creates -wal/-shm sidecar files next to a WAL database.
"""
import os
+import re
import sqlite3
import pytest
@@ -257,7 +258,8 @@ class TestSizeAndRepairHint:
_make_db(db, journal_mode="WAL")
doctor._report_database_journal_modes(tmp_path, VULNERABLE)
out = capsys.readouterr().out
- assert "MB)" in out
+ # _format_size picks the unit (a fresh test DB is KB-scale).
+ assert re.search(r"\(\d[\d.]* [KMGT]?B\)", out)
assert "To clear the exposure:" in out
def test_no_repair_hint_when_nothing_is_exposed(self, tmp_path, capsys):