From 5acba3ed09b4f2eb8085d113e6f8df39816c4880 Mon Sep 17 00:00:00 2001 From: Magnetarman <40738529+Magnetarman@users.noreply.github.com> Date: Sun, 11 Oct 2026 15:19:12 +0200 Subject: [PATCH 1/9] Update WinCleaner.Tests.ps1 --- .github/tests/Unit/WinCleaner.Tests.ps1 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/tests/Unit/WinCleaner.Tests.ps1 b/.github/tests/Unit/WinCleaner.Tests.ps1 index 5a5320ed..4ead21b2 100644 --- a/.github/tests/Unit/WinCleaner.Tests.ps1 +++ b/.github/tests/Unit/WinCleaner.Tests.ps1 @@ -57,4 +57,27 @@ 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\)'" + } } \ No newline at end of file From 09969047ccdce2f3d4ef6a8a83c49a90024824ea Mon Sep 17 00:00:00 2001 From: Magnetarman <40738529+Magnetarman@users.noreply.github.com> Date: Sun, 11 Oct 2026 15:19:15 +0200 Subject: [PATCH 2/9] Update WinCleaner.ps1 --- tools/WinCleaner.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/WinCleaner.ps1 b/tools/WinCleaner.ps1 index a9c353ec..15a5588a 100644 --- a/tools/WinCleaner.ps1 +++ b/tools/WinCleaner.ps1 @@ -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 { From 5cd11d25c2ecf9d0000f868df7d847aae84c6cbd Mon Sep 17 00:00:00 2001 From: Magnetarman <40738529+Magnetarman@users.noreply.github.com> Date: Sun, 11 Oct 2026 13:21:13 +0000 Subject: [PATCH 3/9] =?UTF-8?q?=E2=9C=85=20Build=20WinToolkit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinToolkit.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WinToolkit.ps1 b/WinToolkit.ps1 index 136f1c95..2633af04 100644 --- a/WinToolkit.ps1 +++ b/WinToolkit.ps1 @@ -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 { From 69baf703ca8616221ca0e0325d8d8ebd4be16b42 Mon Sep 17 00:00:00 2001 From: Magnetarman <40738529+Magnetarman@users.noreply.github.com> Date: Sun, 11 Oct 2026 15:31:08 +0200 Subject: [PATCH 4/9] Update WinCleaner.Tests.ps1 --- .github/tests/Unit/WinCleaner.Tests.ps1 | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/tests/Unit/WinCleaner.Tests.ps1 b/.github/tests/Unit/WinCleaner.Tests.ps1 index 4ead21b2..fe034439 100644 --- a/.github/tests/Unit/WinCleaner.Tests.ps1 +++ b/.github/tests/Unit/WinCleaner.Tests.ps1 @@ -80,4 +80,20 @@ Describe 'WinCleaner โ€” Invoke-CommandAction displayName (regression for empty $source | Should -Match "Name\s*=\s*'Running CleanMgr with /sagerun:65'" $source | Should -Match "Name\s*=\s*'Removing Windows\.old \(CleanMgr\)'" } -} \ No newline at end of file +} + +Describe 'WinCleaner โ€” Get-LocalUserProfiles (regression for undefined function)' { + + It 'WinCleaner.ps1 must define a Get-LocalUserProfiles helper' { + # WinCleaner per-user rules call Get-LocalUserProfiles; if undefined the cleaner + # aborts with "Il termine 'Get-LocalUserProfiles' non รจ riconosciuto" right after + # the Windows Update cache step. + $source = Get-Content -Path $script:ToolPath -Raw + $source | Should -Match 'function Get-LocalUserProfiles\s*\{' + } + + It 'Get-LocalUserProfiles must delegate to the shared core helper' { + $source = Get-Content -Path $script:ToolPath -Raw + $source | Should -Match 'Get-SourceTextLocalUserProfiles' + } +} From 3c3a588d09374cae4c3d9021a50035245f1895ac Mon Sep 17 00:00:00 2001 From: Magnetarman <40738529+Magnetarman@users.noreply.github.com> Date: Sun, 11 Oct 2026 15:31:12 +0200 Subject: [PATCH 5/9] Update WinCleaner.ps1 --- tools/WinCleaner.ps1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/WinCleaner.ps1 b/tools/WinCleaner.ps1 index 15a5588a..8d7a8f2c 100644 --- a/tools/WinCleaner.ps1 +++ b/tools/WinCleaner.ps1 @@ -69,6 +69,14 @@ function WinCleaner { } + function Get-LocalUserProfiles { + if (Get-Command Get-SourceTextLocalUserProfiles -ErrorAction SilentlyContinue) { + return Get-SourceTextLocalUserProfiles + } + return Get-ChildItem -Path 'C:\Users' -Directory -ErrorAction SilentlyContinue | + Where-Object { $_.Name -notmatch '^(Public|Default|Default User|All Users)$' } + } + function Invoke-CommandAction { param($Rule) $displayName = if ($Rule.NameKey) { Get-SourceTextLoc $Rule.NameKey } else { $Rule.Name } From 4260482e5bf9ee7799b97161a6f4da4babf3e20b Mon Sep 17 00:00:00 2001 From: Magnetarman <40738529+Magnetarman@users.noreply.github.com> Date: Sun, 11 Oct 2026 15:34:29 +0200 Subject: [PATCH 6/9] Update 40-Module.System.ps1 --- wintoolkit-modules/40-Module.System.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wintoolkit-modules/40-Module.System.ps1 b/wintoolkit-modules/40-Module.System.ps1 index 83f718c5..6b34032c 100644 --- a/wintoolkit-modules/40-Module.System.ps1 +++ b/wintoolkit-modules/40-Module.System.ps1 @@ -75,7 +75,7 @@ function Get-BitlockerStatus { } -function Get-SourceTextLocalUserProfiles { +function Get-LocalUserProfiles { <# .SYNOPSIS Restituisce le directory utente reali, escludendo i profili di sistema. From 17e19f3ffb82c4b5a67efc95813a542a0ae8927f Mon Sep 17 00:00:00 2001 From: Magnetarman <40738529+Magnetarman@users.noreply.github.com> Date: Sun, 11 Oct 2026 15:34:34 +0200 Subject: [PATCH 7/9] Update WinCleaner.ps1 --- tools/WinCleaner.ps1 | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tools/WinCleaner.ps1 b/tools/WinCleaner.ps1 index 8d7a8f2c..15a5588a 100644 --- a/tools/WinCleaner.ps1 +++ b/tools/WinCleaner.ps1 @@ -69,14 +69,6 @@ function WinCleaner { } - function Get-LocalUserProfiles { - if (Get-Command Get-SourceTextLocalUserProfiles -ErrorAction SilentlyContinue) { - return Get-SourceTextLocalUserProfiles - } - return Get-ChildItem -Path 'C:\Users' -Directory -ErrorAction SilentlyContinue | - Where-Object { $_.Name -notmatch '^(Public|Default|Default User|All Users)$' } - } - function Invoke-CommandAction { param($Rule) $displayName = if ($Rule.NameKey) { Get-SourceTextLoc $Rule.NameKey } else { $Rule.Name } From ac0ebc1ba816f5aff7786e568c824ec97909f15b Mon Sep 17 00:00:00 2001 From: Magnetarman <40738529+Magnetarman@users.noreply.github.com> Date: Sun, 11 Oct 2026 15:34:41 +0200 Subject: [PATCH 8/9] Update WinCleaner.Tests.ps1 --- .github/tests/Unit/WinCleaner.Tests.ps1 | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/tests/Unit/WinCleaner.Tests.ps1 b/.github/tests/Unit/WinCleaner.Tests.ps1 index fe034439..82ff1b7b 100644 --- a/.github/tests/Unit/WinCleaner.Tests.ps1 +++ b/.github/tests/Unit/WinCleaner.Tests.ps1 @@ -84,16 +84,18 @@ Describe 'WinCleaner โ€” Invoke-CommandAction displayName (regression for empty Describe 'WinCleaner โ€” Get-LocalUserProfiles (regression for undefined function)' { - It 'WinCleaner.ps1 must define a Get-LocalUserProfiles helper' { - # WinCleaner per-user rules call Get-LocalUserProfiles; if undefined the cleaner - # aborts with "Il termine 'Get-LocalUserProfiles' non รจ riconosciuto" right after - # the Windows Update cache step. - $source = Get-Content -Path $script:ToolPath -Raw - $source | Should -Match 'function Get-LocalUserProfiles\s*\{' + 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 'Get-LocalUserProfiles must delegate to the shared core helper' { + It 'WinCleaner references Get-LocalUserProfiles and does not define a local copy' { $source = Get-Content -Path $script:ToolPath -Raw - $source | Should -Match 'Get-SourceTextLocalUserProfiles' + $source | Should -Match 'Get-LocalUserProfiles' + $source | Should -Not -Match 'function Get-LocalUserProfiles\s*\{' } } From 85c0f63dc912c57921ab6c3e1fba6541640578d6 Mon Sep 17 00:00:00 2001 From: Magnetarman <40738529+Magnetarman@users.noreply.github.com> Date: Sun, 11 Oct 2026 13:38:33 +0000 Subject: [PATCH 9/9] =?UTF-8?q?=E2=9C=85=20Build=20WinToolkit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinToolkit.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WinToolkit.ps1 b/WinToolkit.ps1 index 2633af04..36a15d7d 100644 --- a/WinToolkit.ps1 +++ b/WinToolkit.ps1 @@ -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)$' } }