Skip to content

Fix HelpSystem tests for invariant culture#27547

Open
KirtiRamchandani wants to merge 2 commits into
PowerShell:masterfrom
KirtiRamchandani:fix/help-culture-tests
Open

Fix HelpSystem tests for invariant culture#27547
KirtiRamchandani wants to merge 2 commits into
PowerShell:masterfrom
KirtiRamchandani:fix/help-culture-tests

Conversation

@KirtiRamchandani
Copy link
Copy Markdown

PR Summary

Make the help function uses full view by default CI tests switch to en-US when the process culture or UI culture is invariant, then restore the original cultures after the describe block.

PR Context

Fixes #27532.

These tests assert against the PARAMETERS section from the bundled full help content. On Linux environments where the culture resolves to invariant culture (LCID 127), the localized help content is not selected, so those assertions can fail even though the full-view behavior is not broken. This mirrors the invariant-culture guard already used by the UpdatableHelp tests.

Validation

  • git diff --check -- test/powershell/engine/Help/HelpSystem.Tests.ps1
  • Parsed test/powershell/engine/Help/HelpSystem.Tests.ps1 with System.Management.Automation.Language.Parser
  • Verified the culture guard switches invariant culture to en-US and restores the saved cultures
  • Start-PSBuild -Clean -PSModuleRestore -UseNuGetOrg
  • Start-PSPester -Path test/powershell/engine/Help/HelpSystem.Tests.ps1 -Tag CI -UseNuGetOrg (local run reached the targeted file but the desktop host hit existing non-interactive Help test failures: invalid console handle in help calls plus unrelated help-file lookup misses)

PR Checklist

  • I have read the CONTRIBUTING document.
  • If this PR is work in progress, I am opening the PR as a draft.
  • The PR is made against the master branch.
  • My commit messages follow the repository guidelines.
  • I have added tests or validation that prove my fix is effective or that my feature works.
  • I have added necessary documentation, if appropriate.

Copilot AI review requested due to automatic review settings June 1, 2026 07:01
@KirtiRamchandani KirtiRamchandani requested a review from a team as a code owner June 1, 2026 07:01
Copy link
Copy Markdown
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

Note

Copilot was unable to run its full agentic suite in this review.

Updates the HelpSystem Pester tests to be resilient when running under the invariant culture by temporarily switching to en-US so localized assertions remain stable.

Changes:

  • Adds BeforeAll/AfterAll hooks to capture and restore CurrentCulture/CurrentUICulture.
  • Forces en-US culture when the current culture or UI culture is invariant (LCID 127) for the “full view by default” tests.

Comment on lines +426 to +427
if ($script:helpFullViewCultureState.CurrentCulture.LCID -eq 127 -or
$script:helpFullViewCultureState.CurrentUICulture.LCID -eq 127) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in 9c863a1f7: the invariant culture comparison now uses [System.Globalization.CultureInfo]::InvariantCulture.LCID instead of the hard-coded 127.

Comment on lines +429 to +432
$enUSCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
[System.Globalization.CultureInfo]::CurrentCulture = $enUSCulture
[System.Globalization.CultureInfo]::CurrentUICulture = $enUSCulture
$script:helpFullViewCultureState.Changed = $true
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in 9c863a1f7: the culture fallback is now scoped with BeforeEach/AfterEach, and it only replaces the culture slots that are actually invariant before restoring them after each test. Checks run: git diff --check; script parse via [scriptblock]::Create(...). I also attempted Start-PSPester -Path test\powershell\engine\Help\HelpSystem.Tests.ps1; this local run failed in existing help-system environment cases, including IOException: The handle is invalid and missing about_test* help content.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HelpSystem.Tests.ps1 cannot handle culture not being defined

2 participants