Repository navigation
test(cli): keep the CSV, processService and fetchAllRecs tests off the network - #2225
Conversation
The offline AWS stub added for the max-instances duplicate check is needed by tests in several other files. Move it to cmd/aws_fixture_stub_test.go and rename it to awsFixtureStub / newAWSFixtureConfig. No behaviour change. Refs #2162 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
isolateAWSEnv only set invalid static credentials, so the runToolFromCSV tests still sent requests to the real organizations, rds and elasticache endpoints and failed on the 403 from there. Serve a local 403 AccessDeniedException through AWS_ENDPOINT_URL instead, clear AWS_IGNORE_CONFIGURED_ENDPOINT_URLS and every AWS_ENDPOINT_URL_* so a developer's overrides cannot bypass it, and return the request counter. TestRunToolFromCSV asserts the counter so the wiring cannot go vacuous. Refs #2162 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… stub Nine tests built an aws.Config literal with no HTTP client, so their duplicate, coverage and region lookups went to the real rds, elasticache, savingsplans, ce and ec2 endpoints. Inject the shared fixture stub instead and assert the requests it served, so a test cannot pass without reaching it. The stub learns three things for these callers: the operation comes from the form Action, else X-Amz-Target, else the URL path tail; the fixture lookup ignores the region in the host; a fixture may carry a status. The tests keep the path they exercised before: the fetch-failure and fail-closed real purchase cases get an error fixture, the dry-run cases an empty one, and the GetAllAWSRegions integration subtest runs against a fixture and no longer needs real credentials. Closes #2162 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reached
This review includes 6 billable files and costs up to $1.50.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 22 minutes for your next included review. View limit details
Comment |
Independent review verdict: CLEAN at 7a7a427Reviewer: fresh Claude agent (Sonnet, high effort), not the author, cold brief. Coordinator: claude-cc-reviewer. Blocking findings: none. Non-blocking notes:
What was attacked and how (
Gate:
|
Closes #2162
Summary
14
cmdtests sent real requests to AWS endpoints. This PR makes them hermetic. The change is test-only, with no production code changes. Measured with a CONNECT-logging proxy, the sweep goes from 74 off-host connections to 0.The AWS fixture stub moves to
cmd/aws_fixture_stub_test.go. The stub came from test(cli): route MaxInstances duplicate checks to a stub transport #2215. The move is a straight cut, rename and paste with no behaviour change. The stub is then extended:requireRequestsasserts what the stub actually received.isolateAWSEnvpoints the SDK at a local deny endpoint. It starts an httptest server that answers 403 and setsAWS_ENDPOINT_URLto it. It also clearsAWS_IGNORE_CONFIGURED_ENDPOINT_URLSand everyAWS_ENDPOINT_URL_*variable, so a developer's own endpoint settings can't send requests off the machine. This covers the fiverunToolFromCSVtests, which build their config internally. The 403 is not retried, so these tests take the same warn-and-continue path they took before with invalid credentials.Nine literal-config tests use the stub through
aws.Config.HTTPClient. These are fiveprocessServicetests, twofetchAllRecstests,TestFetchExistingCoverage_FetchFailureandTestGetAllAWSRegions. Most are dry runs and take the empty-fixture success path. Two keep a failure path, because that is what they test:TestProcessServiceWithMockskeeps an ElastiCache 403 and now asserts that the real-purchase case returns no results.TestFetchExistingCoverage_FetchFailureuses a ce 400.TestGetAllAWSRegionsused to skip its subtest without credentials. It now runs unconditionally on an ec2 fixture and asserts exactly one request.The issue's
TestCSVCap*claims were stale: those tests,TestCSVMinCount*andTestFilterAndAdjustRecommendations_MaxInstancesAppliedalready made 0 requests, becauseTestMainstubs the engine-version and caller-account fetchers.Evidence
All runs are local, on macOS, with
GOTOOLCHAIN=go1.26.9, using fixtures and a CONNECT-logging proxy.runToolFromCSV(5 tests)processService(5 tests)fetchAllRecs(2 tests)FetchExistingCoverageGetAllAWSRegionsAWS_IGNORE_CONFIGURED_ENDPOINT_URLS=trueand service-specificAWS_ENDPOINT_URL_*overrides set, the 14 tests pass with 0 CONNECTs.AWS_ENDPOINT_URLset:TestRunToolFromCSV.TestProcessService_WithInstanceLimit.TestProcessServiceWithMocks.requireRequests.make build,go vet ./...,go test -race ./cmd/...andgo test -race ./cmd/ -shuffle=onpass. The shuffle failures are only the known flag-state issue test(cli): cmd tests fail under -shuffle=on via shared flag state #2208.scripts/test-git-secrets-allowlist.sh: 44/44.Follow-ups filed
cmdpackage on any off-host request (aTestMainguard), deferred from this plan.rdsAPIStub.serveEnvandconfigure_gcp_signal_test.go:225set only one endpoint variable, so service-specific overrides defeat them. They should reuse this PR's helper.🤖 Generated with Claude Code