diff --git a/Editor/Tools/RunTestsTool.cs b/Editor/Tools/RunTestsTool.cs index 08757ef5..eee2d9f3 100644 --- a/Editor/Tools/RunTestsTool.cs +++ b/Editor/Tools/RunTestsTool.cs @@ -19,6 +19,7 @@ public class RunTestsTool : McpToolBase, ICallbacks private readonly ITestRunnerService _testRunnerService; private bool _isRunning = false; + private bool _returnsOnlyFailures = true; private TaskCompletionSource _testRunCompletionSource; private List _testResults = new List(); @@ -31,6 +32,7 @@ private class TestResult public string Message { get; set; } public double Duration { get; set; } public bool Passed => ResultState == "Passed"; + public bool Skipped => ResultState.StartsWith("Skipped"); } public RunTestsTool(ITestRunnerService testRunnerService) @@ -65,6 +67,7 @@ public override void ExecuteAsync(JObject parameters, TaskCompletionSource() ?? "editmode"; string testFilter = parameters["testFilter"]?.ToObject() ?? ""; + _returnsOnlyFailures = parameters["returnsOnlyFailures"]?.ToObject() ?? true; // Parse test mode TestMode testMode; @@ -157,6 +160,12 @@ public void RunFinished(ITestResultAdaptor result) var resultArray = new JArray(); foreach (var testResult in _testResults) { + // If returnsOnlyFailures is true, only include failed tests + if (_returnsOnlyFailures && (testResult.Passed || testResult.Skipped)) + { + continue; + } + resultArray.Add(new JObject { ["name"] = testResult.Name, diff --git a/Server/build/tools/runTestsTool.js b/Server/build/tools/runTestsTool.js index cd2c00d0..acdc76e6 100644 --- a/Server/build/tools/runTestsTool.js +++ b/Server/build/tools/runTestsTool.js @@ -5,7 +5,8 @@ const toolName = 'run_tests'; const toolDescription = 'Runs Unity\'s Test Runner tests'; const paramsSchema = z.object({ testMode: z.string().optional().describe('The test mode to run (EditMode or PlayMode) - defaults to EditMode (optional)'), - testFilter: z.string().optional().describe('The specific test filter to run (e.g. specific test name or namespace) (optional)') + testFilter: z.string().optional().describe('The specific test filter to run (e.g. specific test name or namespace) (optional)'), + returnsOnlyFailures: z.boolean().optional().default(true).describe('Whether to show only failed tests in the results (optional)') }); /** * Creates and registers the Run Tests tool with the MCP server @@ -40,13 +41,14 @@ export function createRunTestsTool(server, mcpUnity, logger) { * @throws McpUnityError if the request to Unity fails */ async function toolHandler(mcpUnity, params) { - const { testMode = 'EditMode', testFilter } = params; + const { testMode = 'EditMode', testFilter, returnsOnlyFailures = true } = params; // Create and wait for the test run const response = await mcpUnity.sendRequest({ method: toolName, params: { testMode, - testFilter + testFilter, + returnsOnlyFailures } }); // Process the test results @@ -65,6 +67,7 @@ async function toolHandler(mcpUnity, params) { if (testCount > 0 && passCount < testCount) { resultMessage += `. Failed tests: ${testResults .filter((r) => r.result !== 'Passed') + .filter((r) => !r.result.startsWith('Skipped')) .map((r) => r.name) .join(', ')}`; } diff --git a/Server/src/tools/runTestsTool.ts b/Server/src/tools/runTestsTool.ts index b8de19a3..2d510fea 100644 --- a/Server/src/tools/runTestsTool.ts +++ b/Server/src/tools/runTestsTool.ts @@ -10,7 +10,8 @@ const toolName = 'run_tests'; const toolDescription = 'Runs Unity\'s Test Runner tests'; const paramsSchema = z.object({ testMode: z.string().optional().describe('The test mode to run (EditMode or PlayMode) - defaults to EditMode (optional)'), - testFilter: z.string().optional().describe('The specific test filter to run (e.g. specific test name or namespace) (optional)') + testFilter: z.string().optional().describe('The specific test filter to run (e.g. specific test name or namespace) (optional)'), + returnsOnlyFailures: z.boolean().optional().default(true).describe('Whether to show only failed tests in the results (optional)') }); /** @@ -52,14 +53,15 @@ export function createRunTestsTool(server: McpServer, mcpUnity: McpUnity, logger * @throws McpUnityError if the request to Unity fails */ async function toolHandler(mcpUnity: McpUnity, params: any): Promise { - const { testMode = 'EditMode', testFilter } = params; + const { testMode = 'EditMode', testFilter, returnsOnlyFailures = true } = params; // Create and wait for the test run const response = await mcpUnity.sendRequest({ method: toolName, params: { testMode, - testFilter + testFilter, + returnsOnlyFailures } }); @@ -84,6 +86,7 @@ async function toolHandler(mcpUnity: McpUnity, params: any): Promise 0 && passCount < testCount) { resultMessage += `. Failed tests: ${testResults .filter((r: any) => r.result !== 'Passed') + .filter((r: any) => !r.result.startsWith('Skipped')) .map((r: any) => r.name) .join(', ')}`; }