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:
kshitijk4poor 2026-05-29 02:04:58 +05:30 committed by Teknium
parent a4d8f0f62a
commit 66827f8947
644 changed files with 254 additions and 1326 deletions

View file

@ -10,10 +10,8 @@ Verifies that:
"""
import os
import uuid
from datetime import datetime
from pathlib import Path
from unittest.mock import MagicMock, patch, PropertyMock
from unittest.mock import MagicMock
import pytest

View file

@ -4,11 +4,8 @@ Ensures the TUI is properly refreshed before printing background task output
to prevent spinner/status bar overlap (#2718).
"""
import threading
from types import SimpleNamespace
from unittest.mock import MagicMock, patch
import pytest
from cli import HermesCLI

View file

@ -1,9 +1,6 @@
"""Tests for _detect_file_drop — file path detection that prevents
dragged/pasted absolute paths from being mistaken for slash commands."""
import os
import tempfile
from pathlib import Path
import pytest

View file

@ -12,7 +12,6 @@ minimal ``HermesCLI`` stub (pattern used elsewhere in tests/cli).
from __future__ import annotations
import queue
import sys
import uuid
from pathlib import Path
from unittest.mock import MagicMock, patch

View file

@ -10,15 +10,12 @@ This tests the COMPLETE path including _run_single_child, _active_children
registration, interrupt propagation, and child detection.
"""
import json
import os
import queue
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
class TestCLISubagentInterrupt(unittest.TestCase):

View file

@ -8,7 +8,6 @@ before the terminal query, which is the path most users hit.
from __future__ import annotations
import importlib
import pytest

View file

@ -568,7 +568,6 @@ class TestStatusBarWidthSource:
"""Ensure status bar fragments don't overflow the terminal width."""
def _make_wide_cli(self):
from datetime import datetime, timedelta
cli_obj = _attach_agent(
_make_cli(),
prompt_tokens=100_000,

View file

@ -1,6 +1,6 @@
"""Tests for /tools slash command handler in the interactive CLI."""
from unittest.mock import MagicMock, patch, call
from unittest.mock import MagicMock, patch
from cli import HermesCLI

View file

@ -6,8 +6,6 @@ Rules:
- Non-local with explicit path: keep as-is.
"""
import os
import pytest
_CWD_PLACEHOLDERS = (".", "auto", "cwd")

View file

@ -1,6 +1,6 @@
"""Tests for /personality none — clearing personality overlay."""
import pytest
from unittest.mock import MagicMock, patch, mock_open
from unittest.mock import MagicMock, patch
import yaml

View file

@ -1,7 +1,7 @@
"""Tests for user-defined quick commands that bypass the agent loop."""
import os
import subprocess
from unittest.mock import MagicMock, patch, AsyncMock
from unittest.mock import MagicMock, patch
from rich.text import Text
import pytest

View file

@ -10,7 +10,6 @@ import sys
from io import StringIO
from unittest.mock import MagicMock, patch
import pytest
import cli as cli_mod
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
@ -719,7 +718,6 @@ class TestResumeDisplayConfig:
def test_cli_defaults_have_resume_display(self):
"""cli.py load_cli_config defaults include resume_display."""
import cli as _cli_mod
from cli import load_cli_config
with (

View file

@ -13,7 +13,6 @@ Interactive mode (tool_progress_mode == "full") still uses ChatConsole.
from datetime import datetime
from unittest.mock import MagicMock, patch
import pytest
from cli import HermesCLI

View file

@ -11,7 +11,6 @@ the absolute path plus the resume hint for the live session.
from __future__ import annotations
import json
import os
import sys
from datetime import datetime
from pathlib import Path

View file

@ -1,9 +1,5 @@
import pytest
from unittest.mock import MagicMock, patch
from hermes_cli.plugins import VALID_HOOKS, PluginManager
import os
import shutil
import tempfile
from cli import HermesCLI

View file

@ -11,7 +11,7 @@ prompt_toolkit input loop. We exercise the same try/except by calling
through a thin wrapper that mirrors the real dispatch shape.
"""
from unittest.mock import MagicMock, patch
from unittest.mock import patch
from cli import HermesCLI

View file

@ -20,7 +20,6 @@ import threading
import time
from unittest.mock import MagicMock, patch
import pytest
def _make_cli():

View file

@ -3,7 +3,6 @@ import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))
import pytest
def _make_cli_stub():

View file

@ -13,7 +13,6 @@ from run_agent import (
_sanitize_surrogates,
_sanitize_messages_surrogates,
_sanitize_structure_surrogates,
_SURROGATE_RE,
)

View file

@ -9,7 +9,6 @@ import shutil
import subprocess
import pytest
from pathlib import Path
from unittest.mock import patch, MagicMock
@pytest.fixture
@ -397,7 +396,6 @@ class TestWorktreeInclude:
assert info is not None
# Manually copy .worktreeinclude entries (mirrors cli.py logic)
import shutil
include_file = git_repo / ".worktreeinclude"
wt_path = Path(info["path"])
for line in include_file.read_text().splitlines():