2.6 KiB
2.6 KiB
Specification: Hook API & Test Harness Hardening
Overview
This track focuses on stabilizing the local development and testing environment by hardening the Hook API and its associated live_gui test harness. The goal is to eliminate port conflicts, ensure graceful teardowns, and standardize state serialization, laying the groundwork for a future WebSockets implementation.
Functional Requirements
- Dynamic Port Allocation:
- The Hook Server (
src/api_hooks.py) will implement a Sequential Fallback strategy for port binding. - It will attempt to bind to port
8999. IfAddress already in useis encountered, it will sequentially try ports up to9010until successful. - The successfully bound port will be written to a temporary artifact file (e.g.,
.mcp_portor similar) so the test harness can discover it.
- The Hook Server (
- Graceful Teardown:
- Implement a new
/api/shutdownPOST endpoint in the Hook API. - When called, this endpoint should safely signal the
AppControllerandAppto initiate a clean shutdown (joining threads, closing files) rather than relying on the OS to forcefully kill the process tree. - Update the
live_guifixture to call this endpoint during thefinallyblock before resorting totaskkillas a last-resort fallback.
- Implement a new
- State Serialization Audit:
- Formalize the structure returned by
/api/gui/state. - Ensure all fields defined in
_gettable_fieldsare safely serialized using standard dataclass/dict traversal (avoiding deep Pydantic dependencies for now, keeping it lightweight but strictly typed for future WebSocket pipeline compatibility). - Add missing fields discovered during recent UI tracks (e.g.,
show_windowsstates).
- Formalize the structure returned by
Non-Functional Requirements
- Stability: The
live_guifixture must pass 100% of the time without port conflict errors when tests are run sequentially. - Performance: The port scanning logic should fail fast and bind within milliseconds.
Acceptance Criteria
- A test script can successfully launch two concurrent
live_guiinstances, and they bind to different ports. - Calling
/api/shutdownsuccessfully stops the GUI process and returns a 200 OK. - The
live_guifixture uses the shutdown endpoint and the test suite passes without leaving orphaned processes. - The state returned by
/api/gui/stateis fully documented and includes all relevant nested objects (likeshow_windows).
Out of Scope
- Implementing the WebSockets streaming logic (this track only prepares the state schema for it).
- Fixing failing simulation tests that are unrelated to the harness itself.