forked from Rockachopa/Timmy-time-dashboard
feat: code quality audit + autoresearch integration + infra hardening (#150)
This commit is contained in:
committed by
GitHub
parent
fd0ede0d51
commit
ae3bb1cc21
@@ -24,7 +24,7 @@ def is_server_running():
|
||||
@pytest.fixture(scope="session")
|
||||
def live_server():
|
||||
"""Start the real Timmy server for E2E tests.
|
||||
|
||||
|
||||
Yields the base URL (http://localhost:8000).
|
||||
Kills the server after tests complete.
|
||||
"""
|
||||
@@ -33,27 +33,36 @@ def live_server():
|
||||
print(f"\n📡 Using existing server at {DASHBOARD_URL}")
|
||||
yield DASHBOARD_URL
|
||||
return
|
||||
|
||||
|
||||
# Start server in subprocess
|
||||
print(f"\n🚀 Starting server on {DASHBOARD_URL}...")
|
||||
|
||||
|
||||
env = os.environ.copy()
|
||||
env["PYTHONPATH"] = "src"
|
||||
env["TIMMY_ENV"] = "test" # Use test config if available
|
||||
|
||||
|
||||
# Determine project root
|
||||
project_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
||||
|
||||
|
||||
proc = subprocess.Popen(
|
||||
[sys.executable, "-m", "uvicorn", "dashboard.app:app",
|
||||
"--host", "127.0.0.1", "--port", "8000",
|
||||
"--log-level", "warning"],
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"uvicorn",
|
||||
"dashboard.app:app",
|
||||
"--host",
|
||||
"127.0.0.1",
|
||||
"--port",
|
||||
"8000",
|
||||
"--log-level",
|
||||
"warning",
|
||||
],
|
||||
cwd=project_root,
|
||||
env=env,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
|
||||
|
||||
# Wait for server to start
|
||||
max_retries = 30
|
||||
for i in range(max_retries):
|
||||
@@ -66,9 +75,9 @@ def live_server():
|
||||
proc.terminate()
|
||||
proc.wait()
|
||||
raise RuntimeError("Server failed to start")
|
||||
|
||||
|
||||
yield DASHBOARD_URL
|
||||
|
||||
|
||||
# Cleanup
|
||||
print("\n🛑 Stopping server...")
|
||||
proc.terminate()
|
||||
@@ -83,11 +92,13 @@ def live_server():
|
||||
@pytest.fixture
|
||||
def app_client():
|
||||
"""FastAPI test client for functional tests.
|
||||
|
||||
|
||||
Same as the 'client' fixture in root conftest but available here.
|
||||
"""
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from dashboard.app import app
|
||||
|
||||
with TestClient(app) as c:
|
||||
yield c
|
||||
|
||||
@@ -96,7 +107,9 @@ def app_client():
|
||||
def timmy_runner():
|
||||
"""Typer CLI runner for timmy CLI tests."""
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from timmy.cli import app
|
||||
|
||||
yield CliRunner(), app
|
||||
|
||||
|
||||
@@ -104,17 +117,20 @@ def timmy_runner():
|
||||
def serve_runner():
|
||||
"""Typer CLI runner for timmy-serve CLI tests."""
|
||||
from typer.testing import CliRunner
|
||||
|
||||
from timmy_serve.cli import app
|
||||
|
||||
yield CliRunner(), app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def docker_stack():
|
||||
"""Docker stack URL for container-level tests.
|
||||
|
||||
|
||||
Skips if FUNCTIONAL_DOCKER env var is not set to "1".
|
||||
"""
|
||||
import os
|
||||
|
||||
if os.environ.get("FUNCTIONAL_DOCKER") != "1":
|
||||
pytest.skip("Set FUNCTIONAL_DOCKER=1 to run Docker tests")
|
||||
yield "http://localhost:18000"
|
||||
@@ -124,8 +140,10 @@ def docker_stack():
|
||||
def serve_client():
|
||||
"""FastAPI test client for timmy-serve app."""
|
||||
pytest.importorskip("timmy_serve.app", reason="timmy_serve not available")
|
||||
from timmy_serve.app import create_timmy_serve_app
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from timmy_serve.app import create_timmy_serve_app
|
||||
|
||||
app = create_timmy_serve_app()
|
||||
with TestClient(app) as c:
|
||||
yield c
|
||||
@@ -145,5 +163,3 @@ def pytest_addoption(parser):
|
||||
def headed_mode(request):
|
||||
"""Check if --headed flag was passed."""
|
||||
return request.config.getoption("--headed")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user