chore: prune unused imports and duplicate import redefinitions
Remove unused imports (F401) and duplicate/shadowed import redefinitions (F811) across the codebase using ruff's safe autofixes. No behavioral changes -- imports only. - ~1400 safe autofixes applied across 644 files (net -1072 lines) - __init__.py re-exports preserved (excluded from F401 removal so public re-export surfaces stay intact) - Re-exports that are imported or monkeypatched by tests but look unused in their defining module are kept with explicit # noqa: F401 (gateway/run.py load_dotenv; run_agent re-exports from agent.message_sanitization, agent.context_compressor, agent.retry_utils, agent.prompt_builder, agent.process_bootstrap, agent.codex_responses_adapter) - Unsafe F841 (unused-variable) fixes deliberately skipped -- those can change behavior when the RHS has side effects - ruff lints remain disabled in pyproject.toml (only PLW1514 is selected); this is a one-time cleanup, not a config change Verification: - python -m compileall: clean - pytest --collect-only: all 27161 tests collect (zero import errors) - core entry points import clean (run_agent, model_tools, cli, toolsets, hermes_state, batch_runner, gateway) - static scan: every name any test imports directly from an edited module still resolves
This commit is contained in:
@@ -8,8 +8,6 @@ Verifies that:
|
||||
3. Context-overflow failures produce helpful error messages suggesting /compact.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
|
||||
|
||||
@@ -11,11 +11,9 @@ import pytest
|
||||
|
||||
|
||||
|
||||
import uuid
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from agent.context_compressor import SUMMARY_PREFIX
|
||||
from run_agent import AIAgent
|
||||
|
||||
@@ -7,14 +7,11 @@ Verifies that:
|
||||
4. The gateway doesn't double-write messages the agent already persisted
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import sqlite3
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -4,7 +4,7 @@ Closes #11616 — make the hardcoded ``max_retries = 3`` in the agent's API
|
||||
retry loop user-configurable so fallback-provider setups can fail over
|
||||
faster on flaky primaries instead of burning ~3x180s on the same stall.
|
||||
"""
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import patch
|
||||
|
||||
from run_agent import AIAgent
|
||||
|
||||
|
||||
@@ -13,8 +13,6 @@ The three-layer defence:
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import threading
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -13,7 +13,6 @@ runtime via a thread-local whitelist on the existing
|
||||
that caused the prefix-cache miss.
|
||||
"""
|
||||
|
||||
import threading
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
|
||||
@@ -26,9 +26,8 @@ Covered:
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from types import SimpleNamespace
|
||||
from typing import cast
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import types
|
||||
from types import SimpleNamespace
|
||||
from typing import Any, Dict, List
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -31,7 +31,7 @@ Three distinct failure modes the user community hit during rollout:
|
||||
"""
|
||||
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -500,7 +500,6 @@ def test_recover_with_credential_pool_skips_refresh_on_entitlement_403():
|
||||
the entitlement guard, recovery returns False so the error surfaces
|
||||
normally with the friendly hint from _summarize_api_error.
|
||||
"""
|
||||
from run_agent import AIAgent
|
||||
from agent.error_classifier import FailoverReason
|
||||
|
||||
agent = _make_codex_agent()
|
||||
@@ -590,7 +589,6 @@ def test_recover_with_credential_pool_skips_refresh_on_bare_403_for_xai_oauth():
|
||||
|
||||
def test_recover_with_credential_pool_still_refreshes_genuine_auth_failure():
|
||||
"""Regression guard: legitimate auth errors must still trigger refresh."""
|
||||
from run_agent import AIAgent
|
||||
from agent.error_classifier import FailoverReason
|
||||
|
||||
agent = _make_codex_agent()
|
||||
@@ -772,7 +770,6 @@ def test_recover_with_credential_pool_refreshes_on_xai_bad_credentials_403():
|
||||
the very body that pre-fix tripped the entitlement classifier
|
||||
and short-circuited the refresh path.
|
||||
"""
|
||||
from run_agent import AIAgent
|
||||
from agent.error_classifier import FailoverReason
|
||||
|
||||
agent = _make_codex_agent()
|
||||
@@ -829,7 +826,6 @@ def test_recover_with_credential_pool_still_blocks_real_entitlement():
|
||||
survive the new disambiguator. A real unsubscribed-account body
|
||||
has no WKE suffix and no OAuth2-validation phrase, so the
|
||||
classifier still classifies it as entitlement and short-circuits."""
|
||||
from run_agent import AIAgent
|
||||
from agent.error_classifier import FailoverReason
|
||||
|
||||
agent = _make_codex_agent()
|
||||
|
||||
@@ -9,7 +9,6 @@ on older plugins.
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from run_agent import AIAgent
|
||||
|
||||
|
||||
@@ -4,8 +4,7 @@ Verifies that _align_boundary_backward correctly handles tool result groups
|
||||
so that parallel tool calls are never split during compression.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock
|
||||
from unittest.mock import patch
|
||||
|
||||
from agent.context_compressor import ContextCompressor
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import tempfile
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
class TestCompressionBoundaryHook:
|
||||
|
||||
@@ -19,9 +19,8 @@ Bug scenario (pre-fix):
|
||||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -6,8 +6,6 @@ trigger must use only prompt_tokens so sessions aren't prematurely split.
|
||||
"""
|
||||
|
||||
import types
|
||||
import pytest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
|
||||
def _make_agent_stub(prompt_tokens, completion_tokens, threshold_tokens):
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
"""Tests for interrupt handling in concurrent tool execution."""
|
||||
|
||||
import concurrent.futures
|
||||
import threading
|
||||
import time
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ That is the exact scenario this test reproduces at object level without a
|
||||
network, so it runs in CI on every PR.
|
||||
"""
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import patch
|
||||
|
||||
from run_agent import AIAgent
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
When has_retried_429 is lost (user cancels between 429s), the pool should
|
||||
still rotate if the current credential is already marked exhausted.
|
||||
"""
|
||||
import pytest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from agent.credential_pool import PooledCredential, STATUS_EXHAUSTED
|
||||
|
||||
@@ -6,9 +6,7 @@ abort remaining cleanup steps. These tests exercise the actual production
|
||||
code paths — not a copy of the try/except pattern.
|
||||
"""
|
||||
|
||||
import atexit
|
||||
import weakref
|
||||
from unittest.mock import MagicMock, patch, call
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -11,13 +11,9 @@ _swap_credential continue operating on the PRIMARY's credential pool during
|
||||
fallback calls, contaminating primary state with fallback-provider errors.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import sys
|
||||
import types
|
||||
from dataclasses import dataclass, replace
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
# ── Helpers ──────────────────────────────────────────────────────────
|
||||
|
||||
@@ -18,9 +18,7 @@ payload rewriter.
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from agent.error_classifier import FailoverReason, classify_api_error
|
||||
|
||||
|
||||
@@ -8,9 +8,6 @@ Logs every step to stderr (which isn't affected by redirect_stdout)
|
||||
so we can see exactly where the interrupt gets lost.
|
||||
"""
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import json
|
||||
import logging
|
||||
import queue
|
||||
import sys
|
||||
@@ -27,7 +24,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspa
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
from run_agent import AIAgent, IterationBudget
|
||||
from tools.interrupt import set_interrupt, is_interrupted
|
||||
from tools.interrupt import set_interrupt
|
||||
|
||||
def make_slow_response(delay=2.0):
|
||||
"""API response that takes a while."""
|
||||
|
||||
@@ -4,13 +4,12 @@ Reproduces the CLI scenario: user sends a message while delegate_task is
|
||||
running, main thread calls parent.interrupt(), child should stop.
|
||||
"""
|
||||
|
||||
import json
|
||||
import threading
|
||||
import time
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch, PropertyMock
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from tools.interrupt import set_interrupt, is_interrupted, _interrupt_event
|
||||
from tools.interrupt import set_interrupt, is_interrupted
|
||||
|
||||
|
||||
class TestInterruptPropagationToChild(unittest.TestCase):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Tests that invalid context_length values in config produce visible warnings."""
|
||||
|
||||
from unittest.mock import patch, MagicMock, call
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
def _build_agent(model_cfg, custom_providers=None, model="anthropic/claude-opus-4.6"):
|
||||
|
||||
@@ -3,11 +3,8 @@
|
||||
The `used` property must acquire the lock before reading `_used` to prevent
|
||||
data races with concurrent `consume()` / `refund()` calls.
|
||||
"""
|
||||
import threading
|
||||
import time
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def test_iteration_budget_used_is_thread_safe():
|
||||
|
||||
@@ -8,9 +8,7 @@ reduce context_length to 200k and compress instead of retrying.
|
||||
Only Sonnet is affected — Opus 1M is general access.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -25,7 +25,6 @@ See: https://github.com/NousResearch/hermes-agent/issues/27344
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from agent.error_classifier import FailoverReason, classify_api_error
|
||||
|
||||
|
||||
@@ -10,10 +10,8 @@ Verifies that:
|
||||
"""
|
||||
|
||||
import time
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, patch, PropertyMock
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from run_agent import AIAgent
|
||||
|
||||
|
||||
@@ -4,12 +4,10 @@ and handles responses properly for all supported providers.
|
||||
Ensures changes to one provider path don't silently break another.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import types
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch, MagicMock
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from agent.codex_responses_adapter import _chat_content_to_responses_parts, _chat_messages_to_responses_input, _normalize_codex_response, _preflight_codex_input_items
|
||||
|
||||
@@ -4,14 +4,13 @@ This uses a real AIAgent with mocked HTTP responses to test the complete
|
||||
interrupt flow through _run_single_child → child.run_conversation().
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch, PropertyMock
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from tools.interrupt import set_interrupt, is_interrupted
|
||||
from tools.interrupt import set_interrupt
|
||||
|
||||
|
||||
def _make_slow_api_response(delay=5.0):
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""Tests for _repair_tool_call_arguments — malformed JSON repair pipeline."""
|
||||
|
||||
import json
|
||||
import pytest
|
||||
|
||||
from run_agent import _repair_tool_call_arguments
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ silently dropped.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from run_agent import AIAgent
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from types import SimpleNamespace
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from agent.codex_responses_adapter import _chat_messages_to_responses_input, _normalize_codex_response, _preflight_codex_input_items
|
||||
from agent.codex_responses_adapter import _normalize_codex_response
|
||||
|
||||
import run_agent
|
||||
from run_agent import AIAgent
|
||||
@@ -4630,7 +4630,6 @@ class TestSafeWriter:
|
||||
|
||||
def test_double_wrap_prevented(self):
|
||||
"""Wrapping an already-wrapped stream doesn't add layers."""
|
||||
import sys
|
||||
from run_agent import _SafeWriter
|
||||
from io import StringIO
|
||||
inner = StringIO()
|
||||
|
||||
@@ -6,8 +6,6 @@ _sanitize_api_messages() and the CLI session-restore paths.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import types
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from run_agent import AIAgent
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import sys
|
||||
import types
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
# Ensure repo root is importable
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent))
|
||||
|
||||
@@ -281,7 +281,7 @@ class TestSteerCommandRegistry:
|
||||
"""The /steer slash command must be registered so it reaches all
|
||||
platforms (CLI, gateway, TUI autocomplete, Telegram/Slack menus).
|
||||
"""
|
||||
from hermes_cli.commands import resolve_command, ACTIVE_SESSION_BYPASS_COMMANDS
|
||||
from hermes_cli.commands import resolve_command
|
||||
|
||||
cmd = resolve_command("steer")
|
||||
assert cmd is not None
|
||||
|
||||
@@ -21,9 +21,7 @@ import logging
|
||||
import time
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
import run_agent
|
||||
from run_agent import AIAgent
|
||||
|
||||
|
||||
|
||||
@@ -3,11 +3,8 @@
|
||||
Tests the unified streaming API call, delta callbacks, tool-call
|
||||
suppression, provider fallback, and CLI streaming display.
|
||||
"""
|
||||
import json
|
||||
import threading
|
||||
import uuid
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, patch, PropertyMock
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ unclosed brackets, Python None) don't kill the session.
|
||||
"""
|
||||
|
||||
import json
|
||||
import pytest
|
||||
|
||||
from run_agent import _repair_tool_call_arguments
|
||||
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
import sys
|
||||
import types
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
sys.modules.setdefault("fire", types.SimpleNamespace(Fire=lambda *a, **k: None))
|
||||
sys.modules.setdefault("firecrawl", types.SimpleNamespace(Firecrawl=object))
|
||||
|
||||
@@ -6,7 +6,6 @@ final displayed assistant text (after streaming) without depending on the
|
||||
AIAgent instance. It must stay in sync with run_agent.py::_strip_think_blocks
|
||||
for tool-call tag coverage."""
|
||||
|
||||
import pytest
|
||||
|
||||
from cli import _strip_reasoning_tags
|
||||
|
||||
|
||||
@@ -26,9 +26,8 @@ import logging
|
||||
import socket as _socket
|
||||
import threading
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -185,7 +184,6 @@ def test_close_from_stranger_thread_aborts_only_no_close():
|
||||
the worker's eventual ``finally`` must still see the client in the
|
||||
holder so IT can be the one releasing the FD.
|
||||
"""
|
||||
from agent.chat_completion_helpers import interruptible_api_call
|
||||
|
||||
# We can't easily invoke just `_close_request_client_once` because it's
|
||||
# a closure local to ``interruptible_api_call``. Re-extract the same
|
||||
|
||||
@@ -6,7 +6,6 @@ coerce_tool_args() fixes these type mismatches by comparing argument values
|
||||
against the tool's JSON Schema before dispatch.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from unittest.mock import patch
|
||||
|
||||
from model_tools import (
|
||||
|
||||
@@ -15,7 +15,6 @@ from __future__ import annotations
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from run_agent import AIAgent
|
||||
|
||||
|
||||
Reference in New Issue
Block a user