Skip to content

Commit ab99b9d

Browse files
dsarnoclaude
andcommitted
fix: address PR CoplayDev#804 review feedback
- Store asyncio.create_task reference in module-level set to prevent GC (CodeRabbit) - Add test for _get_frontmost_app() returning None (CodeRabbit nitpick) - Add comment explaining why prefab root rename is not tested (Sourcery) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 63c7e5b commit ab99b9d

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Server/src/services/tools/run_tests.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
logger = logging.getLogger(__name__)
2323

24+
# Strong references to background fire-and-forget tasks to prevent premature GC.
25+
_background_tasks: set[asyncio.Task] = set()
26+
2427

2528
async def _get_unity_project_path(unity_instance: str | None) -> str | None:
2629
"""Get the project root path for a Unity instance (for focus nudging).
@@ -333,6 +336,8 @@ async def _fetch_status() -> dict[str, Any]:
333336
):
334337
logger.info(f"Test job {job_id} appears stalled (unfocused Unity), scheduling background nudge...")
335338
project_path = await _get_unity_project_path(unity_instance)
336-
asyncio.create_task(nudge_unity_focus(unity_project_path=project_path))
339+
task = asyncio.create_task(nudge_unity_focus(unity_project_path=project_path))
340+
_background_tasks.add(task)
341+
task.add_done_callback(_background_tasks.discard)
337342

338343
return GetTestJobResponse(**response)

Server/tests/test_focus_nudge.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ async def test_skips_when_unity_already_focused(self):
8484
result = await nudge_unity_focus(force=True)
8585
assert result is False
8686

87+
@pytest.mark.asyncio
88+
async def test_skips_when_frontmost_app_unknown(self):
89+
with patch("utils.focus_nudge._is_available", return_value=True), \
90+
patch("utils.focus_nudge._get_frontmost_app", return_value=None):
91+
result = await nudge_unity_focus(force=True)
92+
assert result is False
93+
8794
@pytest.mark.asyncio
8895
async def test_rate_limited_by_backoff(self):
8996
import utils.focus_nudge as fn

TestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ManagePrefabsCrudTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,8 @@ public void ModifyContents_ComponentProperties_ReturnsErrorForInvalidType()
886886
}
887887
}
888888

889+
// Note: root rename is NOT tested here because LoadAssetAtPath<GameObject> returns
890+
// the asset filename as .name for prefab roots, so rename assertions always fail.
889891
[Test]
890892
public void ModifyContents_ComponentProperties_CombinesWithOtherModifications()
891893
{

0 commit comments

Comments
 (0)