Skip to content

The agent that grows with you

test(agent): align safe-worker and azure-scope probes with main's env_loader and scoped reads

teknium1dbf401a10702
diff --git a/tests/agent/test_safe_worker_policy.py b/tests/agent/test_safe_worker_policy.py
index 987ce71366c..b116a355596 100644
--- a/tests/agent/test_safe_worker_policy.py
+++ b/tests/agent/test_safe_worker_policy.py
@@ -18,7 +18,7 @@ def run_worker(tmp_path, body, mode="safe"):
env.pop(key, None)
root = Path(__file__).resolve().parents[2]
script = home / "worker_probe.py"
- script.write_text(f"import sys; sys.path.insert(0, {str(root)!r})\n" + textwrap.dedent(body))
+ script.write_text(f"import sys; sys.path.insert(0, {str(root)!r})\n" + textwrap.dedent(body), encoding="utf-8")
result = subprocess.run(
[sys.executable, str(script)], env=env,
cwd=root, stdin=subprocess.DEVNULL,
@@ -47,7 +47,7 @@ def test_worker_config_is_frozen_before_any_profile_read(tmp_path, mode):
from hermes_cli.config import load_config, load_config_readonly, read_raw_config, read_raw_config_readonly, DEFAULT_CONFIG
from hermes_cli import env_loader
callbacks = []
- env_loader._apply_managed_env = lambda: callbacks.append("managed")
+ env_loader._apply_managed_env = lambda **kw: callbacks.append("managed")
env_loader._apply_external_secret_sources = lambda home: callbacks.append("secrets")
env_loader._reapply_terminal_config_bridge = lambda home: callbacks.append("terminal")
env_loader.load_hermes_dotenv()
diff --git a/tests/agent/test_secret_scope_tier1_migration.py b/tests/agent/test_secret_scope_tier1_migration.py
index 260273fa40b..7fdf46f35b1 100644
--- a/tests/agent/test_secret_scope_tier1_migration.py
+++ b/tests/agent/test_secret_scope_tier1_migration.py
@@ -243,12 +243,12 @@ class TestAzureIdentityPresence:
def test_scoped_client_secret_detected(self, monkeypatch):
describe = self._describe()
- monkeypatch.setenv("AZURE_CLIENT_ID", "cid")
- monkeypatch.setenv("AZURE_TENANT_ID", "tid")
- monkeypatch.delenv("AZURE_CLIENT_SECRET", raising=False)
- monkeypatch.delenv("AZURE_FEDERATED_TOKEN_FILE", raising=False)
+ # Every AZURE_* read is scoped: a served profile's env-borrowed client/tenant id is the
+ # launch profile's identity, so the whole service-principal triplet comes from the scope.
+ for name in ("AZURE_CLIENT_ID", "AZURE_TENANT_ID", "AZURE_CLIENT_SECRET", "AZURE_FEDERATED_TOKEN_FILE"):
+ monkeypatch.delenv(name, raising=False)
ss.set_multiplex_active(True)
- with _Scope({"AZURE_CLIENT_SECRET": "scoped-secret"}):
+ with _Scope({"AZURE_CLIENT_ID": "cid", "AZURE_TENANT_ID": "tid", "AZURE_CLIENT_SECRET": "scoped-secret"}):
info = describe(timeout_seconds=0.01, allow_install=False)
assert any("EnvironmentCredential" in s for s in info.get("env_sources", []))