Skip to content

Commit 9b7bace

Browse files
Adding L0 tests for Legacy NodeHandler logic | Adding 2 Knobs for feature flag & EOL toggle status value (#5421)
* Initial commit | node handler strategies | orchestrator to get selected node | L0 tests for node handlers * Adding collection definition for unning all node handling tests in sequence | Preventing leakage of test specific environment settings for knobs between node handler tests (both new and legacy) * Adding selectedNode field in UnifiedNodeContext | Removing duplicate checks from handlers | Adding string tempalates for errors and warning and removing hard-coded erros and warning from code * Adding equivalence and diverging test for legacy and new approach | Simplyfying unit test scenarios to avoid using redundant code | Update NodeHandlerTestBase to reflect the simplified test scenario usage for unning tests * Node Handler integrtion fix for custom node (moved legacy custom node check inside getnodeLocation function) | Added custom node path L0 tests | Updated test base code to integrate custom node tests * Merged custom node scnario tests with all other test specs * Code cleaning * Test scenarios updates * Minor fixes * Adding CustomNodeHandlerData handler * minor fixes * L0 unit tests for node handler with all scenarios for node handlers * minor fix * Code cleaning * Updating knob name to be consistent with server side updates. * refactor: Replace 'unified' terminology with 'strategy' in Node.js handler tests - Replace useUnifiedStrategy → useStrategy parameter - Replace unifiedExpectedNode → strategyExpectedNode property - Replace unifiedExpectSuccess → strategyExpectSuccess property - Replace unifiedExpectedError → strategyExpectedError property - Replace shouldMatchBetweenModes → shouldMatchBetweenLegacyAndStrategy property - Update environment variable AGENT_USE_UNIFIED_NODE_STRATEGY → AGENT_USE_NODE_STRATEGY - Update test descriptions to use "strategy-based" instead of "unified" - Update TestScenario class properties and constructor parameters This improves code clarity by using terminology that directly relates to the strategy pattern implementation rather than the generic term "unified". * Removed strategyExpectSuccess, legacyExpectSuccess and ExpectSuccess fields | Using Trt - Catch intest rnner code instead of this to reduce complexity | updated agnet knob text || Updated knob description to be more meaningful
1 parent 7f0507d commit 9b7bace

File tree

6 files changed

+1154
-0
lines changed

6 files changed

+1154
-0
lines changed

src/Agent.Sdk/Knob/AgentKnobs.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,13 @@ public class AgentKnobs
568568
new EnvironmentKnobSource("AGENT_DISABLE_NODE6_TASKS"),
569569
new BuiltInDefaultKnobSource("false"));
570570

571+
public static readonly Knob EnableEOLNodeVersionPolicy = new Knob(
572+
nameof(EnableEOLNodeVersionPolicy),
573+
"When enabled, tasks that specify end-of-life Node.js versions (6, 10, 16) will run using a supported Node.js version available on the agent (Node 20.1 or Node 24), ignoring the EOL Node.js version(s) in respective task. An error is thrown if no supported version is available.",
574+
new PipelineFeatureSource("AGENT_RESTRICT_EOL_NODE_VERSIONS"),
575+
new EnvironmentKnobSource("AGENT_RESTRICT_EOL_NODE_VERSIONS"),
576+
new BuiltInDefaultKnobSource("false"));
577+
571578
public static readonly Knob DisableTeePluginRemoval = new Knob(
572579
nameof(DisableTeePluginRemoval),
573580
"Disables removing TEE plugin after using it during checkout.",
@@ -929,5 +936,12 @@ public class AgentKnobs
929936
new PipelineFeatureSource("EnableDockerExecDiagnostics"),
930937
new EnvironmentKnobSource("AGENT_ENABLE_DOCKER_EXEC_DIAGNOSTICS"),
931938
new BuiltInDefaultKnobSource("false"));
939+
940+
public static readonly Knob UseNodeVersionStrategy = new Knob(
941+
nameof(UseNodeVersionStrategy),
942+
"If true, use the strategy pattern for Node.js version selection (both host and container). This provides centralized node selection logic with EOL policy enforcement. Set to false to use legacy node selection logic.",
943+
new PipelineFeatureSource("UseNodeVersionStrategy"),
944+
new EnvironmentKnobSource("AGENT_USE_NODE_STRATEGY"),
945+
new BuiltInDefaultKnobSource("false"));
932946
}
933947
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using Xunit;
5+
6+
namespace Microsoft.VisualStudio.Services.Agent.Tests
7+
{
8+
/// <summary>
9+
/// Single collection for ALL NodeHandler tests (legacy and unified).
10+
/// This ensures sequential execution to prevent environment variable conflicts.
11+
/// </summary>
12+
[CollectionDefinition("Unified NodeHandler Tests")]
13+
public class UnifiedNodeHandlerTestFixture : ICollectionFixture<UnifiedNodeHandlerTestFixture>
14+
{
15+
// This class is never instantiated, it's just a collection marker
16+
}
17+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using System.Linq;
5+
using Xunit;
6+
7+
namespace Microsoft.VisualStudio.Services.Agent.Tests
8+
{
9+
/// <summary>
10+
/// Unified test runner for ALL NodeHandler test specifications.
11+
/// Executes every scenario defined in NodeHandlerTestSpecs.AllScenarios.
12+
/// </summary>
13+
[Trait("Level", "L0")]
14+
[Trait("Category", "NodeHandler")]
15+
[Collection("Unified NodeHandler Tests")]
16+
public sealed class NodeHandlerL0AllSpecs : NodeHandlerTestBase
17+
{
18+
[Theory]
19+
[MemberData(nameof(GetAllNodeHandlerScenarios))]
20+
public void NodeHandler_AllScenarios(TestScenario scenario)
21+
{
22+
RunScenarioAndAssert(scenario);
23+
}
24+
25+
public static object[][] GetAllNodeHandlerScenarios()
26+
{
27+
return NodeHandlerTestSpecs.AllScenarios
28+
.Select(scenario => new object[] { scenario })
29+
.ToArray();
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)