Fix run_tests array params double-encoding when client sends JSON-str…#695
Fix run_tests array params double-encoding when client sends JSON-str…#695voonfoo wants to merge 2 commits intoCoplayDev:betafrom
Conversation
…ingified lists When MCP clients send array parameters like test_names as JSON arrays, FastMCP/Pydantic can coerce list[str] | str union types to the str variant, producing a JSON-stringified array (e.g. '["test1"]') instead of a native list. _coerce_string_list then wraps this string as ['["test1"]'], causing Unity's test filter to receive the literal string '["test1"]' instead of 'test1' — matching zero tests. The fix detects JSON-stringified arrays in the str branch and parses them back to a proper list before forwarding to Unity.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts run_tests string list coercion to correctly handle JSON-stringified arrays, preventing double-encoded test filters from resulting in zero matches. File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider moving the
jsonimport to the module level instead of importing inside_coerce_string_listto avoid repeated imports on hot paths. - The JSON detection currently only checks
stripped.startswith("["); you might also guard withstripped.endswith("]")or a more explicit heuristic to avoid accidentally treating non-JSON strings that start with[as lists. - When JSON parsing fails you silently fall back to treating the value as a scalar string; if this is unexpected input, you may want to at least log at debug level to make future mis-encodings easier to diagnose.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider moving the `json` import to the module level instead of importing inside `_coerce_string_list` to avoid repeated imports on hot paths.
- The JSON detection currently only checks `stripped.startswith("[")`; you might also guard with `stripped.endswith("]")` or a more explicit heuristic to avoid accidentally treating non-JSON strings that start with `[` as lists.
- When JSON parsing fails you silently fall back to treating the value as a scalar string; if this is unexpected input, you may want to at least log at debug level to make future mis-encodings easier to diagnose.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…ug logging
- Move json import to module level to avoid repeated imports
- Guard JSON detection with both startswith("[") and endswith("]")
- Log at debug level when JSON parsing fails for easier diagnostics
|
duplicated PR #690, will close this |
Description
Fix
run_testsarray parameter filtering (test_names, group_names, category_names, assembly_names) returning zero matching tests due to double-encoding.Type of Change
Save your change type
Changes Made
_coerce_string_listinServer/src/services/tools/run_tests.pyto detect and parse JSON-stringified arrays before forwarding to Unitylist[str] | strunion parameter to str, it produces'["test1"]'instead of a native list. The helper now parses these back to a properlist[str]Testing/Screenshots/Recordings
Debug logs on the C# side confirmed the double-encoding:
Before (broken):
{"testNames":["[\"Namespace.Test1\"]"]}Unity receives the literal string ["Namespace.Test1"] as the test name — matches nothing, returns 0 tests.
After (fixed):
{"testNames":["Namespace.Test1"]}Unity correctly matches and runs targeted tests correctly.
Summary by Sourcery
Bug Fixes:
Summary by CodeRabbit