abb3856525
Adds a new endpoint that exposes the project-switch state machine so tests
can poll for completion instead of guessing with timeouts.
- AppController: track _project_switch_error on failure paths
- src/api_hooks.py: GET /api/project_switch_status returns
{in_progress, pending_path, active_path, error}
- src/api_hook_client.py: get_project_switch_status() helper
- tests/test_api_hooks_project_switch.py: 3 unit tests for client + endpoint
shape, 1 live_gui test for the default-idle case
53 lines
1.9 KiB
Python
53 lines
1.9 KiB
Python
import pytest
|
|
import sys
|
|
import os
|
|
from unittest.mock import patch
|
|
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
|
|
|
from src.api_hook_client import ApiHookClient
|
|
|
|
|
|
def test_get_project_switch_status_calls_correct_endpoint() -> None:
|
|
"""get_project_switch_status() hits GET /api/project_switch_status."""
|
|
client = ApiHookClient()
|
|
with patch.object(client, "_make_request") as mock_make:
|
|
mock_make.return_value = {"in_progress": False, "path": None, "error": None}
|
|
result = client.get_project_switch_status()
|
|
assert "in_progress" in result
|
|
assert "path" in result
|
|
assert "error" in result
|
|
mock_make.assert_called_once_with("GET", "/api/project_switch_status")
|
|
|
|
|
|
def test_get_project_switch_status_handles_empty_response() -> None:
|
|
"""get_project_switch_status() returns safe default when server returns None."""
|
|
client = ApiHookClient()
|
|
with patch.object(client, "_make_request") as mock_make:
|
|
mock_make.return_value = None
|
|
result = client.get_project_switch_status()
|
|
assert result == {"in_progress": False, "path": None, "error": None}
|
|
|
|
|
|
def test_get_project_switch_status_default_is_idle() -> None:
|
|
"""get_project_switch_status() returns idle state when not in a live session."""
|
|
client = ApiHookClient()
|
|
result = client.get_project_switch_status()
|
|
assert result["in_progress"] is False
|
|
assert result["path"] is None
|
|
assert result["error"] is None
|
|
|
|
|
|
def test_live_project_switch_status_endpoint_idle(live_gui) -> None:
|
|
"""Live: GET /api/project_switch_status returns well-formed idle response."""
|
|
client = ApiHookClient()
|
|
assert client.wait_for_server(timeout=10)
|
|
status = client.get_project_switch_status()
|
|
assert "in_progress" in status
|
|
assert "path" in status
|
|
assert "error" in status
|
|
assert isinstance(status["in_progress"], bool)
|
|
assert status["in_progress"] is False, "expected no project switch in flight at session start"
|
|
assert status["path"] is None
|
|
assert status["error"] is None
|