Skip to content

The agent that grows with you

test(dashboard): invariant for deleted_wal/state_db_replaced 503 mapping

kshitijk4poorb3e9032b09d6
diff --git a/tests/hermes_cli/test_web_analytics_corrupt_store.py b/tests/hermes_cli/test_web_analytics_corrupt_store.py
index 0f3d02dc4e1..3f8372a157b 100644
--- a/tests/hermes_cli/test_web_analytics_corrupt_store.py
+++ b/tests/hermes_cli/test_web_analytics_corrupt_store.py
@@ -62,3 +62,29 @@ def test_corrupt_store_polls_return_status_and_warn_once_per_interval(tmp_path,
r.levelno >= logging.WARNING and r.name.startswith("hermes_cli.web_server")
for r in caplog.records
) == 1
+
+
+def test_corrupt_store_as_status_maps_replaced_store_errors_to_503_without_fix_nudge(tmp_path, monkeypatch):
+ """A retired WAL generation / replaced state.db (RuntimeError subclasses, not sqlite3 errors)
+ must come back as a structured 503 like the corrupt case, and the guidance must never tell the
+ user to run `doctor --fix` while a holder is live (#110054). Busy/locked still propagates."""
+ from fastapi import HTTPException
+ from hermes_state_errors import DeletedWalGenerationError, StateDbReplacedError
+
+ monkeypatch.setattr(_common, "_corrupt_store_warned_at", {})
+ db_path = tmp_path / "state.db"
+ for exc_cls, code in ((DeletedWalGenerationError, "deleted_wal"), (StateDbReplacedError, "state_db_replaced")):
+ with pytest.raises(HTTPException) as info:
+ with _common.corrupt_store_as_status(db_path):
+ raise exc_cls("retired WAL held by pid 4242")
+ assert info.value.status_code == 503
+ assert info.value.detail["error"] == code
+ assert info.value.detail["path"] == str(db_path)
+ msg = info.value.detail["message"]
+ assert "run `hermes doctor`" in msg
+ # `--fix` may only appear negated — never as the action to take while a holder is live.
+ assert msg.count("`hermes doctor --fix`") == 1 and "Do not run `hermes doctor --fix`" in msg
+
+ with pytest.raises(sqlite3.OperationalError):
+ with _common.corrupt_store_as_status(db_path):
+ raise sqlite3.OperationalError("database is locked")