diff --git a/backend/ai.py b/backend/ai.py index 3ce2889..07ad0e3 100644 --- a/backend/ai.py +++ b/backend/ai.py @@ -5,7 +5,6 @@ Configured via environment variables. """ import os -import json import logging import httpx from typing import Optional, Literal diff --git a/backend/ai_routes.py b/backend/ai_routes.py index cb21b86..fb82b1a 100644 --- a/backend/ai_routes.py +++ b/backend/ai_routes.py @@ -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 diff --git a/backend/watcher.py b/backend/watcher.py index 1281b6c..bc640c4 100644 --- a/backend/watcher.py +++ b/backend/watcher.py @@ -1,6 +1,5 @@ import asyncio import logging -import os import time from pathlib import Path from typing import Callable, Dict, List, Optional diff --git a/generate_pwa_icons.py b/generate_pwa_icons.py index 62c1843..8141895 100644 --- a/generate_pwa_icons.py +++ b/generate_pwa_icons.py @@ -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): diff --git a/tests/conftest.py b/tests/conftest.py index 1405933..4941bf7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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) diff --git a/tests/test_api_main.py b/tests/test_api_main.py index 35dca2f..f6fb126 100644 --- a/tests/test_api_main.py +++ b/tests/test_api_main.py @@ -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() diff --git a/tests/test_auth.py b/tests/test_auth.py index 9ba981c..4276738 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -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 diff --git a/tests/test_auth_api.py b/tests/test_auth_api.py index cf79f88..a19a46c 100644 --- a/tests/test_auth_api.py +++ b/tests/test_auth_api.py @@ -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()): diff --git a/tests/test_indexer.py b/tests/test_indexer.py index 1751e5c..846d48f 100644 --- a/tests/test_indexer.py +++ b/tests/test_indexer.py @@ -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, diff --git a/tests/test_indexer_advanced.py b/tests/test_indexer_advanced.py index 8e08bf0..7bc30b0 100644 --- a/tests/test_indexer_advanced.py +++ b/tests/test_indexer_advanced.py @@ -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, ) diff --git a/tests/test_modules.py b/tests/test_modules.py index cb529fc..1c574df 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -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 diff --git a/tests/test_search.py b/tests/test_search.py index c049fea..8bf563d 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -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 diff --git a/tests/test_search_advanced.py b/tests/test_search_advanced.py index 1e10356..417ad57 100644 --- a/tests/test_search_advanced.py +++ b/tests/test_search_advanced.py @@ -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 # ═══════════════════════════════════════════════════════════════════ diff --git a/tests/test_watcher.py b/tests/test_watcher.py index 932418d..46c5ef9 100644 --- a/tests/test_watcher.py +++ b/tests/test_watcher.py @@ -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 \ No newline at end of file