Skip to content

test: Guest helper windows unit tests#28

Open
ema-aka-young wants to merge 1 commit into
kubevirt:mainfrom
ema-aka-young:guest-helper-windows-tests
Open

test: Guest helper windows unit tests#28
ema-aka-young wants to merge 1 commit into
kubevirt:mainfrom
ema-aka-young:guest-helper-windows-tests

Conversation

@ema-aka-young

@ema-aka-young ema-aka-young commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:
Add Pester unit tests for the Windows guest helper script (filerestore.bat) and refactor the script to make it testable.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:
The script was restructured from top-level procedural code into functions to enable unit testing. The runtime behavior is unchanged: the entrypoint at the bottom of the file calls the same logic in the same order.

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note:

NONE

Copilot AI review requested due to automatic review settings July 3, 2026 14:27
@kubevirt-prow

kubevirt-prow Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@kubevirt-prow kubevirt-prow Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 3, 2026
@kubevirt-prow

kubevirt-prow Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign arnongilboa for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copilot AI 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.

Pull request overview

Adds a containerized Pester test suite for the Windows guest-helper (guest-helpers/windows/filerestore.bat) and refactors the script so its logic is callable/testable from PowerShell while preserving the .bat entrypoint behavior.

Changes:

  • Introduce make test-scripts / make test-scripts-windows to run Windows guest-helper Pester tests in a container.
  • Add Pester test harness/module plus a README-style TESTING.md describing how tests work.
  • Refactor filerestore.bat into functions (plus wrapper functions for native executables) to enable mocking and unit testing, and add an SSH command validation helper.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Makefile Adds containerized Pester-based script test targets and related variables.
guest-helpers/windows/TESTING.md Documents how to run and understand the Windows guest-helper script tests.
guest-helpers/windows/test/TestHelper.psm1 Adds helpers to extract the PowerShell portion of the polyglot .bat and stub Windows-only cmdlets.
guest-helpers/windows/test/filerestore.Tests.ps1 Adds Pester coverage for argument parsing, disk/partition logic, BitLocker, junction handling, and SSH command restriction behavior.
guest-helpers/windows/filerestore.bat Refactors into functions for testability and adds wrappers to allow Pester mocking.
.gitignore Ignores testResults.xml produced by test runs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +81 to +87
if (-not $env:SSH_ORIGINAL_COMMAND) { return $null }
if ($env:SSH_ORIGINAL_COMMAND -notmatch '^"?C:\\Program Files\\filerestore\\filerestore\.bat"?(\s|$)') {
Write-Host "ERROR: Only filerestore.bat commands are allowed" -ForegroundColor Red
return 'rejected'
}
$arguments = $env:SSH_ORIGINAL_COMMAND -replace '^"?C:\\Program Files\\filerestore\\filerestore\.bat"?\s*', ''
return $arguments

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this is a theorethical concern with close to zero risk. I'd prefer not to change it at this time

@ema-aka-young ema-aka-young changed the title Guest helper windows tests testG/ uest helper windows tests Jul 8, 2026
@ema-aka-young ema-aka-young changed the title testG/ uest helper windows tests test: Guest helper windows unit tests Jul 8, 2026
@kubevirt-prow kubevirt-prow Bot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 8, 2026
@ema-aka-young ema-aka-young marked this pull request as ready for review July 8, 2026 11:39
@kubevirt-prow kubevirt-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 8, 2026
@kubevirt-prow kubevirt-prow Bot requested review from arnongilboa and noamasu July 8, 2026 11:39
@kubevirt-prow kubevirt-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 8, 2026
Copilot AI review requested due to automatic review settings July 8, 2026 13:44
@kubevirt-prow kubevirt-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 8, 2026
@ema-aka-young ema-aka-young force-pushed the guest-helper-windows-tests branch from 12e44cf to 394f27c Compare July 8, 2026 13:48

Copilot AI 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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comment thread Makefile Outdated
Comment on lines 192 to 193
test-scripts: test-scripts-linux ## Run guest-helper script tests

Comment on lines +80 to 88
function Test-SshCommand {
if (-not $env:SSH_ORIGINAL_COMMAND) { return $null }
if ($env:SSH_ORIGINAL_COMMAND -notmatch '^"?C:\\Program Files\\filerestore\\filerestore\.bat"?(\s|$)') {
Write-Host "ERROR: Only filerestore.bat commands are allowed" -ForegroundColor Red
return 'rejected'
}
$arguments = $env:SSH_ORIGINAL_COMMAND -replace '^"?C:\\Program Files\\filerestore\\filerestore\.bat"?\s*', ''
return $arguments
}
Comment on lines +207 to +213
# Create a junction point to redirect $MountPath to the drive
if (Test-Path $MountPath) { Remove-Junction -Path $MountPath }
New-Junction -Path $MountPath -Target "${driveLetter}:\"
if (-not (Test-Path $MountPath)) {
Write-Host "ERROR: Failed to create junction from $MountPath to ${driveLetter}:\"
return 1
}
Copilot AI review requested due to automatic review settings July 8, 2026 13:52

Copilot AI 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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Comment thread Makefile Outdated
Comment on lines +269 to +270
# When dot-sourced (e.g. by Pester), load functions but skip main logic
if ($MyInvocation.InvocationName -eq '.') { return }
Comment thread guest-helpers/windows/TESTING.md Outdated
Comment on lines +229 to +235
if ($SourcePath -match '^\\\\') {
Write-Host "ERROR: UNC paths are not supported for --source-path"
return 1
}
$RelativePath = $SourcePath -replace '^[A-Za-z]:\\', ''
$RelativePath = $RelativePath.TrimStart('\')
$BackupPath = Join-Path $MountPath $RelativePath
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@ema-aka-young, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 37 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e0f82da7-b842-4dbb-a797-2ab181b0e752

📥 Commits

Reviewing files that changed from the base of the PR and between fc5acf1 and 6717f19.

📒 Files selected for processing (6)
  • Makefile
  • guest-helpers/linux/TESTING.md
  • guest-helpers/windows/TESTING.md
  • guest-helpers/windows/filerestore.bat
  • guest-helpers/windows/test/TestHelper.psm1
  • guest-helpers/windows/test/filerestore.Tests.ps1
📝 Walkthrough

Walkthrough

This PR refactors guest-helpers/windows/filerestore.bat into helper functions and a guarded entry point, adds containerized Windows Pester execution in the Makefile, adds shared test helpers and a Pester suite, and documents Windows and Linux test commands.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

  • kubevirt/vm-file-restore-operator#23: Updates the same root Makefile test-target orchestration for guest-helper script testing, with the main PR extending that setup to Windows Pester coverage.

Warning

Review ran into problems

🔥 Problems

Linked repositories: Public OSS repositories can only analyze public repositories installed in this organization. Analyzed kubevirt/hyperconverged-cluster-operator, kubevirt/monitoring, skipped kubevirt/kubevirt, kubevirt/containerized-data-importer.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🧹 Nitpick comments (2)
guest-helpers/windows/filerestore.bat (1)

223-232: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Optional: fail fast on UNC --source-path before mounting.

The UNC rejection (Line 229-232) runs inside the try block, after the disk has already been brought online, unlocked, and junction-mounted. Since this check doesn't depend on the mount at all, validating it during argument parsing would avoid an unnecessary mount/unmount cycle for a request that's guaranteed to fail.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@guest-helpers/windows/filerestore.bat` around lines 223 - 232, Move the UNC
--source-path validation out of the try/finally flow in filerestore.bat so it
happens during argument parsing or before any disk mount/unlock work begins. The
current check inside the automatic mode block still allows the mount lifecycle
to run first; update the handling around the SourcePath validation to fail fast
with the same error message and return code before any side effects occur.
guest-helpers/windows/test/filerestore.Tests.ps1 (1)

329-336: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add cleanup assertion once junction-failure disk cleanup is fixed.

This test only checks ExitCode -eq 1. Once the missing disk-offline cleanup on junction failure (see filerestore.bat Lines 207-213) is addressed, extend this test to assert Should -Invoke Set-Disk -ParameterFilter { $IsOffline -eq $true } so the fix is regression-locked.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@guest-helpers/windows/test/filerestore.Tests.ps1` around lines 329 - 336, The
junction-failure test in filerestore.Tests.ps1 only asserts the nonzero exit
code, but it should also cover the disk-offline cleanup path once the
filerestore failure handling is fixed. Update the existing `It 'exits 1 when
junction creation fails'` case around `Invoke-TestScript`, `New-Junction`, and
`Set-Disk` to add an assertion that `Set-Disk` is invoked with `-ParameterFilter
{ $IsOffline -eq $true }`, so the cleanup behavior is regression-locked
alongside the exit code check.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@guest-helpers/windows/filerestore.bat`:
- Around line 36-38: The `New-Junction` and `Remove-Junction` wrapper functions
are interpolating `$Path` and `$Target` directly into `cmd /c` commands, which
allows shell metacharacters to break out of the quoted arguments. Update these
helpers to avoid `cmd.exe` entirely by using PowerShell-native junction
operations (for example, `New-Item -ItemType Junction` and `Remove-Item -Force`)
and keep the same wrapper function names so the call sites continue to work
safely.

In `@Makefile`:
- Around line 180-192: The Makefile has two `test-scripts` target definitions,
which leaves redundant and potentially divergent prerequisites. Remove the stale
duplicate `test-scripts: test-scripts-linux` rule and keep the consolidated
`test-scripts` target that depends on both `test-scripts-windows` and
`test-scripts-linux`, using the existing `test-scripts`, `test-scripts-windows`,
and `test-scripts-linux` targets as the reference points.

---

Nitpick comments:
In `@guest-helpers/windows/filerestore.bat`:
- Around line 223-232: Move the UNC --source-path validation out of the
try/finally flow in filerestore.bat so it happens during argument parsing or
before any disk mount/unlock work begins. The current check inside the automatic
mode block still allows the mount lifecycle to run first; update the handling
around the SourcePath validation to fail fast with the same error message and
return code before any side effects occur.

In `@guest-helpers/windows/test/filerestore.Tests.ps1`:
- Around line 329-336: The junction-failure test in filerestore.Tests.ps1 only
asserts the nonzero exit code, but it should also cover the disk-offline cleanup
path once the filerestore failure handling is fixed. Update the existing `It
'exits 1 when junction creation fails'` case around `Invoke-TestScript`,
`New-Junction`, and `Set-Disk` to add an assertion that `Set-Disk` is invoked
with `-ParameterFilter { $IsOffline -eq $true }`, so the cleanup behavior is
regression-locked alongside the exit code check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4f9f287b-13fe-497c-95b8-0a047a1b5dd5

📥 Commits

Reviewing files that changed from the base of the PR and between ceec1be and efadff6.

📒 Files selected for processing (5)
  • Makefile
  • guest-helpers/windows/TESTING.md
  • guest-helpers/windows/filerestore.bat
  • guest-helpers/windows/test/TestHelper.psm1
  • guest-helpers/windows/test/filerestore.Tests.ps1
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • kubevirt/hyperconverged-cluster-operator (manual)
  • kubevirt/monitoring (manual)

Comment thread guest-helpers/windows/filerestore.bat
Comment thread Makefile Outdated
Copilot AI review requested due to automatic review settings July 9, 2026 08:28
@ema-aka-young ema-aka-young force-pushed the guest-helper-windows-tests branch from 394f27c to fc5acf1 Compare July 9, 2026 08:28

Copilot AI 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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread guest-helpers/windows/TESTING.md Outdated
- Introduced Pester tests for the Windows guest helper script (`filerestore.bat`).
- Updated Makefile to include a new target for running Windows tests.
- Created `TESTING.md` for Windows guest helper with instructions on running tests.
- Refactored `filerestore.bat` to support testing and improve argument parsing.
- Added `TestHelper.psm1` for shared functions used in Pester tests.
- Implemented comprehensive Pester tests covering various scenarios for the Windows guest helper.

Signed-off-by: Emanuele Prella <eprella@redhat.com>
Copilot AI review requested due to automatic review settings July 9, 2026 08:34
@ema-aka-young ema-aka-young force-pushed the guest-helper-windows-tests branch from fc5acf1 to 6717f19 Compare July 9, 2026 08:34

Copilot AI 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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment on lines +229 to +233
if ($SourcePath -match '^\\\\') {
Write-Host "ERROR: UNC paths are not supported for --source-path"
return 1
}
$RelativePath = $SourcePath -replace '^[A-Za-z]:\\', ''
Comment on lines +37 to +55
function script:Invoke-TestScript {
param(
[string[]]$Arguments = @(),
[hashtable]$Env = @{}
)
try {
foreach ($key in $Env.Keys) {
Set-Item "env:$key" $Env[$key]
}
return @{ ExitCode = (Invoke-FileRestore $Arguments) }
} catch {
throw "Invoke-FileRestore threw unexpectedly: $_"
} finally {
foreach ($key in $Env.Keys) {
Remove-Item "env:$key" -ErrorAction SilentlyContinue
}
}
}
}

@coderabbitai coderabbitai 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.

♻️ Duplicate comments (1)
guest-helpers/windows/filerestore.bat (1)

269-284: 🔒 Security & Privacy | 🔴 Critical | 🏗️ Heavy lift

Critical: SSH forced-command bypass via cmd /c re-injection of SSH_ORIGINAL_COMMAND.

Test-SshCommand only validates that the command starts with the fixed filerestore.bat path (Line 82); everything after that prefix is returned unmodified as $sshResult. That raw, attacker-supplied string is then re-interpolated into cmd /c "<path> $sshResult" (Line 279). Since cmd /c parses the entire resulting line, any shell metacharacters in $sshResult (&, |, &&, >, etc.) execute as additional commands — e.g. an SSH client sending "...\filerestore.bat" restore & calc.exe sails through the prefix check and then runs calc.exe (or any attacker payload) via the reinvoked cmd /c. This completely defeats the SSH forced-command restriction and grants arbitrary command execution as the sshd service account — a strictly worse outcome than the previously-discussed (and accepted) junction-wrapper interpolation risk, since it requires no --mount-path control at all.

Avoid re-invoking through cmd /c with a reconstructed string entirely. Since the functions are already loaded in this same process, tokenize $sshResult (respecting quotes, without shell-operator interpretation) and call Invoke-FileRestore directly instead of shelling out:

🔒 Proposed fix — avoid cmd.exe reinterpretation
 if ($null -ne $sshResult) {
     $env:SSH_ORIGINAL_COMMAND = $null
-    cmd /c "`"C:\Program Files\filerestore\filerestore.bat`" $sshResult"
-    exit $LASTEXITCODE
+    # Tokenize like a native command line (quote-aware) without invoking a
+    # shell, so `&`, `|`, etc. in SSH_ORIGINAL_COMMAND cannot be interpreted
+    # as command separators.
+    $parsedArgs = [regex]::Matches($sshResult, '"[^"]*"|\S+') |
+        ForEach-Object { $_.Value.Trim('"') }
+    exit (Invoke-FileRestore $parsedArgs)
 }

Please verify the tokenization approach against real-world --mount-path/--source-path values that may contain quoted spaces before landing this fix, since it changes how the SSH forced-command path parses arguments.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@guest-helpers/windows/filerestore.bat` around lines 269 - 284, The SSH
forced-command path in Test-SshCommand and the entry-point block is vulnerable
because $sshResult is re-injected into cmd /c, allowing shell metacharacters to
be executed as extra commands. Remove the cmd /c round-trip in the entry point
and dispatch directly to Invoke-FileRestore after safely tokenizing $sshResult
as arguments, preserving quoted paths without letting cmd.exe reinterpret them.
Keep the Test-SshCommand prefix check, but ensure the main flow uses the parsed
argument list rather than a reconstructed command string.
🧹 Nitpick comments (2)
Makefile (1)

180-191: 🧹 Nitpick | 🔵 Trivial

Network dependency on every CI run.

test-scripts-windows calls Install-Module Pester -RequiredVersion $(PESTER_VERSION) ... on every invocation, so CI reliability now depends on PowerShell Gallery availability with no local caching/fallback. Consider caching the module (e.g., a persisted volume or pre-baked image) if this test target ends up running frequently.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Makefile` around lines 180 - 191, The test-scripts-windows target currently
installs Pester inside the Invoke-Pester container on every run, creating an
unnecessary network dependency. Update the Makefile target so it reuses a cached
or preinstalled Pester module instead of always calling Install-Module, for
example by using a persisted volume or a pre-baked $(PWSH_IMAGE); keep the
change localized to test-scripts-windows and related test-scripts behavior.
guest-helpers/windows/test/filerestore.Tests.ps1 (1)

1-89: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Coverage gap: SSH dispatch/reinvocation entry point is untested.

All tests call Test-SshCommand or Invoke-FileRestore directly; none exercise the actual entry-point block in filerestore.bat (Lines 269-284) that reinvokes the script via cmd /c with the extracted SSH arguments. That's exactly the code path flagged as a critical command-injection risk in filerestore.bat — once fixed, it would be valuable to add a test (e.g., mocking the dispatch call) asserting that shell metacharacters in SSH_ORIGINAL_COMMAND are not given special interpretation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@guest-helpers/windows/test/filerestore.Tests.ps1` around lines 1 - 89, The
SSH dispatch entry point is not covered by these tests, so the reinvocation path
can still mishandle injected shell metacharacters. Add a Pester test around the
actual entry-point logic in filerestore.bat by invoking the script through its
SSH command path and mocking the cmd /c reinvocation, then assert the extracted
arguments are passed through as plain data and not reinterpreted. Use the
existing Test-SshCommand and Invoke-FileRestore helpers as the basis, but target
the top-level dispatch block that calls cmd /c.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@guest-helpers/windows/filerestore.bat`:
- Around line 269-284: The SSH forced-command path in Test-SshCommand and the
entry-point block is vulnerable because $sshResult is re-injected into cmd /c,
allowing shell metacharacters to be executed as extra commands. Remove the cmd
/c round-trip in the entry point and dispatch directly to Invoke-FileRestore
after safely tokenizing $sshResult as arguments, preserving quoted paths without
letting cmd.exe reinterpret them. Keep the Test-SshCommand prefix check, but
ensure the main flow uses the parsed argument list rather than a reconstructed
command string.

---

Nitpick comments:
In `@guest-helpers/windows/test/filerestore.Tests.ps1`:
- Around line 1-89: The SSH dispatch entry point is not covered by these tests,
so the reinvocation path can still mishandle injected shell metacharacters. Add
a Pester test around the actual entry-point logic in filerestore.bat by invoking
the script through its SSH command path and mocking the cmd /c reinvocation,
then assert the extracted arguments are passed through as plain data and not
reinterpreted. Use the existing Test-SshCommand and Invoke-FileRestore helpers
as the basis, but target the top-level dispatch block that calls cmd /c.

In `@Makefile`:
- Around line 180-191: The test-scripts-windows target currently installs Pester
inside the Invoke-Pester container on every run, creating an unnecessary network
dependency. Update the Makefile target so it reuses a cached or preinstalled
Pester module instead of always calling Install-Module, for example by using a
persisted volume or a pre-baked $(PWSH_IMAGE); keep the change localized to
test-scripts-windows and related test-scripts behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 164063e0-4a3b-4179-8316-a8242986ea24

📥 Commits

Reviewing files that changed from the base of the PR and between efadff6 and fc5acf1.

📒 Files selected for processing (6)
  • Makefile
  • guest-helpers/linux/TESTING.md
  • guest-helpers/windows/TESTING.md
  • guest-helpers/windows/filerestore.bat
  • guest-helpers/windows/test/TestHelper.psm1
  • guest-helpers/windows/test/filerestore.Tests.ps1
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • kubevirt/hyperconverged-cluster-operator (manual)
  • kubevirt/monitoring (manual)
✅ Files skipped from review due to trivial changes (1)
  • guest-helpers/linux/TESTING.md

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

Labels

dco-signoff: yes Indicates the PR's author has DCO signed all their commits. release-note-none Denotes a PR that doesn't merit a release note. size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants