feat(api_hooks): add /api/project_switch_status endpoint for deterministic test signaling
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
This commit is contained in:
@@ -114,6 +114,26 @@ class HookHandler(BaseHTTPRequestHandler):
|
||||
self.end_headers()
|
||||
flat = project_manager.flat_config(_get_app_attr(app, "project"))
|
||||
self.wfile.write(json.dumps({"project": flat}).encode("utf-8"))
|
||||
elif self.path == "/api/project_switch_status":
|
||||
# Determinstic signal for tests waiting on a project switch to complete.
|
||||
# Polling /api/project returns derived state that may be stale from prior
|
||||
# tests; this endpoint tracks in_progress/error explicitly.
|
||||
# in_progress: True while _do_project_switch is scheduled or running
|
||||
# path: target path (or last completed path)
|
||||
# error: string error if last switch failed; None on success/idle
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.end_headers()
|
||||
controller = _get_app_attr(app, "controller", None)
|
||||
if controller is None:
|
||||
payload = {"in_progress": False, "path": None, "error": None}
|
||||
else:
|
||||
payload = {
|
||||
"in_progress": bool(getattr(controller, "_project_switch_in_progress", False)),
|
||||
"path": getattr(controller, "_project_switch_pending_path", None) or getattr(controller, "active_project_path", None),
|
||||
"error": getattr(controller, "_project_switch_error", None),
|
||||
}
|
||||
self.wfile.write(json.dumps(payload).encode("utf-8"))
|
||||
elif self.path == "/api/session":
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
|
||||
Reference in New Issue
Block a user