@@ -61,6 +61,7 @@ public void UseNodeForNodeHandlerEnvVarNotSet()
6161 }
6262
6363 [ Theory ]
64+ [ InlineData ( "node" ) ]
6465 [ InlineData ( "node10" ) ]
6566 [ InlineData ( "node16" ) ]
6667 [ InlineData ( "node20_1" ) ]
@@ -74,7 +75,7 @@ public void UseNewNodeForNewNodeHandler(string nodeVersion)
7475 // For node24, set the required knob
7576 if ( nodeVersion == "node24" )
7677 {
77- Environment . SetEnvironmentVariable ( "AGENT_USE_NODE24 " , "true" ) ;
78+ Environment . SetEnvironmentVariable ( "AGENT_USE_NODE24_WITH_HANDLER_DATA " , "true" ) ;
7879 }
7980
8081 try
@@ -91,6 +92,7 @@ public void UseNewNodeForNewNodeHandler(string nodeVersion)
9192 nodeHandler . ExecutionContext = CreateTestExecutionContext ( thc ) ;
9293 nodeHandler . Data = nodeVersion switch
9394 {
95+ "node" => new NodeHandlerData ( ) ,
9496 "node10" => new Node10HandlerData ( ) ,
9597 "node16" => new Node16HandlerData ( ) ,
9698 "node20_1" => new Node20_1HandlerData ( ) ,
@@ -110,11 +112,101 @@ public void UseNewNodeForNewNodeHandler(string nodeVersion)
110112 {
111113 if ( nodeVersion == "node24" )
112114 {
113- Environment . SetEnvironmentVariable ( "AGENT_USE_NODE24 " , null ) ;
115+ Environment . SetEnvironmentVariable ( "AGENT_USE_NODE24_WITH_HANDLER_DATA " , null ) ;
114116 }
115117 }
116118 }
117119
120+ //test the AGENT_USE_NODE24_WITH_HANDLER_DATA knob
121+ [ Theory ]
122+ [ InlineData ( "node" ) ]
123+ [ InlineData ( "node10" ) ]
124+ [ InlineData ( "node16" ) ]
125+ [ InlineData ( "node20_1" ) ]
126+ [ InlineData ( "node24" ) ]
127+ [ Trait ( "Level" , "L0" ) ]
128+ [ Trait ( "Category" , "Common" ) ]
129+ public void ForceUseNode24Knob ( string nodeVersion )
130+ {
131+ ResetNodeKnobs ( ) ;
132+
133+ Environment . SetEnvironmentVariable ( "AGENT_USE_NODE24" , "true" ) ;
134+
135+ try
136+ {
137+ // Use a unique test name per data row to avoid sharing the same trace file across parallel runs
138+ using ( TestHostContext thc = CreateTestHostContext ( $ "{ nameof ( ForceUseNode24Knob ) } _{ nodeVersion } ") )
139+ {
140+ thc . SetSingleton ( new WorkerCommandManager ( ) as IWorkerCommandManager ) ;
141+ thc . SetSingleton ( new ExtensionManager ( ) as IExtensionManager ) ;
142+
143+ NodeHandler nodeHandler = new NodeHandler ( nodeHandlerHalper . Object ) ;
144+
145+ nodeHandler . Initialize ( thc ) ;
146+ nodeHandler . ExecutionContext = CreateTestExecutionContext ( thc ) ;
147+ nodeHandler . Data = nodeVersion switch
148+ {
149+ "node" => new NodeHandlerData ( ) ,
150+ "node10" => new Node10HandlerData ( ) ,
151+ "node16" => new Node16HandlerData ( ) ,
152+ "node20_1" => new Node20_1HandlerData ( ) ,
153+ "node24" => new Node24HandlerData ( ) ,
154+ _ => throw new Exception ( "Invalid node version" ) ,
155+ } ;
156+
157+ string actualLocation = nodeHandler . GetNodeLocation ( node20ResultsInGlibCError : false , node24ResultsInGlibCError : false , inContainer : false ) ;
158+ string expectedLocation = Path . Combine ( thc . GetDirectory ( WellKnownDirectory . Externals ) ,
159+ "node24" ,
160+ "bin" ,
161+ $ "node{ IOUtil . ExeExtension } ") ;
162+ Assert . Equal ( expectedLocation , actualLocation ) ;
163+ }
164+ }
165+ finally
166+ {
167+ Environment . SetEnvironmentVariable ( "AGENT_USE_NODE24" , null ) ;
168+ }
169+ }
170+
171+ //tests that Node24 is NOT used when handler data exists but knob is false
172+ [ Fact ]
173+ [ Trait ( "Level" , "L0" ) ]
174+ [ Trait ( "Category" , "Common" ) ]
175+ public void DoNotUseNode24WhenHandlerDataKnobIsFalse ( )
176+ {
177+ ResetNodeKnobs ( ) ;
178+
179+ Environment . SetEnvironmentVariable ( "AGENT_USE_NODE24_WITH_HANDLER_DATA" , "false" ) ;
180+
181+ try
182+ {
183+ using ( TestHostContext thc = CreateTestHostContext ( ) )
184+ {
185+ thc . SetSingleton ( new WorkerCommandManager ( ) as IWorkerCommandManager ) ;
186+ thc . SetSingleton ( new ExtensionManager ( ) as IExtensionManager ) ;
187+
188+ NodeHandler nodeHandler = new NodeHandler ( nodeHandlerHalper . Object ) ;
189+
190+ nodeHandler . Initialize ( thc ) ;
191+ nodeHandler . ExecutionContext = CreateTestExecutionContext ( thc ) ;
192+ // Task has Node24HandlerData but knob is false
193+ nodeHandler . Data = new Node24HandlerData ( ) ;
194+
195+ string actualLocation = nodeHandler . GetNodeLocation ( node20ResultsInGlibCError : false , node24ResultsInGlibCError : false , inContainer : false ) ;
196+ // Should fall back to Node20_1 (the default)
197+ string expectedLocation = Path . Combine ( thc . GetDirectory ( WellKnownDirectory . Externals ) ,
198+ "node20_1" ,
199+ "bin" ,
200+ $ "node{ IOUtil . ExeExtension } ") ;
201+ Assert . Equal ( expectedLocation , actualLocation ) ;
202+ }
203+ }
204+ finally
205+ {
206+ Environment . SetEnvironmentVariable ( "AGENT_USE_NODE24_WITH_HANDLER_DATA" , null ) ;
207+ }
208+ }
209+
118210 [ Fact ]
119211 [ Trait ( "Level" , "L0" ) ]
120212 [ Trait ( "Category" , "Common" ) ]
@@ -491,6 +583,7 @@ private void ResetNodeKnobs()
491583 Environment . SetEnvironmentVariable ( "AGENT_USE_NODE20_IN_UNSUPPORTED_SYSTEM" , null ) ;
492584 Environment . SetEnvironmentVariable ( "AGENT_USE_NODE24" , null ) ;
493585 Environment . SetEnvironmentVariable ( "AGENT_USE_NODE24_IN_UNSUPPORTED_SYSTEM" , null ) ;
586+ Environment . SetEnvironmentVariable ( "AGENT_USE_NODE24_WITH_HANDLER_DATA" , null ) ;
494587 }
495588 }
496589}
0 commit comments