From e371bf5d6826cb929587f1fb1d00a4618ea4a56c Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Thu, 28 May 2026 21:10:34 -0700 Subject: [PATCH] fix: re-export pruned names for tests that mock.patch or from-import them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The mechanical ruff prune in the previous commit removed several names that `appear` unused inside their defining module but are external test/runtime anchors: run_agent OpenAI, _SafeWriter get_tool_definitions, handle_function_call, check_toolset_requirements estimate_request_tokens_rough DEFAULT_AGENT_IDENTITY, build_context_files_prompt, build_environment_hints, build_nous_subscription_prompt _is_destructive_command, _extract_parallel_scope_path, _paths_overlap, _append_subdir_hint_to_multimodal, _trajectory_normalize_msg tools/web_tools Firecrawl, _get_firecrawl_client These get accessed via four channels that are invisible to ruff's in-module usage analysis: 1. `mock.patch('module.name', ...)` in tests — resolves the attribute lazily, so `pytest --collect-only` passes even when the name is gone, but every test using the patch fails at runtime with AttributeError. 2. `from run_agent import X` in production siblings (agent/transports /codex.py, etc.). 3. The `_ra().X` indirection pattern in agent/system_prompt.py et al. — explicitly documented ("Many tests patch('run_agent.load_soul_md')") to preserve the patch contract. 4. `from tools.web_tools import _get_firecrawl_client` in tests. Each re-added import carries an explicit `# noqa: F401` with a comment naming the channel, so future cleanup passes won't strip them again. --- run_agent.py | 20 +++++++++++++++++++- tools/web_tools.py | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/run_agent.py b/run_agent.py index f5834867a9c..d35857cc3f2 100644 --- a/run_agent.py +++ b/run_agent.py @@ -66,6 +66,8 @@ from hermes_constants import get_hermes_home # OpenAI lazy proxy + safe stdio + proxy URL helpers — see agent/process_bootstrap.py. # `OpenAI` is re-exported here so `patch("run_agent.OpenAI", ...)` in tests works. from agent.process_bootstrap import ( + OpenAI, # noqa: F401 # re-exported for tests that mock.patch("run_agent.OpenAI") + _SafeWriter, # noqa: F401 # re-exported for tests that `from run_agent import _SafeWriter` _get_proxy_for_base_url, ) from agent.iteration_budget import IterationBudget @@ -89,7 +91,10 @@ else: # Import our tool system from model_tools import ( + get_tool_definitions, # noqa: F401 # re-exported for tests that mock.patch("run_agent.get_tool_definitions") get_toolset_for_tool, + handle_function_call, # noqa: F401 # re-exported for tests that mock.patch("run_agent.handle_function_call") + check_toolset_requirements, # noqa: F401 # re-exported for tests that mock.patch("run_agent.check_toolset_requirements") ) from tools.terminal_tool import cleanup_vm from tools.interrupt import set_interrupt as _set_interrupt @@ -101,13 +106,21 @@ from agent.memory_manager import sanitize_context from agent.error_classifier import FailoverReason from agent.redact import redact_sensitive_text from agent.model_metadata import ( + estimate_request_tokens_rough, # noqa: F401 # re-exported for tests that mock.patch("run_agent.estimate_request_tokens_rough") is_local_endpoint, ) from agent.usage_pricing import normalize_usage # Re-exported for tests that monkeypatch these symbols on run_agent. from agent.context_compressor import ContextCompressor # noqa: F401 from agent.retry_utils import jittered_backoff # noqa: F401 -from agent.prompt_builder import build_skills_system_prompt, load_soul_md # noqa: F401 +from agent.prompt_builder import ( # noqa: F401 # re-exported via _ra() / mock.patch("run_agent.") / from run_agent import + DEFAULT_AGENT_IDENTITY, + build_skills_system_prompt, + build_context_files_prompt, + build_environment_hints, + build_nous_subscription_prompt, + load_soul_md, +) from agent.process_bootstrap import _get_proxy_from_env # noqa: F401 from agent.message_sanitization import ( # noqa: F401 _SURROGATE_RE, @@ -143,10 +156,15 @@ from agent.trajectory import ( ) from agent.tool_dispatch_helpers import ( _should_parallelize_tool_batch, + _is_destructive_command, # noqa: F401 # re-exported for tests that access `run_agent._is_destructive_command` + _extract_parallel_scope_path, # noqa: F401 # re-exported for tests that `from run_agent import _extract_parallel_scope_path` + _paths_overlap, # noqa: F401 # re-exported for tests that `from run_agent import _paths_overlap` _is_multimodal_tool_result, _multimodal_text_summary, + _append_subdir_hint_to_multimodal, # noqa: F401 # re-exported for tests that `from run_agent import _append_subdir_hint_to_multimodal` _extract_file_mutation_targets, _extract_error_preview, + _trajectory_normalize_msg, # noqa: F401 # re-exported for tests that `from run_agent import _trajectory_normalize_msg` ) from utils import atomic_json_write, base_url_host_matches, base_url_hostname diff --git a/tools/web_tools.py b/tools/web_tools.py index 33dbd39c9e6..36440b97844 100644 --- a/tools/web_tools.py +++ b/tools/web_tools.py @@ -51,7 +51,9 @@ import httpx # noqa: F401 — kept at module top so tests can patch tools.web_t if TYPE_CHECKING: from firecrawl import Firecrawl # noqa: F401 — type hints only from plugins.web.firecrawl.provider import ( + Firecrawl, # noqa: F401 # re-exported for tests that mock.patch("tools.web_tools.Firecrawl") _firecrawl_backend_help_suffix, + _get_firecrawl_client, # noqa: F401 # re-exported for tests that `from tools.web_tools import _get_firecrawl_client` _get_firecrawl_gateway_url, _is_tool_gateway_ready, check_firecrawl_api_key,