From 7771b7050ebe4f8ab7aa8b7671dfe90749313566 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 04:12:11 +0000 Subject: [PATCH 1/3] Initial plan From a3c6b51c3eb9301979a181867a33372479cf476b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 04:28:12 +0000 Subject: [PATCH 2/3] Fix PowerShell test failures - handle empty MyDocuments path and fix test assertions Co-authored-by: AprilDeFeu <36605389+AprilDeFeu@users.noreply.github.com> --- .../maintenance/system-maintenance.ps1 | 4 ++++ .../PowerShell/system-maintenance.Tests.ps1 | 21 +++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/PowerShell/system-administration/maintenance/system-maintenance.ps1 b/PowerShell/system-administration/maintenance/system-maintenance.ps1 index b6b6a3d..43a2527 100644 --- a/PowerShell/system-administration/maintenance/system-maintenance.ps1 +++ b/PowerShell/system-administration/maintenance/system-maintenance.ps1 @@ -46,6 +46,10 @@ $ErrorActionPreference = 'Stop' function Get-LogFilePath { $userDocs = [Environment]::GetFolderPath('MyDocuments') + # Fallback to temp directory if MyDocuments is not available + if ([string]::IsNullOrWhiteSpace($userDocs)) { + $userDocs = [System.IO.Path]::GetTempPath() + } $logRoot = Join-Path $userDocs 'SystemLogs' if (-not (Test-Path $logRoot)) { New-Item -Path $logRoot -ItemType Directory -Force | Out-Null } $timestamp = (Get-Date).ToString('yyyy-MM-dd_HH-mm-ss') diff --git a/tests/unit/PowerShell/system-maintenance.Tests.ps1 b/tests/unit/PowerShell/system-maintenance.Tests.ps1 index b9c4645..3fb7359 100644 --- a/tests/unit/PowerShell/system-maintenance.Tests.ps1 +++ b/tests/unit/PowerShell/system-maintenance.Tests.ps1 @@ -3,8 +3,15 @@ BeforeAll { # Suppress verbose output from the script itself during tests $VerbosePreference = 'SilentlyContinue' - # Path to the script being tested - $scriptPath = "$PSScriptRoot/../../../PowerShell/system-administration/maintenance/system-maintenance.ps1" + # Path to the script being tested - resolve to absolute path + $testDir = $PSScriptRoot + if (-not $testDir) { + $testDir = Split-Path -Parent $MyInvocation.MyCommand.Path + } + if (-not $testDir) { + $testDir = Get-Location + } + $script:scriptPath = Join-Path $testDir "../../../PowerShell/system-administration/maintenance/system-maintenance.ps1" | Resolve-Path | Select-Object -ExpandProperty Path } Describe "system-maintenance.ps1" { @@ -14,20 +21,22 @@ Describe "system-maintenance.ps1" { } It "should have comment-based help" { - $help = Get-Help -Path $scriptPath -ErrorAction SilentlyContinue + $help = Get-Help $scriptPath -ErrorAction SilentlyContinue $help | Should -Not -BeNull - ($help.Name -eq 'system-maintenance') | Should -Be $true + $help.Name | Should -Be 'system-maintenance.ps1' } It "should support -WhatIf" { - $command = Get-Command -Path $scriptPath + $command = Get-Command -Name $scriptPath $command.Parameters.Keys | Should -Contain 'WhatIf' } } Context "Execution Smoke Test" { It "should run without throwing errors with default parameters" { - { & $scriptPath -WhatIf } | Should -Not -Throw + # Capture the path in a local variable to ensure it's available in the scriptblock + $localPath = $scriptPath + { & $localPath -WhatIf } | Should -Not -Throw } } } From 66f7b4b99c736252a7d887161a28522f630bd0e2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 12 Nov 2025 04:46:03 +0000 Subject: [PATCH 3/3] Apply code review suggestions: add path validation and trim temp path separators Co-authored-by: AprilDeFeu <36605389+AprilDeFeu@users.noreply.github.com> --- .../maintenance/system-maintenance.ps1 | 2 +- tests/unit/PowerShell/system-maintenance.Tests.ps1 | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/PowerShell/system-administration/maintenance/system-maintenance.ps1 b/PowerShell/system-administration/maintenance/system-maintenance.ps1 index 43a2527..51c051e 100644 --- a/PowerShell/system-administration/maintenance/system-maintenance.ps1 +++ b/PowerShell/system-administration/maintenance/system-maintenance.ps1 @@ -48,7 +48,7 @@ function Get-LogFilePath { $userDocs = [Environment]::GetFolderPath('MyDocuments') # Fallback to temp directory if MyDocuments is not available if ([string]::IsNullOrWhiteSpace($userDocs)) { - $userDocs = [System.IO.Path]::GetTempPath() + $userDocs = [System.IO.Path]::GetTempPath().TrimEnd([System.IO.Path]::DirectorySeparatorChar, [System.IO.Path]::AltDirectorySeparatorChar) } $logRoot = Join-Path $userDocs 'SystemLogs' if (-not (Test-Path $logRoot)) { New-Item -Path $logRoot -ItemType Directory -Force | Out-Null } diff --git a/tests/unit/PowerShell/system-maintenance.Tests.ps1 b/tests/unit/PowerShell/system-maintenance.Tests.ps1 index 3fb7359..89e19d6 100644 --- a/tests/unit/PowerShell/system-maintenance.Tests.ps1 +++ b/tests/unit/PowerShell/system-maintenance.Tests.ps1 @@ -11,7 +11,11 @@ BeforeAll { if (-not $testDir) { $testDir = Get-Location } - $script:scriptPath = Join-Path $testDir "../../../PowerShell/system-administration/maintenance/system-maintenance.ps1" | Resolve-Path | Select-Object -ExpandProperty Path + $relativePath = Join-Path $testDir "../../../PowerShell/system-administration/maintenance/system-maintenance.ps1" + if (-not (Test-Path $relativePath)) { + throw "Script not found at: $relativePath" + } + $script:scriptPath = Resolve-Path $relativePath | Select-Object -ExpandProperty Path } Describe "system-maintenance.ps1" {