Repository navigation
test(cmd): make CSV purchase-path tests assert real behavior - #1225
Conversation
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 15 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
6dd5831 to
496a914
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
Adversarial reviewWhat this PR does well:
Findings: 1. The test as written makes this bug harder to fix because the comment legitimizes the behavior as a contract. The underlying fix is small (~5 LOC: 2. "Real behavior" only covers the dry-run path. 3. CSV parser still silently tolerates unknown / missing required columns -- the root cause TEST-02 worked around. 4. CSV edge-case coverage is thin. 5. Idempotency not tested. 6. PR-acknowledged sibling occurrences. Notes on the CI failures (UNSTABLE state):
Verification done locally:
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
496a914 to
2d88fbd
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
2d88fbd to
5b35a70
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
5b35a70 to
b39daab
Compare
|
Rebased onto origin/main (73166c2). Clean rebase (conflict in cmd/multi_service.go resolved by keeping main's helper functions + PR's return nil / error-returning signatures, and PR's test struct fields). Gates: go build, go vet, gocyclo -over 10, golangci-lint (0 new issues). Tests: cmd (739 passed). |
|
@coderabbitai review |
✅ Action performedReview finished.
|
runToolFromCSV now returns an error instead of calling log.Fatalf, so its error branches are testable; runToolMultiService keeps the fail-loud CLI behavior by turning the returned error fatal. Test changes: - TestRunToolFromCSV asserts observable output (the written purchase report: resource types, counts, dry-run success flags) instead of assert.NotPanics. The old fixture used CSV headers the parser does not recognize (Instance Type, Instance Count), so every row loaded with Count=0, the whole run processed nothing, and NotPanics stayed green; the fixture now uses the real round-trip column names. - Un-skip TestRunToolFromCSV_NonExistentFile and _EmptyFile with real error assertions (previously skipped citing nonexistent integration coverage). - TestRunToolFromCSV_WithMaxInstances/_WithOverrideCount assert the cap and override against the report rows. - Replace tautological, live-AWS TestQueryMajorEngineVersions_Success and _ProfileHandling (ran real API calls under CI go test -short on credentialed machines) with hermetic stubbed-client tests of queryMajorEngineVersionsWithClient and a deterministic profile-precedence test that fails at config load, no network. - isolateAWSEnv pins invalid static credentials so the CSV-path tests behave identically on credentialed and bare machines. Closes #1154
Making runToolFromCSV return an error (so the CSV purchase path is
unit-testable) added an `if err != nil { log.Fatalf }` branch to
runToolMultiService, pushing its cyclomatic complexity from 10 to 11 and
tripping the gocyclo pre-commit hook (over 10).
Extract the error-to-fatal glue into runCSVPathOrFatal so the entrypoint
drops back to complexity 10 while runToolFromCSV keeps its testable
error return.
b39daab to
12e80c5
Compare
|
Rebased onto current origin/main (81cd1f4) to pick up the flaky-test fix from #1399 (TestVerifyRetry_RebuildRateLimited is now deterministic). The two PR-owned commits are the only ones on this branch; validator_test.go now matches main's version. All gates passed: go build, go vet, scheduledauth -count=5 (exit 0), cmd package tests, gocyclo -over 10 (clean), golangci-lint full run (0 issues). |
|
Merged to main (rebased onto current main, all CI green) closes #1154. CSV purchase-path tests now assert real behavior instead of always-passing stubs. |
…ath-tests test(cmd): make CSV purchase-path tests assert real behavior
Problem
Closes #1154 (review finding TEST-02, P2).
The CLI purchase-path tests in
cmd/were exercise-only or tautological:TestRunToolFromCSVdrove the CSV purchase entry point and asserted nothing (assert.NotPanics). Worse, its fixture used CSV headers the parser does not recognize (Instance Type,Instance Count), so every row loaded withCount=0, the entire run processed zero recommendations, and the test stayed green, exactly the silent-regression mode the finding warned about.TestRunToolFromCSV_NonExistentFileand_EmptyFileweret.Skip-ped, citing integration coverage that does not exist;runToolFromCSVcalledlog.Fatalf, making the branches structurally untestable.TestQueryMajorEngineVersions_Successand_ProfileHandlingwere tautological and non-hermetic: they loaded live AWS config and asserted on whichever branch the environment produced, issuing real AWS API calls on credentialed machines with notesting.Short()guard, so they ran under CI'sgo test -short ./....Fix
runToolFromCSVnow returns anerrorinstead of callinglog.Fatalf;runToolMultiServicekeeps the fail-loud CLI behavior by turning the returned error fatal. No behavior change for users.TestRunToolFromCSVasserts observable output: the written purchase report's resource types, post-sizing counts, and dry-run success flags, for both the 100% and 50% coverage paths, using the real round-trip column names (ResourceType,Count, ...)._WithMaxInstances/_WithOverrideCountassert the instance cap and count override against the report rows instead ofNotPanics.queryMajorEngineVersionsWithClient(full engine fan-out, result merging, warn-and-continue on per-engine failure) plus a deterministic profile-precedence test that fails at config load time against a redirected empty shared config, so no network or credentials are involved.isolateAWSEnvhelper pins invalid static credentials so the CSV-path orchestration tests behave identically on credentialed developer machines and bare CI runners, and never touch a real account.Test evidence
go build ./...clean;go vet ./cmd/clean;gofmt -l cmd/clean.go test ./cmd/ -run 'TestRunToolFromCSV|TestQueryMajorEngineVersions': 16 passed.go test -short ./cmd/...: 752 passed in 7 packages.log.Fatalfexits the process), and the happy-path assertions were observed failing against the old broken fixture shape (report never written because the run processed zero recommendations) before the fixture was corrected, demonstrating they catch the silent-orchestration-regression mode described in the finding.Out of scope (sibling occurrences, same defect shape)
TestQueryMajorEngineVersions_ErrorHandlingandTestQueryRunningInstanceEngineVersions_ErrorHandlingincmd/multi_service_engine_versions_test.gohave the same live-config tautological pattern but were not cited by TEST-02; left untouched to keep the diff focused.