Repository navigation
fix(ci): repair main pre-commit (gocyclo recEffectiveSavingsPct #1222 + Dockerfile.test non-root) - #1254
Conversation
trivy >=0.70.0 flags DS-0002 (no non-root USER) on Dockerfile.test, failing the pre-commit trivy-config hook for any contributor on a newer local trivy (CI pins v0.69.3, which did not report it). Add a dedicated non-root user and point GOCACHE at its home so both the build-time pre-compile and the runtime `go test` run unprivileged. tests/e2e is stdlib-only, so no module downloads are needed. Verified with `docker build -f Dockerfile.test`: go vet and go test run cleanly as the non-root user.
…loses #1222) recEffectiveSavingsPct had cyclomatic complexity 12, above the pre-commit gocyclo `-over 10` threshold, so every PR's pre-commit CI job failed regardless of what it touched. Extract the on-demand baseline derivation into a new helper recOnDemandBaseline, bringing both functions under the threshold. Behavior is identical: the helper returns the same (baseline, ok) for every input branch (explicit OnDemandCost, monthly_cost reconstruction, AWS-without-baseline and no-monthly_cost guards), so the net-savings semantics from #1103/#1148 are unchanged.
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Important Review skippedNo new commits to review since the last review. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe E2E test Dockerfile is updated to run as a non-root ChangesNon-root E2E Container
On-demand Baseline Extraction
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
During rebase onto main, two items needed manual cleanup: - store_postgres_recommendations.go: the `if rec.Term == 0` guard in recEffectiveSavingsPct was dropped when resolving the conflict with main's #1254 refactor (which already extracted recOnDemandBaseline). The guard lives in the caller per the new docstring; restore it so term=0 rows still return (0, false) as the test asserts. - 000074_audit_actor_stamps.{up,down}.sql: these files were already on the branch at its branching point and collide with 000074_repair_partial_migration_058_067 (already on main). They were renumbered to 000077 on main via fix/migration-74-collision; remove the stale 000074 files here so there is no duplicate migration number.
During rebase onto main, two items needed manual cleanup: - store_postgres_recommendations.go: the `if rec.Term == 0` guard in recEffectiveSavingsPct was dropped when resolving the conflict with main's #1254 refactor (which already extracted recOnDemandBaseline). The guard lives in the caller per the new docstring; restore it so term=0 rows still return (0, false) as the test asserts. - 000074_audit_actor_stamps.{up,down}.sql: these files were already on the branch at its branching point and collide with 000074_repair_partial_migration_058_067 (already on main). They were renumbered to 000077 on main via fix/migration-74-collision; remove the stale 000074 files here so there is no duplicate migration number.
During rebase onto main, two items needed manual cleanup: - store_postgres_recommendations.go: the `if rec.Term == 0` guard in recEffectiveSavingsPct was dropped when resolving the conflict with main's #1254 refactor (which already extracted recOnDemandBaseline). The guard lives in the caller per the new docstring; restore it so term=0 rows still return (0, false) as the test asserts. - 000074_audit_actor_stamps.{up,down}.sql: these files were already on the branch at its branching point and collide with 000074_repair_partial_migration_058_067 (already on main). They were renumbered to 000077 on main via fix/migration-74-collision; remove the stale 000074 files here so there is no duplicate migration number.
During rebase onto main, two items needed manual cleanup: - store_postgres_recommendations.go: the `if rec.Term == 0` guard in recEffectiveSavingsPct was dropped when resolving the conflict with main's #1254 refactor (which already extracted recOnDemandBaseline). The guard lives in the caller per the new docstring; restore it so term=0 rows still return (0, false) as the test asserts. - 000074_audit_actor_stamps.{up,down}.sql: these files were already on the branch at its branching point and collide with 000074_repair_partial_migration_058_067 (already on main). They were renumbered to 000077 on main via fix/migration-74-collision; remove the stale 000074 files here so there is no duplicate migration number.
Summary
Repairs two pre-commit failures on
mainthat block every PR.1. gocyclo (closes #1222) — the CI blocker
recEffectiveSavingsPcthad cyclomatic complexity 12, above the pre-commitgocyclo -over 10threshold, so the "Run pre-commit hooks" CI job failed on every PR regardless of what it touched (the hook scans all non-test.gofiles). Extracted the on-demand baseline derivation into a new helperrecOnDemandBaseline, bringing both functions under the threshold.Behavior is identical — the helper returns the same
(baseline, ok)for every input branch (explicitOnDemandCost,monthly_costreconstruction, the AWS-without-baseline and no-monthly_costguards), so the net-savings semantics from #1103/#1148 are unchanged.2. trivy DS-0002 on
Dockerfile.testNewer trivy (>=0.70.0) flags
Dockerfile.test(the ephemeral docker-compose E2E test-runner) for running as root; CI pins trivy v0.69.3 which doesn't report it, so the hook was clean on CI but failed for contributors on a newer local trivy. Rather than suppress the finding, the test image now runs as a dedicated non-roote2euser, withGOCACHEin its home so both the build-time pre-compile and the runtimego testrun unprivileged.tests/e2eis stdlib-only, so no module downloads are needed.Testing
gocyclo -over 10 internal/config/store_postgres_recommendations.go-> cleantrivy config --severity HIGH,CRITICAL --exit-code 1 ... .-> exit 0go build ./...-> ok;go test ./internal/config/-> okdocker build -f Dockerfile.test .->go vet+go testrun cleanly as non-roote2eUnblocks the QA-sheet fix PRs (#1247, #1248, #1251, #1249/#1250, #1252) which stack on this branch.
Summary by CodeRabbit
Tests
Refactor