Files
ss-tools/backend/tests/test_smoke_app.py
busya 154c9bb3b1 qa: orthogonal test review — 20 files sampled, 16+ fixed
QA AGENT FINDINGS (new issues not in audit):
1. Legacy @PURPOSE→@BRIEF: test_datasets.py (44 occurrences)
2. Legacy @SEMANTICS:→[SEMANTICS]: test_superset_matrix.py, test_smoke_app.py
3. @PRE/@POST on C2 functions: test_models.py violation
4. Unclosed #endregion anchors: test_datasets.py (56→1), test_db_executor.py, etc.

FIXES APPLIED:
- Module #region anchors added: test_smoke_plugins.py, test_models.py, api/test_tasks.py, core/test_defensive_guards.py
- @RELATION BINDS_TO added: 14 files
- @TEST_EDGE added (≥3 each): 16 files
- Legacy syntax converted: test_datasets.py, test_superset_matrix.py, test_smoke_app.py
- @PRE/@POST removed from C2 functions: test_models.py
- Unclosed #endregion fixed: test_smoke_app.py, test_db_executor.py, test_connection_service.py, test_orchestrator_direct_db.py

VERIFIED: 7778/7778 tests pass, 0 new failures

REMAINING: 947 @BRIEF gaps, 165 @TEST_EDGE gaps, 38 oversized files
2026-06-16 12:11:49 +03:00

82 lines
3.0 KiB
Python

# #region Test.SmokeApp [C:3] [TYPE Module] [SEMANTICS test, smoke, app, imports, fastapi]
# @BRIEF Minimal smoke tests verifying the full application import chain succeeds without errors.
# @RELATION BINDS_TO -> [App]
# @TEST_EDGE: import_failure -> ImportError/SyntaxError prevents app startup
# @TEST_EDGE: missing_middleware -> TraceContextMiddleware not registered
# @TEST_EDGE: missing_db_url -> App requires DATABASE_URL env var
# @INVARIANT: All tests must pass without a running PostgreSQL instance.
# @RATIONALE: Uses SQLite in-memory database URLs to avoid requiring a live PostgreSQL server during smoke testing.
"""Smoke test: verify the full application imports without errors.
Catches: SyntaxError, IndentationError, ImportError, NameError in any module
that is part of the application import chain.
Database dependency:
The application's database module (src.core.database) creates SQLAlchemy
engines at import time. To avoid needing a running PostgreSQL instance,
environment variables are set to SQLite in-memory databases before the
app is imported.
"""
import os
from pathlib import Path
import sys
# ---------------------------------------------------------------------------
# Database URL override: use SQLite in-memory so no PostgreSQL is needed.
# Must happen before ANY application module is imported.
# ---------------------------------------------------------------------------
os.environ.setdefault("DATABASE_URL", "sqlite:///:memory:")
os.environ.setdefault("TASKS_DATABASE_URL", "sqlite:///:memory:")
os.environ.setdefault("AUTH_DATABASE_URL", "sqlite:///:memory:")
# Ensure the backend root is on sys.path so `src` package is importable
_src_path = str(Path(__file__).resolve().parent.parent)
if _src_path not in sys.path:
sys.path.insert(0, _src_path)
def test_app_imports_cleanly():
"""The application module tree imports without errors."""
from src.app import app
assert app is not None
assert app.title == "Superset Tools API"
def test_app_has_expected_middleware():
"""TraceContextMiddleware is registered (trace_id propagation)."""
from src.app import app
middleware_classes = [m.cls.__name__ for m in app.user_middleware]
assert "TraceContextMiddleware" in middleware_classes, (
f"TraceContextMiddleware not found in app middleware: {middleware_classes}"
)
def test_cot_logger_imports():
"""Core logging infrastructure is importable."""
from src.core.cot_logger import (
get_trace_id,
log,
pop_span,
push_span,
seed_trace_id,
)
from src.core.cot_logger import _span_id as _cot_span_id
# Reset span context to isolate from prior tests
_cot_span_id.set("")
tid = seed_trace_id()
assert tid is not None
assert get_trace_id() == tid
log("test", "REASON", "Smoke test log entry", {"ok": True})
# Verify push_span / pop_span round-trip
prev = push_span("test_span")
assert prev == "" # default empty span
pop_span(prev)
# #endregion Test.SmokeApp