test(retaindb): guard scoped secret config resolution

This commit is contained in:
ehz0ah
2026-08-03 15:07:17 +08:00
committed by kshitij
parent 8fb9c3b3e3
commit e443d32718
2 changed files with 37 additions and 1 deletions
+2 -1
View File
@@ -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
@@ -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)