Merge dev to main: Security improvements and comprehensive test infrastructure #39

Merged
jimmy merged 195 commits from dev into main 2026-04-08 01:42:27 +08:00
2 changed files with 14 additions and 14 deletions
Showing only changes of commit 3942a344c7 - Show all commits
+10
View File
@@ -223,4 +223,14 @@ app.include_router(opc_projects.router, prefix="/api/opc",
app.add_api_websocket_route("/ws/terminal", terminal.ws_endpoint) app.add_api_websocket_route("/ws/terminal", terminal.ws_endpoint)
app.add_api_websocket_route("/ws/opc", opc_ws.websocket_endpoint) app.add_api_websocket_route("/ws/opc", opc_ws.websocket_endpoint)
# Mount static files (skip if directory doesn't exist, e.g., in test environments)
import os
if os.path.isdir("/app/static"):
app.mount("/", StaticFiles(directory="/app/static", html=True), name="static") app.mount("/", StaticFiles(directory="/app/static", html=True), name="static")
else:
# In test environment, create a minimal fallback
import tempfile
_test_static = tempfile.mkdtemp()
with open(os.path.join(_test_static, "index.html"), "w") as f:
f.write("<html><body>Test Environment</body></html>")
app.mount("/", StaticFiles(directory=_test_static, html=True), name="static")
+3 -13
View File
@@ -143,20 +143,10 @@ def mock_httpx_client():
@pytest.fixture @pytest.fixture
def test_app(mock_config, temp_auth_file, temp_rbac_file, mock_docker_client, tmp_path): def test_app(mock_config, temp_auth_file, temp_rbac_file, mock_docker_client):
"""Create FastAPI test client with mocked dependencies.""" """Create FastAPI test client with mocked dependencies."""
# Create dummy static directory for tests # Patch Docker client before importing main
static_dir = tmp_path / "static" with patch("docker.DockerClient", return_value=mock_docker_client):
static_dir.mkdir()
(static_dir / "index.html").write_text("<html><body>Test</body></html>")
# Patch Docker client and static directory before importing main
with patch("docker.DockerClient", return_value=mock_docker_client), \
patch("main.StaticFiles") as mock_static:
# Make StaticFiles work with our test directory
from fastapi.staticfiles import StaticFiles
mock_static.return_value = StaticFiles(directory=str(static_dir), html=True)
from main import app from main import app
client = TestClient(app) client = TestClient(app)
yield client yield client