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
43 changes: 42 additions & 1 deletion .github/tests/Unit/WinCleaner.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,45 @@ Describe 'WinCleaner — VitalExclusions' {
$source = Get-Content -Path $script:ToolPath -Raw
$source | Should -Match 'LocalAppData.*WinToolkit'
}
}
}

Describe 'WinCleaner — Invoke-CommandAction displayName (regression for empty NameKey)' {

It 'Resolves DisplayName via Get-SourceTextLoc only when NameKey is present' {
$source = Get-Content -Path $script:ToolPath -Raw
$source | Should -Match '\$displayName\s*=\s*if\s*\(\s*\$Rule\.NameKey\s*\)\s*\{'
$source | Should -Match 'Get-SourceTextLoc\s+\$Rule\.NameKey\s*\}\s*else\s*\{\s*\$Rule\.Name\s*\}'
}

It 'Never calls Get-SourceTextLoc with a bare (unguarded) NameKey' {
# Before the fix: "$displayName = Get-SourceTextLoc $Rule.NameKey" → throws
# "Cannot bind argument to parameter 'Key' because it is an empty string"
# when a Command rule omits NameKey (e.g. the inline cleanmgr rules).
$source = Get-Content -Path $script:ToolPath -Raw
$source | Should -Not -Match '\$displayName\s*=\s*Get-SourceTextLoc\s+\$Rule\.NameKey\s*$'
}

It 'Inline CleanMgr Command rules still expose a Name for the NameKey fallback' {
$source = Get-Content -Path $script:ToolPath -Raw
$source | Should -Match "Name\s*=\s*'Running CleanMgr with /sagerun:65'"
$source | Should -Match "Name\s*=\s*'Removing Windows\.old \(CleanMgr\)'"
}
}

Describe 'WinCleaner — Get-LocalUserProfiles (regression for undefined function)' {

It 'Get-LocalUserProfiles is defined by the core and callable at runtime' {
# Before the fix the function was undefined, so every per-user rule aborted
# WinCleaner with "Il termine 'Get-LocalUserProfiles' non è riconosciuto".
# It is provided by the shared core (wintoolkit-modules/40-Module.System.ps1)
# and must therefore be available after the template + tool are imported.
Get-Command Get-LocalUserProfiles -ErrorAction SilentlyContinue | Should -Not -BeNull
{ Get-LocalUserProfiles } | Should -Not -Throw
}

It 'WinCleaner references Get-LocalUserProfiles and does not define a local copy' {
$source = Get-Content -Path $script:ToolPath -Raw
$source | Should -Match 'Get-LocalUserProfiles'
$source | Should -Not -Match 'function Get-LocalUserProfiles\s*\{'
}
}
4 changes: 2 additions & 2 deletions WinToolkit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ function Get-BitlockerStatus {
return (Get-SourceTextLoc 'bitlocker.status.off')
}
}
function Get-SourceTextLocalUserProfiles {
function Get-LocalUserProfiles {
return Get-ChildItem "C:\Users" -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.Name -notmatch '^(Public|Default|Default User|All Users)$' }
}
Expand Down Expand Up @@ -3105,7 +3105,7 @@ function WinCleaner {
}
function Invoke-CommandAction {
param($Rule)
$displayName = Get-SourceTextLoc $Rule.NameKey
$displayName = if ($Rule.NameKey) { Get-SourceTextLoc $Rule.NameKey } else { $Rule.Name }
Clear-ProgressLine
Write-StyledMessage -Type 'Info' -Text ("🚀 " + (Get-SourceTextLoc 'toolText.commandExecution0' -Args @($displayName)))
try {
Expand Down
2 changes: 1 addition & 1 deletion tools/WinCleaner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function WinCleaner {

function Invoke-CommandAction {
param($Rule)
$displayName = Get-SourceTextLoc $Rule.NameKey
$displayName = if ($Rule.NameKey) { Get-SourceTextLoc $Rule.NameKey } else { $Rule.Name }
Clear-ProgressLine
Write-StyledMessage -Type 'Info' -Text ("🚀 " + (Get-SourceTextLoc 'toolText.commandExecution0' -Args @($displayName)))
try {
Expand Down
2 changes: 1 addition & 1 deletion wintoolkit-modules/40-Module.System.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function Get-BitlockerStatus {
}


function Get-SourceTextLocalUserProfiles {
function Get-LocalUserProfiles {
<#
.SYNOPSIS
Restituisce le directory utente reali, escludendo i profili di sistema.
Expand Down
Loading