Skip to content

The agent that grows with you

fix(http): bind every native ticket to its owning profile scope

David Dudok de Wit611bdaeff272
diff --git a/hermes_cli/dashboard_auth/native_http.py b/hermes_cli/dashboard_auth/native_http.py
index afd18acae7a..2bba4b1cf39 100644
--- a/hermes_cli/dashboard_auth/native_http.py
+++ b/hermes_cli/dashboard_auth/native_http.py
@@ -29,11 +29,8 @@ def native_profile_scope(request):
if grant is None:
yield
return
- from hermes_constants import get_process_hermes_home, reset_hermes_home_override, set_hermes_home_override
+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override
home = Path(grant['profile_id'])
- if home.resolve() == get_process_hermes_home().resolve():
- yield
- return
token = set_hermes_home_override(str(home))
try:
yield
diff --git a/tests/gateway/test_native_config_owner_scope.py b/tests/gateway/test_native_config_owner_scope.py
new file mode 100644
index 00000000000..0dde3ff34c0
--- /dev/null
+++ b/tests/gateway/test_native_config_owner_scope.py
@@ -0,0 +1,32 @@
+"""A native ticket's implicit selectors retain its secrets through nested config scopes."""
+import asyncio
+from pathlib import Path
+from types import SimpleNamespace
+
+import pytest
+
+
+async def test_concurrent_ticket_profiles_bind_nested_config_secrets(tmp_path, monkeypatch):
+ from agent.secret_scope import get_secret
+ from hermes_cli.dashboard_auth.native_http import native_profile_scope
+ from hermes_cli.web_server_profiles import _config_profile_scope
+ from hermes_constants import get_hermes_home
+ home = tmp_path / '.hermes'
+ home.mkdir()
+ monkeypatch.setenv('HERMES_HOME', str(home))
+ monkeypatch.setattr(Path, 'home', lambda: tmp_path)
+ monkeypatch.setenv('SCOPE_SENTINEL', 'launch')
+ monkeypatch.setenv('SCOPE_MISSING', 'launch-only')
+ beta, gamma = home / 'profiles' / 'beta', home / 'profiles' / 'gamma'
+ for profile in (beta, gamma):
+ profile.mkdir(parents=True)
+ (profile / '.env').write_text('SCOPE_SENTINEL=' + profile.name + '\n', encoding='utf-8')
+ async def read(profile, selector):
+ request = SimpleNamespace(state=SimpleNamespace(native_http_principal={'profile_id': str(profile)}))
+ with native_profile_scope(request), _config_profile_scope(selector):
+ await asyncio.sleep(0)
+ assert get_hermes_home() == profile
+ assert get_secret('SCOPE_SENTINEL') == profile.name
+ assert get_secret('SCOPE_MISSING') is None
+ await asyncio.gather(*(read(profile, selector) for profile in (beta, gamma) for selector in (None, '', 'current')))