[BUG] Port is dropped from HTTP git URL when persisted to apm.yaml
Describe the bug
When adding a git dependency whose repository URL uses an explicit port (e.g. http://
The parser itself (DependencyReference.parse()) correctly extracts and stores the port. The bug is isolated to DependencyReference.to_apm_yml_entry() in src/apm_cli/models/dependency/reference.py: unlike to_canonical(), get_identity(), and to_github_url() (which all build the netloc as f"{host}:{self.port}" when a port is present), the HTTP/is_insecure branch of to_apm_yml_entry() builds the URL from host alone, omitting self.port entirely.
if self.is_insecure: host = self.host or default_host() entry = {"git": f"http://{host}/{self.repo_url}"} # port is never included
To Reproduce
Steps to reproduce the behavior:
- Run apm install "http://192.168.1.10:8080/owner/repo" --allow-insecure (or add the equivalent entry under dependencies.apm in apm.yml)
- Inspect the resulting apm.yml / apm.yaml
- See that the recorded git: URL is http://192.168.1.10/owner/repo — the :8080 port suffix is missing
- Re-run apm install (or any command that re-reads the lockfile/manifest) and observe the connection attempt going to the default port instead of 8080, causing the connection to fail
Expected behavior
The port specified in the original repository URL should be preserved verbatim when the dependency is written to apm.yaml/apm.yml, so that http://192.168.1.10:8080/owner/repo round-trips as http://192.168.1.10:8080/owner/repo and subsequent commands can connect successfully.
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
apm.yml before write (user input)
git: http://192.168.1.10:8080/owner/repo
apm.yml after write (actual, buggy output)
git: http://192.168.1.10/owner/repo
Additional context
Root cause confirmed via unit reproduction:
dep = DependencyReference.parse("http://192.168.1.10:8080/owner/repo") dep.host, dep.port # ('192.168.1.10', 8080) -- parsed correctly dep.to_github_url() # 'http://192.168.1.10:8080/owner/repo' -- correct dep.to_apm_yml_entry() # {'git': 'http://192.168.1.10/owner/repo', ...} -- port lost
A fix is straightforward: mirror the netloc = f"{host}:{self.port}" if self.port else host pattern already used by to_canonical()/get_identity()/to_github_url() inside the is_insecure branch of to_apm_yml_entry(). Happy to submit a PR with this fix plus a regression test if useful.
Triage Panel Verdict
Thank you for the report, @fabuchimk2.
Issue: Port is dropped from HTTP git URL when persisted to apm.yaml
Panel Synthesis
This is a clear, well-isolated bug in DependencyReference.to_apm_yml_entry(). The insecure (HTTP) branch builds the URL from host alone, omitting self.port. All other URL-building methods in the same class correctly include the port. The bug causes a silent data loss: the user specifies a custom port, APM records a portless URL, and subsequent commands fail to connect -- but nothing tells the user why.
DevX UX: Silent round-trip corruption. The user specified a working URL; APM persists a broken one. Subsequent apm install fails with a connection error that looks like a network problem rather than an APM bug. This is a high-severity UX failure.
Supply Chain Security: No security implications.
APM CEO: One-line fix in the HTTP branch of to_apm_yml_entry(). High priority patch.
Decision
- Verdict: Accept -- confirmed data-loss bug, trivial fix
- Labels:
area/cli,theme/portability,priority/high,status/triaged(existingtype/bugretained) - Milestone: Next patch release
- Suggested next action: In the HTTP (
is_insecure) branch ofDependencyReference.to_apm_yml_entry(), changef"(redacted) tof"(redacted) whenself.portis set, matching the pattern used into_canonical()andget_identity(). Note: also see related #2203 for the HTTPS custom-port round-trip failure.
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: #2210 — builds the netloc as {host}:{port} in the is_insecure branch of to_apm_yml_entry(), matching to_canonical()/get_identity()/to_github_url(), plus regression tests for serialization and the full parse → serialize → re-parse round-trip.