Skip to content

Commit 18cfc8f

Browse files
ilia-cyclaude
andcommitted
CM-59469 switch SCA/IAC from file_name to file_path in detection_details
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f673b80 commit 18cfc8f

File tree

6 files changed

+90
-4
lines changed

6 files changed

+90
-4
lines changed

cycode/cli/apps/scan/scan_result.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def _get_file_name_from_detection(scan_type: str, raw_detection: dict) -> str:
8888
if scan_type == consts.SECRET_SCAN_TYPE:
8989
return _get_secret_file_name_from_detection(raw_detection)
9090

91-
return raw_detection['detection_details']['file_name']
91+
return raw_detection['detection_details']['file_path']
9292

9393

9494
def _get_secret_file_name_from_detection(raw_detection: dict) -> str:

cycode/cli/printers/tables/sca_table_printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _enrich_table_with_values(table: Table, detection: Detection) -> None:
8686
table.add_cell(SEVERITY_COLUMN, 'N/A')
8787

8888
table.add_cell(REPOSITORY_COLUMN, detection_details.get('repository_name'))
89-
table.add_file_path_cell(CODE_PROJECT_COLUMN, detection_details.get('file_name'))
89+
table.add_file_path_cell(CODE_PROJECT_COLUMN, detection_details.get('file_path'))
9090
table.add_cell(ECOSYSTEM_COLUMN, detection_details.get('ecosystem'))
9191
table.add_cell(PACKAGE_COLUMN, detection_details.get('package_name'))
9292

cycode/cli/printers/utils/detection_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ def get_detection_file_path(scan_type: str, detection: 'Detection') -> Path:
105105

106106
return Path(file_path)
107107

108-
return Path(detection.detection_details.get('file_name', ''))
108+
return Path(detection.detection_details.get('file_path', ''))

cycode/cli/printers/utils/detection_ordering/sca_ordering.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def sort_and_group_detections(detections: list['Detection']) -> tuple[list['Dete
4949

5050
grouped_by_repository = __group_by(sorted_detections, 'repository_name')
5151
for repository_group in grouped_by_repository.values():
52-
grouped_by_code_project = __group_by(repository_group, 'file_name')
52+
grouped_by_code_project = __group_by(repository_group, 'file_path')
5353
for code_project_group in grouped_by_code_project.values():
5454
grouped_by_package = __group_by(code_project_group, 'package_name')
5555
for package_group in grouped_by_package.values():
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from cycode.cli.apps.scan.scan_result import _get_file_name_from_detection
2+
from cycode.cli.consts import IAC_SCAN_TYPE, SAST_SCAN_TYPE, SCA_SCAN_TYPE, SECRET_SCAN_TYPE
3+
4+
5+
def test_get_file_name_from_detection_sca_uses_file_path() -> None:
6+
raw_detection = {
7+
'detection_details': {
8+
'file_name': 'package.json',
9+
'file_path': '/repo/path/package.json',
10+
},
11+
}
12+
result = _get_file_name_from_detection(SCA_SCAN_TYPE, raw_detection)
13+
assert result == '/repo/path/package.json'
14+
15+
16+
def test_get_file_name_from_detection_iac_uses_file_path() -> None:
17+
raw_detection = {
18+
'detection_details': {
19+
'file_name': 'main.tf',
20+
'file_path': '/repo/infra/main.tf',
21+
},
22+
}
23+
result = _get_file_name_from_detection(IAC_SCAN_TYPE, raw_detection)
24+
assert result == '/repo/infra/main.tf'
25+
26+
27+
def test_get_file_name_from_detection_sast_uses_file_path() -> None:
28+
raw_detection = {
29+
'detection_details': {
30+
'file_path': '/repo/src/app.py',
31+
},
32+
}
33+
result = _get_file_name_from_detection(SAST_SCAN_TYPE, raw_detection)
34+
assert result == '/repo/src/app.py'
35+
36+
37+
def test_get_file_name_from_detection_secret_uses_file_path_and_file_name() -> None:
38+
raw_detection = {
39+
'detection_details': {
40+
'file_path': '/repo/src',
41+
'file_name': '.env',
42+
},
43+
}
44+
result = _get_file_name_from_detection(SECRET_SCAN_TYPE, raw_detection)
45+
assert result == '/repo/src/.env'
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from pathlib import Path
2+
from unittest.mock import MagicMock
3+
4+
from cycode.cli.consts import IAC_SCAN_TYPE, SAST_SCAN_TYPE, SCA_SCAN_TYPE, SECRET_SCAN_TYPE
5+
from cycode.cli.printers.utils.detection_data import get_detection_file_path
6+
7+
8+
def _make_detection(**details: str) -> MagicMock:
9+
detection = MagicMock()
10+
detection.detection_details = dict(details)
11+
return detection
12+
13+
14+
def test_get_detection_file_path_sca_uses_file_path() -> None:
15+
detection = _make_detection(file_name='package.json', file_path='/repo/path/package.json')
16+
result = get_detection_file_path(SCA_SCAN_TYPE, detection)
17+
assert result == Path('/repo/path/package.json')
18+
19+
20+
def test_get_detection_file_path_iac_uses_file_path() -> None:
21+
detection = _make_detection(file_name='main.tf', file_path='/repo/infra/main.tf')
22+
result = get_detection_file_path(IAC_SCAN_TYPE, detection)
23+
assert result == Path('/repo/infra/main.tf')
24+
25+
26+
def test_get_detection_file_path_sca_fallback_empty() -> None:
27+
detection = _make_detection()
28+
result = get_detection_file_path(SCA_SCAN_TYPE, detection)
29+
assert result == Path('')
30+
31+
32+
def test_get_detection_file_path_secret() -> None:
33+
detection = _make_detection(file_path='/repo/src', file_name='.env')
34+
result = get_detection_file_path(SECRET_SCAN_TYPE, detection)
35+
assert result == Path('/repo/src/.env')
36+
37+
38+
def test_get_detection_file_path_sast() -> None:
39+
detection = _make_detection(file_path='repo/src/app.py')
40+
result = get_detection_file_path(SAST_SCAN_TYPE, detection)
41+
assert result == Path('/repo/src/app.py')

0 commit comments

Comments
 (0)