test(state): assert the live-DB guard against the real platform root

`REAL_ROOT` hardcoded `Path.home() / ".hermes"`, but the guard resolves
`%LOCALAPPDATA%\hermes` on Windows. The paths under test were therefore
*correctly* classified as non-production, the guard never fired, and all
five TestProductionPathRefused cases failed for the wrong reason — the
guard was effectively unasserted on Windows.

Derive the root from `_real_platform_state_root()` — the same function the
guard uses — so the tests follow the implementation across platforms, and
build the unnormalized-spelling case from it instead of a second hardcoded
`~/.hermes`. Skips at module level if no platform root resolves.

Refs #82770
This commit is contained in:
joaomarcos
2026-08-09 20:58:54 -03:00
committed by Teknium
parent 174ce8770d
commit 3f026fe210
@@ -24,7 +24,16 @@ from gateway.config import GatewayConfig
from gateway.session import SessionStore
from hermes_state import SessionDB
REAL_ROOT = (Path.home() / ".hermes").resolve()
# Must match the root the guard itself computes. Hardcoding ``~/.hermes``
# silently disarmed every assertion below on Windows, where the real root is
# ``%LOCALAPPDATA%\hermes``: the paths under test were then *correctly*
# classified as non-production, so the guard never raised and the whole
# TestProductionPathRefused class failed for the wrong reason (#82770).
REAL_ROOT = hermes_state._real_platform_state_root()
if REAL_ROOT is None: # pragma: no cover - no resolvable home on this platform
pytest.skip(
"no real platform state root to assert against", allow_module_level=True
)
class TestProductionPathRefused:
@@ -45,7 +54,7 @@ class TestProductionPathRefused:
def test_unnormalized_production_path_raises(self):
"""Symlink-free but unnormalized spellings still resolve and refuse."""
sneaky = Path.home() / "subdir" / ".." / ".hermes" / "state.db"
sneaky = REAL_ROOT.parent / "subdir" / ".." / REAL_ROOT.name / "state.db"
with pytest.raises(RuntimeError, match="live-system guard"):
SessionDB(db_path=sneaky)