Skip to content

fix(appliance): make the Pester Copy-Item mock satisfy the script's copy guard#13

Merged
chrismuench merged 2 commits into
mainfrom
fix/appliance-pester-mock
Jul 20, 2026
Merged

fix(appliance): make the Pester Copy-Item mock satisfy the script's copy guard#13
chrismuench merged 2 commits into
mainfrom
fix/appliance-pester-mock

Conversation

@chrismuench

Copy link
Copy Markdown
Collaborator

Four of the six Hyper-V import tests have failed on every run since they were written — main, v0.5.0, and every dependabot PR since 2026-07-09. Both the test and the guard it trips over landed in the same commit (91f4cc2), so this suite has never been green.

Import-DispatchAppliance.ps1 verifies the VHDX copy actually landed before handing the path to New-VM:

Copy-Item -LiteralPath $VhdxPath -Destination $destVhdx -Force
if (-not (Test-Path -LiteralPath $destVhdx -PathType Leaf)) { throw "VHDX copy failed..." }

That guard is worth keeping — a silently failed copy would otherwise produce a VM pointed at a disk that isn't there. The test mocked Copy-Item to a no-op, so the destination never appeared and the guard threw on every test that reached it. The two that "passed" were the two that fail during validation, before the copy — so the suite reported 2/6 while genuinely testing nothing about the creation path.

The mock now creates the destination file, which is what a real copy does. The existing assertion on Copy-Item's Destination parameter still holds.

Verified on GitHub's Windows runner: Pester reports 6/6 passing.

This is split out from the larger multi-database branch so it isn't gated on that review — it's one file and unrelated to the database work.

🤖 Generated with Claude Code

Chris Muench and others added 2 commits July 20, 2026 17:49
…opy guard

Four of the six Hyper-V import tests have failed on every run since they were
written - main, v0.5.0 and every dependabot PR since 2026-07-09. Both the test and
the guard it trips over landed in the same commit (91f4cc2), so this suite has never
been green.

The script verifies the VHDX copy actually landed before handing the path to New-VM:

    Copy-Item -LiteralPath $VhdxPath -Destination $destVhdx -Force
    if (-not (Test-Path -LiteralPath $destVhdx -PathType Leaf)) { throw "VHDX copy failed..." }

That guard is worth keeping - a silently failed copy would otherwise produce a VM
pointed at a disk that is not there. The test mocked Copy-Item to a no-op, so the
destination never appeared and the guard threw on every test that reached it. The
two that passed were the two that fail during validation, before the copy.

The mock now creates the destination file, which is what a real copy does. The
existing assertion on Copy-Item's Destination parameter still holds.

These tests need Windows identity APIs (WindowsIdentity::GetCurrent) and cannot run
off Windows, so this is verified by the Scripts workflow rather than locally.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Both jobs in scripts.yml start with `Set-PSRepository PSGallery -InstallationPolicy
Trusted`, which fails hard when PSGallery is not registered yet:

    Set-PSRepository: No repository with the name 'PSGallery' was found.

That is an intermittent runner-image state, not a code problem - it flaked this
workflow on a run where the actual test change was correct. Register-if-missing
first, so a runner that has not registered the default gallery does not fail the
job before a single test runs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@chrismuench
chrismuench merged commit 899eec6 into main Jul 20, 2026
8 checks passed
@chrismuench
chrismuench deleted the fix/appliance-pester-mock branch July 20, 2026 16:58
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