Skip to content

The agent that grows with you

test: stop provider-registry fixtures leaking the list cache and picker rows

Teknium9ad5a6270849
diff --git a/tests/agent/test_account_usage_fetch.py b/tests/agent/test_account_usage_fetch.py
index a207b96847d..818159e0c85 100644
--- a/tests/agent/test_account_usage_fetch.py
+++ b/tests/agent/test_account_usage_fetch.py
@@ -123,6 +123,7 @@ def _register_profile(monkeypatch, profile):
monkeypatch.setattr(providers, "_REGISTRY", dict(providers._REGISTRY))
monkeypatch.setattr(providers, "_ALIASES", dict(providers._ALIASES))
+ monkeypatch.setattr(providers, "_PROVIDER_LIST_CACHE", None) # else the fixture profile outlives the test
providers.register_provider(profile)
diff --git a/tests/agent/test_models_dev_provider_capabilities.py b/tests/agent/test_models_dev_provider_capabilities.py
index f01f0085a8f..2de68248721 100644
--- a/tests/agent/test_models_dev_provider_capabilities.py
+++ b/tests/agent/test_models_dev_provider_capabilities.py
@@ -9,8 +9,22 @@ from agent import models_dev
def _isolated_registry(monkeypatch, catalog=None):
+ # A post-discovery registration mirrors the profile into the picker catalog; keep that scoped too.
+ # Both imported before any patch: the catalog's import-time sync must see the real registry, and
+ # hermes_cli.models must bind the real list so the undo restores it.
+ import hermes_cli.models as hm
+ import hermes_cli.models_catalog_static as static
+ monkeypatch.setattr(static, "CANONICAL_PROVIDERS", list(static.CANONICAL_PROVIDERS))
+ monkeypatch.setattr(static, "_canonical_slugs", set(static._canonical_slugs))
+ monkeypatch.setattr(static, "_PROVIDER_LABELS", dict(static._PROVIDER_LABELS))
+ monkeypatch.setattr(hm, "CANONICAL_PROVIDERS", static.CANONICAL_PROVIDERS)
+ monkeypatch.setattr(hm, "_PROVIDER_LABELS", static._PROVIDER_LABELS)
monkeypatch.setattr(providers, "_REGISTRY", {})
monkeypatch.setattr(providers, "_ALIASES", {})
+ # The list cache is filled from the swapped-in registry; without its own patch it outlives the
+ # test and later list_providers() calls see only the fixture profile (hidden ones go unfiltered).
+ monkeypatch.setattr(providers, "_PROVIDER_LIST_CACHE", None)
+ monkeypatch.setattr(providers, "_SOURCES", {})
monkeypatch.setattr(providers, "_discovered", True)
monkeypatch.setattr(models_dev, "_registry_models", lambda *a, **k: catalog)