Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 15, 2025

  • Fix PSCmdlet references in scriptblocks and update documentation
    • Replace 7 instances of $PSCmdlet with $script:ScriptPSCmdlet inside scriptblocks (lines 220, 225, 262, 301, 350, 356, 392)
    • Add .EXAMPLE for -DestructiveMode parameter
    • Remove 2 misleading comments about removed test contexts
    • Add Copilot PR review policy to disable automatic reviews

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…se tests, improve automation support

Co-authored-by: AprilDeFeu <[email protected]>
Copilot AI changed the title [WIP] Fix issues with PowerShell test integration Fix runtime errors and automation blockers from PR #15 review feedback Nov 15, 2025
Copilot AI requested a review from AprilDeFeu November 15, 2025 20:23
@AprilDeFeu AprilDeFeu marked this pull request as ready for review November 15, 2025 20:29
Copilot AI review requested due to automatic review settings November 15, 2025 20:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses critical runtime errors and automation blockers identified in PR #15 code review. The changes fix removed function references, eliminate interactive prompts blocking automation, restore removed edge case tests, and improve CI reliability by removing test result caching.

Key changes:

  • Replaced 5 calls to removed Confirm-Action function with $PSCmdlet.ShouldProcess()
  • Added -DestructiveMode parameter to replace interactive Read-Host prompts
  • Restored 5 edge case tests and Dependencies context that were previously removed
  • Removed CI test result caching optimization to prevent bypassing checks with stale results

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
PowerShell/system-administration/maintenance/system-maintenance.ps1 Added -DestructiveMode parameter, replaced interactive prompts with ShouldProcess()/ShouldContinue(), fixed $script:ScriptPSCmdlet initialization
tests/unit/PowerShell/system-maintenance.Tests.ps1 Restored Edge Cases and Dependencies contexts, simplified assertion patterns
.pre-commit-config.yaml Added specific file pattern to scope pre-commit hook
.github/workflows/ci.yml Removed test result caching logic
.githooks/pre-commit.ps1 Added explicit failure when test file is missing
Comments suppressed due to low confidence (1)

PowerShell/system-administration/maintenance/system-maintenance.ps1:250

  • Inside scriptblocks passed to Invoke-Step, $PSCmdlet is not automatically available. This should use $script:ScriptPSCmdlet instead to properly respect -WhatIf and -Confirm parameters.
                if ($PSCmdlet.ShouldProcess("Delete old files in $p", 'Delete files')) {

Write-Host "Please back up any important files before continuing." -ForegroundColor Yellow
$null = Read-Host "Press Enter to continue with disk cleanup or Ctrl+C to abort"
# Use ShouldContinue for non-interactive compatibility
if (-not $PSCmdlet.ShouldContinue("Continue with disk cleanup after reviewing disk errors?", "Disk errors were found on $sysDrive")) {
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

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

Inside scriptblocks passed to Invoke-Step, $PSCmdlet is not automatically available. This should use $script:ScriptPSCmdlet instead (which is initialized at line 68) to access the correct cmdlet context with -WhatIf and -Confirm support.

Copilot uses AI. Check for mistakes.
# After user review, offer to schedule repair
$scheduleRepair = Read-Host "Would you like to schedule a disk repair on next reboot? [y/N]"
if ($scheduleRepair -match '^[Yy]') {
if ($PSCmdlet.ShouldContinue("Schedule a disk repair on next reboot?", "CHKDSK repair")) {
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

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

Inside scriptblocks passed to Invoke-Step, $PSCmdlet is not automatically available. This should use $script:ScriptPSCmdlet instead to access the correct cmdlet context.

Copilot uses AI. Check for mistakes.
$wuCache = "$env:WINDIR\SoftwareDistribution\Download"
if (Test-Path $wuCache) {
if (Confirm-Action -Target 'Windows Update download cache' -Action 'Clear cache') {
if ($PSCmdlet.ShouldProcess('Windows Update download cache', 'Clear cache')) {
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

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

Inside scriptblocks passed to Invoke-Step, $PSCmdlet is not automatically available. This should use $script:ScriptPSCmdlet instead to properly respect -WhatIf and -Confirm parameters.

Copilot uses AI. Check for mistakes.
$doPath = "$env:ProgramData\Microsoft\Windows\DeliveryOptimization\Cache"
if (Test-Path $doPath) {
if (Confirm-Action -Target 'Delivery Optimization cache' -Action 'Clear cache') {
if ($PSCmdlet.ShouldProcess('Delivery Optimization cache', 'Clear cache')) {
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

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

Inside scriptblocks passed to Invoke-Step, $PSCmdlet is not automatically available. This should use $script:ScriptPSCmdlet instead to properly respect -WhatIf and -Confirm parameters.

Copilot uses AI. Check for mistakes.

if ($isSSD) {
if (Confirm-Action -Target "${letter}: (SSD)" -Action 'ReTrim volume') {
if ($PSCmdlet.ShouldProcess("${letter}: (SSD)", 'ReTrim volume')) {
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

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

Inside scriptblocks passed to Invoke-Step, $PSCmdlet is not automatically available. This should use $script:ScriptPSCmdlet instead to properly respect -WhatIf and -Confirm parameters.

Copilot uses AI. Check for mistakes.
}
else {
if (Confirm-Action -Target "${letter}: (HDD)" -Action 'Defragment volume') {
if ($PSCmdlet.ShouldProcess("${letter}: (HDD)", 'Defragment volume')) {
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

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

Inside scriptblocks passed to Invoke-Step, $PSCmdlet is not automatically available. This should use $script:ScriptPSCmdlet instead to properly respect -WhatIf and -Confirm parameters.

Copilot uses AI. Check for mistakes.
Write-Output ("{0}: {1}" -f $svc.Name, $svc.Status)
if ($svc.Status -ne 'Running') {
if (Confirm-Action -Target $svc.Name -Action 'Start service') {
if ($PSCmdlet.ShouldProcess($svc.Name, 'Start service')) {
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

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

Inside scriptblocks passed to Invoke-Step, $PSCmdlet is not automatically available. This should use $script:ScriptPSCmdlet instead to properly respect -WhatIf and -Confirm parameters.

Suggested change
if ($PSCmdlet.ShouldProcess($svc.Name, 'Start service')) {
if ($script:ScriptPSCmdlet.ShouldProcess($svc.Name, 'Start service')) {

Copilot uses AI. Check for mistakes.
Comment on lines +25 to +28
.PARAMETER DestructiveMode
When specified, enables destructive operations (disk cleanup, network reset,
CHKDSK repair) without interactive prompts. Use with caution in automated
scenarios. Without this flag, destructive operations require confirmation.
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

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

The parameter documentation should include at least one .EXAMPLE demonstrating how to use the new -DestructiveMode parameter, following PowerShell comment-based help best practices. For example: .\system-maintenance.ps1 -DestructiveMode -WhatIf

Copilot uses AI. Check for mistakes.
}
}

# Context "Edge Cases" removed: requires admin rights
Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

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

This comment is misleading because the "Edge Cases" context was just added above at line 93. This comment should be removed or clarified to avoid confusion.

Suggested change
# Context "Edge Cases" removed: requires admin rights

Copilot uses AI. Check for mistakes.
Comment on lines 149 to 150
# Context "Dependencies" removed: requires admin rights

Copy link

Copilot AI Nov 15, 2025

Choose a reason for hiding this comment

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

This comment is misleading because the "Dependencies" context was just added above at line 136. This comment should be removed or clarified to avoid confusion.

Suggested change
# Context "Dependencies" removed: requires admin rights

Copilot uses AI. Check for mistakes.
@AprilDeFeu
Copy link
Owner

@copilot apply changes based on the comments in this thread as a task, not as a new PR

Additionally, parse through the workflow and ensure you deactivate any requirements to or add explicit instructions for copilot to never automatically review PRs marked as ready for review. I want to use my premium requests wisely, and running reviews without any concern is not a good idea, so unless I manually tag you to ask, I do not want a review.

Copy link
Contributor Author

Copilot AI commented Nov 15, 2025

@copilot apply changes based on the comments in this thread as a task, not as a new PR

Additionally, parse through the...

Applied all changes in commit 06938b1:

Fixed PSCmdlet references (7 locations):

  • Lines 220, 225: CHKDSK prompts now use $script:ScriptPSCmdlet.ShouldContinue()
  • Lines 262, 301: Windows Update and Delivery Optimization cache use $script:ScriptPSCmdlet.ShouldProcess()
  • Lines 350, 356: Drive optimization (SSD/HDD) use $script:ScriptPSCmdlet.ShouldProcess()
  • Line 392: Service start operations use $script:ScriptPSCmdlet.ShouldProcess()

Updated documentation:

  • Added .EXAMPLE for -DestructiveMode parameter showing usage with -WhatIf
  • Removed 2 misleading comments about "removed" test contexts

Copilot PR review policy:

  • Added explicit instructions to .github/copilot-instructions.md to never automatically review PRs
  • Reviews will only run when explicitly requested via @copilot tag

All 20 tests passing.

@AprilDeFeu AprilDeFeu merged commit 34de42d into feat/testing-framework Nov 15, 2025
@AprilDeFeu AprilDeFeu deleted the copilot/sub-pr-15 branch November 16, 2025 04:37
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.

2 participants