Skip to content

Commit 7da3f98

Browse files
CM-55207-Fix tests and lint
1 parent 34a1a4b commit 7da3f98

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

cycode/cli/files_collector/commit_range_documents.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ def collect_commit_range_diff_documents(
6767
commit_documents_to_scan = []
6868

6969
repo = git_proxy.get_repo(path)
70-
70+
7171
normalized_commit_range = normalize_commit_range(commit_range, path)
72-
72+
7373
total_commits_count = int(repo.git.rev_list('--count', normalized_commit_range))
74-
logger.debug('Calculating diffs for %s commits in the commit range %s', total_commits_count, normalized_commit_range)
74+
logger.debug('Calculating diffs for %s commits in the commit range %s',
75+
total_commits_count, normalized_commit_range)
7576

7677
progress_bar.set_section_length(ScanProgressBarSection.PREPARE_LOCAL_FILES, total_commits_count)
7778

@@ -100,9 +101,9 @@ def collect_commit_range_diff_documents(
100101
logger.debug(
101102
'Found all relevant files in commit %s',
102103
{
103-
'path': path,
104-
'commit_range': commit_range,
105-
'normalized_commit_range': normalized_commit_range,
104+
'path': path,
105+
'commit_range': commit_range,
106+
'normalized_commit_range': normalized_commit_range,
106107
'commit_id': commit_id,
107108
},
108109
)
@@ -437,7 +438,8 @@ def get_pre_commit_modified_documents(
437438

438439

439440
def parse_commit_range(commit_range: str, path: str) -> tuple[Optional[str], Optional[str], Optional[str]]:
440-
"""Parses a git commit range string and returns the full SHAs for the 'from' and 'to' commits as well as the separator.
441+
"""Parses a git commit range string and returns the full SHAs for the 'from' and 'to' commits.
442+
Also, it returns the separator in the commit range.
441443
442444
Supports:
443445
- 'from..to'
@@ -462,8 +464,10 @@ def parse_commit_range(commit_range: str, path: str) -> tuple[Optional[str], Opt
462464
# If a spec is empty (e.g., from '..master'), default it to 'HEAD'
463465
if not from_spec:
464466
from_spec = consts.GIT_HEAD_COMMIT_REV
467+
separator = '..'
465468
if not to_spec:
466469
to_spec = consts.GIT_HEAD_COMMIT_REV
470+
separator = '..'
467471

468472
try:
469473
# Use rev_parse to resolve each specifier to its full commit SHA
@@ -476,7 +480,7 @@ def parse_commit_range(commit_range: str, path: str) -> tuple[Optional[str], Opt
476480

477481
def normalize_commit_range(commit_range: str, path: str) -> str:
478482
"""Normalize a commit range string to handle various formats consistently with all scan types.
479-
483+
480484
Returns:
481485
A normalized commit range string suitable for Git operations (e.g., 'full_sha1..full_sha2')
482486
"""
@@ -488,7 +492,7 @@ def normalize_commit_range(commit_range: str, path: str) -> str:
488492
)
489493
# Fall back to using the raw commit_range string
490494
return commit_range
491-
495+
492496
# Construct a normalized range string using the original separator for iter_commits
493497
# This preserves the semantics of two-dot vs three-dot syntax
494498
normalized_commit_range = f'{from_commit_rev}{separator}{to_commit_rev}'
@@ -497,4 +501,4 @@ def normalize_commit_range(commit_range: str, path: str) -> str:
497501
commit_range,
498502
normalized_commit_range,
499503
)
500-
return normalized_commit_range
504+
return normalized_commit_range

tests/cli/files_collector/test_commit_range_documents.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -847,40 +847,40 @@ def test_two_dot_linear_history(self) -> None:
847847
with temporary_git_repository() as (temp_dir, repo):
848848
a, b, c = self._make_linear_history(repo, temp_dir)
849849

850-
parsed_from, parsed_to = parse_commit_range(f'{a}..{c}', temp_dir)
851-
assert (parsed_from, parsed_to) == (a, c)
850+
parsed_from, parsed_to, separator = parse_commit_range(f'{a}..{c}', temp_dir)
851+
assert (parsed_from, parsed_to, separator) == (a, c, '..')
852852

853853
def test_three_dot_linear_history(self) -> None:
854854
"""For 'A...C' in linear history, expect (A,C)."""
855855
with temporary_git_repository() as (temp_dir, repo):
856856
a, b, c = self._make_linear_history(repo, temp_dir)
857857

858-
parsed_from, parsed_to = parse_commit_range(f'{a}...{c}', temp_dir)
859-
assert (parsed_from, parsed_to) == (a, c)
858+
parsed_from, parsed_to, separator = parse_commit_range(f'{a}...{c}', temp_dir)
859+
assert (parsed_from, parsed_to, separator) == (a, c, '...')
860860

861861
def test_open_right_linear_history(self) -> None:
862862
"""For 'A..', expect (A,HEAD=C)."""
863863
with temporary_git_repository() as (temp_dir, repo):
864864
a, b, c = self._make_linear_history(repo, temp_dir)
865865

866-
parsed_from, parsed_to = parse_commit_range(f'{a}..', temp_dir)
867-
assert (parsed_from, parsed_to) == (a, c)
866+
parsed_from, parsed_to, separator = parse_commit_range(f'{a}..', temp_dir)
867+
assert (parsed_from, parsed_to, separator) == (a, c, '..')
868868

869869
def test_open_left_linear_history(self) -> None:
870870
"""For '..C' where HEAD==C, expect (HEAD=C,C)."""
871871
with temporary_git_repository() as (temp_dir, repo):
872872
a, b, c = self._make_linear_history(repo, temp_dir)
873873

874-
parsed_from, parsed_to = parse_commit_range(f'..{c}', temp_dir)
875-
assert (parsed_from, parsed_to) == (c, c)
874+
parsed_from, parsed_to, separator = parse_commit_range(f'..{c}', temp_dir)
875+
assert (parsed_from, parsed_to, separator) == (c, c, '..')
876876

877877
def test_single_commit_spec(self) -> None:
878878
"""For 'A', expect (A,HEAD=C)."""
879879
with temporary_git_repository() as (temp_dir, repo):
880880
a, b, c = self._make_linear_history(repo, temp_dir)
881881

882-
parsed_from, parsed_to = parse_commit_range(a, temp_dir)
883-
assert (parsed_from, parsed_to) == (a, c)
882+
parsed_from, parsed_to, separator = parse_commit_range(a, temp_dir)
883+
assert (parsed_from, parsed_to, separator) == (a, c, '..')
884884

885885

886886
class TestParsePreReceiveInput:
@@ -1085,7 +1085,8 @@ def test_collect_with_various_commit_range_formats(self) -> None:
10851085
documents = collect_commit_range_diff_documents(mock_ctx, temp_dir, commit_range)
10861086
assert len(documents) == 2, f'Expected 2 documents from range A..C, got {len(documents)}'
10871087
commit_ids_in_documents = {doc.unique_id for doc in documents if doc.unique_id}
1088-
assert b_commit.hexsha in commit_ids_in_documents and c_commit.hexsha in commit_ids_in_documents
1088+
assert b_commit.hexsha in commit_ids_in_documents
1089+
assert c_commit.hexsha in commit_ids_in_documents
10891090

10901091
# Test three-dot range - should collect documents from commits B and C (2 commits, 2 documents)
10911092
commit_range = f'{a_commit.hexsha}...{c_commit.hexsha}'
@@ -1101,4 +1102,4 @@ def test_collect_with_various_commit_range_formats(self) -> None:
11011102
# Test single commit spec - should be interpreted as A..HEAD (commits B and C, 2 documents)
11021103
commit_range = a_commit.hexsha
11031104
documents = collect_commit_range_diff_documents(mock_ctx, temp_dir, commit_range)
1104-
assert len(documents) == 2, f'Expected 2 documents from single commit A (interpreted as A..HEAD), got {len(documents)}'
1105+
assert len(documents) == 2, f'Expected 2 documents from single commit A, got {len(documents)}'

0 commit comments

Comments
 (0)