From 11fbddc191be267dc77b8c7f649d366b3d6957ef Mon Sep 17 00:00:00 2001 From: Eliel Sousa Date: Tue, 22 Sep 2026 08:09:10 -0300 Subject: [PATCH] refactor(core): aprimorar qualidade de codigo e estreitar catraca de divergencia --- src/nine_rtksync/cli.py | 1 - src/nine_rtksync/config.py | 1 - src/nine_rtksync/cron.py | 1 - src/nine_rtksync/daemon.py | 2 -- src/nine_rtksync/normalizer.py | 2 +- src/nine_rtksync/providers/api_keys.py | 4 ---- src/nine_rtksync/sessao.py | 1 - src/nine_rtksync/sso.py | 2 +- src/nine_rtksync/web.py | 2 +- tests/test_health_semantics.py | 4 +++- tests/test_irmaos_identicos.py | 4 ++-- tests/test_protecao.py | 2 -- tests/test_web_auth.py | 2 +- tests/test_web_security.py | 6 +++--- 14 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/nine_rtksync/cli.py b/src/nine_rtksync/cli.py index 6755528..d0089cc 100644 --- a/src/nine_rtksync/cli.py +++ b/src/nine_rtksync/cli.py @@ -8,7 +8,6 @@ from .identidade import NOME_DO_GATEWAY, NOME_DO_PRODUTO from .gateway import get_all_combos, get_all_connections from .logs import setup_logging -from .web import start_web_server def print_status_table(settings: Settings): diff --git a/src/nine_rtksync/config.py b/src/nine_rtksync/config.py index fc5dbaf..ee18601 100644 --- a/src/nine_rtksync/config.py +++ b/src/nine_rtksync/config.py @@ -1,7 +1,6 @@ """Global settings and environment variable loading for this synchronizer.""" import os -import sys from dataclasses import dataclass from typing import List, Optional, Tuple diff --git a/src/nine_rtksync/cron.py b/src/nine_rtksync/cron.py index b3d02fb..2a4a96c 100644 --- a/src/nine_rtksync/cron.py +++ b/src/nine_rtksync/cron.py @@ -101,7 +101,6 @@ def _execute_cycle(self, reason: str = "scheduled_interval") -> Dict[str, Any]: start_ts = time.time() start_iso = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC") - ts_str = datetime.now().strftime("%Y-%m-%d %H:%M:%S") get_logger().info(f"[CRON] Ciclo disparado ({reason}). Inspecionando conexoes de contas OAuth...") try: diff --git a/src/nine_rtksync/daemon.py b/src/nine_rtksync/daemon.py index 46454a8..7cf3863 100644 --- a/src/nine_rtksync/daemon.py +++ b/src/nine_rtksync/daemon.py @@ -3,7 +3,6 @@ import os import signal import threading -import sys import time from datetime import datetime, timezone from typing import Any, Dict, List @@ -15,7 +14,6 @@ from .gateway import get_all_connections, update_connection_data from .discovery import HostDiscoveryEngine from .logs import get_logger -from .models import ConnectionRecord from .normalizer import normalize_connection_data from .providers import ApiKeyProvider, BaseProvider, GenericOAuthProvider, GoogleProvider, LocalProvider from .web import start_web_server diff --git a/src/nine_rtksync/normalizer.py b/src/nine_rtksync/normalizer.py index aa0d6fd..83ac7b5 100644 --- a/src/nine_rtksync/normalizer.py +++ b/src/nine_rtksync/normalizer.py @@ -1,7 +1,7 @@ """Self-healing and format normalization for credentials and rate-limit locks in the gateway store.""" import time -from datetime import datetime, timezone, timezone +from datetime import datetime, timezone from typing import Any, Dict, List, Optional, Tuple diff --git a/src/nine_rtksync/providers/api_keys.py b/src/nine_rtksync/providers/api_keys.py index 5ff66b8..bc120bf 100644 --- a/src/nine_rtksync/providers/api_keys.py +++ b/src/nine_rtksync/providers/api_keys.py @@ -1,9 +1,5 @@ """Static API key connection handler.""" -import json -import time -import urllib.request -from datetime import datetime, timezone from typing import Any, Dict, List, Optional, Tuple from ..credential_check import ( diff --git a/src/nine_rtksync/sessao.py b/src/nine_rtksync/sessao.py index eb77a37..d486f97 100644 --- a/src/nine_rtksync/sessao.py +++ b/src/nine_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/nine_rtksync/sso.py b/src/nine_rtksync/sso.py index d9a052b..1b6530b 100644 --- a/src/nine_rtksync/sso.py +++ b/src/nine_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/nine_rtksync/web.py b/src/nine_rtksync/web.py index f282d32..a306906 100644 --- a/src/nine_rtksync/web.py +++ b/src/nine_rtksync/web.py @@ -39,7 +39,7 @@ from .identidade import NOME_DO_GATEWAY, NOME_DO_PRODUTO from .logs import get_logger from .prefs import get_preference, set_preference -from . import i18n, protecao, sessao, sso +from . import protecao, sessao, sso from .render import render_dashboard, render_login_page, render_notice_page from .gateway import CATALOGO_INACESSIVEL, carregar_painel, esquece_o_catalogo, sondar from .render import render_landing_page diff --git a/tests/test_health_semantics.py b/tests/test_health_semantics.py index 4591011..364ae0c 100644 --- a/tests/test_health_semantics.py +++ b/tests/test_health_semantics.py @@ -115,7 +115,9 @@ class TestCarimboDeRenovacao(unittest.TestCase): """O ciclo carimba `lastRefreshAt` só quando houve renovação de verdade.""" def ciclo(self, renewed: bool): - import tempfile, os, sqlite3 + import os + import sqlite3 + import tempfile from nine_rtksync.config import Settings from nine_rtksync.daemon import SyncEngine 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 4442cc0..fe738d5 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 nine_rtksync import protecao diff --git a/tests/test_web_auth.py b/tests/test_web_auth.py index 682a182..1879505 100644 --- a/tests/test_web_auth.py +++ b/tests/test_web_auth.py @@ -65,7 +65,7 @@ def test_dashboard_rejects_invalid_auth(self): bad_token = base64.b64encode(b"admin:wrongpass").decode("utf-8") req = urllib.request.Request(url, headers={"Authorization": f"Basic {bad_token}"}) try: - urllib.request.urlopen(url, timeout=3.0) + urllib.request.urlopen(req, timeout=3.0) self.fail("Expected HTTPError 401") except urllib.error.HTTPError as e: self.assertEqual(e.code, 401) diff --git a/tests/test_web_security.py b/tests/test_web_security.py index f860b4a..36d4e62 100644 --- a/tests/test_web_security.py +++ b/tests/test_web_security.py @@ -10,6 +10,9 @@ import urllib.error import urllib.request +from nine_rtksync.config import Settings +from nine_rtksync import web as web_server + class NoRedirect(urllib.request.HTTPRedirectHandler): """Nao segue o 303: o teste precisa ver a resposta, nao o destino.""" @@ -18,9 +21,6 @@ def redirect_request(self, req, fp, code, msg, headers, newurl): return None -from nine_rtksync.config import Settings -from nine_rtksync import web as web_server - PORT = 19294 BASE = f"http://127.0.0.1:{PORT}"