Skip to content

run_tests test filtering broken: snake_case params ignored + double-serialized arrays #689

@bruno1308

Description

@bruno1308

Bug Description

The run_tests tool's test filtering (test_names, group_names, category_names, assembly_names) silently fails — all tests run instead of the filtered subset. This affects any MCP client sending parameters in snake_case (which matches the tool's schema).

Root Causes

1. Snake_case parameter names not recognized

The MCP tool schema defines parameters in snake_case (test_names, group_names, etc.), but GetFilterOptions() in RunTests.cs only reads camelCase keys:

// Line ~149: only checks camelCase
var testNames = ParseStringArray("testNames");

Since MCP clients send test_names (matching the schema), the lookup returns null and no filter is applied.

Fix: Add snake_case fallback to each ParseStringArray call:

var testNames = ParseStringArray("testNames", "test_names");

2. Double-serialized arrays not handled

The MCP bridge serializes array parameters as a stringified JSON array inside an outer array. For example, test_names: ["MyTest"] arrives as:

{"test_names": ["[\"MyTest\"]"]}

The ParseStringArray method's Array branch doesn't detect this pattern, so it tries to extract "[\"MyTest\"]" as a test name string, which never matches any test.

Fix: Add detection for single-element arrays where the element is a stringified JSON array:

if (array.Count == 1 && array[0].Type == JTokenType.String)
{
    var inner = array[0].ToString().Trim();
    if (inner.StartsWith("[") && inner.EndsWith("]"))
    {
        try { array = JArray.Parse(inner); }
        catch { /* use original array */ }
    }
}

3. Same snake_case issue in GetTestJob.cs

GetTestJob.HandleCommand() reads includeDetails and includeFailedTests but the schema uses include_details and include_failed_tests.

Affected Files

  • Editor/Tools/RunTests.csGetFilterOptions() and HandleCommand()
  • Editor/Tools/GetTestJob.csHandleCommand()

Environment

  • Unity 6.2 (6000.3)
  • unity-mcp v9.4.0
  • Claude Code MCP client

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions