From c68c1936d37680fcbc44f9002b82432a0eabb048 Mon Sep 17 00:00:00 2001 From: thefux Date: Fri, 17 Jul 2026 16:07:27 +0000 Subject: [PATCH] chore: fix ruff lint issues (29 fixes, 0 remaining) --- .gitignore | 1 + tests/unit/test_coverage_admin.py | 12 ++++++------ tests/unit/test_coverage_base.py | 3 +-- tests/unit/test_coverage_middleware.py | 2 -- tests/unit/test_coverage_payment_helpers.py | 3 +-- tests/unit/test_coverage_proxy.py | 2 -- tests/unit/test_db_and_payout_resilience.py | 3 --- tests/unit/test_emergency_refund_integrity.py | 7 ++++--- tests/unit/test_zero_cost_fallback.py | 5 ----- 9 files changed, 13 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index f9db7ffb..dbc5f2a0 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ proof_backups *.todo ui_out +.wallet/ diff --git a/tests/unit/test_coverage_admin.py b/tests/unit/test_coverage_admin.py index 6283f74c..9fd161cb 100644 --- a/tests/unit/test_coverage_admin.py +++ b/tests/unit/test_coverage_admin.py @@ -4,12 +4,10 @@ Tests admin endpoints that are testable without full app setup: withdraw validation, password update, CLI token lifecycle. """ -from unittest.mock import AsyncMock, Mock, patch +from unittest.mock import Mock, patch import pytest -from fastapi import HTTPException -from fastapi import Request - +from fastapi import HTTPException, Request # =========================================================================== # withdraw — validation and edge cases @@ -141,6 +139,7 @@ def test_validate_slug_accepts_valid() -> None: def test_validate_slug_rejects_spaces() -> None: """Slugs with spaces are rejected.""" from fastapi import HTTPException + from routstr.core.admin import _validate_slug with pytest.raises(HTTPException): @@ -150,6 +149,7 @@ def test_validate_slug_rejects_spaces() -> None: def test_validate_slug_rejects_too_short() -> None: """Slugs shorter than 3 chars are rejected.""" from fastapi import HTTPException + from routstr.core.admin import _validate_slug with pytest.raises(HTTPException): @@ -163,10 +163,10 @@ def test_validate_slug_rejects_too_short() -> None: @pytest.mark.asyncio async def test_admin_login_requires_payload() -> None: """admin_login requires a payload — verify it exists.""" - from routstr.core.admin import admin_login - # Verify the function signature import inspect + + from routstr.core.admin import admin_login sig = inspect.signature(admin_login) params = list(sig.parameters.keys()) assert "request" in params diff --git a/tests/unit/test_coverage_base.py b/tests/unit/test_coverage_base.py index b6de5e16..4a5cdfc4 100644 --- a/tests/unit/test_coverage_base.py +++ b/tests/unit/test_coverage_base.py @@ -3,13 +3,12 @@ Tests preparers, builders, accessors, and model cache methods. """ -from unittest.mock import AsyncMock, Mock, patch +from unittest.mock import Mock import pytest from routstr.upstream.base import BaseUpstreamProvider - # =========================================================================== # prepare_headers # =========================================================================== diff --git a/tests/unit/test_coverage_middleware.py b/tests/unit/test_coverage_middleware.py index 9a909b45..e0300983 100644 --- a/tests/unit/test_coverage_middleware.py +++ b/tests/unit/test_coverage_middleware.py @@ -4,11 +4,9 @@ Only LoggingMiddleware and request_id_context exist on main. ConcurrencyLimiterMiddleware + TimeoutMiddleware are on an unmerged branch. """ -import pytest from fastapi import FastAPI, Request from fastapi.testclient import TestClient - # --------------------------------------------------------------------------- # LoggingMiddleware # --------------------------------------------------------------------------- diff --git a/tests/unit/test_coverage_payment_helpers.py b/tests/unit/test_coverage_payment_helpers.py index 1ce67a85..b934f021 100644 --- a/tests/unit/test_coverage_payment_helpers.py +++ b/tests/unit/test_coverage_payment_helpers.py @@ -4,11 +4,10 @@ Tests the real public API: check_token_balance, get_max_cost_for_model, estimate_tokens, create_error_response, etc. """ -from unittest.mock import AsyncMock, Mock, patch +from unittest.mock import Mock, patch import pytest - # --------------------------------------------------------------------------- # check_token_balance # --------------------------------------------------------------------------- diff --git a/tests/unit/test_coverage_proxy.py b/tests/unit/test_coverage_proxy.py index b3f3da85..0e834dc5 100644 --- a/tests/unit/test_coverage_proxy.py +++ b/tests/unit/test_coverage_proxy.py @@ -4,12 +4,10 @@ Tests request parsing, model extraction, and routing helpers. """ import json -from unittest.mock import AsyncMock, Mock, patch import pytest from fastapi import HTTPException - # =========================================================================== # parse_request_body_json # =========================================================================== diff --git a/tests/unit/test_db_and_payout_resilience.py b/tests/unit/test_db_and_payout_resilience.py index 6bff9d74..6216c67a 100644 --- a/tests/unit/test_db_and_payout_resilience.py +++ b/tests/unit/test_db_and_payout_resilience.py @@ -5,9 +5,6 @@ RED tests — FAIL against current main until bugs are fixed. import inspect -import pytest - - # =========================================================================== # RED TESTS: Fee payout crash safety # =========================================================================== diff --git a/tests/unit/test_emergency_refund_integrity.py b/tests/unit/test_emergency_refund_integrity.py index 20f9d1f5..89b84309 100644 --- a/tests/unit/test_emergency_refund_integrity.py +++ b/tests/unit/test_emergency_refund_integrity.py @@ -9,11 +9,10 @@ Correct behavior required: 3. A retry wrapper must exist for critical money-path DB writes """ -from unittest.mock import AsyncMock, Mock, patch +from unittest.mock import AsyncMock, patch import pytest - # =========================================================================== # RED TESTS: store_cashu_transaction should RAISE on failure # =========================================================================== @@ -132,6 +131,7 @@ def test_emergency_refund_no_try_except_pass() -> None: the caller can detect failure and at minimum log the token. """ import inspect + from routstr.upstream.base import BaseUpstreamProvider # Check chat emergency refund handler @@ -146,7 +146,6 @@ def test_emergency_refund_no_try_except_pass() -> None: emergency_section = chat_src[emergency_start : emergency_start + 500] # The try/except/pass around store_cashu_transaction must NOT exist - has_try = "try:" in emergency_section has_except_pass = "except Exception:" in emergency_section and "pass" in emergency_section assert not has_except_pass, ( @@ -160,6 +159,7 @@ def test_emergency_refund_no_try_except_pass() -> None: def test_emergency_refund_responses_api_no_silent_failure() -> None: """FIX REQUIRED: Responses API emergency refund same fix as chat.""" import inspect + from routstr.upstream.base import BaseUpstreamProvider responses_src = inspect.getsource( @@ -195,6 +195,7 @@ def test_fee_payout_has_crash_guard() -> None: 3. Record payout in DB and reconcile on startup """ import inspect + from routstr import wallet source = inspect.getsource(wallet.periodic_routstr_fee_payout) diff --git a/tests/unit/test_zero_cost_fallback.py b/tests/unit/test_zero_cost_fallback.py index d5f565fe..0417fa1f 100644 --- a/tests/unit/test_zero_cost_fallback.py +++ b/tests/unit/test_zero_cost_fallback.py @@ -12,9 +12,6 @@ Correct behavior required: import inspect -import pytest - - # =========================================================================== # RED TESTS: No hardcoded zero-cost on billing error # =========================================================================== @@ -153,11 +150,9 @@ def test_messages_streaming_no_silent_billing_failure() -> None: # The finalize_without_usage has except Exception: pass # This should either propagate or log failure - found_finalize = False for segment in source.split("except Exception:"): if "finalize_without_usage" in segment or "finalize" in segment: if "pass" in segment[:100]: - found_finalize = True break # Check if the silent pass pattern exists