diff options
| author | Mohamed Hegazy <mhegazy@anthropic.com> | 2026-10-20 22:57:12 +0000 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-10-20 22:57:12 +0000 |
| commit | 81158d22cc8c2801e86520c3d60c3ba449afcce0 (patch) | |
| tree | f552e5e2c18c922d6e8c1e89509f8337d4620733 /plugins | |
| parent | 3725318ee5052793cbbafd8b92edbdba771ce03a (diff) | |
security-guidance: count Stop reviews that kept a secret-shaped old name
secret_renamed is sent only when it is not zero.
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/security-guidance/hooks/diffstate.py | 5 | ||||
| -rw-r--r-- | plugins/security-guidance/tests/test_secret_renames.py | 3 |
2 files changed, 7 insertions, 1 deletions
diff --git a/plugins/security-guidance/hooks/diffstate.py b/plugins/security-guidance/hooks/diffstate.py index b0fae3cf..3c29efe3 100644 --- a/plugins/security-guidance/hooks/diffstate.py +++ b/plugins/security-guidance/hooks/diffstate.py @@ -835,8 +835,9 @@ def compute_v2_review_set(cwd, baseline_sha, head_at_capture, untracked_at_basel # that would silently zero the review set. Fall back to dirty_now. review_set = (dirty_now & changed_since) if changed_since is not None else dirty_now # Kept beside its new name so that the content diff pairs the two. - review_set = review_set | { + secret_origins = { old for new, old in _secret_rename_origins.items() if new in review_set} + review_set = review_set | secret_origins review_paths = [os.path.join(repo, p) for p in sorted(review_set)] untracked_in_review = sorted(new_untracked & review_set) @@ -848,4 +849,6 @@ def compute_v2_review_set(cwd, baseline_sha, head_at_capture, untracked_at_basel # Only emit when nonzero to stay under the 10-key telemetry cap. if preexisting_unchanged: metrics["preexisting_untracked_excluded"] = len(preexisting_unchanged) + if secret_origins: + metrics["secret_renamed"] = len(secret_origins) return review_paths, diff_base, repo, untracked_in_review, metrics diff --git a/plugins/security-guidance/tests/test_secret_renames.py b/plugins/security-guidance/tests/test_secret_renames.py index e8f9f283..f9b0bb76 100644 --- a/plugins/security-guidance/tests/test_secret_renames.py +++ b/plugins/security-guidance/tests/test_secret_renames.py @@ -48,6 +48,8 @@ def test_stop_review_leaves_the_renamed_file_out(tmp_path, hook_env, stub_api, h m = metrics_of(stdout) assert m.get("skip_reason") is None, m assert m.get("files_reviewed") == 1 + # A plain mv is not a rename to git: the old name is listed as deleted. + assert m.get("secret_renamed") == (None if how == "moved" else 1) assert "os.system" in _sent(stub_api) assert "SECRET_VALUE" not in _sent(stub_api) @@ -103,3 +105,4 @@ def test_review_set_gains_only_the_origin_of_a_reviewed_file(tmp_path, git_env): paths, _base, root, _untracked, metrics = diffstate.compute_v2_review_set(str(repo), None, None, {}) assert sorted(os.path.relpath(p, root) for p in paths) == ["deploy_rsa", "new.py", "settings.py"] assert metrics["dirty_now_count"] == 2 and metrics["review_set_count"] == 3 + assert metrics["secret_renamed"] == 1 |
