From 3dd228037888fe1357560aedcca69ece441ff2d0 Mon Sep 17 00:00:00 2001 From: CleverThis Date: Mon, 13 Apr 2026 22:02:03 +0000 Subject: [PATCH] fix(resource): update validate_clone_into_url to raise ValueError for invalid URLs - Change validate_clone_into_url() return type from bool to None - Raise ValueError for empty or invalid git repository URLs - Update BDD steps to catch ValueError and set clone_url_valid accordingly - Aligns with contract requirement from PR #8304 review feedback --- features/steps/container_clone_into_steps.py | 16 ++++++++++++++-- src/cleveragents/resource/handlers/clone_into.py | 15 +++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/features/steps/container_clone_into_steps.py b/features/steps/container_clone_into_steps.py index 41471629c..7f2657239 100644 --- a/features/steps/container_clone_into_steps.py +++ b/features/steps/container_clone_into_steps.py @@ -25,13 +25,25 @@ from cleveragents.resource.handlers.clone_into import ( @when('I validate clone-into URL "{url}"') def step_validate_url(context: Context, url: str) -> None: """Validate a clone-into URL.""" - context.clone_url_valid = validate_clone_into_url(url) + context.clone_url_error = None + try: + validate_clone_into_url(url) + context.clone_url_valid = True + except ValueError as exc: + context.clone_url_valid = False + context.clone_url_error = exc @when("I validate clone-into URL with whitespace only") def step_validate_whitespace_url(context: Context) -> None: """Validate a whitespace-only clone-into URL.""" - context.clone_url_valid = validate_clone_into_url(" ") + context.clone_url_error = None + try: + validate_clone_into_url(" ") + context.clone_url_valid = True + except ValueError as exc: + context.clone_url_valid = False + context.clone_url_error = exc @when("I call clone_repo_into_container with empty container_id") diff --git a/src/cleveragents/resource/handlers/clone_into.py b/src/cleveragents/resource/handlers/clone_into.py index 0323c3630..13980ce50 100644 --- a/src/cleveragents/resource/handlers/clone_into.py +++ b/src/cleveragents/resource/handlers/clone_into.py @@ -131,7 +131,7 @@ def clone_repo_into_container( return target_dir -def validate_clone_into_url(url: str) -> bool: +def validate_clone_into_url(url: str) -> None: """Validate that a URL is a plausible git repository URL. Accepts: @@ -143,12 +143,11 @@ def validate_clone_into_url(url: str) -> bool: Args: url: The URL string to validate. - Returns: - ``True`` if the URL looks like a valid git repository URL, - ``False`` otherwise. + Raises: + ValueError: If the URL is empty or does not match any valid prefix. """ if not url or not url.strip(): - return False + raise ValueError("URL must be a non-empty string") url = url.strip() valid_prefixes = ( "https://", @@ -160,4 +159,8 @@ def validate_clone_into_url(url: str) -> bool: "./", "../", ) - return any(url.startswith(prefix) for prefix in valid_prefixes) + if not any(url.startswith(prefix) for prefix in valid_prefixes): + raise ValueError( + f"Invalid git repository URL: {url!r}. " + f"Must start with one of: {', '.join(valid_prefixes)}" + )