chore: fix ruff lint issues (29 fixes, 0 remaining)

This commit is contained in:
thefux
2026-07-17 16:10:54 +00:00
parent 49d285571e
commit c68c1936d3
9 changed files with 13 additions and 25 deletions
+1
View File
@@ -38,3 +38,4 @@ proof_backups
*.todo
ui_out
.wallet/
+6 -6
View File
@@ -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
+1 -2
View File
@@ -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
# ===========================================================================
-2
View File
@@ -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
# ---------------------------------------------------------------------------
+1 -2
View File
@@ -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
# ---------------------------------------------------------------------------
-2
View File
@@ -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
# ===========================================================================
@@ -5,9 +5,6 @@ RED tests — FAIL against current main until bugs are fixed.
import inspect
import pytest
# ===========================================================================
# RED TESTS: Fee payout crash safety
# ===========================================================================
@@ -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)
-5
View File
@@ -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