fix: resolve 57 ruff lint errors (unused imports, unused variables, import placement)
CI / lint (push) Failing after 14s
CI / test (push) Has been skipped
CI / build (push) Has been skipped
CI / security (push) Successful in 11s

This commit is contained in:
2026-06-04 23:32:47 -04:00
parent 182e40800e
commit 3b53de1b33
14 changed files with 12 additions and 54 deletions
-1
View File
@@ -5,7 +5,6 @@ Configured via environment variables.
"""
import os
import json
import logging
import httpx
from typing import Optional, Literal
+1 -1
View File
@@ -1,6 +1,6 @@
"""ObsiGate AI — API routes for AI-powered editor features."""
from fastapi import APIRouter, HTTPException, Query
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel, Field
from typing import Optional
import logging
-1
View File
@@ -1,6 +1,5 @@
import asyncio
import logging
import os
import time
from pathlib import Path
from typing import Callable, Dict, List, Optional
-1
View File
@@ -4,7 +4,6 @@ Generate PWA icons for ObsiGate
Creates PNG icons in various sizes from an SVG template
"""
import os
from pathlib import Path
def create_svg_icon(size, output_path):
+2 -3
View File
@@ -1,7 +1,6 @@
# tests/conftest.py — Shared fixtures for ObsiGate test suite
import os
import sys
import tempfile
from pathlib import Path
import pytest
@@ -91,7 +90,7 @@ def app_with_vault(test_vault_dir: str):
backend.main._load_config = lambda: {"watcher_enabled": False}
from backend.main import app
from backend.indexer import build_index, vault_config, index
from backend.indexer import build_index
import asyncio
# Build the index
@@ -100,7 +99,7 @@ def app_with_vault(test_vault_dir: str):
loop.run_until_complete(build_index())
# Build inverted index for search
from backend.search import init_inverted_index, _inverted_index
from backend.search import init_inverted_index
init_inverted_index()
client = TestClient(app)
+1 -4
View File
@@ -1,6 +1,5 @@
# tests/test_api_main.py — Integration tests for main.py API endpoints
# Uses the existing app_with_vault / client fixtures from conftest.py
import pytest
# ═══════════════════════════════════════════════════════════════════
@@ -416,7 +415,7 @@ class TestConfig:
"search_workers": 4,
})
assert resp.status_code == 200
data = resp.json()
_ = resp.json()
# POST /api/config returns the updated config object directly
def test_diagnostics(self, client):
@@ -622,8 +621,6 @@ class TestBackupFile:
def test_backup(self, tmp_path, monkeypatch):
"""Backup is created by save operations"""
from backend.main import _backup_file
from pathlib import Path
import os
monkeypatch.chdir(tmp_path)
vault = tmp_path / "Vault"
vault.mkdir()
+1 -8
View File
@@ -1,7 +1,4 @@
# tests/test_auth.py — Tests for authentication and authorization
import os
import time
from unittest.mock import patch
import pytest
@@ -70,9 +67,7 @@ class TestJWTHandler:
from backend.auth.jwt_handler import (
create_access_token,
decode_token,
ACCESS_TOKEN_EXPIRE_SECONDS,
)
import time
# Override TTL to a value in the past
user = {"username": "testuser", "role": "user", "vaults": [], "display_name": "X"}
@@ -111,7 +106,6 @@ class TestJWTHandler:
def test_wrong_type_token(self):
"""decode_token rejects refresh tokens (type != 'access')."""
from backend.auth.jwt_handler import (
create_access_token,
create_refresh_token,
decode_token,
)
@@ -229,7 +223,7 @@ class TestUserStore:
class TestRateLimiter:
def test_initial_state(self):
from backend.ratelimit import is_rate_limited, get_status
from backend.ratelimit import get_status
status = get_status("192.168.1.1")
assert status["limited"] is False
assert status["failures"] == 0
@@ -268,7 +262,6 @@ class TestRateLimiter:
class TestMiddleware:
def test_is_auth_enabled_logic(self):
"""is_auth_enabled reads OBSIGATE_AUTH_ENABLED env var."""
import os
from backend.auth.middleware import is_auth_enabled
# The function checks if env var != 'false'
# In our test env it may be set by fixture — test the logic
+3 -2
View File
@@ -9,7 +9,8 @@ import pytest
@pytest.fixture
def auth_client():
"""Create a TestClient with auth enabled, isolated temp data."""
import tempfile, shutil
import tempfile
import shutil
from pathlib import Path
tmp = Path(tempfile.mkdtemp())
@@ -58,7 +59,7 @@ def auth_client():
backend.main._load_config = lambda: {"watcher_enabled": False}
from backend.main import app
from backend.indexer import build_index, vault_config, index
from backend.indexer import build_index, index
import asyncio
for key in list(index.keys()):
-3
View File
@@ -1,9 +1,7 @@
# tests/test_indexer.py — Tests for the indexer module
import os
import tempfile
from pathlib import Path
import pytest
from backend.indexer import (
_extract_tags,
@@ -14,7 +12,6 @@ from backend.indexer import (
get_vault_names,
get_vault_data,
get_backlinks,
get_conflicts,
SUPPORTED_EXTENSIONS,
_scan_vault,
load_vault_config,
-11
View File
@@ -1,28 +1,17 @@
# tests/test_indexer_advanced.py — Tests for indexer CRUD operations and hooks
import asyncio
from pathlib import Path
import pytest
from backend.indexer import (
index,
vault_config,
_file_lookup,
path_index,
_index_generation,
_on_index_change,
_add_file_to_structures,
_remove_file_from_structures,
update_single_file,
remove_single_file,
handle_file_move,
_index_single_file_sync,
_ensure_parent_dirs_in_path_index,
find_file_in_index,
get_vault_names,
set_index_change_hook,
_scan_vault,
build_index,
)
-4
View File
@@ -1,10 +1,6 @@
# tests/test_modules.py — Tests for utility modules: audit, history, ratelimit, settings, webhooks, share
import os
import json
import time
import tempfile
from pathlib import Path
from unittest.mock import patch
import pytest
+1 -6
View File
@@ -9,11 +9,6 @@ from backend.search import (
_highlight_terms,
_extract_highlighted_snippet,
_extract_regex_snippet,
get_all_tags,
suggest_titles,
suggest_tags,
search,
advanced_search,
)
@@ -253,7 +248,7 @@ class TestSuggestAPI:
data = resp.json()
except Exception:
pytest.skip(f"Suggest tags non-JSON: {resp.text[:100]}")
tags = [s["tag"] for s in data["suggestions"]]
_ = [s["tag"] for s in data["suggestions"]]
assert len(data["suggestions"]) >= 0 # At minimum, valid response
-5
View File
@@ -3,17 +3,12 @@ import pytest
from backend.search import (
InvertedIndex,
get_inverted_index,
init_inverted_index,
search,
advanced_search,
suggest_titles,
suggest_tags,
get_all_tags,
tokenize,
normalize_text,
_inverted_index,
)
from backend.indexer import index, _add_file_to_structures, _remove_file_from_structures
# ═══════════════════════════════════════════════════════════════════
+3 -4
View File
@@ -2,6 +2,7 @@
import asyncio
import os
from pathlib import Path
import tempfile
from unittest.mock import MagicMock, patch, AsyncMock
import pytest
@@ -140,7 +141,8 @@ class TestVaultWatcher:
class TestOnVaultChange:
@pytest.fixture
def setup_vault(self):
import tempfile, shutil
import tempfile
import shutil
from pathlib import Path
from backend.indexer import build_index, index
import asyncio
@@ -181,6 +183,3 @@ class TestOnVaultChange:
}]
asyncio.run(_on_vault_change(events))
# Should not crash
import tempfile