Skip to content

Fix the DSC test by skipping AfterAll cleanup if the initial setup in BeforeAll failed#26621

Merged
daxian-dbw merged 2 commits intoPowerShell:masterfrom
daxian-dbw:test
Dec 16, 2025
Merged

Fix the DSC test by skipping AfterAll cleanup if the initial setup in BeforeAll failed#26621
daxian-dbw merged 2 commits intoPowerShell:masterfrom
daxian-dbw:test

Conversation

@daxian-dbw
Copy link
Member

PR Summary

The test dsc.profileresource.Tests.ps1 blindly restores $env:PATH to $originalPath, but BeforeAll throws when DSC_ROOT is not set and in that case the $originalPath is not set yet. So, $env:PATH = $originalPath in AftgerAll basically removes the PATH env variable from the current process.

Copilot AI review requested due to automatic review settings December 16, 2025 19:33
@daxian-dbw daxian-dbw added the CL-BuildPackaging Indicates that a PR should be marked as a build or packaging change in the Change Log label Dec 16, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical bug in the DSC profile resource test file where the AfterAll cleanup block was attempting to restore $env:PATH to $originalPath even when the BeforeAll setup had failed and $originalPath was never initialized. This would effectively delete the PATH environment variable from the test process when DSC_ROOT was not set.

Key Changes:

  • Introduced a $skipCleanup flag to track whether BeforeAll setup completed successfully
  • Moved $originalPath initialization to occur before any potential exceptions in the second Describe block
  • Added early return in both AfterAll blocks when cleanup should be skipped

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@daxian-dbw daxian-dbw merged commit b14cd03 into PowerShell:master Dec 16, 2025
36 checks passed
pwshBot pushed a commit to pwshBot/PowerShell that referenced this pull request Dec 16, 2025
@daxian-dbw daxian-dbw deleted the test branch December 16, 2025 20:12
kilasuit pushed a commit to kilasuit/PowerShell that referenced this pull request Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport-7.6.x-Migrated CL-BuildPackaging Indicates that a PR should be marked as a build or packaging change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants