feat(remediation): add auto-remediation for actions-pinned, npm-ci-required, harden-runner-required, readme-exists - #16
Merged
Conversation
…quired, harden-runner-required, and readme-exists Compliance findings are useful but still require a human to go make the fix in every repo. For rules where the fix is a mechanical, deterministic file edit, git-cascade can now open (and keep upserting) a pull request that applies it automatically instead of only reporting the finding. - New `remediation:` config block (global enable + default) and per-rule `auto_remediation` override (rule-level always wins). - New internal/remediation package mirrors the existing Checker registry pattern: each fixable rule registers a Remediator; the engine dispatches failing results to it and opens/updates a PR via new internal/github git-write helpers (branch, blob/tree/commit, PR upsert). - Remediation requires its own --remediate-*/GIT_CASCADE_REMEDIATE_* creds with no fallback to scan/notify tokens, since it writes to scanned repos. - Shared detection logic extracted from the affected checkers (FindUnpinnedActions, FindNodeInstallViolations, FindJobsMissingHardenRunner) so checker and remediator never drift. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #16 +/- ##
==========================================
+ Coverage 75.42% 76.16% +0.73%
==========================================
Files 34 41 +7
Lines 2739 3151 +412
==========================================
+ Hits 2066 2400 +334
- Misses 564 616 +52
- Partials 109 135 +26
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…fault remediation.enabled (master switch) and remediation.auto_remediation (default value applied when a rule doesn't set its own) overlapped awkwardly and were easy to confuse. Collapse to a single enabled gate; each rule now opts in individually via its own auto_remediation field (defaults false), so a newly registered fixer never goes live silently just because remediation as a whole was already turned on. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Add tests for resolveRemediateCredentials (was 0%), the full remediateOne happy/error paths (branch create, commit, PR open) via a fake GitHub server, error branches in internal/github/write.go (non-404 GetRef, CreateRef/CreateTree/CreateCommit/UpdateRef/List/ Create/label failures), and a direct in-package test for FindNodeInstallViolations so it counts toward the checks package's own coverage instead of only the fixes package's. Project coverage 73.6% -> 76.3% (above main's pre-PR 75.4% baseline). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Compliance findings are useful but still require a human to go make the fix in every repo. For rules where the fix is a mechanical, deterministic file edit, git-cascade can now open (and keep upserting) a pull request that applies it automatically instead of only reporting the finding.
remediation:config block (enabledmaster switch +auto_remediationdefault) and a per-ruleauto_remediationoverride (rule-level always wins over the block default).internal/remediationpackage mirrors the existingCheckerregistry pattern: each fixable rule registers aRemediator; the engine dispatches failing results to it and opens/updates a PR via newinternal/githubgit-write helpers (branch create, blob/tree/commit, PR upsert — never a direct commit to the default branch).--remediate-*/GIT_CASCADE_REMEDIATE_*credentials with no fallback to scan/notify tokens, since it writes directly to scanned repositories.actions-pinned(pin tag → resolved SHA),npm-ci-required(lock bare npm/pnpm/yarn installs, skipping compound commands and dependency-adding installs it can't rewrite safely),harden-runner-required(insertstep-security/harden-runneras each job's first step),readme-exists(add a minimal README.md stub).FindUnpinnedActions,FindNodeInstallViolations,FindJobsMissingHardenRunner) so checker and remediator never drift — existing checker tests pass unchanged, confirming no behavior change.Test plan
go build ./...go vet ./...go test -race -coverprofile=coverage.out -covermode=atomic ./...(matches CI)internal/github/write.gogit operations (branch create/no-op, commit create/no-op, PR create/upsert/labeling), and each of the four fixers end-to-end (happy path + a safe-skip case each)🤖 Generated with Claude Code