Skip to content

Commit 7ebf129

Browse files
authored
Remove restriction on duplicate sarif tools (#925)
1 parent f00d4c0 commit 7ebf129

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

src/codemodder/codemodder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from codemodder.project_analysis.file_parsers.package_store import PackageStore
2020
from codemodder.project_analysis.python_repo_manager import PythonRepoManager
2121
from codemodder.result import ResultSet
22-
from codemodder.sarifs import DuplicateToolError, detect_sarif_tools
22+
from codemodder.sarifs import detect_sarif_tools
2323
from codemodder.semgrep import run as run_semgrep
2424

2525

@@ -235,7 +235,7 @@ def _run_cli(original_args) -> int:
235235
tool_result_files_map: DefaultDict[str, list[Path]] = detect_sarif_tools(
236236
[Path(name) for name in argv.sarif or []]
237237
)
238-
except (DuplicateToolError, FileNotFoundError) as err:
238+
except FileNotFoundError as err:
239239
logger.error(err)
240240
return 1
241241

src/codemodder/sarifs.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ def detect(cls, run_data: dict) -> bool:
1515
pass
1616

1717

18-
class DuplicateToolError(ValueError): ...
19-
20-
2118
def detect_sarif_tools(filenames: list[Path]) -> DefaultDict[str, list[Path]]:
2219
results: DefaultDict[str, list[Path]] = defaultdict(list)
2320

@@ -42,15 +39,7 @@ def detect_sarif_tools(filenames: list[Path]) -> DefaultDict[str, list[Path]]:
4239
try:
4340
if det.detect(run):
4441
logger.debug("detected %s sarif: %s", name, fname)
45-
# According to the Codemodder spec, it is invalid to have multiple SARIF results for the same tool
46-
# https://github.com/pixee/codemodder-specs/pull/36
47-
if name in results:
48-
raise DuplicateToolError(
49-
f"duplicate tool sarif detected: {name}"
50-
)
5142
results[name].append(Path(fname))
52-
except DuplicateToolError as err:
53-
raise err
5443
except (KeyError, AttributeError, ValueError):
5544
continue
5645

tests/test_sarif_processing.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66

7-
from codemodder.sarifs import DuplicateToolError, detect_sarif_tools
7+
from codemodder.sarifs import detect_sarif_tools
88
from codemodder.semgrep import SemgrepResult, SemgrepResultSet
99

1010

@@ -102,15 +102,14 @@ def test_codeql_sarif_input_two_sarifs_same_tool(self, tmpdir):
102102
check=False,
103103
capture_output=True,
104104
)
105-
assert completed_process.returncode == 1
106-
assert (
107-
"duplicate tool sarif detected: codeql" in completed_process.stderr.decode()
108-
)
105+
assert completed_process.returncode == 0
109106

110107
def test_two_sarifs_same_tool(self):
111-
with pytest.raises(DuplicateToolError) as exc:
112-
detect_sarif_tools([Path("tests/samples/webgoat_v8.2.0_codeql.sarif")] * 2)
113-
assert "duplicate tool sarif detected: codeql" in str(exc.value)
108+
results = detect_sarif_tools(
109+
[Path("tests/samples/webgoat_v8.2.0_codeql.sarif")] * 2
110+
)
111+
assert len(results) == 1
112+
assert len(results["codeql"]) == 2
114113

115114
def test_bad_sarif(self, tmpdir, caplog):
116115
sarif_file = Path("tests") / "samples" / "semgrep.sarif"

0 commit comments

Comments
 (0)