Repository navigation
CI: harden the Windows Pester bootstrap against the nuget.exe PSGallery failure - #7743
Conversation
…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.
There was a problem hiding this comment.
💡 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"), ( |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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")): |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
|
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):
Cancelled here and running on staging instead: |
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.
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.
There was a problem hiding this comment.
💡 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".
| for cmd in ("Register-PSRepository", "Register-PSResourceRepository"): | ||
| if not stripped.startswith(cmd): | ||
| continue | ||
| seen.add(cmd) | ||
| assert "SilentlyContinue" not in stripped, ( |
There was a problem hiding this comment.
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 👍 / 👎.
| assert run.index("Install-PSResource -Name") < run.index( | ||
| "Install-Module " | ||
| ), "PSResourceGet must be tried before the nuget.exe-backed Install-Module path" |
There was a problem hiding this comment.
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 👍 / 👎.
| 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 |
There was a problem hiding this comment.
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 👍 / 👎.
) 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.
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:
PSGallery is intermittently missing from the repository list on GitHub's Windows runners, so
Set-PSRepository PSGallerydied withNo repository with the name 'PSGallery' was found.The guard added for (1) in Harden Windows Pester install against missing PSGallery #6892 called
Register-PSRepository -Defaultwith-ErrorAction SilentlyContinue. On a runner where the legacy PackageManagement provider cannot bootstrapnuget.exe, that call fails withNuGet.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, theInstall Pester v5step:windows-latestimage ships Pester 5.x, so the common path should never touch PSGallery. It only does now because the step installs unconditionally.Install-PSResourceoverInstall-Module. PSResourceGet resolves PSGallery over HTTPS directly and never shells out tonuget.exe, which is the component that fails in (2). The legacy path stays as a fallback.Register-PSRepository/Register-PSResourceRepositoryfailures now surface, so the log names the real cause rather than the misleading downstream one.Install-PSResourcereturned 500s whileInstall-Modulekept 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.tests/studio/test_pester_bootstrap_hardening.pyis 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 SilentlyContinueto the registration.Verification
Validated on a staging repo against the real
windows-latestrunner, not just locally:Install Pester v5found Pester 5.9.0 preinstalled, made zero network calls, and imported in 1.4s.Locally, under pwsh 7.6 with PSResourceGet 1.2.0, each failure path was exercised against the script extracted from the YAML:
tests/studio_setup_ps1suiteC:drive on Linuxnuget.exefailure, no PSResourceGetInstall-Module, recoversNotes
Run.Path,Run.Exit,Run.Throw,TestResult.*,Output.Verbosity,NUnitXml) is unchanged in Pester 6, so there is no reason to invent a ceiling.image-generationandvideo-diffusion-improvementssince 13 July. Those will conflict trivially with this once it merges.