2a95791992
run_agent.py: delete the `# noqa: F401` re-export block (agent.process_bootstrap
OpenAI/_SafeWriter/_get_proxy_*, model_tools get_tool_definitions/
handle_function_call/check_toolset_requirements, FailoverReason,
_qwen_portal_headers/_routermint_headers, session_persistence names,
estimate_request_tokens_rough, ContextCompressor + friends, jittered_backoff,
prompt_builder names, message_sanitization names, tool_dispatch_helpers
names) — 41 names run_agent never used itself — and the `_STREAM_DIAG_HEADERS`
back-compat class alias (no in-tree reader). run_agent now imports only what
it uses (get_toolset_for_tool, is_local_endpoint, coalesce/uniquify tool-call
ids, cleanup_vm/get_active_env from terminal_tool_lifecycle).
agent/*: `_ra().X` late-binds that only reached a re-export now import the
defining module directly (agent_runtime_helpers -> process_bootstrap.OpenAI,
model_tools.handle_function_call, session_persistence._safe_session_filename_component;
agent_init -> model_tools.get_tool_definitions/check_toolset_requirements,
_lazy_headers("agent.client_lifecycle", ...) for qwen/routermint;
system_prompt -> agent.prompt_builder / model_tools directly, dropping its
own _ra() shim and the `_r` parameter threading). `_ra()` stays for
run_agent-resident names (logger, AIAgent, _hermes_home, _set_interrupt, ...).
toolsets.py: remove resolve_multiple_toolsets (shim-only, restored by
34abf954bd); tests/test_toolsets.py pins the same union behavior via
resolve_toolset over each name.
providers/__init__.py: drop the OMIT_TEMPERATURE re-export (no callers via the
package); ProviderProfile stays because __init__ uses it for annotations —
2 tests repointed to providers.base.
agent/iteration_budget.py: drop the "run_agent re-exports the class"
docstring pointer; 4 tests import IterationBudget from its home.
model_tools.py (arg_coercion names), agent/tool_executor.py, and
hermes_cli/cli_session_mixin.py repoints landed via a sibling commit on this
shared worktree.
Callers repointed: gateway/run.py, hermes_cli/cli_chat_turn_mixin.py,
hermes_cli/cli_tui_mixin.py, tui_gateway/session_workdir.py,
agent/transports/codex.py (one-line imports) + comment pointers in
tools/file_state.py, tools/schema_sanitizer.py, scripts/tool_search_livetest.py.
Tests: patch("run_agent.X") / monkeypatch.setattr(run_agent, "X") /
`from run_agent import X` -> defining module across 99 test files.
67 lines
1.8 KiB
Python
67 lines
1.8 KiB
Python
import pytest
|
|
|
|
from providers.base import ProviderProfile
|
|
import providers
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def isolate_provider_registry():
|
|
registry = providers._REGISTRY.copy()
|
|
aliases = providers._ALIASES.copy()
|
|
provider_list_cache = (
|
|
None
|
|
if providers._PROVIDER_LIST_CACHE is None
|
|
else list(providers._PROVIDER_LIST_CACHE)
|
|
)
|
|
discovered = providers._discovered
|
|
|
|
yield
|
|
|
|
providers._REGISTRY.clear()
|
|
providers._REGISTRY.update(registry)
|
|
providers._ALIASES.clear()
|
|
providers._ALIASES.update(aliases)
|
|
providers._PROVIDER_LIST_CACHE = provider_list_cache
|
|
providers._discovered = discovered
|
|
|
|
|
|
def _profile(name: str, *aliases: str) -> ProviderProfile:
|
|
return ProviderProfile(name=name, aliases=aliases)
|
|
|
|
|
|
def _reset_registry() -> None:
|
|
providers._REGISTRY.clear()
|
|
providers._ALIASES.clear()
|
|
providers._PROVIDER_LIST_CACHE = None
|
|
providers._discovered = True
|
|
|
|
|
|
def test_list_providers_reuses_cached_snapshot_until_registration_changes():
|
|
_reset_registry()
|
|
first = _profile("alpha")
|
|
providers.register_provider(first)
|
|
|
|
listed = providers.list_providers()
|
|
listed.clear()
|
|
|
|
assert providers.list_providers() == [first]
|
|
|
|
# Hit-path copy guard: mutating a CACHED return must not corrupt the
|
|
# module-level snapshot for later callers (aliasing bug class).
|
|
providers.list_providers().clear()
|
|
assert providers.list_providers() == [first]
|
|
|
|
second = _profile("beta")
|
|
providers.register_provider(second)
|
|
|
|
assert providers.list_providers() == [first, second]
|
|
|
|
|
|
def test_list_providers_dedupes_aliases_in_cached_snapshot():
|
|
_reset_registry()
|
|
profile = _profile("kimi", "moonshot", "kimi-k2")
|
|
providers.register_provider(profile)
|
|
|
|
assert providers.get_provider_profile("moonshot") is profile
|
|
assert providers.list_providers() == [profile]
|