Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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().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 }
$timestamp = (Get-Date).ToString('yyyy-MM-dd_HH-mm-ss')
Expand Down
25 changes: 19 additions & 6 deletions tests/unit/PowerShell/system-maintenance.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@
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
}
$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" {
Expand All @@ -14,20 +25,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
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

Get-Command -Name expects a command name (like 'Get-Process'), not a file path. When working with script file paths, you should use the -LiteralPath parameter instead:

$command = Get-Command -LiteralPath $scriptPath

The -Name parameter will fail to find the command or may behave unpredictably when given a full file path.

Suggested change
$command = Get-Command -Name $scriptPath
$command = Get-Command -LiteralPath $scriptPath

Copilot uses AI. Check for mistakes.
$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
}
}
}