[BUG] apm.yml entry written for HTTPS git URL with custom port cannot be re-parsed
Describe the bug
When adding a git dependency whose repository URL uses HTTPS with a custom port (e.g. https://git.example.com:8443/owner/repo), the initial parse succeeds and the port is preserved in the entry written to apm.yml. However, the persisted entry is unreadable: HTTPS dependencies are serialized via DependencyReference.to_canonical() into the scheme-free shorthand form git.example.com:8443/owner/repo, and DependencyReference.parse() rejects that form with ValueError. As a result, any subsequent command that re-reads apm.yml (install, update, resolve, uninstall, etc.) fails on an entry that APM itself wrote.
The root cause is in the shorthand resolver _resolve_shorthand_to_parsed_url() (src/apm_cli/models/dependency/reference.py): the leading segment git.example.com:8443 fails is_supported_git_host() because is_valid_fqdn() does not accept a : in the hostname, and since the segment contains a dot it also fails the bare user/repo branch, so parsing falls through to the final else branch and raises. In other words, to_canonical() deliberately emits host:port/... for custom-port deps ("Custom port is part of the transport and must travel with the host label"), but the parser has no branch that accepts it — the serializer and the parser disagree on the canonical grammar.
This is related to but distinct from the HTTP case (issue for http://
To Reproduce
Steps to reproduce the behavior:
- Run apm install "https://git.example.com:8443/owner/repo" (the initial parse and install succeed; the port is captured correctly)
- Inspect apm.yml — the dependency is recorded as the scheme-free shorthand git.example.com:8443/owner/repo
- Run any command that re-reads apm.yml (e.g. apm install again)
- See error: ValueError: Use 'user/repo' or 'github.com/user/repo' or 'dev.azure.com/org/project/repo' format
Minimal reproduction without the CLI:
from apm_cli.models.dependency.reference import DependencyReference
dep = DependencyReference.parse("https://git.example.com:8443/owner/repo") print(dep.host, dep.port) # git.example.com 8443 -- parsed correctly
entry = dep.to_apm_yml_entry() print(entry) # 'git.example.com:8443/owner/repo' -- port preserved
DependencyReference.parse(entry) # ValueError -- APM cannot read what it wrote
Expected behavior
A dependency string produced by to_apm_yml_entry() / to_canonical() should always be accepted by DependencyReference.parse() (write/read round-trip invariant). Concretely, the shorthand parser should accept host:port/owner/repo and restore the host and port, so that an HTTPS dependency with a custom port keeps working across every command after it has been persisted to apm.yml.
Environment (please complete the following information):
- OS: Windows 11
- Python Version: 3.12.9
- APM Version: 0.25.0
- VSCode Version (if relevant): N/A
Logs
DependencyReference.parse("git.example.com:8443/owner/repo") Traceback (most recent call last): ... File "src/apm_cli/models/dependency/reference.py", line 1775, in _parse_standard_url parsed_url, host = cls._resolve_shorthand_to_parsed_url(repo_url, host) File "src/apm_cli/models/dependency/reference.py", line 1566, in _resolve_shorthand_to_parsed_url raise ValueError( ValueError: Use 'user/repo' or 'github.com/user/repo' or 'dev.azure.com/org/project/repo' format
Additional context
- to_canonical() and get_identity() intentionally include the port in the host label (f"{host}:{self.port}" with the comment "Custom port is part of the transport and must travel with the host label"), so the serialization side treats host:port/... as valid canonical grammar. The fix likely belongs on the parse side: teach _resolve_shorthand_to_parsed_url() (and the underlying host validation, e.g. is_valid_fqdn / is_supported_git_host call sites) to split off an optional :port suffix from the leading host segment before validating it.
- Because get_identity() also emits host:port/..., the same grammar mismatch may affect identity-based flows such as duplicate detection and apm uninstall matching for custom-port HTTPS deps.
- The sibling HTTP bug (http://
: losing its port in to_apm_yml_entry()) is tracked #2202 ; it has a different root cause (the insecure branch built the URL from host alone) and does not require parser changes.
Triage Panel Verdict
Thank you for the report, @fabuchimk2.
Issue: apm.yml entry written for HTTPS git URL with custom port cannot be re-parsed
Panel Synthesis
This is a confirmed serializer/parser round-trip contract violation. The to_canonical() serializer deliberately emits the scheme-free shorthand host:port/owner/repo for custom-port HTTPS URLs, but DependencyReference.parse() has no branch that accepts a host:port/... prefix -- the colon in the hostname segment causes it to fail both is_supported_git_host() and the bare user/repo branch, raising ValueError. APM writes an entry it cannot read back.
This is related to #2202 (HTTP port dropped on write) but structurally distinct: here the port is written correctly but the parser rejects the written form.
DevX UX: The initial apm install succeeds. Every subsequent command fails with a cryptic ValueError pointing at the format documentation -- not at the persisted entry. The user has no obvious recovery path without manually editing apm.yml.
Supply Chain Security: No security implications beyond correctness. The parse rejection happens before any network operation.
APM CEO: A tool that writes entries it cannot re-read is a reliability failure. High priority. These two port-related bugs (#2202, #2203) should be fixed together in a single PR with shared test coverage.
Decision
- Verdict: Accept -- confirmed serializer/parser contract violation, fix required
- Labels:
area/cli,theme/portability,priority/high,status/triaged(existingtype/bugretained) - Milestone: Next patch release
- Suggested next action: Fix
_resolve_shorthand_to_parsed_url()to recognize thehost:port/owner/reposhorthand pattern produced byto_canonical()for custom-port HTTPS URLs. Alternatively, changeto_canonical()to emit a full(host/redacted):port/owner/repoURL for non-standard ports to avoid the ambiguous shorthand. Fix together with #2202 in a single PR.
Triage status: agentic proposal pending human ratification. Silence is approval. Maintainers can:
- Override any label or milestone above by editing it directly -- human edits are authoritative and will not be reverted on subsequent runs.
- Re-trigger triage by applying the
status/needs-triagelabel, or by removingstatus/triagedto enroll the issue in the next daily sweep.Posted by the Triage Panel workflow. See .apm/skills/apm-triage-panel for the panel skill.
Generated by Triage Panel · 97 AIC · ⌖ 8 AIC · ⊞ 9.2K · ◷
Opened a fix for this: #2211 — teaches the shorthand parser (_resolve_shorthand_to_parsed_url) to split an optional :port off the leading host segment, so the host:port/owner/repo form that to_canonical()/get_identity() emit re-parses back to the same host and port. Restores the write/read round-trip invariant (and the custom-port uninstall/dedup matching this issue notes). Regression tests included.