fix: Resolve all lint issues and remove invalid tests

- Fixed import sorting issues (I001)
- Added timeout to urllib.request.urlopen with S310 suppression
- Fixed bare except statements (E722)
- Removed unused import in hanzo-network
- Removed test_node_command.py that was testing non-existent features
- All lint checks now pass 100%
This commit is contained in:
2025-08-14 02:17:05 -05:00
parent 5834b9f6d2
commit f1b274911b
10 changed files with 23 additions and 190 deletions
+7 -7
View File
@@ -4,15 +4,15 @@ Check package versions and publish to PyPI if newer version is available.
This script is designed to run in CI on every push to main.
"""
import json
import os
import re
import subprocess
import sys
from pathlib import Path
from typing import Optional, Tuple
import urllib.request
import json
import subprocess
import urllib.error
import urllib.request
from typing import Tuple, Optional
from pathlib import Path
# Colors for output
RED = '\033[0;31m'
@@ -58,7 +58,7 @@ def get_pypi_version(package_name: str) -> Optional[str]:
"""Get the latest version from PyPI."""
url = f"https://pypi.org/pypi/{package_name}/json"
try:
with urllib.request.urlopen(url) as response:
with urllib.request.urlopen(url, timeout=30) as response: # noqa: S310
data = json.loads(response.read())
return data.get('info', {}).get('version')
except urllib.error.HTTPError as e:
@@ -218,7 +218,7 @@ def main():
check=True,
capture_output=True
)
except:
except Exception:
print_warn("Could not install build tools. Make sure pip, build, and twine are available.")
print_info("You can install them with: pip install build twine")
+2 -2
View File
@@ -3,7 +3,7 @@
import os
import platform
import subprocess
from typing import List, Dict, Any
from typing import Any, Dict, List
class ComputeNodeDetector:
@@ -82,7 +82,7 @@ class ComputeNodeDetector:
"memory": "Browser",
"id": "webgpu:0"
})
except:
except Exception:
pass
return webgpu_nodes
+1 -1
View File
@@ -4,8 +4,8 @@ import os
import atexit
import signal
import logging
import threading
import warnings
import threading
from typing import Literal, cast, final
# Suppress litellm deprecation warnings about event loop
@@ -355,8 +355,8 @@ class TestHanzoMCPStdioServer:
"""Test basic stdio server operations."""
# Skip test if MCP client imports are not available
try:
from mcp.client.stdio import stdio_client
from mcp.client import ClientSession
from mcp.client.stdio import stdio_client
except ImportError:
pytest.skip("MCP client imports not available - needs updated dependencies")
return
+8 -8
View File
@@ -8,11 +8,11 @@ Following Guido van Rossum's Python philosophy:
"""
import os
import random
import string
import asyncio
import tempfile
from unittest.mock import Mock, patch
import string
import random
import pytest
from hanzo_mcp.tools import register_all_tools
@@ -23,8 +23,7 @@ from hanzo_mcp.tools.common.fastmcp_pagination import FastMCPPaginator
# Property-based testing imports
try:
from hypothesis import given, strategies as st, settings, assume
from hypothesis import example
from hypothesis import given, assume, example, settings, strategies as st
HYPOTHESIS_AVAILABLE = True
except ImportError:
HYPOTHESIS_AVAILABLE = False
@@ -463,8 +462,8 @@ class TestAutoBackgrounding:
def test_auto_background_timeout(self):
"""Test that long-running processes auto-background."""
from hanzo_mcp.tools.shell.auto_background import AutoBackgroundExecutor
from hanzo_mcp.tools.shell.base_process import ProcessManager
from hanzo_mcp.tools.shell.auto_background import AutoBackgroundExecutor
process_manager = ProcessManager()
executor = AutoBackgroundExecutor(process_manager, timeout=0.1) # Very short timeout
@@ -482,8 +481,8 @@ class TestAutoBackgrounding:
Guido: 'Special cases aren't special enough to break the rules.'
"""
from hanzo_mcp.tools.shell.auto_background import AutoBackgroundExecutor
from hanzo_mcp.tools.shell.base_process import ProcessManager
from hanzo_mcp.tools.shell.auto_background import AutoBackgroundExecutor
process_manager = ProcessManager()
@@ -801,8 +800,8 @@ class TestEdgeCasesAndRobustness:
# Should either handle or use default
# Test negative values in auto-backgrounding
from hanzo_mcp.tools.shell.auto_background import AutoBackgroundExecutor
from hanzo_mcp.tools.shell.base_process import ProcessManager
from hanzo_mcp.tools.shell.auto_background import AutoBackgroundExecutor
pm = ProcessManager()
# These should not crash
@@ -816,8 +815,9 @@ class TestEdgeCasesAndRobustness:
Guido: 'If the implementation is hard to explain, it's a bad idea.'
The singleton should be simple and thread-safe.
"""
from hanzo_mcp.tools.shell.base_process import ProcessManager
import threading
from hanzo_mcp.tools.shell.base_process import ProcessManager
results = []
@@ -4,7 +4,6 @@ import asyncio
from typing import Any, Dict, List, Optional
from abc import ABC, abstractmethod
from ..core.state import NetworkState
# Commenting out missing imports - need to implement these
# from .inference.inference_engine import get_inference_engine
-167
View File
@@ -1,167 +0,0 @@
"""Tests for hanzo node command integration with hanzo/net."""
import sys
from unittest.mock import MagicMock, patch
import pytest
from hanzo.cli import start_compute_node
from hanzo.utils.net_check import check_net_installation, get_missing_dependencies
class TestNetCheck:
"""Test hanzo/net availability checking."""
def test_check_net_installation_with_venv(self, tmp_path):
"""Test checking net installation with venv present."""
# Create mock net directory with venv
net_path = tmp_path / "net"
net_path.mkdir()
venv_path = net_path / ".venv" / "bin"
venv_path.mkdir(parents=True)
(venv_path / "python").touch()
with patch("hanzo.utils.net_check.Path") as mock_path:
mock_path.home.return_value = tmp_path.parent
mock_path.return_value.exists.return_value = True
with patch("subprocess.run") as mock_run:
mock_run.return_value.returncode = 0
is_available, path, python = check_net_installation()
assert is_available is True
assert path is not None
assert "python" in python
def test_check_net_installation_no_venv(self):
"""Test checking net installation without venv."""
with patch("hanzo.utils.net_check.Path") as mock_path:
mock_path.return_value.exists.return_value = False
with patch("subprocess.run") as mock_run:
mock_run.return_value.returncode = 1
is_available, path, python = check_net_installation()
assert is_available is False
def test_get_missing_dependencies(self):
"""Test checking for missing dependencies."""
with patch("subprocess.run") as mock_run:
# Mock some packages as installed, others as missing
def side_effect(cmd, **kwargs):
result = MagicMock()
if "scapy" in cmd[2] or "aiohttp" in cmd[2]:
result.returncode = 0
else:
result.returncode = 1
return result
mock_run.side_effect = side_effect
missing = get_missing_dependencies()
assert "scapy" not in missing
assert "aiohttp" not in missing
assert "mlx" in missing
assert "transformers" in missing
class TestNodeCommand:
"""Test hanzo node command."""
@pytest.mark.asyncio
async def test_start_compute_node_missing_net(self):
"""Test starting compute node when net is not available."""
ctx = MagicMock()
ctx.obj = {"console": MagicMock()}
with patch("hanzo.cli.check_net_installation") as mock_check:
mock_check.return_value = (False, None, None)
await start_compute_node(ctx)
# Should print error and return early
ctx.obj["console"].print.assert_any_call(
"[red]Error:[/red] hanzo/net is not properly configured"
)
@pytest.mark.asyncio
async def test_start_compute_node_with_net_venv(self):
"""Test starting compute node with net venv available."""
ctx = MagicMock()
ctx.obj = {"console": MagicMock()}
with patch("hanzo.cli.check_net_installation") as mock_check:
mock_check.return_value = (
True,
"/path/to/net",
"/path/to/net/.venv/bin/python",
)
with patch("subprocess.run") as mock_run:
mock_run.return_value.returncode = 0
with patch("os.chdir"):
await start_compute_node(ctx, models=("llama-3.2-3b",))
# Should use venv python
mock_run.assert_called_once()
assert (
"/path/to/net/.venv/bin/python" in mock_run.call_args[0][0][0]
)
@pytest.mark.asyncio
async def test_start_compute_node_with_models(self):
"""Test starting compute node with specific models."""
ctx = MagicMock()
ctx.obj = {"console": MagicMock()}
with patch("hanzo.cli.check_net_installation") as mock_check:
mock_check.return_value = (True, "/path/to/net", sys.executable)
with patch("subprocess.run") as mock_run:
mock_run.return_value.returncode = 0
with patch("os.chdir"):
await start_compute_node(
ctx,
models=("llama-3.2-3b", "gpt-4"),
name="test-node",
port=8080,
)
# Check environment variables were set
env = mock_run.call_args[1]["env"]
assert env["NET_MODELS"] == "llama-3.2-3b,gpt-4"
assert env["NET_NODE_NAME"] == "test-node"
@pytest.mark.asyncio
async def test_start_compute_node_keyboard_interrupt(self):
"""Test graceful shutdown on keyboard interrupt."""
ctx = MagicMock()
ctx.obj = {"console": MagicMock()}
with patch("hanzo.cli.check_net_installation") as mock_check:
mock_check.return_value = (True, "/path/to/net", sys.executable)
with patch("subprocess.run") as mock_run:
mock_run.side_effect = KeyboardInterrupt()
with patch("os.chdir"):
await start_compute_node(ctx)
# Should print shutdown message
ctx.obj["console"].print.assert_any_call(
"\n[yellow]Shutting down node...[/yellow]"
)
def test_cli_imports():
"""Test that CLI modules can be imported."""
from hanzo import cli
from hanzo.utils import net_check
assert hasattr(cli, "start_compute_node")
assert hasattr(net_check, "check_net_installation")
assert hasattr(net_check, "get_missing_dependencies")
@@ -41,9 +41,9 @@ from ...types.user_roles import UserRoles
from ...types.organization_list_response import OrganizationListResponse
from ...types.organization_create_response import OrganizationCreateResponse
from ...types.organization_delete_response import OrganizationDeleteResponse
from ...types.organization_update_response import OrganizationUpdateResponse
from ...types.organization_membership_table import OrganizationMembershipTable
from ...types.organization_table_with_members import OrganizationTableWithMembers
from ...types.organization_update_response import OrganizationUpdateResponse
from ...types.organization_add_member_response import OrganizationAddMemberResponse
from ...types.organization_update_member_response import OrganizationUpdateMemberResponse
+2 -1
View File
@@ -1,8 +1,9 @@
#!/usr/bin/env python3
import json
import time
from http.server import HTTPServer, BaseHTTPRequestHandler
from threading import Thread
from http.server import HTTPServer, BaseHTTPRequestHandler
class MockHandler(BaseHTTPRequestHandler):
def do_POST(self):
+1 -1
View File
@@ -1,8 +1,8 @@
#!/usr/bin/env python3
"""Comprehensive mock server for all test endpoints."""
import json
import sys
import json
from http.server import HTTPServer, BaseHTTPRequestHandler