|
25 | 25 | from codeflash.cli_cmds.cli_common import apologize_and_exit |
26 | 26 | from codeflash.cli_cmds.console import console, logger |
27 | 27 | from codeflash.cli_cmds.extension import install_vscode_extension |
| 28 | +from codeflash.code_utils.code_utils import validate_relative_directory_path |
28 | 29 | from codeflash.code_utils.compat import LF |
29 | 30 | from codeflash.code_utils.config_parser import parse_config_file |
30 | 31 | from codeflash.code_utils.env_utils import check_formatter_installed, get_codeflash_api_key |
@@ -349,20 +350,32 @@ def collect_setup_info() -> CLISetupInfo: |
349 | 350 | console.print(custom_panel) |
350 | 351 | console.print() |
351 | 352 |
|
352 | | - custom_questions = [ |
353 | | - inquirer.Path( |
354 | | - "custom_path", |
355 | | - message="Enter the path to your module directory", |
356 | | - path_type=inquirer.Path.DIRECTORY, |
357 | | - exists=True, |
358 | | - ) |
359 | | - ] |
| 353 | + # Retry loop for custom module root path |
| 354 | + module_root = None |
| 355 | + while module_root is None: |
| 356 | + custom_questions = [ |
| 357 | + inquirer.Path( |
| 358 | + "custom_path", |
| 359 | + message="Enter the path to your module directory", |
| 360 | + path_type=inquirer.Path.DIRECTORY, |
| 361 | + exists=True, |
| 362 | + ) |
| 363 | + ] |
360 | 364 |
|
361 | | - custom_answers = inquirer.prompt(custom_questions, theme=CodeflashTheme()) |
362 | | - if custom_answers: |
363 | | - module_root = Path(custom_answers["custom_path"]) |
364 | | - else: |
365 | | - apologize_and_exit() |
| 365 | + custom_answers = inquirer.prompt(custom_questions, theme=CodeflashTheme()) |
| 366 | + if not custom_answers: |
| 367 | + apologize_and_exit() |
| 368 | + return None # unreachable but satisfies type checker |
| 369 | + |
| 370 | + custom_path_str = str(custom_answers["custom_path"]) |
| 371 | + # Validate the path is safe |
| 372 | + is_valid, error_msg = validate_relative_directory_path(custom_path_str) |
| 373 | + if not is_valid: |
| 374 | + click.echo(f"❌ Invalid path: {error_msg}") |
| 375 | + click.echo("Please enter a valid relative directory path.") |
| 376 | + console.print() # Add spacing before retry |
| 377 | + continue # Retry the prompt |
| 378 | + module_root = Path(custom_path_str) |
366 | 379 | else: |
367 | 380 | module_root = module_root_answer |
368 | 381 | ph("cli-project-root-provided") |
@@ -420,20 +433,32 @@ def collect_setup_info() -> CLISetupInfo: |
420 | 433 | console.print(custom_tests_panel) |
421 | 434 | console.print() |
422 | 435 |
|
423 | | - custom_tests_questions = [ |
424 | | - inquirer.Path( |
425 | | - "custom_tests_path", |
426 | | - message="Enter the path to your tests directory", |
427 | | - path_type=inquirer.Path.DIRECTORY, |
428 | | - exists=True, |
429 | | - ) |
430 | | - ] |
| 436 | + # Retry loop for custom tests root path |
| 437 | + tests_root = None |
| 438 | + while tests_root is None: |
| 439 | + custom_tests_questions = [ |
| 440 | + inquirer.Path( |
| 441 | + "custom_tests_path", |
| 442 | + message="Enter the path to your tests directory", |
| 443 | + path_type=inquirer.Path.DIRECTORY, |
| 444 | + exists=True, |
| 445 | + ) |
| 446 | + ] |
431 | 447 |
|
432 | | - custom_tests_answers = inquirer.prompt(custom_tests_questions, theme=CodeflashTheme()) |
433 | | - if custom_tests_answers: |
434 | | - tests_root = Path(curdir) / Path(custom_tests_answers["custom_tests_path"]) |
435 | | - else: |
436 | | - apologize_and_exit() |
| 448 | + custom_tests_answers = inquirer.prompt(custom_tests_questions, theme=CodeflashTheme()) |
| 449 | + if not custom_tests_answers: |
| 450 | + apologize_and_exit() |
| 451 | + return None # unreachable but satisfies type checker |
| 452 | + |
| 453 | + custom_tests_path_str = str(custom_tests_answers["custom_tests_path"]) |
| 454 | + # Validate the path is safe |
| 455 | + is_valid, error_msg = validate_relative_directory_path(custom_tests_path_str) |
| 456 | + if not is_valid: |
| 457 | + click.echo(f"❌ Invalid path: {error_msg}") |
| 458 | + click.echo("Please enter a valid relative directory path.") |
| 459 | + console.print() # Add spacing before retry |
| 460 | + continue # Retry the prompt |
| 461 | + tests_root = Path(curdir) / Path(custom_tests_path_str) |
437 | 462 | else: |
438 | 463 | tests_root = Path(curdir) / Path(cast("str", tests_root_answer)) |
439 | 464 |
|
|
0 commit comments