The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(memory): resolve OAuth flow in requested profile scope
wangtao20552e1f5ee3
diff --git a/hermes_cli/memory_oauth.py b/hermes_cli/memory_oauth.pyindex b4fc095a26b..9877629c97f 100644--- a/hermes_cli/memory_oauth.py+++ b/hermes_cli/memory_oauth.py@@ -51,10 +51,10 @@ def _scope_to_profile(profile: Optional[str]):@router.post("/{provider}/oauth/start")async def start_memory_oauth(provider: str, profile: Optional[str] = None):"""Begin a provider's zero-CLI OAuth flow (browser + loopback listener); returns immediately, poll status."""- flow = _resolve_flow(provider)try:# The flow resolves its config path eagerly inside this scope; its worker thread outlives it.with _scope_to_profile(profile):+ flow = _resolve_flow(provider)return flow.start_loopback_flow_background()except HTTPException:raise@@ -65,9 +65,9 @@ async def start_memory_oauth(provider: str, profile: Optional[str] = None):@router.get("/{provider}/oauth/status")async def memory_oauth_status(provider: str, profile: Optional[str] = None):"""Poll a provider's OAuth flow: idle | pending | connected | error."""- flow = _resolve_flow(provider)try:with _scope_to_profile(profile):+ flow = _resolve_flow(provider)return flow.get_flow_status()except HTTPException:raisediff --git a/tests/hermes_cli/test_web_memory_user_dir_provider.py b/tests/hermes_cli/test_web_memory_user_dir_provider.pyindex 9fb83150987..4fb4d5cf110 100644--- a/tests/hermes_cli/test_web_memory_user_dir_provider.py+++ b/tests/hermes_cli/test_web_memory_user_dir_provider.py@@ -6,6 +6,7 @@ not a hard-coded ``plugins.memory.<name>`` import that only the bundled copy satimport jsonimport sysimport textwrap+from pathlib import Pathimport pytest@@ -87,3 +88,39 @@ def test_user_dir_provider_oauth_flow_resolves_from_its_directory(user_dir_honchassert flow.__file__ == str(user_dir_honcho / "oauth_flow.py")assert flow.start_loopback_flow_background()["state"] == "pending"+++def test_oauth_routes_load_the_provider_from_the_requested_profile(tmp_path, monkeypatch):+ """A desktop serving two homes must not import the launch home's OAuth flow for both."""+ import plugins.memory as memory_pkg+ from hermes_cli.web_server import _SESSION_HEADER_NAME, _SESSION_TOKEN, app+ from starlette.testclient import TestClient++ default_home = tmp_path / ".hermes"+ work_home = default_home / "profiles" / "work"+ work_home.mkdir(parents=True)+ (work_home / "profile.yaml").write_text("name: work\n", encoding="utf-8")+ monkeypatch.setattr(Path, "home", lambda: tmp_path)+ monkeypatch.setenv("HERMES_HOME", str(default_home))+ monkeypatch.setattr(memory_pkg, "_MEMORY_PLUGINS_DIR", tmp_path / "no-bundled")++ for home, label in ((default_home, "default"), (work_home, "work")):+ plugin_dir = home / "plugins" / "honcho"+ plugin_dir.mkdir(parents=True)+ (plugin_dir / "__init__.py").write_text('"""register_memory_provider"""\n', encoding="utf-8")+ (plugin_dir / "oauth_flow.py").write_text(+ "def get_flow_status():\n"+ f" return {{'state': 'idle', 'profile': {label!r}}}\n"+ "def start_loopback_flow_background():\n"+ f" return {{'state': 'pending', 'profile': {label!r}}}\n",+ encoding="utf-8",+ )++ client = TestClient(app, headers={_SESSION_HEADER_NAME: _SESSION_TOKEN})+ for profile in ("default", "work", "default"):+ status = client.get("/api/memory/providers/honcho/oauth/status", params={"profile": profile})+ assert status.status_code == 200, status.text+ assert status.json()["profile"] == profile+ start = client.post("/api/memory/providers/honcho/oauth/start", params={"profile": profile})+ assert start.status_code == 200, start.text+ assert start.json()["profile"] == profile