The primary goal is to significantly improve the local developer workflow by enabling key CI tasks to be executed from the command line on an already running Unity Editor instance. This avoids the slow process of shutting down the GUI and relaunching Unity in -batchmode.
The new workflow will be triggered by a -mode=u flag in the existing run-tests.sh script.
We need a solution that allows a simple CLI command to trigger the following operations within a running Unity Editor:
- Refresh Asset Database: Trigger
AssetDatabase.Refresh(). - Regenerate C# Project Files: Trigger the regeneration of
.csprojfiles (equivalent toUnityEditor.SyncVS.SyncSolution()). - Run Test Runner: Execute Unity tests (EditMode and/or PlayMode) with specified filters.
- Built, Not Sourced: The core server logic should be custom-built for this project, not reliant on external, unmaintained third-party HTTP server libraries.
- Secure: All communication with the editor must be authenticated (e.g., via a bearer token).
- Performant & Non-Blocking: The editor-side server must operate without blocking the Unity Editor's main thread. All operations, including the server's listening loop and the execution of Unity API calls, should be handled asynchronously where possible, avoiding explicit blocking calls or manual thread management that could impact editor responsiveness.
- Simple CLI Interaction: The CLI interface should be straightforward, using standard tools like
curl. - Harvest Test Results: The CLI script must be able to receive and parse detailed test results (pass/fail status, counts, path to XML report) from the editor.
- Ideally Testable: The core logic should be designed to be testable, adhering to TDD principles where practical.
All code developed for this project MUST adhere to the following software design and development principles:
- KISS (Keep It Simple, Stupid): Prefer the simplest possible solution that meets the requirements.
- DRY (Don't Repeat Yourself): Avoid code duplication.
- SRP (Single Responsibility Principle): Classes and methods should have one clear responsibility.
- SOLID: Ensure all C# code is written following SOLID principles.
- In-Editor HTTP Server: Implement a lightweight HTTP server within the Unity Editor using native .NET capabilities (
System.Net.HttpListener). - Authentication: Integrate a robust authentication mechanism (e.g., bearer token) for all API endpoints.
- Asynchronous Operations: Design the server to handle requests and execute Unity API calls asynchronously, ensuring the Unity Editor's main thread remains responsive. This will likely involve using Unity's
Editor Coroutinesor similar asynchronous patterns for dispatching tasks to the main thread without blocking the HTTP listener. - API Endpoints: Define clear, RESTful-style API endpoints for each required operation (
refresh,regenerate C#,run testrunner). - Structured Responses: Ensure API responses are well-structured (e.g., JSON) and provide clear status, messages, and detailed test results where applicable.
- Script Modification: Enhance the
run-tests.shscript to detect a-mode=uflag. - HTTP Client: Use
curlto send authenticated HTTP requests to the editor-side API. - Result Parsing: Parse the JSON responses from the editor API (e.g., using
jq) to extract relevant information, especially test results. - Exit Status: The script must exit with an appropriate status code (0 for success, 1 for failure) to integrate with CI systems.
- A feature branch
feature/fast-editor-workflowhas been created and contains all changes. - The editor-side HTTP server is implemented, secure, and non-blocking.
- The server exposes API endpoints for refreshing assets, regenerating C# project files, and running tests.
- The test-running endpoint accepts filters and returns detailed JSON results.
- The
run-tests.shscript correctly uses the-mode=uflag to interact with the editor API. - The CLI script correctly parses results and exits with appropriate status codes.
- The entire workflow is demonstrably faster and more convenient for local development than batch mode execution.
- All code adheres to the specified guiding principles (KISS, DRY, SRP, SOLID, Testable).