Skip to content

Conversation

@rishabhmalikMS
Copy link
Contributor

@rishabhmalikMS rishabhmalikMS commented Jan 21, 2026

Context

This PR addresses L1 testing for Azure Pipelines Agent host-based node version selection. The existing test infrastructure was lacked to validate both strategy mode (new) and legacy mode node selection behaviors for Node.js task execution.


Description

  • Enhanced Host Node Selection L1 Tests: Fixed and improved NodeSelectionL1Tests.cs to support both strategy mode and legacy mode validation with proper logging pattern detection
  • Dual-Mode Testing Support: Tests now properly validate both AGENT_USE_NODE_STRATEGY=true (strategy mode) and false (legacy mode) behaviors
  • Cross-Platform Compatibility: Tests handle Windows (PowerShell), Linux, and macOS execution environments with appropriate platform-specific test skipping
  • Robust Logging Validation: Improved test helpers to detect different logging patterns between strategy and legacy modes
  • Comprehensive Test Coverage: 6 test scenarios covering environment knobs, default behavior, conflicting knobs, and glibc compatibility

Risk Assessment (Low)

Low Risk - This PR only adds and enhances test infrastructure without modifying production agent logic. The changes are isolated to the test suite (src/Test/L1/Worker/) and improve validation coverage of existing node selection functionality. No runtime behavior changes for end users.


Unit Tests Added or Updated (Yes / No)

Unit tests (L0 tests) were already added in previous PR.


Additional Testing Performed

List manual or automated tests performed beyond unit tests (e.g., integration, scenario, regression).


Change Behind Feature Flag (Yes / No)

No - These are test infrastructure improvements only.


Tech Design / Approach

  • Design has been written and reviewed.
  • Any architectural decisions, trade-offs, and alternatives are captured.

Documentation Changes Required (Yes/No)

Indicate whether related documentation needs to be updated.

  • User guides, API specs, system diagrams, or runbooks are updated.

Logging Added/Updated (Yes/No)

  • Appropriate log statements are added with meaningful messages.
  • Logging does not expose sensitive data.
  • Log levels are used correctly (e.g., info, warn, error).

Telemetry Added/Updated (Yes/No)

  • Custom telemetry (e.g., counters, timers, error tracking) is added as needed.
  • Events are tagged with proper metadata for filtering and analysis.
  • Telemetry is validated in staging or test environments.

Rollback Scenario and Process (Yes/No)

  • Rollback plan is documented.

Dependency Impact Assessed and Regression Tested (Yes/No)

  • All impacted internal modules, APIs, services, and third-party libraries are analyzed.
  • Results are reviewed and confirmed to not break existing functionality.

@rishabhmalikMS
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rishabhmalikMS rishabhmalikMS marked this pull request as ready for review January 22, 2026 04:18
@rishabhmalikMS rishabhmalikMS requested review from a team as code owners January 22, 2026 04:18
@rishabhmalikMS
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rishabhmalikMS
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

else if (useStrategy)
{
// Strategy mode is allowed to fail during testing
Assert.True(actualResult == TaskResult.Failed, $"Strategy mode should either succeed or fail cleanly: {modeDescription}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we have this test, what is the assertion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is removed

hasNodeSelection = log.Any(x => x.Contains(NODE_SELECTION_LOG_PATTERN));
}

Assert.True(hasNodeSelection, $"Should have node selection log: {modeDescription}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are we asserting?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not check that if function is called? why do we have assertion based on log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are asserting the actual node selection outcome from timeline logs here. Since we do not get any output from internal classes/utilities that run to decide node version to use. In L1 tests, we could only rely on timeline logs, hence this pattern matching is used.

private const string NODE_SELECTION_LOG_PATTERN = "Using node path:";
private const string NODE20_LOG_PATTERN = "node20";

private void AssertTaskResult(TaskResult actualResult, bool useStrategy, string context = "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the significance of this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This AssertTaskResult function is removed.

hasExpectedSelection = log.Any(x => x.Contains(NODE_SELECTION_LOG_PATTERN) && x.Contains(expectedPattern));
}

Assert.True(hasExpectedSelection, $"Expected node selection '{expectedPattern}': {modeDescription}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we check the final return value? why do we have test cases based on log statements?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node selection doesn't return accessible values in L1 tests - it affects internal state only visible through logs. Logs are the final result that users see. Unit tests are handling return value testing.


if (results.Result == TaskResult.Succeeded)
{
if (expectedNodeFolder == NODE16_FOLDER)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we are setting up the data, so why do we have if/else isn't we know what should be the expectedNodeFolder

Copy link
Contributor Author

@rishabhmalikMS rishabhmalikMS Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We donot get any output from internal classes/utilities that run to decide node version to use. In L1 tests, we could only rely on timeline logs, hence this pattern matching is used. This is similar to CoreL1Tests that we have in existing L1 test suite.


AssertNodeSelectionAttempted(log, results.Result, useStrategy, "default behavior");

if (results.Result == TaskResult.Succeeded)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is false then also test case will be successful, is that expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is removed to not have conditional assertions. All other places have been updated as well for this.

Assert.True(results.Result == TaskResult.Succeeded || results.Result == TaskResult.Failed,
"Strategy mode should complete execution (success or failure expected)");
}
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we have separate test cases for both legacy and strategy, instead of if/else as if/else test case might pass in some other unexpected scenario

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to use InlineData attribute to distinguish between legacy and strategy code flow. We do not have conditional assertions anymore. Only for distinguishing between legacy and strategy, the consditions are present,


var steps = GetSteps();
var taskStep = steps.FirstOrDefault(s => s.Name == "CmdLine");
Assert.NotNull(taskStep);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are we confirming that the execution is correct? Is it only a null check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In windows, it used powershell and node node, so here taskStep being not null is the only assertion


if (actualResult == TaskResult.Succeeded)
{
// Both modes can succeed - this is fine
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a log line for this case as well?

…ives

- Remove AssertTaskResult method that incorrectly allowed strategy mode failures
- Update both legacy and strategy modes to expect success with proper error handling
- Simplify assertions by removing unnecessary TaskResult.Succeeded conditions
- Make test validation straightforward without conditional logic weaknesses
- Address PR feedback on log-based testing approach and assertion reliability
Both modes now properly assert success, making tests meaningful validation
of actual node selection behavior in L1 integration scenarios.
@rishabhmalikMS
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants