fix(cli): gc 'print'/'tag' progress no longer shows NaN% or misleading '0 assets' - #1873
Open
lemon0333 wants to merge 1 commit into
Open
fix(cli): gc 'print'/'tag' progress no longer shows NaN% or misleading '0 assets'#1873lemon0333 wants to merge 1 commit into
lemon0333 wants to merge 1 commit into
Conversation
The garbage collection progress printer divided `assetsScanned / totalAssets`
without guarding against `totalAssets === 0`. Empty buckets/repos (and the final
flush of one) produced `[NaN%]`, and because the `print` action never tags or
deletes anything, its output always read `0 assets tagged, 0 assets deleted` even
when stale assets existed. Together these made users think `cdk gc` was broken
when it was working correctly.
- Guard the percentage math so an empty environment reports `[100.00%]` instead of
`[NaN%]`.
- For the `print` action, report the assets that are eligible for garbage
collection ("N assets (X MiB) eligible for deletion") instead of the misleading
"0 tagged, 0 deleted" line.
Added unit tests for the progress printer covering the NaN guard, a known-total
percentage, and the print-action eligible-asset messaging.
Fixes aws#625
lemon0333
requested a deployment
to
integ-approval
August 22, 2026 05:56 — with
GitHub Actions
Waiting
aws-cdk-automation
enabled auto-merge
August 22, 2026 05:57
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1873 +/- ##
==========================================
+ Coverage 91.10% 91.13% +0.03%
==========================================
Files 80 80
Lines 12205 12205
Branches 1742 1744 +2
==========================================
+ Hits 11119 11123 +4
+ Misses 1050 1046 -4
Partials 36 36
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #625
Problem
Running
cdk gc --action print(and--action tagon a bucket/repo that was already tagged) produced output that made users believe garbage collection was broken, even though it was working:Two things are wrong:
[NaN%]—ProgressPrinter.print()computesassetsScanned / totalAssets. For an empty bucket/repo (or the final flush of one)totalAssetsis0, so0 / 0renders asNaN%.printaction intentionally never tags or deletes, so those counters are always0. The message therefore reads as "nothing to do" even when stale/isolated assets exist and would be collected.Fix
[100.00%]instead of[NaN%].printaction, report the assets that are eligible for garbage collection (isolated assets not referenced by any deployed stack) — e.g.N assets (X MiB) eligible for deletion— instead of the misleading0 tagged, 0 deletedline. Thetag/delete-tagged/fulloutput is unchanged.This is a messaging/counter clarity fix only; garbage-collection semantics are unchanged.
Added unit tests under the gc test suite covering the NaN guard, a known-total percentage, and the print-action eligible-asset messaging.
Follow-up (not in this PR): a repeated
tagrun reports0 taggedbecause the assets are already tagged; clarifying that "already tagged" state is a separate, larger change and left for a follow-up.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license