Skip to content

Commit f772026

Browse files
committed
Add returnsOnlyFailures option into run_tests tool
1 parent 79153f4 commit f772026

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

Editor/Tools/RunTestsTool.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class RunTestsTool : McpToolBase, ICallbacks
1919
private readonly ITestRunnerService _testRunnerService;
2020

2121
private bool _isRunning = false;
22+
private bool _returnsOnlyFailures = true;
2223
private TaskCompletionSource<JObject> _testRunCompletionSource;
2324
private List<TestResult> _testResults = new List<TestResult>();
2425

@@ -31,6 +32,7 @@ private class TestResult
3132
public string Message { get; set; }
3233
public double Duration { get; set; }
3334
public bool Passed => ResultState == "Passed";
35+
public bool Skipped => ResultState.StartsWith("Skipped");
3436
}
3537

3638
public RunTestsTool(ITestRunnerService testRunnerService)
@@ -65,6 +67,7 @@ public override void ExecuteAsync(JObject parameters, TaskCompletionSource<JObje
6567
// Extract parameters
6668
string testModeStr = parameters["testMode"]?.ToObject<string>() ?? "editmode";
6769
string testFilter = parameters["testFilter"]?.ToObject<string>() ?? "";
70+
_returnsOnlyFailures = parameters["returnsOnlyFailures"]?.ToObject<bool>() ?? true;
6871

6972
// Parse test mode
7073
TestMode testMode;
@@ -157,6 +160,12 @@ public void RunFinished(ITestResultAdaptor result)
157160
var resultArray = new JArray();
158161
foreach (var testResult in _testResults)
159162
{
163+
// If returnsOnlyFailures is true, only include failed tests
164+
if (_returnsOnlyFailures && (testResult.Passed || testResult.Skipped))
165+
{
166+
continue;
167+
}
168+
160169
resultArray.Add(new JObject
161170
{
162171
["name"] = testResult.Name,

Server/build/tools/runTestsTool.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const toolName = 'run_tests';
55
const toolDescription = 'Runs Unity\'s Test Runner tests';
66
const paramsSchema = z.object({
77
testMode: z.string().optional().describe('The test mode to run (EditMode or PlayMode) - defaults to EditMode (optional)'),
8-
testFilter: z.string().optional().describe('The specific test filter to run (e.g. specific test name or namespace) (optional)')
8+
testFilter: z.string().optional().describe('The specific test filter to run (e.g. specific test name or namespace) (optional)'),
9+
returnsOnlyFailures: z.boolean().optional().default(true).describe('Whether to show only failed tests in the results (optional)')
910
});
1011
/**
1112
* Creates and registers the Run Tests tool with the MCP server
@@ -40,13 +41,14 @@ export function createRunTestsTool(server, mcpUnity, logger) {
4041
* @throws McpUnityError if the request to Unity fails
4142
*/
4243
async function toolHandler(mcpUnity, params) {
43-
const { testMode = 'EditMode', testFilter } = params;
44+
const { testMode = 'EditMode', testFilter, returnsOnlyFailures = true } = params;
4445
// Create and wait for the test run
4546
const response = await mcpUnity.sendRequest({
4647
method: toolName,
4748
params: {
4849
testMode,
49-
testFilter
50+
testFilter,
51+
returnsOnlyFailures
5052
}
5153
});
5254
// Process the test results
@@ -65,6 +67,7 @@ async function toolHandler(mcpUnity, params) {
6567
if (testCount > 0 && passCount < testCount) {
6668
resultMessage += `. Failed tests: ${testResults
6769
.filter((r) => r.result !== 'Passed')
70+
.filter((r) => !r.result.startsWith('Skipped'))
6871
.map((r) => r.name)
6972
.join(', ')}`;
7073
}

Server/src/tools/runTestsTool.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const toolName = 'run_tests';
1010
const toolDescription = 'Runs Unity\'s Test Runner tests';
1111
const paramsSchema = z.object({
1212
testMode: z.string().optional().describe('The test mode to run (EditMode or PlayMode) - defaults to EditMode (optional)'),
13-
testFilter: z.string().optional().describe('The specific test filter to run (e.g. specific test name or namespace) (optional)')
13+
testFilter: z.string().optional().describe('The specific test filter to run (e.g. specific test name or namespace) (optional)'),
14+
returnsOnlyFailures: z.boolean().optional().default(true).describe('Whether to show only failed tests in the results (optional)')
1415
});
1516

1617
/**
@@ -52,14 +53,15 @@ export function createRunTestsTool(server: McpServer, mcpUnity: McpUnity, logger
5253
* @throws McpUnityError if the request to Unity fails
5354
*/
5455
async function toolHandler(mcpUnity: McpUnity, params: any): Promise<CallToolResult> {
55-
const { testMode = 'EditMode', testFilter } = params;
56+
const { testMode = 'EditMode', testFilter, returnsOnlyFailures = true } = params;
5657

5758
// Create and wait for the test run
5859
const response = await mcpUnity.sendRequest({
5960
method: toolName,
6061
params: {
6162
testMode,
62-
testFilter
63+
testFilter,
64+
returnsOnlyFailures
6365
}
6466
});
6567

@@ -84,6 +86,7 @@ async function toolHandler(mcpUnity: McpUnity, params: any): Promise<CallToolRes
8486
if (testCount > 0 && passCount < testCount) {
8587
resultMessage += `. Failed tests: ${testResults
8688
.filter((r: any) => r.result !== 'Passed')
89+
.filter((r: any) => !r.result.startsWith('Skipped'))
8790
.map((r: any) => r.name)
8891
.join(', ')}`;
8992
}

0 commit comments

Comments
 (0)