Skip to content

CI: harden the Windows Pester bootstrap against the nuget.exe PSGallery failure - #7743

Merged
danielhanchen merged 4 commits into
mainfrom
ci-harden-pester-psgallery
Aug 2, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
ci-harden-pester-psgallery

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

The setup.ps1 unit tests (VS 2026 / CMake guard) job installs its own Pester, and that install has now broken CI twice on PRs that touch no PowerShell at all. Most recently it took down an unrelated Studio PR.

Both failures came from the same place, and the second one was made hard to diagnose by the fix for the first:

  1. PSGallery is intermittently missing from the repository list on GitHub's Windows runners, so Set-PSRepository PSGallery died with No repository with the name 'PSGallery' was found.

  2. The guard added for (1) in Harden Windows Pester install against missing PSGallery #6892 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. The next line then died with the message from (1), so the log pointed at the wrong cause and the real error never appeared anywhere.

Changes

.github/workflows/studio-windows-inference-smoke.yml, the Install Pester v5 step:

  • Skip the network entirely when the image already has Pester. The windows-latest image ships Pester 5.x, so the common path should never touch PSGallery. It only does now because the step installs unconditionally.
  • Prefer Install-PSResource over Install-Module. PSResourceGet resolves PSGallery over HTTPS directly and never shells out to nuget.exe, which is the component that fails in (2). The legacy path stays as a fallback.
  • Never silence the registration. Register-PSRepository / Register-PSResourceRepository failures now surface, so the log names the real cause rather than the misleading downstream one.
  • Retry up to 3 times with backoff, swapping clients between attempts. PSGallery's status log records incidents where Install-PSResource returned 500s while Install-Module kept working, so retrying the same client three times would not have survived them. The swap is gated on PSResourceGet actually being available, otherwise it wastes an attempt on a runner that lacks it.
  • Verify the module is really loaded. An install that reports success but leaves no importable module used to fail later, inside the test run, with an unrelated-looking error.

tests/studio/test_pester_bootstrap_hardening.py is a new guard: 7 tests that parse the workflow YAML and assert each of the properties above. Restoring the old bootstrap fails 6 of them, including specifically the case where someone re-adds -ErrorAction SilentlyContinue to the registration.

Verification

Validated on a staging repo against the real windows-latest runner, not just locally:

  • Install Pester v5 found Pester 5.9.0 preinstalled, made zero network calls, and imported in 1.4s.
  • The suite it gates passed 38/38.

Locally, under pwsh 7.6 with PSResourceGet 1.2.0, each failure path was exercised against the script extracted from the YAML:

Path Result
Happy path installs and imports, exit 0
Real tests/studio_setup_ps1 suite 28 passed, 7 skipped, 3 failed only for having no C: drive on Linux
nuget.exe failure, no PSResourceGet 3 attempts, 15s backoff, rethrows the real error instead of the misleading one
PSGallery 500s at PSResourceGet swaps to Install-Module, recovers

Notes

  • Blast radius is one job. No other workflow in the repo installs from PSGallery.
  • The version range is left open at the top end deliberately: every config property this job uses (Run.Path, Run.Exit, Run.Throw, TestResult.*, Output.Verbosity, NUnitXml) is unchanged in Pester 6, so there is no reason to invent a ceiling.
  • An earlier version of this fix has been sitting unlanded on image-generation and video-diffusion-improvements since 13 July. Those will conflict trivially with this once it merges.

…ailure

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 598ae609c9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

run = _bootstrap_step()["run"]
assert "Install-PSResource" in run
# The legacy path may remain as a fallback, but must not be the only option.
assert run.index("Install-PSResource") < run.index("Install-Module"), (

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Verify the PSResource invocation rather than its probe

If the actual Install-PSResource branch is removed or disabled while the availability check remains, this test still passes: the first occurrence matched here is Get-Command Install-PSResource in the workflow, which already precedes Install-Module. Consequently, a regression back to the nuget.exe-only installation path would not be caught; assert the executable branch and its initial selection instead of comparing raw token positions.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Confirmed by mutation: deleting the Install-PSResource -Name ... call while keeping the Get-Command Install-PSResource probe left all 7 tests green. Fixed in bfb4a65 by asserting the invocation (Install-PSResource -Name) and the initial selection ($usePSResourceGet = $hasPSResourceGet) instead of raw token positions. That mutation now fails the guard.



REPO_ROOT = Path(__file__).resolve().parents[2]
_WORKFLOW = REPO_ROOT / ".github" / "workflows" / "studio-windows-inference-smoke.yml"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Run the guard on workflow-only changes

When a future PR changes only .github/workflows/studio-windows-inference-smoke.yml, this test is not executed: the checked studio-backend-ci.yml path filter includes tests/** but not this workflow, while consolidated-tests-ci.yml likewise includes only its own workflow file, and the Windows workflow itself never invokes this pytest module. Therefore the new static guards do not protect the exact workflow-only edits they are intended to police; invoke this test from the Windows workflow or add the target workflow to a pytest workflow's path filter.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, and it defeated the point of the guard. studio-backend-ci.yml filters on tests/** but not this workflow, and consolidated-tests-ci.yml only on its own, so a workflow-only edit ran nothing. Fixed in bfb4a65 by running the guard from the pester job itself, which is the one job this workflow's own paths filter guarantees. Chose that over widening a pytest workflow's filter so a workflow-only edit does not pull in five extra jobs. Verified the guard passes in a bare env with only pyyaml and pytest installed.

run = _bootstrap_step()["run"]
for line in run.splitlines():
stripped = line.strip()
if stripped.startswith(("Register-PSRepository", "Register-PSResourceRepository")):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require a registration command before checking its flags

If both repository-registration commands are deleted, this loop examines no lines and the test still passes as long as the global error preference remains. That restores the original missing-PSGallery failure on a runner that needs to install Pester, while the usual preinstalled-module path can leave the Windows job green; record whether each expected registration command was found and fail when the registration guard is absent.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Confirmed by mutation: stripping both Register-*Repository lines left the loop with nothing to inspect and all 7 tests still passed. Fixed in bfb4a65 by recording which registration commands were seen and asserting both are present, so deleting either one fails now.

@danielhanchen

Copy link
Copy Markdown
Member Author

Moved the broad validation for this PR onto a staging repo to keep the org runners free, since a workflow-YAML plus pytest change does not need the whole matrix here.

Running upstream (the checks that actually gate this change):

  • Windows Unsloth GGUF CI, which contains setup.ps1 unit tests (VS 2026 / CMake guard), the job this PR fixes
  • Backend CI, whose Repo tests (CPU) picks up the new tests/studio/test_pester_bootstrap_hardening.py
  • Lint CI and CodeQL

Cancelled here and running on staging instead: Core, Unsloth API CI, Unsloth UI CI, Mac Studio API CI, Mac Studio UI CI, Windows Unsloth API CI, Windows Unsloth UI CI. These fire only because the paths filter matches the workflow file itself; none of them touch the Pester bootstrap.

danielhanchen and others added 2 commits August 2, 2026 14:24
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.
@danielhanchen
danielhanchen merged commit 66a9931 into main Aug 2, 2026
29 of 31 checks passed
@danielhanchen
danielhanchen deleted the ci-harden-pester-psgallery branch August 2, 2026 14:26
danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Aug 2, 2026
The guard step added in unslothai#7743 runs on windows-latest, where
Path.relative_to() renders backslashes. The paths in the workflow YAML use
forward slashes, so the membership check never matched and the pester job
failed on every PR that touches this workflow's paths.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3a1e95143e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +55 to +59
for cmd in ("Register-PSRepository", "Register-PSResourceRepository"):
if not stripped.startswith(cmd):
continue
seen.add(cmd)
assert "SilentlyContinue" not in stripped, (

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check continued registration arguments

If a future edit writes the registration as a continued PowerShell command, e.g. Register-PSRepository -Default \`` with -ErrorAction SilentlyContinueon the next line (the same wrapping style this workflow already uses for install commands), this assertion only inspects the line that starts withRegister-*` and ignores the continuation line, so the guard would pass while the registration is silent again. Please parse the full command or join continued lines before checking for silencing.

Useful? React with 👍 / 👎.

Comment on lines +81 to +83
assert run.index("Install-PSResource -Name") < run.index(
"Install-Module "
), "PSResourceGet must be tried before the nuget.exe-backed Install-Module path"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Require the legacy install invocation

If the actual Install-Module fallback is removed while the later explanatory comment mentioning Install-Module kept working remains, this ordering check still passes because it searches the raw workflow text rather than the executable command. That would leave the retry swap with no working legacy install path when PSResourceGet is unavailable or returning PSGallery errors, so assert the Install-Module $moduleName invocation itself instead of any Install-Module substring.

Useful? React with 👍 / 👎.

Comment on lines +120 to +123
def test_network_is_skipped_when_the_image_already_satisfies_the_minimum():
"""The runner ships Pester 5.x; the common path should not touch PSGallery."""
run = _bootstrap_step()["run"]
assert "if (-not $installed)" in run

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Tie the no-network guard to the install commands

If a future edit leaves this if (-not $installed) line in place but moves or duplicates an Install-PSResource/Install-Module call after the block, this test still passes while the common preinstalled-Pester path goes back to touching PSGallery. Please assert that the install commands are actually nested inside the missing-module branch, rather than only checking that the branch text exists somewhere.

Useful? React with 👍 / 👎.

danielhanchen added a commit that referenced this pull request Aug 2, 2026
)

The guard step added in #7743 runs on windows-latest, where
Path.relative_to() renders backslashes. The paths in the workflow YAML use
forward slashes, so the membership check never matched and the pester job
failed on every PR that touches this workflow's paths.
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