Private
Public Access
0
0
Files
manual_slop/tests/test_api_hooks_project_switch.py
T
ed 6ecb31ea0a feat(app_controller): reset project state in _handle_reset_session
Stale project state from prior live_gui tests (shared session-scoped
subprocess) was leaking into subsequent tests, causing the
test_full_live_workflow race condition: 'Project not switched' errors
when self.project still claimed to be a different project.

The fix: _handle_reset_session now mirrors the default-project branch
of __init__ (lines 1743-1745), creating a fresh default project dict,
clearing active_project_path and project_paths, and reinitializing
the workspace manager.

- src/app_controller.py: 6 new lines in _handle_reset_session
- tests/test_handle_reset_session_clears_project.py: 3 tests
  (active_project_path, project_paths, self.project)
2026-06-08 10:13:07 -04:00

57 lines
2.3 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 server reports idle."""
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 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["error"] is None, f"expected no error at session start, got {status['error']!r}"
# path may be None (no project) or a str (current project loaded) - both are valid idle states
assert status["path"] is None or isinstance(status["path"], str)
assert status["error"] is None