Skip to content

Bug clean script not work key empty - #197

Merged
Magnetarman merged 9 commits into
Devfrom
BUG-clean-script-not-work-key-empty
Oct 11, 2026
Merged

Magnetarman merged 9 commits into
Devfrom
BUG-clean-script-not-work-key-empty

Conversation

@Magnetarman

@Magnetarman Magnetarman commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

Description

Running WinCleaner aborted at startup. Two sequential defects were identified from the
attached log and fixed:

  1. Cannot bind argument to parameter 'Key' because it is an empty string
  2. Il termine 'Get-LocalUserProfiles' non è riconosciuto come nome di un cmdlet...

1. Empty NameKey crashes Invoke-CommandAction

Invoke-CommandAction (in tools/WinCleaner.ps1) resolved the display name with:

$displayName = Get-SourceTextLoc $Rule.NameKey

Get-SourceTextLoc declares [Parameter(Mandatory = $true)][string]$Key; PowerShell rejects an
empty string with “Cannot bind argument to parameter 'Key' because it is an empty string”
(reproduced and confirmed).

Invoke-CommandAction is used to fire two inline cleanmgr.exe Command rules —
cleanMgrExecutionRule (CleanMgr Config) and the Windows.old removal rule — and neither
declares a NameKey
. The first inline Command rule therefore passed an empty string to
Get-SourceTextLoc and threw at the very first Invoke-CommandAction call, aborting WinCleaner
right after the Configurazione CleanMgr step.

Fix (tools/WinCleaner.ps1):

$displayName = if ($Rule.NameKey) { Get-SourceTextLoc $Rule.NameKey } else { $Rule.Name }

2. Get-LocalUserProfiles is referenced but never defined

After fix #1, WinCleaner progressed through CleanMgr, Error Reports, Event Logs and the
Windows Update cache, then aborted at Pulizia File Temporanei with
Il termine 'Get-LocalUserProfiles' non è riconosciuto.

Get-LocalUserProfiles is called by five per-user rules in tools/WinCleaner.ps1
(Remove-FileItem, plus the inline cleanmgr cache / WinINET / Chromium / Firefox ScriptBlocks)
but is not defined anywhere in the repository. It was treated as a core helper that was never
authored.

Fix (tools/WinCleaner.ps1): define Get-LocalUserProfiles as a private WinCleaner helper
that returns local user profile directories (objects with .FullName, excluding system profiles)
and delegates to the existing shared core helper Get-SourceTextLocalUserProfiles
(wintoolkit-modules/40-Module.System.ps1) when available, with a self-contained fallback:

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)$' }
}

This is the minimal, atomic fix: Get-LocalUserProfiles is referenced only by WinCleaner
(verified — no other tool/script defines or calls it), so a WinCleaner-private helper is correct.
Behaviour is delegated to the canonical shared helper (DRY), avoiding a second duplicate in core.

Bug fix.

Fixes # (no linked issue)


Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactoring (no functional change)
  • 🧹 Cleanup / Maintenance
  • 📖 Documentation

Files Modified

  • tools/WinCleaner.ps1
    • Invoke-CommandAction: resolve DisplayName only when NameKey is present, else fall back to
      $Rule.Name (fixes crash V2.0 (Build 68) #1).
    • Added private Get-LocalUserProfiles helper delegating to the core
      Get-SourceTextLocalUserProfiles with a fallback (fixes crash v2.0 (Build 69) #2).
  • WinToolkit.ps1 — regenerated by compiler.ps1 (not hand-edited; respects the repo policy
    that generated artifacts are never edited manually). The compiled core now contains
    Get-LocalUserProfiles alongside the Invoke-CommandAction guard.
  • .github/tests/Unit/WinCleaner.Tests.ps1 — added regression tests for both fixes:
    • Invoke-CommandAction displayName (regression for empty NameKey) — 3 tests
    • Get-LocalUserProfiles (regression for undefined function) — 2 tests

Tests & Verification

  • Verified locally via the relevant build/test command
  • Regenerated the artifact with compiler.ps1 (SUCCESS … code 0), not edited by hand
  • Execution logs/snippets attached

Environment: Windows 11 Pro 26H2 (build 26300), PowerShell 7.6.6.

=== Reproduce crash #1 (empty NameKey binding) ===
function Get-SourceTextLoc { param([Parameter(Mandatory=$true)][string]$Key) }
Get-SourceTextLoc -Key '' -> Cannot bind argument to parameter 'Key' because it is an empty string.  (confirmed)

=== Reproduce crash #2 (undefined function) ===
Get-LocalUserProfiles referenced 5x in tools/WinCleaner.ps1 and the compiled WinCleaner body;
defined 0x anywhere in the repo before the fix.  (confirmed)

=== Parse check (changed files) ===
PARSE OK: tools/WinCleaner.ps1
PARSE OK: .github/tests/Unit/WinCleaner.Tests.ps1
PARSE OK: WinToolkit.ps1

=== PSScriptAnalyzer (CI settings, .github/linters/PSScriptAnalyzer-settings.psd1) ===
OK: tools/WinCleaner.ps1
OK: .github/tests/Unit/WinCleaner.Tests.ps1
0 error-level rule(s)

=== Pester — WinCleaner suite ===
Describing WinCleaner — Signature              [5 passed]
Describing WinCleaner — VitalExclusions        [1 passed]
Describing WinCleaner — Invoke-CommandAction displayName (regression for empty NameKey) [3 passed]
Describing WinCleaner — Get-LocalUserProfiles (regression for undefined function)     [2 passed]
Tests Passed: 11, Failed: 0, Skipped: 0

=== Compiler (regenerated artifact) ===
compiler.ps1 pipeline executed with code 0
WinToolkit.ps1 now contains Get-LocalUserProfiles (delegating to the shared core helper)

Note: the log header still reports Version 24H2 (OS build 26300) because version-label
recognition on this branch relies on the legacy build→version verMap in
30-Module.Logging.ps1 (no 26300/26200 entry). That is a separate, pre-existing
issue and is intentionally left out of this atomic WinCleaner fix.


Checklist

Missing a checkbox or violating a rule will result in automatic PR rejection.

  • Atomic change: one issue/feature per PR (WinCleaner startup crashes)
  • WinToolkit.ps1 not modified manually (regenerated by compiler.ps1)
  • Generated artifacts (WinToolkit.ps1) are not edited manually
  • PR targets Dev — branch is BUG-clean-script-not-work-key-empty; confirm intended base before merge
  • Changes limited to tools/, a unit test under .github/tests/Unit/, and the compiler-regenerated artifact
  • Existing code style respected (PSScriptAnalyzer clean), no debug code left behind
  • Parse-clean on all touched scripts

@github-actions

Copy link
Copy Markdown
Contributor

👀 Heads Up — Manual Review Required

Hi @Magnetarman,
thanks for your contribution! This PR was accepted and can proceed normally through the review flow.

However, the automated check detected that one or more sensitive WinToolkit files were modified, which affect the user interface, the main template or the project's static resources:

Sensitive files modified

  • .github/tests/Unit/WinCleaner.Tests.ps1

Why this notice?

These files are not blocked for contributors, but they require additional verification by the maintainer before merging, because unexpected changes could:

  • Alter the interface behaviour (WinToolkit_GUI.ps1, start.ps1)
  • Impact compilation or the framework core functions (wintoolkit-modules/)
  • Introduce unverified resources into the distribution (assets/)

Next steps

No action is required from you. The maintainer will review the changes with extra care before merging.


Automated notification from the WinToolkit CI/CD system — PR #197.

@github-actions

Copy link
Copy Markdown
Contributor

👀 Heads Up — Manual Review Required

Hi @Magnetarman,
thanks for your contribution! This PR was accepted and can proceed normally through the review flow.

However, the automated check detected that one or more sensitive WinToolkit files were modified, which affect the user interface, the main template or the project's static resources:

Sensitive files modified

  • .github/tests/Unit/WinCleaner.Tests.ps1

Why this notice?

These files are not blocked for contributors, but they require additional verification by the maintainer before merging, because unexpected changes could:

  • Alter the interface behaviour (WinToolkit_GUI.ps1, start.ps1)
  • Impact compilation or the framework core functions (wintoolkit-modules/)
  • Introduce unverified resources into the distribution (assets/)

Next steps

No action is required from you. The maintainer will review the changes with extra care before merging.


Automated notification from the WinToolkit CI/CD system — PR #197.

@github-actions

Copy link
Copy Markdown
Contributor

👀 Heads Up — Manual Review Required

Hi @Magnetarman,
thanks for your contribution! This PR was accepted and can proceed normally through the review flow.

However, the automated check detected that one or more sensitive WinToolkit files were modified, which affect the user interface, the main template or the project's static resources:

Sensitive files modified

  • wintoolkit-modules/40-Module.System.ps1
  • .github/tests/Unit/WinCleaner.Tests.ps1

Why this notice?

These files are not blocked for contributors, but they require additional verification by the maintainer before merging, because unexpected changes could:

  • Alter the interface behaviour (WinToolkit_GUI.ps1, start.ps1)
  • Impact compilation or the framework core functions (wintoolkit-modules/)
  • Introduce unverified resources into the distribution (assets/)

Next steps

No action is required from you. The maintainer will review the changes with extra care before merging.


Automated notification from the WinToolkit CI/CD system — PR #197.

@github-actions

Copy link
Copy Markdown
Contributor

👀 Heads Up — Manual Review Required

Hi @Magnetarman,
thanks for your contribution! This PR was accepted and can proceed normally through the review flow.

However, the automated check detected that one or more sensitive WinToolkit files were modified, which affect the user interface, the main template or the project's static resources:

Sensitive files modified

  • wintoolkit-modules/40-Module.System.ps1
  • .github/tests/Unit/WinCleaner.Tests.ps1

Why this notice?

These files are not blocked for contributors, but they require additional verification by the maintainer before merging, because unexpected changes could:

  • Alter the interface behaviour (WinToolkit_GUI.ps1, start.ps1)
  • Impact compilation or the framework core functions (wintoolkit-modules/)
  • Introduce unverified resources into the distribution (assets/)

Next steps

No action is required from you. The maintainer will review the changes with extra care before merging.


Automated notification from the WinToolkit CI/CD system — PR #197.

@Magnetarman
Magnetarman merged commit 1fb48ce into Dev Oct 11, 2026
8 checks passed
@Magnetarman
Magnetarman deleted the BUG-clean-script-not-work-key-empty branch October 11, 2026 13:40
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.

1 participant