Skip to content

Harden Windows Pester install against missing PSGallery - #6892

Merged
danielhanchen merged 1 commit into
mainfrom
ci-harden-psgallery-pester
Jul 6, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci-harden-psgallery-pester

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

The setup.ps1 unit tests (VS 2026 / CMake guard) job in this workflow intermittently fails on the windows-latest runner at the Install Pester v5 step:

Set-PSRepository PSGallery -InstallationPolicy Trusted
  | No repository with the name 'PSGallery' was found.
##[error]Process completed with exit code 1.

The default PowerShell Gallery is occasionally not registered on GitHub's hosted Windows runners. Set-PSRepository only modifies an already-registered repository, so it throws before Pester can be installed and the whole job fails, even though nothing in the change under test is at fault.

Fix

Re-register the default gallery when it is missing, before setting its policy and installing Pester:

if (-not (Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue)) {
  Register-PSRepository -Default -ErrorAction SilentlyContinue
}
Set-PSRepository PSGallery -InstallationPolicy Trusted

Register-PSRepository -Default recreates the built-in PSGallery entry, so the subsequent Set-PSRepository and Install-Module always have a repository to target. When PSGallery is already present (the common case) the guard is a no-op, so behavior is unchanged on healthy runners. This is the standard remedy for the "No repository with the name 'PSGallery' was found" error on hosted runners.

Only the Install Pester v5 step is touched; the smoke jobs and Pester suite are unchanged.

The setup.ps1 unit-tests job intermittently fails on the windows-latest
runner with 'No repository with the name PSGallery was found.' when the
default PowerShell Gallery is not registered, so Set-PSRepository throws
before Pester can be installed. Register the default gallery first when it
is missing, then set its policy and install Pester as before.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Note

Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported.

@danielhanchen
danielhanchen merged commit 53a071c into main Jul 6, 2026
17 checks passed
@danielhanchen
danielhanchen deleted the ci-harden-psgallery-pester branch July 6, 2026 03:25
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Aug 2, 2026
…ailure

The setup.ps1 Pester job has now broken twice on PRs that touch no PowerShell.

unslothai#6892 added a guard for PSGallery being absent from the runner's repository
list, but called Register-PSRepository -Default with -ErrorAction
SilentlyContinue. On a runner where the legacy PackageManagement provider cannot
bootstrap nuget.exe, that call fails with

  NuGet.Commands.CommandException: Missing option value for: '-source'

silently, and the next line dies with the misleading "No repository with the
name 'PSGallery' was found" from the original bug, so the log points at the
wrong cause.

Changes:
- Prefer PSResourceGet, which resolves PSGallery over HTTPS and never shells out
  to nuget.exe. Keep Install-Module as a fallback for images without it.
- Skip the network entirely when the image already ships a new enough Pester.
- Stop silencing the registration, so the real error reaches the log.
- Retry with backoff, swapping install client between attempts when both are
  available. PSGallery has served 500s to PSResourceGet while Install-Module
  kept working, so retrying one client three times does not survive that.
- Verify the module actually imported instead of assuming the install worked.

Add tests/studio/test_pester_bootstrap_hardening.py, which parses the workflow
and fails if the registration is silenced again, if PSResourceGet stops being
preferred, or if the retry, client swap or verification are dropped. Restoring
the previous bootstrap fails 6 of its 7 tests.

Verified with pwsh 7.6 and PSResourceGet 1.2.0: the step extracted from the
workflow parses and installs Pester, the setup.ps1 suite runs against it, a
forced nuget failure retries and rethrows the real error, and a simulated
PSGallery 500 against PSResourceGet recovers via Install-Module.
danielhanchen added a commit that referenced this pull request Aug 2, 2026
…ry failure (#7743)

* Harden the Windows Pester bootstrap against the nuget.exe PSGallery failure

The setup.ps1 Pester job has now broken twice on PRs that touch no PowerShell.

#6892 added a guard for PSGallery being absent from the runner's repository
list, but called Register-PSRepository -Default with -ErrorAction
SilentlyContinue. On a runner where the legacy PackageManagement provider cannot
bootstrap nuget.exe, that call fails with

  NuGet.Commands.CommandException: Missing option value for: '-source'

silently, and the next line dies with the misleading "No repository with the
name 'PSGallery' was found" from the original bug, so the log points at the
wrong cause.

Changes:
- Prefer PSResourceGet, which resolves PSGallery over HTTPS and never shells out
  to nuget.exe. Keep Install-Module as a fallback for images without it.
- Skip the network entirely when the image already ships a new enough Pester.
- Stop silencing the registration, so the real error reaches the log.
- Retry with backoff, swapping install client between attempts when both are
  available. PSGallery has served 500s to PSResourceGet while Install-Module
  kept working, so retrying one client three times does not survive that.
- Verify the module actually imported instead of assuming the install worked.

Add tests/studio/test_pester_bootstrap_hardening.py, which parses the workflow
and fails if the registration is silenced again, if PSResourceGet stops being
preferred, or if the retry, client swap or verification are dropped. Restoring
the previous bootstrap fails 6 of its 7 tests.

Verified with pwsh 7.6 and PSResourceGet 1.2.0: the step extracted from the
workflow parses and installs Pester, the setup.ps1 suite runs against it, a
forced nuget failure retries and rethrows the real error, and a simulated
PSGallery 500 against PSResourceGet recovers via Install-Module.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Close three vacuity gaps in the Pester bootstrap guard

The guard passed under mutations it was meant to catch:

- matching the bare string Install-PSResource hit the Get-Command probe, so
  deleting the install branch left the ordering assertion satisfied
- deleting both registration commands left the silencing loop with no lines to
  inspect, so it passed on an unregistered-PSGallery runner
- no pytest workflow filters on studio-windows-inference-smoke.yml, so a
  workflow-only edit never ran the guard at all

Assert the invocation and the initial client choice, require both registration
commands to be present, and run the guard from the pester job itself, which is
the only job a workflow-only edit triggers.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

1 participant