fix(cli): --clone-into URL parsing broken by naive colon split #1214

Open
opened 2026-03-31 00:43:39 +00:00 by freemo · 0 comments
Owner

Background and Context

PR #1192 (feature/m4-resource-flags) adds the --clone-into flag to resource add for container types. The flag accepts the format REPO_URL:CONTAINER_PATH per the specification (line 10592).

Current Parsing Code

In src/cleveragents/cli/commands/resource.py, the value is parsed with:

parts = clone_into.split(":", 1)
if len(parts) != 2 or not parts[0] or not parts[1]:
    # error

The Bug

.split(":", 1) splits on the first colon. For any URL with a scheme (which is virtually all URLs), this breaks:

Input Expected split Actual split
https://github.com/acme/api.git:/workspace ["https://github.com/acme/api.git", "/workspace"] ["https", "//github.com/acme/api.git:/workspace"]
git@github.com:org/repo.git:/workspace ["git@github.com:org/repo.git", "/workspace"] ["git@github.com", "org/repo.git:/workspace"]

The spec's own example (line 10689) uses exactly this format:

agents resource add container-instance cloud/ci-runner \
    --clone-into https://github.com/acme/api.git:/workspace

Suggested Fix

Since CONTAINER_PATH is always an absolute path inside the container (starts with /), the parser should split on the last :/ boundary, or more robustly, find the last occurrence of : that is immediately followed by / and preceded by a non-/ character (to avoid matching ://). For example:

# Find the last ':' followed by '/' that isn't part of '://'
import re
m = re.match(r'^(.+):(/\S+)$', clone_into)

Or split from the right on : and check that the right part starts with /.

Acceptance Criteria

  • --clone-into https://github.com/acme/api.git:/workspace correctly parses to repo=https://github.com/acme/api.git, path=/workspace
  • --clone-into git@github.com:org/repo.git:/workspace correctly parses
  • --clone-into with an invalid format (no container path, no colon separator before an absolute path) produces a clear error
  • Test coverage for URL parsing edge cases

Spec References

  • --clone-into definition: line 10592
  • Example with HTTPS URL: line 10689
  • Devcontainer clone-into scenario: lines 42758–42787
## Background and Context PR #1192 (`feature/m4-resource-flags`) adds the `--clone-into` flag to `resource add` for container types. The flag accepts the format `REPO_URL:CONTAINER_PATH` per the specification (line 10592). ### Current Parsing Code In `src/cleveragents/cli/commands/resource.py`, the value is parsed with: ```python parts = clone_into.split(":", 1) if len(parts) != 2 or not parts[0] or not parts[1]: # error ``` ### The Bug `.split(":", 1)` splits on the **first** colon. For any URL with a scheme (which is virtually all URLs), this breaks: | Input | Expected split | Actual split | |-------|---------------|--------------| | `https://github.com/acme/api.git:/workspace` | `["https://github.com/acme/api.git", "/workspace"]` | `["https", "//github.com/acme/api.git:/workspace"]` | | `git@github.com:org/repo.git:/workspace` | `["git@github.com:org/repo.git", "/workspace"]` | `["git@github.com", "org/repo.git:/workspace"]` | The spec's own example (line 10689) uses exactly this format: ``` agents resource add container-instance cloud/ci-runner \ --clone-into https://github.com/acme/api.git:/workspace ``` ### Suggested Fix Since `CONTAINER_PATH` is always an absolute path inside the container (starts with `/`), the parser should split on the last `:/` boundary, or more robustly, find the last occurrence of `:` that is immediately followed by `/` and preceded by a non-`/` character (to avoid matching `://`). For example: ```python # Find the last ':' followed by '/' that isn't part of '://' import re m = re.match(r'^(.+):(/\S+)$', clone_into) ``` Or split from the right on `:` and check that the right part starts with `/`. ## Acceptance Criteria - [ ] `--clone-into https://github.com/acme/api.git:/workspace` correctly parses to repo=`https://github.com/acme/api.git`, path=`/workspace` - [ ] `--clone-into git@github.com:org/repo.git:/workspace` correctly parses - [ ] `--clone-into` with an invalid format (no container path, no colon separator before an absolute path) produces a clear error - [ ] Test coverage for URL parsing edge cases ## Spec References - `--clone-into` definition: line 10592 - Example with HTTPS URL: line 10689 - Devcontainer clone-into scenario: lines 42758–42787
freemo added this to the v3.4.0 milestone 2026-04-02 08:08:54 +00:00
freemo self-assigned this 2026-04-02 18:45:28 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#1214
No description provided.