fix(resource): update validate_clone_into_url to raise ValueError for invalid URLs
CI / lint (pull_request) Successful in 33s
CI / typecheck (pull_request) Successful in 49s
CI / quality (pull_request) Successful in 49s
CI / security (pull_request) Successful in 1m19s
CI / build (pull_request) Successful in 28s
CI / push-validation (pull_request) Successful in 20s
CI / helm (pull_request) Successful in 36s
CI / e2e_tests (pull_request) Successful in 4m41s
CI / integration_tests (pull_request) Successful in 4m44s
CI / unit_tests (pull_request) Failing after 7m9s
CI / docker (pull_request) Has been skipped
CI / coverage (pull_request) Successful in 19m52s
CI / status-check (pull_request) Failing after 2s
CI / benchmark-publish (pull_request) Has been skipped
CI / benchmark-regression (pull_request) Successful in 57m18s

- 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
This commit is contained in:
2026-04-13 22:02:03 +00:00
parent c515e03540
commit 3dd2280378
2 changed files with 23 additions and 8 deletions
+14 -2
View File
@@ -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")
@@ -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)}"
)