fix(tests): sandbox a dev shell whose HERMES_HOME is the Windows platform root, and pin lazy state.db home resolution
The conftest session sandbox only recognised ~/.hermes as "production", so a Windows dev shell exporting HERMES_HOME=%LOCALAPPDATA%\hermes was honoured as a custom home; every import-time path capture (tui_gateway.server._hermes_home) then pointed at the live install and the state.db guard tripped on store-touching tests (#112692). Compare against the same platform-default root the guard itself uses. Adds the invariant test for the lazy resolve: a HERMES_HOME redirected after import is honoured while the context-local override is still ignored (#102526).
This commit is contained in:
@@ -77,8 +77,14 @@ def _hermes_home_points_at_production(value: str) -> bool:
|
||||
if not value:
|
||||
return True
|
||||
try:
|
||||
# The platform-default root, not a hardcoded ``~/.hermes``: Windows installs live under
|
||||
# ``%LOCALAPPDATA%\hermes``, and a dev shell exporting that path used to be honored as
|
||||
# "custom", pinning import-time paths (``tui_gateway.server._hermes_home``) to the live
|
||||
# install so the state.db guard tripped on every store-touching test (#112692).
|
||||
from hermes_state_guard import _real_platform_state_root
|
||||
|
||||
resolved = Path(value).expanduser().resolve()
|
||||
real_root = (Path.home() / ".hermes").resolve()
|
||||
real_root = _real_platform_state_root() or (Path.home() / ".hermes").resolve()
|
||||
except Exception:
|
||||
return True
|
||||
if resolved == real_root:
|
||||
|
||||
@@ -46,6 +46,23 @@ def test_get_db_first_touch_under_foreign_override_uses_launch_path(launch_db_en
|
||||
reset_hermes_home_override(token)
|
||||
|
||||
|
||||
def test_get_db_follows_a_process_home_redirected_after_import(monkeypatch, tmp_path):
|
||||
"""The launch handle resolves ``HERMES_HOME`` at first use, not at import (#112692): a harness
|
||||
that redirects the env after ``tui_gateway.server`` is imported must not open the import-time
|
||||
home's state.db. Only the context-local override is ignored (#102526), never the process env."""
|
||||
redirected = tmp_path / "redirected"
|
||||
redirected.mkdir()
|
||||
monkeypatch.setattr(server, "_db", None)
|
||||
monkeypatch.setattr(server, "_db_error", None)
|
||||
monkeypatch.setenv("HERMES_HOME", str(redirected))
|
||||
try:
|
||||
db = server._get_db()
|
||||
assert db is not None
|
||||
assert db.db_path.resolve() == (redirected / "state.db").resolve()
|
||||
finally:
|
||||
registry.close_all()
|
||||
|
||||
|
||||
def test_insights_get_reads_the_requested_profile_store_not_the_launch_handle(launch_db_env, monkeypatch, tmp_path):
|
||||
"""``insights.get {profile}`` was ``scoped=True`` then ``_get_db()``: a scoped first touch pinned
|
||||
the launch handle to the foreign store. It must count the requested profile's sessions through
|
||||
|
||||
Reference in New Issue
Block a user