diff options
| author | Claude <noreply@anthropic.com> | 2026-12-04 21:58:44 +0000 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-12-04 21:58:44 +0000 |
| commit | 2c0cac490b2d0f50b1a640c1395768fc7ae285a4 (patch) | |
| tree | be6a963509b5cc55914c613879a3b2f68d465bca /plugins | |
| parent | 9b1b0188cc150f706d18ea1a9413dffeb844716f (diff) | |
Cut a diff far over the limit in build_refute_promptmhegazy/sg-second-look-diff
Co-authored-by: mhegazy <mhegazy@anthropic.com>
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/security-guidance/hooks/review_api.py | 4 | ||||
| -rw-r--r-- | plugins/security-guidance/tests/test_second_look_diff.py | 3 |
2 files changed, 7 insertions, 0 deletions
diff --git a/plugins/security-guidance/hooks/review_api.py b/plugins/security-guidance/hooks/review_api.py index 86dc494b..0ffeb206 100644 --- a/plugins/security-guidance/hooks/review_api.py +++ b/plugins/security-guidance/hooks/review_api.py @@ -208,6 +208,10 @@ SURVIVED_SCHEMA = { def build_refute_prompt(candidates: list[dict[str, Any]], diff_text: str) -> str: + """`diff_text` is the diff the first look was given. One that is far over + the limit the first look has is cut, with a marker.""" + if len(diff_text) > 2 * DIFF_TOTAL_BYTES: + diff_text = diff_text[:DIFF_TOTAL_BYTES] + "\n[... diff truncated ...]" return ( "You previously flagged these candidate vulnerabilities:\n\n" + json.dumps(candidates, indent=2) diff --git a/plugins/security-guidance/tests/test_second_look_diff.py b/plugins/security-guidance/tests/test_second_look_diff.py index ff2ccafd..e6eb2f58 100644 --- a/plugins/security-guidance/tests/test_second_look_diff.py +++ b/plugins/security-guidance/tests/test_second_look_diff.py @@ -60,3 +60,6 @@ def test_a_cut_file_is_marked_in_both_looks(prompts, tmp_path): def test_importable_prompt_has_the_whole_diff(): diff = "+padding\n" * 2000 + SINK assert diff in review_api.build_refute_prompt([{"filePath": "a.py"}], diff) + raw = "+padding\n" * review_api.DIFF_TOTAL_BYTES + prompt = review_api.build_refute_prompt([{"filePath": "a.py"}], raw) + assert len(prompt) < 2 * review_api.DIFF_TOTAL_BYTES and "diff truncated" in prompt |
