Skip to content

fix: match dashboard hasDiff and exclude deleted resources from fixes#6

Merged
liamcervante merged 2 commits intomainfrom
match-dashboard-diff-and-deleted-resources
May 1, 2026
Merged

fix: match dashboard hasDiff and exclude deleted resources from fixes#6
liamcervante merged 2 commits intomainfrom
match-dashboard-diff-and-deleted-resources

Conversation

@liamcervante
Copy link
Copy Markdown
Collaborator

Summary

Two related fixes to the PR comment so it lines up with what the dashboard renders.

Cost section visibility (hasDiff)

processDisplayCosts previously decided whether to render the cost section by scanning project.Resources for Action ∈ {CREATE, MODIFY, DELETE}. The scanner output doesn't currently stamp Action, so the cost section was being suppressed even when there were obvious changes (e.g. removed RDS instances).

Switched the check to len(project.DiffBreakdown.Resources) > 0, matching the dashboard's projectHasDiff in dashboard/api/src/services/templates/helpers.ts. hasUnsupported now reads from data.Summary.TotalUnsupportedResources (already aggregated upstream) instead of iterating project.Resources.

With those two consumers gone, ProjectResult.Resources had no remaining readers in the comment package — removed the field.

Fixed-issue count

processFixedIssues was counting any previously-failing resource that no longer appears in the current policy's failing list as "fixed". On PRs that just delete resources (e.g. glenngillen/demo-missing-tags#2) this inflated the count: removing 12 RDS instances showed up as "12 issues fixed" across various RDS policies, even though nothing was fixed — the resources were just gone.

Added a deleted-resources set (built from policy results — a previously-failing resource is "deleted" if it doesn't appear in any current policy result, passing or failing). Both finopsFixedIssueCounts and taggingFixedIssueCounts skip resources in that set when counting fixes. Same approach the dashboard takes via allCurrentResources in policies.ts, except keyed off policy results instead of a canonical resource list — slightly less precise on the rare "policy applicability changed" edge case, but correctly tightens the common "resource was deleted" case.

A follow-up in actions will remove the now-orphaned pr.Resources = head.Resources assignment in the scanner caller and finish matching the dashboard's diff calculation. Once that lands the cost section becomes visible end-to-end.

Switches the cost section visibility (hasDiff) and per-project diff check
to key off DiffBreakdown.Resources rather than per-resource Action, matching
the dashboard's projectHasDiff. ProjectResult.Resources is no longer read
anywhere in the comment package and has been removed.

Also filters fixed-issue counts to exclude resources that no longer appear
in any current policy result (passing or failing) — claiming a "fix" for a
resource that has disappeared, or whose policy is no longer applicable, is
misleading.
- formatCost: negative values render as `-$X` (sign before currency
  symbol) and integer parts get thousand-separators (e.g. `-$1,616`).
- formatCarbonWithExample: take a pluralize flag; the run-level
  summary uses it so we say `avoids`/`emits` instead of `avoid`/`emit`.
- formatNumber: rewrite to use the dashboard's "decimal places to
  surface the first non-zero digit" rule. Whole numbers render with no
  decimals (`16`), fractional values keep needed precision (`335.7`),
  and thousand-separators are applied.
- processCostChangesAndBudgets: sort budget-tag-note keys before
  joining to fix non-deterministic ordering.
- Template: blank lines around the governance sentence so HTML blocks
  that follow are recognised as block-level by GitHub's markdown parser.
@liamcervante liamcervante merged commit bcf51e5 into main May 1, 2026
3 checks passed
@liamcervante liamcervante deleted the match-dashboard-diff-and-deleted-resources branch May 1, 2026 07:03
liamcervante added a commit to infracost/actions that referenced this pull request May 1, 2026
#243)

* fix: match dashboard's diff calculation and remove ProjectResult.Resources

- diffCostBreakdown rewritten to recursively compare cost components and
  sub-resources, matching the runner's CalculateDiff. A resource lands
  in the diff when costs, components, or sub-resources differ — not
  just when total monthly cost differs. Adds and removes are always
  included.
- Drop pr.Resources = head.Resources: the field was removed from
  comment.ProjectResult upstream because nothing in the comment package
  reads it any more (hasDiff now keys off DiffBreakdown, hasUnsupported
  off Summary).
- Bump infracost/vcs to pull in the matching comment-formatting fixes
  (thousand separators, '-$X' negative formatting, carbon verb
  conjugation, distance precision).

Depends on infracost/vcs#6 — once that's tagged and released, bump go.mod
to the released version.

* vcs latest
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.

2 participants