Fix: address all code review findings#6
Conversation
- Remove-OldFiles: add Mandatory/ValidateScript on -Path, ValidateRange on -Days, use LiteralPath, filter by LastWriteTime (not CreationTime), enumerate files with ShouldProcess before Remove-Item - Clear-CurrentUserTemp: fix Out-Null pipe that nulled the collection, wrap directory removal in ShouldProcess, add break guard for WhatIf - Clear-OldExchangeLog: fix wrong function name Clear-OldIisLogFiles -> Clear-OldIISLog, pass -WhatIf:False, use Remove-Item with LiteralPath instead of .Delete(), add ValidateRange on -Days - Clear-OldIISLog: add SupportsShouldProcess, wrap each Remove-OldFiles call in ShouldProcess so -WhatIf/-Confirm propagate correctly - Get-StaleUserProfile: fix missing \$ prefix on !(StaleUserProfiles) - Start-Cleaning: fix comment-based help -NoLogo -> -Dedication - TheCleaners.psd1: remove WebAdministration from ExternalModuleDependencies (the module is optional at runtime) - Activate skipped tests: move ExportedFunctions and TheCleaners-Module tests from SkipUnit/ to Unit/, add CleanupBehavior regression suite - Update ExportedFunctions tests to Pester v5 -ForEach pattern - CI workflow: switch to windows-latest, add permissions: contents: read, remove verbose debug step and auto-commit step, update generated docs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Up to standards ✅🟢 Issues
|
| Category | Results |
|---|---|
| CodeStyle | 2 minor |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull request overview
This PR addresses prior repository code review findings by improving safety/ShouldProcess behavior in cleanup cmdlets, correcting logic bugs, promoting/adding unit tests, and updating CI to run on Windows.
Changes:
- Fix and harden cleanup cmdlets (
Clear-OldExchangeLog,Clear-CurrentUserTemp,Clear-OldIISLog,Remove-OldFiles) with corrected filtering andShouldProcesssupport. - Promote/add Pester v5 unit tests and update build code coverage configuration.
- Update documentation and CI workflow (Windows runner, least-privilege permissions, remove auto-commit behavior).
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/TheCleaners/TheCleaners.psd1 | Removes hard dependency on WebAdministration by clearing ExternalModuleDependencies. |
| src/TheCleaners/Public/Start-Cleaning.ps1 | Updates comment-based help parameter documentation. |
| src/TheCleaners/Public/Get-StaleUserProfile.ps1 | Fixes stale profile empty-check logic. |
| src/TheCleaners/Public/Clear-OldIISLog.ps1 | Adds SupportsShouldProcess and wraps cleanup calls in ShouldProcess. |
| src/TheCleaners/Public/Clear-OldExchangeLog.ps1 | Fixes IIS delegation call, date filtering, and removal method; adds validation. |
| src/TheCleaners/Public/Clear-CurrentUserTemp.ps1 | Fixes empty-directory capture and adds ShouldProcess guard + WhatIf loop exit. |
| src/TheCleaners/Private/Remove-OldFiles.ps1 | Adds parameter validation, uses LastWriteTime, and implements per-file ShouldProcess. |
| src/TheCleaners.build.ps1 | Updates Pester code coverage paths to use module source path joins. |
| src/Tests/Unit/TheCleaners-Module.Tests.ps1 | Refactors module manifest tests for Pester v5 structure. |
| src/Tests/Unit/ExportedFunctions.Tests.ps1 | Promotes exported-functions/help coverage tests into Unit suite. |
| src/Tests/Unit/CleanupBehavior.Tests.ps1 | Adds regression coverage for cleanup behaviors and WhatIf handling. |
| src/Tests/SkipUnit/ExportedFunctions.Tests.ps1 | Removes the skipped version of exported-functions tests (now promoted). |
| docs/Start-Cleaning.md | Updates generated help text for -Dedication. |
| docs/Clear-OldIISLog.md | Documents -WhatIf/-Confirm and refreshes help formatting. |
| .github/workflows/Build Module.yml | Switches CI to windows-latest, adds read-only permissions, removes debug/auto-commit steps. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot apply changes based on the comments in this thread |
- Change [int] to [int16] for Days in Clear-OldExchangeLog (type/range consistency) - Wrap Remove-Item in try/catch in Clear-CurrentUserTemp empty-dir loop - Fix example cmdlet name in docs/Clear-OldIISLog.md (Clear-OldIISLogFile → Clear-OldIISLog) - Fix default Days description in docs/Clear-OldIISLog.md (30 → 60) Agent-Logs-Url: https://github.com/SamErde/TheCleaners/sessions/a9cd91d7-216d-48e8-bce3-bbbac2f05bf1 Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com>
All four review findings have been addressed in commit a08eb46:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
src/TheCleaners/Public/Clear-OldIISLog.ps1:29
- The comment-based help is now out of sync with the function: it still says the default is 30 days and the example uses
Clear-OldIISLogFile, but the parameter default is$Days = 60and the function name isClear-OldIISLog. Please update the help block so the documented default and example match the implementation.
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
[Alias('Clean-IISLog')]
#[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns')]
param (
[Parameter()]
|
@copilot apply changes based on the comments in this thread |
- Remove leading backslashes from Join-Path ChildPath in Clear-OldExchangeLog so paths stay under ExchangeInstallPath instead of resolving from drive root - Fix Remove-OldFiles help example: remove -Recurse (no such param), fix typo 'does' → 'days' - Add -CommandType Function to Get-Command in ExportedFunctions.Tests.ps1 so the runtime query matches the manifest's ExportedFunctions collection Agent-Logs-Url: https://github.com/SamErde/TheCleaners/sessions/21c43959-dae5-453b-af3c-86f58b8a38f6 Co-authored-by: SamErde <20478745+SamErde@users.noreply.github.com>
All three findings addressed in commit 3262877:
|
Summary
This PR addresses all findings from the repository code review. Changes span bug fixes, safety improvements, test coverage, and CI improvements.
Bug Fixes
Clear-OldExchangeLogClear-OldIisLogFiles; corrected toClear-OldIISLog$_.LastWriteTime -le $LastWriteDatedirectly.Delete()withRemove-Item -LiteralPathso WhatIf/Confirm are honoured-WhatIf:$WhatIfPreferencepassthrough toClear-OldIISLogcall[ValidateRange(1,[int16]::MaxValue)]on-Days-FiletoGet-ChildItemto exclude directoriesClear-CurrentUserTempOut-Nullbug:$EmptyDirectories = … | Out-Nullsilently assigned$null; wrapped pipeline in@(…)ShouldProcessguard around directory removaldo/untilloop now breaks if WhatIf skipped all removalsGet-StaleUserProfile$prefix:!(StaleUserProfiles)→-not $StaleUserProfilesSafety / ShouldProcess
Remove-OldFiles(private helper)[Parameter(Mandatory)],[ValidateNotNullOrEmpty()], and[ValidateScript({Test-Path …})]on-Path[ValidateRange(1,[int16]::MaxValue)]on-DaysCreationTime→LastWriteTime(creation time is unreliable on Windows when files are copied)Remove-Itemin per-file$PSCmdlet.ShouldProcessloop using-LiteralPathSuppressMessageAttribute— was missing required second (empty string) argumentClear-OldIISLogSupportsShouldProcess, ConfirmImpact = 'Medium'toCmdletBinding-WhatIfon everyRemove-OldFilescall (was always forcing WhatIf mode)Remove-OldFilescall in$PSCmdlet.ShouldProcessHelp / Metadata
Start-Cleaning-Dedicationhelp string (was documenting the removed-NoLogoparameter)docs/Clear-OldIISLog.md-WhatIfand-Confirmparameter documentationTheCleaners.psd1WebAdministrationfromExternalModuleDependencies— the code already guards it as optional at runtime; declaring it as a hard dependency causedImport-Modulefailures on systems without IISTests
SkipUnit/toUnit/:ExportedFunctions.Tests.ps1andTheCleaners-Module.Tests.ps1now run as part of the normal buildExportedFunctions.Tests.ps1: Rewrote to Pester v5-ForEachpattern; removedAfterAll { Remove-Module }block that unloaded the module beforeplatyPShelp generation ranCleanupBehavior.Tests.ps1: Regression tests for the fixed logic — age filter, WhatIf behaviour, empty-dir removal, Exchange log cleanup, IIS log delegationCI
windows-latest(module uses Windows-only CIM, registry, and IIS APIs)permissions: contents: read(least-privilege)stefanzweifel/git-auto-commit-actionauto-commit step (generated artifacts should not be committed back to PR branches)Validation
Full build passes: 18 tasks, 0 errors, 0 warnings, 16 unit tests passing