From cc200df0881fb3577e1ff9c4aa45555e528582be Mon Sep 17 00:00:00 2001 From: andrecs <12188364+andrecsilva@users.noreply.github.com> Date: Mon, 30 Jun 2025 07:55:16 -0300 Subject: [PATCH 1/2] Fixed behavior of sast_only flag --- src/codemodder/codemodder.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/codemodder/codemodder.py b/src/codemodder/codemodder.py index 54ae063b..9ae4d37e 100644 --- a/src/codemodder/codemodder.py +++ b/src/codemodder/codemodder.py @@ -285,7 +285,10 @@ def _run_cli(original_args, remediation=False) -> int: max_workers=argv.max_workers, original_cli_args=original_args, codemod_registry=codemod_registry, - sast_only=argv.sonar_issues_json or argv.sarif, + sast_only=argv.sonar_issues_json + or argv.sarif + or argv.sonar_hotspots_json + or argv.sonar_json, log_matched_files=True, remediation=remediation, ) From 1cea1b61f0199a6f5239d58f945e5cecc2cc14c9 Mon Sep 17 00:00:00 2001 From: andrecs <12188364+andrecsilva@users.noreply.github.com> Date: Mon, 30 Jun 2025 08:43:41 -0300 Subject: [PATCH 2/2] Modified test to include new flags --- integration_tests/test_program.py | 44 +++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/integration_tests/test_program.py b/integration_tests/test_program.py index af6383c2..865c3695 100644 --- a/integration_tests/test_program.py +++ b/integration_tests/test_program.py @@ -1,4 +1,8 @@ import subprocess +from pathlib import Path + +import pytest +from sarif_pydantic.sarif import Run, Sarif, Tool, ToolDriver from core_codemods.remove_assertion_in_pytest_raises import ( RemoveAssertionInPytestRaises, @@ -26,14 +30,50 @@ def test_codemods_include_exclude_conflict(self): ) assert completed_process.returncode == 3 - def test_load_sast_only_by_flag(self, tmp_path): + @pytest.mark.parametrize( + "cli_args", + [ + "--sonar-issues-json", + "--sonar-hotspots-json", + "--sonar-json", + ], + ) + def test_load_sast_only_by_sonar_flag(self, tmp_path, cli_args): tmp_file_path = tmp_path / "sonar.json" tmp_file_path.touch() completed_process = subprocess.run( [ "codemodder", "tests/samples/", - "--sonar-issues-json", + cli_args, + f"{tmp_file_path}", + "--dry-run", + ], + check=False, + capture_output=True, + text=True, + ) + print(completed_process.stdout) + print(completed_process.stderr) + assert completed_process.returncode == 0 + assert RemoveAssertionInPytestRaises.id not in completed_process.stdout + + def test_load_sast_only_by_sarif_flag(self, tmp_path: Path): + tmp_file_path = tmp_path / "sarif.json" + sarif_run = Run( + tool=Tool(driver=ToolDriver(name="test")), + results=[], + ) + sarif = Sarif(runs=[sarif_run], **{"$schema": ""}) + tmp_file_path.write_text( + sarif.model_dump_json(indent=2, exclude_none=True, by_alias=True) + ) + + completed_process = subprocess.run( + [ + "codemodder", + "tests/samples/", + "--sarif", f"{tmp_file_path}", "--dry-run", ],