From e443d327181a4dd2eb4dd7db0b410e9cd7b3b4a9 Mon Sep 17 00:00:00 2001 From: ehz0ah Date: Mon, 3 Aug 2026 15:07:17 +0800 Subject: [PATCH] test(retaindb): guard scoped secret config resolution --- plugins/memory/retaindb/__init__.py | 3 +- .../plugins/memory/test_retaindb_provider.py | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/plugins/memory/retaindb/__init__.py b/plugins/memory/retaindb/__init__.py index 9c24d4d334..f65d5018be 100644 --- a/plugins/memory/retaindb/__init__.py +++ b/plugins/memory/retaindb/__init__.py @@ -49,7 +49,8 @@ def _load_retaindb_config() -> Dict[str, Any]: Non-secret fields (``base_url``, ``project``) are persisted here by the Dashboard; the runtime must read them back when the matching env var is - unset. The secret ``api_key`` continues to come from the environment. + unset. The secret ``api_key`` continues to come through profile-scoped + secret resolution rather than config.yaml. """ try: from hermes_cli.config import load_config_readonly diff --git a/tests/plugins/memory/test_retaindb_provider.py b/tests/plugins/memory/test_retaindb_provider.py index 9fede04e8c..0372edaefd 100644 --- a/tests/plugins/memory/test_retaindb_provider.py +++ b/tests/plugins/memory/test_retaindb_provider.py @@ -141,6 +141,41 @@ def test_initialize_env_overrides_config_yaml(tmp_path, monkeypatch): assert captured["base_url"] == "https://env.example.com" +def test_initialize_combines_scoped_secret_with_dashboard_config(tmp_path, monkeypatch): + """Rebase regression: scoped secrets and non-secret config must coexist.""" + from agent.secret_scope import ( + is_multiplex_active, + reset_secret_scope, + set_multiplex_active, + set_secret_scope, + ) + + monkeypatch.setenv("RETAINDB_API_KEY", "env-other-profile") + monkeypatch.delenv("RETAINDB_BASE_URL", raising=False) + monkeypatch.delenv("RETAINDB_PROJECT", raising=False) + retaindb_module, captured = _capture_initialized_client(monkeypatch, tmp_path) + monkeypatch.setattr( + retaindb_module, + "_load_retaindb_config", + lambda: {"base_url": "https://dashboard.example.com/", "project": "dashboard-project"}, + ) + + previous_multiplex_state = is_multiplex_active() + set_multiplex_active(True) + token = set_secret_scope({"RETAINDB_API_KEY": "scoped-key"}) + try: + RetainDBMemoryProvider().initialize("sess-1") + finally: + reset_secret_scope(token) + set_multiplex_active(previous_multiplex_state) + + assert captured == { + "api_key": "scoped-key", + "base_url": "https://dashboard.example.com", + "project": "dashboard-project", + } + + def test_initialize_falls_back_to_default_base_url(tmp_path, monkeypatch): for var in ("RETAINDB_API_KEY", "RETAINDB_BASE_URL", "RETAINDB_PROJECT"): monkeypatch.delenv(var, raising=False)