From 45d05f9496670c7672da8ace6b157fed7cf2c1bb Mon Sep 17 00:00:00 2001 From: Eliel Sousa Date: Tue, 22 Sep 2026 08:09:42 -0300 Subject: [PATCH] refactor(core): aprimorar qualidade de codigo e estreitar catraca de divergencia --- src/litellm_rtksync/cli.py | 2 +- src/litellm_rtksync/config.py | 6 +----- src/litellm_rtksync/sessao.py | 1 - src/litellm_rtksync/sso.py | 2 +- src/litellm_rtksync/web.py | 7 ++----- tests/test_cron.py | 8 ++++---- tests/test_env_documentation.py | 1 - tests/test_irmaos_identicos.py | 4 ++-- tests/test_protecao.py | 2 -- tests/test_web.py | 1 - tools/registra_gateways.py | 4 ++-- 11 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/litellm_rtksync/cli.py b/src/litellm_rtksync/cli.py index eeaf893..8918acf 100644 --- a/src/litellm_rtksync/cli.py +++ b/src/litellm_rtksync/cli.py @@ -47,7 +47,7 @@ def imprimir_status(settings: Settings) -> int: print(f" {chave.alias[:25]:<26} {(chave.team_id or '-')[:17]:<18} " f"{chave.health_status(settings.refresh_margin):<14} {validade}") - print(f"\n[*] Resumo: " + ", ".join(f"{v} {k}" for k, v in resumo.items() if v)) + print("\n[*] Resumo: " + ", ".join(f"{v} {k}" for k, v in resumo.items() if v)) print(f"[*] Times: {len(times)} Modelos cadastrados: {len(modelos)}") relatorio = avaliar(chaves, times, settings.platform_caps()) diff --git a/src/litellm_rtksync/config.py b/src/litellm_rtksync/config.py index f3529e5..ec4327a 100644 --- a/src/litellm_rtksync/config.py +++ b/src/litellm_rtksync/config.py @@ -1,16 +1,12 @@ """Configuração deste sincronizador, toda por variável de ambiente.""" import os -from dataclasses import dataclass, field +from dataclasses import dataclass from typing import Optional, Tuple from .identidade import PREFIXO_DE_CONTAINER from .auth import ( - AUTH_PASSWORD_KEY, - AUTH_USER_KEY, - derive_recovery_hash, ensure_recovery_hash, - hash_password, read_db_credentials, resolve_recovery_hash, validate_password_strength, diff --git a/src/litellm_rtksync/sessao.py b/src/litellm_rtksync/sessao.py index eb77a37..d486f97 100644 --- a/src/litellm_rtksync/sessao.py +++ b/src/litellm_rtksync/sessao.py @@ -18,7 +18,6 @@ import base64 import hashlib import hmac -import os import secrets import time from typing import Optional diff --git a/src/litellm_rtksync/sso.py b/src/litellm_rtksync/sso.py index d9a052b..1b6530b 100644 --- a/src/litellm_rtksync/sso.py +++ b/src/litellm_rtksync/sso.py @@ -1034,7 +1034,7 @@ def testar_conexao_oidc(issuer: str, client_id: str = "", client_secret: str = " if not _transporte_seguro(val): return False, f"Endpoint '{endpoint}' não utiliza HTTPS." - return True, f"Conexão OIDC validada com sucesso! Endpoints encontrados." + return True, "Conexão OIDC validada com sucesso! Endpoints encontrados." testa_conexao_oidc = testar_conexao_oidc diff --git a/src/litellm_rtksync/web.py b/src/litellm_rtksync/web.py index 09c1fe6..0b6849e 100644 --- a/src/litellm_rtksync/web.py +++ b/src/litellm_rtksync/web.py @@ -23,20 +23,17 @@ import json import os import re -import secrets import sys import threading import time -import urllib.error -import urllib.request from http import HTTPStatus from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer -from typing import Any, Callable, Dict, List, Optional +from typing import Any, Dict, List, Optional from urllib.parse import parse_qs, urlencode, urlparse from .config import Settings from .i18n import DEFAULT_LANGUAGE, LANGUAGES, normalize_language, translate -from .identidade import NOME_DO_GATEWAY, NOME_DO_PRODUTO +from .identidade import NOME_DO_PRODUTO from .logs import get_logger from .prefs import get_preference, set_preference from . import protecao, sessao, sso diff --git a/tests/test_cron.py b/tests/test_cron.py index adcea02..14e98e4 100644 --- a/tests/test_cron.py +++ b/tests/test_cron.py @@ -70,9 +70,9 @@ def test_the_log_carries_the_actions_and_names_what_produced_them(self): linhas = cron.trigger_now()["log"] # Só o que tem ação entra: a chave sem achado não polui o histórico. self.assertEqual(len(linhas), 2) - self.assertTrue(any("limit · producao" in l for l in linhas), linhas) - self.assertTrue(any("model · gpt-4o" in l for l in linhas), linhas) - self.assertTrue(any("acima do teto" in l for l in linhas), linhas) + self.assertTrue(any("limit · producao" in line for line in linhas), linhas) + self.assertTrue(any("model · gpt-4o" in line for line in linhas), linhas) + self.assertTrue(any("acima do teto" in line for line in linhas), linhas) def test_a_partial_read_failure_reaches_the_history_with_its_reason(self): """`errors` é uma lista: uma rota fora do ar não derruba o ciclo inteiro.""" @@ -83,7 +83,7 @@ def test_a_partial_read_failure_reaches_the_history_with_its_reason(self): self.assertFalse(entrada["success"]) self.assertIn("modelos: HTTP 404", entrada["error"]) self.assertIn("times: timeout", entrada["error"]) - self.assertTrue(any("ERRO: modelos: HTTP 404" in l for l in entrada["log"])) + self.assertTrue(any("ERRO: modelos: HTTP 404" in line for line in entrada["log"])) def test_a_callback_that_raises_becomes_a_failed_cycle_not_a_dead_scheduler(self): def ciclo_que_explode(): diff --git a/tests/test_env_documentation.py b/tests/test_env_documentation.py index 4e66034..2741966 100644 --- a/tests/test_env_documentation.py +++ b/tests/test_env_documentation.py @@ -9,7 +9,6 @@ defasagem aparece no CI em vez de aparecer em producao. """ -import os import pathlib import re import unittest diff --git a/tests/test_irmaos_identicos.py b/tests/test_irmaos_identicos.py index 005d427..bb1b2cf 100644 --- a/tests/test_irmaos_identicos.py +++ b/tests/test_irmaos_identicos.py @@ -93,8 +93,8 @@ # leitura para `gateway.py`, e isso continua em aberto. TETOS_DE_DIVERGENCIA = { "models.py": 7, - "render.py": 862, - "web.py": 689, + "render.py": 560, + "web.py": 578, } # O que cada produto troca de propósito, e que não conta como divergência. diff --git a/tests/test_protecao.py b/tests/test_protecao.py index bf2f698..621dc62 100644 --- a/tests/test_protecao.py +++ b/tests/test_protecao.py @@ -5,8 +5,6 @@ freio tem de já estar instalado quando ele apertar. """ -import hashlib -import time import unittest from litellm_rtksync import protecao diff --git a/tests/test_web.py b/tests/test_web.py index f6d92aa..54c0ed4 100644 --- a/tests/test_web.py +++ b/tests/test_web.py @@ -12,7 +12,6 @@ """ import base64 -import os import re import tempfile import time diff --git a/tools/registra_gateways.py b/tools/registra_gateways.py index a67e08c..1e13abb 100644 --- a/tools/registra_gateways.py +++ b/tools/registra_gateways.py @@ -211,7 +211,7 @@ def registrar(api: AdminAPI, escrever: bool = True) -> int: chave = os.environ.get(gw["env_var"], "") if not chave: log(f" ! {gw['env_var']} não está no ambiente — este gateway fica de fora.") - log(f" A chave sai do painel do gateway (POST /api/keys) e mora no .env.") + log(" A chave sai do painel do gateway (POST /api/keys) e mora no .env.") continue log(f" chave {gw['env_var']} = {mascara(chave)}") @@ -401,7 +401,7 @@ def testar(api: AdminAPI) -> int: log(f" ✗ CREDENCIAL: {estado_da_chave}") falhas += 1 continue - log(f" ✓ credencial aceita pelo gateway (/v1/models)") + log(" ✓ credencial aceita pelo gateway (/v1/models)") try: r = api.request("POST", "/v1/chat/completions", { "model": gw["model_name"],