fix(cli): reject negative account quota flags before sending PATCH - #829
fix(cli): reject negative account quota flags before sending PATCH#829rohithb-hub wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAccount update quota flags now default to zero and use Cobra flag-presence detection. Negative quotas are rejected with field-specific errors. Tests cover validation, zero values, backend request suppression, PATCH payloads, and JSON output. ChangesAccount quota updates
Estimated code review effort: 3 (Moderate) | ~20 minutes Mergeability Score: ⚪ Minimal · up to Negative quota values are now rejected before an update request is sent, preventing empty PATCH requests and confusing backend errors; no actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
TL;DR
Fixes
nvcf-cli admin accounts updatesilently dropping negative quota values (e.g.--max-functions -2) instead of rejecting them, which previously caused an empty PATCH request and a confusing backend error.Additional Details (optional for docs, build, test, refactor, ci, chore, style, and revert PRs)
The four quota flags (
--max-functions,--max-tasks,--max-telemetries,--max-registry-credentials) used-1as an int flag default to mean "not passed," then only added the field to the request when the value was>= 0. A user-supplied negative value was indistinguishable from "not passed" under that check, so it was silently dropped. If it was the only flag given, the CLI sent an empty PATCH and surfaced the backend's genericEither name, credential fields or limits should be specifiederror instead of identifying the invalid flag.buildAccountUpdateRequestnow takes the*cobra.Commandand usescmd.Flags().Changed(...)to detect whether a flag was actually passed, then explicitly rejects negative values per flag with a message like--max-functions must be greater than or equal to 0before any request is built. This mirrors the existing--min-instancesvalidation pattern incmd/deploy.go. Flag defaults changed from-1to0since0is now a legitimate "unset" default rather than a sentinel.For the Reviewer
Main change is in
src/clis/nvcf-cli/cmd/admin.go(buildAccountUpdateRequest,runAccountsUpdate). Tests added insrc/clis/nvcf-cli/cmd/admin_test.go.For QA (optional for docs, build, test, refactor, ci, chore, style, and revert PRs)
admin_test.gocovering: no fields provided, valid quotas,0as an explicit legitimate value, negative values rejected per flag (all four flags), values exceeding the 50 cap, and a regression test asserting no HTTP request is sent when a negative quota is passed.go build ./...andgo test ./cmd/...pass for the changed package.--max-functions=-2sent an empty PATCH and returned the generic 400), then confirmed the fixed binary rejects all four flags client-side with no request sent, and that a valid update (--max-functions 50) still round-trips correctly end-to-end.Issues
NO-REF
Checklist
Summary by CodeRabbit
Bug Fixes
Tests