fix(cmd): reject NaN and Inf for numeric sizing flags by cristim · Pull Request #2165 · LeanerCloud/cloud-commitments-cli · GitHub
Skip to content

fix(cmd): reject NaN and Inf for numeric sizing flags - #2165

Merged
cristim merged 1 commit into
mainfrom
fix/2136-target-coverage-nan
Oct 10, 2026
Merged

cristim merged 1 commit into
mainfrom
fix/2136-target-coverage-nan

Conversation

@cristim

@cristim cristim commented Oct 9, 2026

Copy link
Copy Markdown
Member

Summary

Rejects NaN and +/-Inf for --coverage, --target-coverage, --min-pool-size and --min-savings-pct in the flag validators (one requireFinite(name, v) helper), before any API call. Explicit --target-coverage 0 stays valid (documented disabled); ranges are unchanged.

Root cause: every ordered comparison with NaN is false, so --target-coverage NaN passed the <0 || >100 check, then applySizing/fetchExistingCoverage read TargetCoverage > 0 as "unset" and silently sized with --coverage (default 80). --coverage NaN reaches recfilter.ApplyCoverage (sizing.go:23), producing NaN HourlyCommitment/costs for SP recs and an arch-dependent int(NaN*count) for RI recs. --min-pool-size NaN passed the whole-number check; --min-savings-pct had no validation.

Evidence (offline)

  • TestValidateNumericFlagsRejectNonFinite drives the real flags via rootCmd.ParseFlags then the validators; it never calls runTool, so no AWS client is built. Cases: NaN, nan, +/-Inf per flag, 1e999 (rejected by the flag parser), explicit 0 and valid values.

  • Pre-fix (validators.go stashed): all 9 non-finite cases fail; post-fix pass. go vet ./..., build and go test ./cmd (463s) pass; pre-commit hooks (incl. gocyclo) pass.

Not in this PR

Closes #2136

🤖 Generated with Claude Code

Every comparison with NaN is false, so --target-coverage NaN passed the
range check and then read as "unset" in applySizing, silently sizing with
--coverage. Add requireFinite and apply it to --coverage, --target-coverage,
--min-pool-size and --min-savings-pct, before any API call.

Closes #2136

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@cristim cristim added triaged Item has been triaged priority/p2 Backlog-worthy severity/medium Moderate harm urgency/this-quarter Within the quarter impact/few Limited audience effort/xs Trivial / one-liner type/bug Defect labels Oct 9, 2026
@coderabbitai

coderabbitai Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

@cristim

cristim commented Oct 10, 2026

Copy link
Copy Markdown
Member Author

@cristim
cristim merged commit 0d02dc8 into main Oct 10, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/xs Trivial / one-liner impact/few Limited audience priority/p2 Backlog-worthy severity/medium Moderate harm triaged Item has been triaged type/bug Defect urgency/this-quarter Within the quarter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cmd): validateTargetCoverage accepts NaN and applySizing silently falls back to --coverage

1 participant