The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(left-core): test the runtime install wiring; skip re-reads after this process's attempt
Tekniumc574ab413f23
diff --git a/hermes_cli/left_core_migration.py b/hermes_cli/left_core_migration.pyindex 3d0e0dc1c4c..02f5a0594f4 100644--- a/hermes_cli/left_core_migration.py+++ b/hermes_cli/left_core_migration.py@@ -507,9 +507,11 @@ def recover_for_provider(name: Optional[str]) -> None:feature = _provider_feature(name or "")if feature is None:return- from hermes_constants import get_hermes_home+ from hermes_constants import get_hermes_home, hermes_home_keyfrom providers import get_provider_profilehome = Path(get_hermes_home())+ if hermes_home_key(home) in _attempted: # this process already tried: skip the config/auth/.env reads+ returnif plugin_present(feature.plugin, home) or get_provider_profile(str(name).strip().lower()) is not None:returnif feature.in_use(home, process_env=True):diff --git a/tests/hermes_cli/test_left_core_provider_rows.py b/tests/hermes_cli/test_left_core_provider_rows.pyindex 4ac1232b6cd..a032e595c58 100644--- a/tests/hermes_cli/test_left_core_provider_rows.py+++ b/tests/hermes_cli/test_left_core_provider_rows.py@@ -120,13 +120,6 @@ def test_gh_only_home_is_told_to_log_in_on_every_migration_outcome(tmp_path):assert "could not be installed automatically" in said[0] and "run `hermes auth add copilot`" in said[0]-def test_token_home_gets_the_plain_success_line(tmp_path):- home = _home(tmp_path, config="model:\n provider: copilot\n", env="COPILOT_GITHUB_TOKEN=gho_x\n")- said = []- lcm.migrate_home(home, install=lambda name: {"ok": True}, say=said.append)- assert "COPILOT_GITHUB_TOKEN / GH_TOKEN / GITHUB_TOKEN" in said[0] and "to sign in" not in said[0]--# ── generic seams through a fake row ─────────────────────────────────────────────────────────────@@ -181,19 +174,6 @@ def test_profile_env_is_refused_by_env_writers_only_while_the_plugin_is_absent(avalidate_env_var_name_for_write("ACME_CLI_PATH")-def test_copilot_row_keeps_the_env_core_kept(monkeypatch):- """Static, before discovery: the profile-managed scrub and `hermes config set` keep knowing the names,- and the token/base-URL overrides stay out of children (Tier 2) with no Copilot profile registered."""- from hermes_cli.config import _EXTRA_ENV_KEYS- from hermes_cli.env_loader import _PROFILE_MANAGED_ENV_KEYS- from tools.environments.local_env_policy import _left_core_env- names = {"HERMES_COPILOT_ACP_COMMAND", "HERMES_COPILOT_ACP_ARGS", "COPILOT_CLI_PATH", "COPILOT_ACP_BASE_URL"}- assert names <= _PROFILE_MANAGED_ENV_KEYS and names <= _EXTRA_ENV_KEYS- assert {"COPILOT_GITHUB_TOKEN", "COPILOT_API_BASE_URL"} <= _left_core_env(secrets_only=False)- assert not {"GH_TOKEN", "GITHUB_TOKEN"} & set(next(f for f in lcm.LEFT_CORE if f.plugin == "github-copilot")- .private_env)--def test_models_dev_never_stands_in_for_a_provider_whose_plugin_left_core(acme_row, monkeypatch):"""models.dev lists the vendor's endpoint under the same id: resolving it there would send the user'sraw token to that endpoint through a generic client the plugin never was."""diff --git a/tests/hermes_cli/test_left_core_provider_runtime.py b/tests/hermes_cli/test_left_core_provider_runtime.pynew file mode 100644index 00000000000..76370778787--- /dev/null+++ b/tests/hermes_cli/test_left_core_provider_runtime.py@@ -0,0 +1,90 @@+"""Runtime wiring of the ``LEFT_CORE`` provider rows: the real ``resolve_runtime_provider`` installs the+plugin of a provider that left core for a home that uses it, once per process, honouring the failure+backoff and ``security.allow_lazy_installs``.++Real config files under a temp ``HERMES_HOME``; the catalog lookup and the network install are stand-ins.+"""++from __future__ import annotations++from pathlib import Path++import pytest++import hermes_cli.left_core_migration as lcm++[email protected](autouse=True)+def _fresh(monkeypatch):+ monkeypatch.setattr(lcm, "_attempted", set())+ monkeypatch.setattr(lcm, "_undelivered", {})+ for name in ("HERMES_INFERENCE_PROVIDER", "COPILOT_GITHUB_TOKEN", "GH_TOKEN", "GITHUB_TOKEN"):+ monkeypatch.delenv(name, raising=False)+ import hermes_cli.memory_provider_migration as mpm+ monkeypatch.setattr(mpm, "catalog_source", lambda name: name) # never the network+++def installs(monkeypatch):+ calls = []++ def fake_install(identifier, *, force, enable, catalog_name=None, assume_deps_consent=None, **kw):+ calls.append((catalog_name, assume_deps_consent))+ return {"ok": False, "error": "fatal: unable to access the catalog repo"}+ import hermes_cli.plugins_cmd as pc+ monkeypatch.setattr(pc, "dashboard_install_plugin", fake_install)+ monkeypatch.delenv("HERMES_DISABLE_LAZY_INSTALLS", raising=False) # the harness's bridge; config decides+ return calls+++def _copilot_home(tmp_path: Path, monkeypatch, config: str = "model:\n provider: copilot\n") -> Path:+ home = tmp_path / "home"+ home.mkdir()+ (home / "config.yaml").write_text(config, encoding="utf-8")+ monkeypatch.setenv("HERMES_HOME", str(home))+ return home+++def _resolve(**kw):+ from hermes_cli.auth import AuthError+ from hermes_cli.runtime_provider import resolve_runtime_provider+ with pytest.raises(AuthError): # the install failed: still an unknown provider, with the hint+ resolve_runtime_provider(**kw)+++def test_runtime_resolution_installs_once_per_process_and_honours_the_backoff(tmp_path, monkeypatch, installs):+ _copilot_home(tmp_path, monkeypatch)+ for _ in range(3):+ _resolve()+ assert installs == [("github-copilot", True)]+ monkeypatch.setattr(lcm, "_attempted", set()) # a second process inside the failure backoff+ _resolve()+ assert len(installs) == 1+++def test_runtime_resolution_without_lazy_installs_fetches_nothing(tmp_path, monkeypatch, installs):+ _copilot_home(tmp_path, monkeypatch,+ "model:\n provider: copilot\nsecurity:\n allow_lazy_installs: false\n")+ _resolve()+ assert installs == []+++def test_a_failed_attempt_is_not_rechecked_on_every_resolution(tmp_path, monkeypatch, installs):+ """After this process's attempt, a resolution of the provider costs a set lookup, not a re-read of the+ home's config, jobs, auth store and .env."""+ _copilot_home(tmp_path, monkeypatch)+ feature = next(f for f in lcm.LEFT_CORE if f.plugin == "github-copilot")+ calls = []++ def counted(home, **kw):+ calls.append(home)+ return lcm.copilot_in_use(home, **kw)+ from dataclasses import replace+ monkeypatch.setattr(lcm, "LEFT_CORE", tuple(replace(f, in_use=counted) if f is feature else f+ for f in lcm.LEFT_CORE))+ lcm.recover_for_provider("copilot")+ first = len(calls)+ for _ in range(5):+ lcm.recover_for_provider("copilot")+ assert len(calls) == first+