1+ using System . Collections . Generic ;
2+ using System . Linq ;
13using NUnit . Framework ;
24using MCPForUnity . Editor . Helpers ;
35using MCPForUnity . External . Tommy ;
@@ -10,6 +12,31 @@ namespace MCPForUnityTests.Editor.Helpers
1012{
1113 public class CodexConfigHelperTests
1214 {
15+ /// <summary>
16+ /// Validates that a TOML args array contains the expected uvx structure:
17+ /// --from, a mcpforunityserver reference, mcp-for-unity package name,
18+ /// and optionally --prerelease/explicit (only for prerelease builds).
19+ /// </summary>
20+ private static void AssertValidUvxArgs ( TomlArray args )
21+ {
22+ var argValues = new List < string > ( ) ;
23+ foreach ( TomlNode child in args . Children )
24+ argValues . Add ( ( child as TomlString ) . Value ) ;
25+
26+ Assert . IsTrue ( argValues . Contains ( "--from" ) , "Args should contain --from" ) ;
27+ Assert . IsTrue ( argValues . Any ( a => a . Contains ( "mcpforunityserver" ) ) , "Args should contain PyPI package reference" ) ;
28+ Assert . IsTrue ( argValues . Contains ( "mcp-for-unity" ) , "Args should contain package name" ) ;
29+
30+ // Prerelease builds include --prerelease explicit before --from
31+ int fromIndex = argValues . IndexOf ( "--from" ) ;
32+ int prereleaseIndex = argValues . IndexOf ( "--prerelease" ) ;
33+ if ( prereleaseIndex >= 0 )
34+ {
35+ Assert . IsTrue ( prereleaseIndex < fromIndex , "--prerelease should come before --from" ) ;
36+ Assert . AreEqual ( "explicit" , argValues [ prereleaseIndex + 1 ] , "--prerelease should be followed by explicit" ) ;
37+ }
38+ }
39+
1340 /// <summary>
1441 /// Mock platform service for testing
1542 /// </summary>
@@ -244,19 +271,7 @@ public void BuildCodexServerBlock_OnWindows_IncludesSystemRootEnv()
244271
245272 // Verify args contains the proper uvx command structure
246273 var args = argsNode as TomlArray ;
247- Assert . IsTrue ( args . ChildrenCount >= 5 , "Args should contain --prerelease, explicit, --from, PyPI package reference, and package name" ) ;
248-
249- var firstArg = ( args [ 0 ] as TomlString ) . Value ;
250- var secondArg = ( args [ 1 ] as TomlString ) . Value ;
251- var thirdArg = ( args [ 2 ] as TomlString ) . Value ;
252- var fourthArg = ( args [ 3 ] as TomlString ) . Value ;
253- var fifthArg = ( args [ 4 ] as TomlString ) . Value ;
254-
255- Assert . AreEqual ( "--prerelease" , firstArg , "First arg should be --prerelease" ) ;
256- Assert . AreEqual ( "explicit" , secondArg , "Second arg should be explicit" ) ;
257- Assert . AreEqual ( "--from" , thirdArg , "Third arg should be --from" ) ;
258- Assert . IsTrue ( fourthArg . Contains ( "mcpforunityserver" ) , "Fourth arg should be PyPI package reference" ) ;
259- Assert . AreEqual ( "mcp-for-unity" , fifthArg , "Fifth arg should be mcp-for-unity" ) ;
274+ AssertValidUvxArgs ( args ) ;
260275
261276 // Verify env.SystemRoot is present on Windows
262277 bool hasEnv = unityMcp . TryGetNode ( "env" , out var envNode ) ;
@@ -313,19 +328,7 @@ public void BuildCodexServerBlock_OnNonWindows_ExcludesEnv()
313328
314329 // Verify args contains the proper uvx command structure
315330 var args = argsNode as TomlArray ;
316- Assert . IsTrue ( args . ChildrenCount >= 5 , "Args should contain --prerelease, explicit, --from, PyPI package reference, and package name" ) ;
317-
318- var firstArg = ( args [ 0 ] as TomlString ) . Value ;
319- var secondArg = ( args [ 1 ] as TomlString ) . Value ;
320- var thirdArg = ( args [ 2 ] as TomlString ) . Value ;
321- var fourthArg = ( args [ 3 ] as TomlString ) . Value ;
322- var fifthArg = ( args [ 4 ] as TomlString ) . Value ;
323-
324- Assert . AreEqual ( "--prerelease" , firstArg , "First arg should be --prerelease" ) ;
325- Assert . AreEqual ( "explicit" , secondArg , "Second arg should be explicit" ) ;
326- Assert . AreEqual ( "--from" , thirdArg , "Third arg should be --from" ) ;
327- Assert . IsTrue ( fourthArg . Contains ( "mcpforunityserver" ) , "Fourth arg should be PyPI package reference" ) ;
328- Assert . AreEqual ( "mcp-for-unity" , fifthArg , "Fifth arg should be mcp-for-unity" ) ;
331+ AssertValidUvxArgs ( args ) ;
329332
330333 // Verify env is NOT present on non-Windows platforms
331334 bool hasEnv = unityMcp . TryGetNode ( "env" , out _ ) ;
@@ -384,19 +387,7 @@ public void UpsertCodexServerBlock_OnWindows_IncludesSystemRootEnv()
384387
385388 // Verify args contains the proper uvx command structure
386389 var args = argsNode as TomlArray ;
387- Assert . IsTrue ( args . ChildrenCount >= 5 , "Args should contain --prerelease, explicit, --from, PyPI package reference, and package name" ) ;
388-
389- var firstArg = ( args [ 0 ] as TomlString ) . Value ;
390- var secondArg = ( args [ 1 ] as TomlString ) . Value ;
391- var thirdArg = ( args [ 2 ] as TomlString ) . Value ;
392- var fourthArg = ( args [ 3 ] as TomlString ) . Value ;
393- var fifthArg = ( args [ 4 ] as TomlString ) . Value ;
394-
395- Assert . AreEqual ( "--prerelease" , firstArg , "First arg should be --prerelease" ) ;
396- Assert . AreEqual ( "explicit" , secondArg , "Second arg should be explicit" ) ;
397- Assert . AreEqual ( "--from" , thirdArg , "Third arg should be --from" ) ;
398- Assert . IsTrue ( fourthArg . Contains ( "mcpforunityserver" ) , "Fourth arg should be PyPI package reference" ) ;
399- Assert . AreEqual ( "mcp-for-unity" , fifthArg , "Fifth arg should be mcp-for-unity" ) ;
390+ AssertValidUvxArgs ( args ) ;
400391
401392 // Verify env.SystemRoot is present on Windows
402393 bool hasEnv = unityMcp . TryGetNode ( "env" , out var envNode ) ;
@@ -462,19 +453,7 @@ public void UpsertCodexServerBlock_OnNonWindows_ExcludesEnv()
462453
463454 // Verify args contains the proper uvx command structure
464455 var args = argsNode as TomlArray ;
465- Assert . IsTrue ( args . ChildrenCount >= 5 , "Args should contain --prerelease, explicit, --from, PyPI package reference, and package name" ) ;
466-
467- var firstArg = ( args [ 0 ] as TomlString ) . Value ;
468- var secondArg = ( args [ 1 ] as TomlString ) . Value ;
469- var thirdArg = ( args [ 2 ] as TomlString ) . Value ;
470- var fourthArg = ( args [ 3 ] as TomlString ) . Value ;
471- var fifthArg = ( args [ 4 ] as TomlString ) . Value ;
472-
473- Assert . AreEqual ( "--prerelease" , firstArg , "First arg should be --prerelease" ) ;
474- Assert . AreEqual ( "explicit" , secondArg , "Second arg should be explicit" ) ;
475- Assert . AreEqual ( "--from" , thirdArg , "Third arg should be --from" ) ;
476- Assert . IsTrue ( fourthArg . Contains ( "mcpforunityserver" ) , "Fourth arg should be PyPI package reference" ) ;
477- Assert . AreEqual ( "mcp-for-unity" , fifthArg , "Fifth arg should be mcp-for-unity" ) ;
456+ AssertValidUvxArgs ( args ) ;
478457
479458 // Verify env is NOT present on non-Windows platforms
480459 bool hasEnv = unityMcp . TryGetNode ( "env" , out _ ) ;
0 commit comments