569c20cf63
The frontend router navigates to /instances/:instanceId/terminal without
project_id or repo_id. The backend terminal REST endpoints were requiring
these path params, causing 404s.
- Simplify _get_terminal_instance to validate by instance_id only
- Update all REST routes from /projects/{pid}/repositories/{rid}/instances/{iid}/terminal/*
to /instances/{instance_id}/terminal/*
- Update frontend API client to match new paths
- Update useTerminalSessions hook to take instanceId only
- Update TerminalPage to use simplified hook
- Update tests to match new paths
Fixes: 404 on GET /projects/repositories/instances/{id}/terminal/sessions
68 lines
2.6 KiB
Python
68 lines
2.6 KiB
Python
"""Integration tests for multi-session terminal WebSocket and REST API."""
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from src.main import app
|
|
|
|
|
|
@pytest.fixture
|
|
def client():
|
|
return TestClient(app)
|
|
|
|
|
|
class TestTerminalWebSocketMultiSession:
|
|
"""Tests for multi-session WebSocket routing."""
|
|
|
|
def test_specific_session_websocket_route_exists(self, client):
|
|
"""The specific session WebSocket route should be registered."""
|
|
# We can't easily test WebSocket without auth, but we can verify
|
|
# the route exists by checking for a 403 (no auth cookie)
|
|
response = client.get("/ws/tool-instances/test-instance/terminal/test-session")
|
|
# WebSocket endpoint returns 403 when accessed via HTTP GET
|
|
assert response.status_code in (403, 404)
|
|
|
|
def test_default_session_alias_route_exists(self, client):
|
|
"""The default session alias route should still exist."""
|
|
response = client.get("/ws/tool-instances/test-instance/terminal")
|
|
assert response.status_code in (403, 404)
|
|
|
|
|
|
class TestTerminalRestApi:
|
|
"""Tests for REST API endpoints."""
|
|
|
|
def test_list_sessions_requires_auth(self, client):
|
|
"""List sessions endpoint requires authentication."""
|
|
response = client.get("/instances/test/terminal/sessions")
|
|
assert response.status_code == 401
|
|
|
|
def test_create_session_requires_auth(self, client):
|
|
"""Create session endpoint requires authentication."""
|
|
response = client.post(
|
|
"/instances/test/terminal/sessions",
|
|
json={},
|
|
)
|
|
assert response.status_code == 401
|
|
|
|
def test_close_session_requires_auth(self, client):
|
|
"""Close session endpoint requires authentication."""
|
|
response = client.delete("/instances/test/terminal/sessions/test-session")
|
|
assert response.status_code == 401
|
|
|
|
def test_reset_session_requires_auth(self, client):
|
|
"""Reset session endpoint requires authentication."""
|
|
response = client.post("/instances/test/terminal/sessions/test-session/reset")
|
|
assert response.status_code == 401
|
|
|
|
def test_rename_session_requires_auth(self, client):
|
|
"""Rename session endpoint requires authentication."""
|
|
response = client.post(
|
|
"/instances/test/terminal/sessions/test-session/rename",
|
|
json={"name": "New Name"},
|
|
)
|
|
assert response.status_code == 401
|
|
|
|
def test_legacy_reset_alias_requires_auth(self, client):
|
|
"""Legacy reset endpoint still requires auth."""
|
|
response = client.post("/instances/test/terminal/reset")
|
|
assert response.status_code == 401
|