Skip to content

Commit 397b741

Browse files
fix linting
1 parent 6371ca5 commit 397b741

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

codeflash/code_utils/git_worktree_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def remove_worktree(worktree_dir: Path) -> None:
127127
# If we can't access the repository, try manual cleanup
128128
# Log at debug level since this is expected in some edge cases
129129
from codeflash.cli_cmds.console import logger
130+
130131
logger.debug(f"Could not access git repository at {worktree_dir}: {e}. Attempting manual cleanup.")
131132
_manual_cleanup_worktree_directory(worktree_dir)
132133
return
@@ -150,6 +151,7 @@ def remove_worktree(worktree_dir: Path) -> None:
150151
except (OSError, PermissionError) as e:
151152
# Log unexpected errors for debugging
152153
from codeflash.cli_cmds.console import logger
154+
153155
logger.debug(f"Worktree removal attempt {attempt + 1} failed with unexpected error: {e}")
154156
break
155157

codeflash/discovery/discover_unit_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ def discover_tests_pytest(
606606
check=False,
607607
**run_kwargs,
608608
)
609-
except subprocess.TimeoutExpired as e:
609+
except subprocess.TimeoutExpired:
610610
logger.error(
611611
f"Test discovery subprocess timed out after {run_kwargs.get('timeout', 600)} seconds. "
612612
f"Command: {discovery_script}"

codeflash/discovery/functions_to_optimize.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -667,52 +667,54 @@ def filter_functions(
667667

668668
def _validate_path_no_traversal(path: Path | str) -> bool:
669669
"""Validate that a path does not contain path traversal components.
670-
670+
671671
This prevents path traversal attacks by rejecting paths with '..' components.
672672
Paths passed to this function should be from trusted sources (git operations,
673673
file system discovery), but we validate defensively.
674-
674+
675675
Args:
676676
path: Path to validate
677-
677+
678678
Returns:
679679
True if path is safe (no traversal components), False otherwise
680+
680681
"""
681682
path_str = str(path)
682683
# Check for path traversal attempts
683-
if ".." in path_str:
684-
return False
685684
# Check for absolute paths that might escape (additional safety check)
686685
# Note: We allow absolute paths as they're needed for worktree paths
687-
return True
686+
return ".." not in path_str
688687

689688
def _resolve_path(path: Path | str) -> Path:
690689
# Use strict=False so we don't fail on paths that don't exist yet (e.g. worktree paths)
691690
# SECURITY: Validate path before resolution to prevent traversal attacks
692691
if not _validate_path_no_traversal(path):
693-
raise ValueError(f"Path contains traversal components: {path}")
692+
error_msg = f"Path contains traversal components: {path}"
693+
raise ValueError(error_msg)
694694
return Path(path).resolve(strict=False)
695695

696696
def _resolve_path_consistent(path: Path | str) -> Path:
697697
"""Resolve path consistently: use strict resolution if path exists, otherwise non-strict.
698-
698+
699699
SECURITY: This function validates paths to prevent traversal attacks before resolution.
700700
Paths should come from trusted sources (git operations, file system discovery),
701701
but we validate defensively.
702-
702+
703703
Args:
704704
path: Path to resolve (from trusted sources like git diff or file discovery)
705-
705+
706706
Returns:
707707
Resolved absolute Path
708-
708+
709709
Raises:
710710
ValueError: If path contains traversal components
711+
711712
"""
712713
# SECURITY: Validate path before any resolution to prevent traversal attacks
713714
if not _validate_path_no_traversal(path):
714-
raise ValueError(f"Path contains traversal components: {path}")
715-
715+
error_msg = f"Path contains traversal components: {path}"
716+
raise ValueError(error_msg)
717+
716718
path_obj = Path(path)
717719
if path_obj.exists():
718720
try:

0 commit comments

Comments
 (0)