Repository navigation
fix(deps): include a non-default port in the dependency identity key - #3932
Daniel Meppiel (danielmeppiel) merged 9 commits into
Conversation
build_dependency_unique_key now qualifies the host with a non-default port (host:port/owner/repo, github.com included), and both DependencyReference and LockedDependency pass it. Port-less keys and the bare default-host form are unchanged. Two ports of one repository are now two packages, so MaterializationSlots rejects them on their shared apm_modules directory (#3696) unless one sets alias:. Exec deny matching stays port-blind, like dependency-policy host matching, so a deny cannot be bypassed by naming another port. Aligns with req-rs-016 (repository identity includes explicit port). Refs #3927 Co-authored-by: Copilot App <[email protected]>
…7-port-identity-key
Co-authored-by: Copilot App <[email protected]>
apm-spec-waiver: implements existing req-rs-016 port identity; no spec text change Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The changelog omits the breaking approval-key migration for existing non-default-port dependencies and the required reapproval step using apm approve.
1 open issue
What changed in this PR
Fixes the dependency-identity portion of #3927 by treating non-default ports as distinct authorities. This prevents lockfile entries and dependency deduplication from silently merging different packages; the MCP conflict-hint fix remains separate in #3930.
Changes:
- Threads ports through the canonical identity builder while preserving port-less keys.
- Keeps executable approvals port-specific and deny matching port-blind.
- Adds identity, collision, lockfile, and architecture regression coverage, plus documentation updates.
| File | Description |
|---|---|
tests/unit/test_generic_git_urls.py |
Tests port-qualified keys and lockfile round trips. |
tests/unit/security/test_executables.py |
Tests that alternate ports cannot bypass denials. |
tests/unit/deps/test_replacement_resolver.py |
Distinguishes identity ambiguity from directory collisions. |
tests/integration/test_same_repo_two_hosts_lifecycle.py |
Covers port collisions, aliases, and stable lockfile replay. |
tests/integration/test_architecture_owner_rule_mutations.py |
Adds mutations proving port-forwarding guards. |
src/apm_cli/security/executables.py |
Removes ports when canonicalizing deny identities. |
src/apm_cli/models/dependency/reference.py |
Passes the reference port to the identity builder. |
src/apm_cli/models/dependency/identity.py |
Includes non-default ports in dependency keys. |
src/apm_cli/install/plan.py |
Preserves ports in fallback key construction. |
src/apm_cli/deps/lockfile.py |
Includes persisted ports when reconstructing keys. |
scripts/architecture_linter/checks/contracts_test_taxonomy.py |
Guards port handling across identity owners. |
packages/apm-guide/.apm/skills/apm-usage/dependencies.md |
Explains port-sensitive identity and alias requirements. |
docs/src/content/docs/reference/lockfile-spec.md |
Documents port-qualified lockfile keys. |
CHANGELOG.md |
Records the user-visible identity correction. |
Review effort: Balanced
The deny identity dropped the port inside executables.py. identity.py now owns it as build_port_blind_dependency_key, the guard pins both the helper and its deny caller, and two mutation cases prove it. Tests pin that a grant names one port while project and org denies cover all. Addresses python-architect FU-1/FU-2, test-coverage FU-2 and supply-chain FU-1. Co-authored-by: Copilot App <[email protected]>
A v3 lock written before #3927 recorded a ported parent as its port-blind key, so reading it failed with 'Replacement graph parent ... is absent from the lockfile'. The lockfile read path now points such a parent at its one ported entry. Addresses test-coverage FU-1. Co-authored-by: Copilot App <[email protected]>
Deny ignores the port; allow, recommend and require name the ported key. The installed-CLI test now uninstalls the default-port package and keeps the ported one. Addresses supply-chain FU-2 and test-coverage FU-3. Co-authored-by: Copilot App <[email protected]>
Existing ported dependencies change approval key, so previously approved hooks and MCP servers become gated until re-approved. Addresses Copilot inline on CHANGELOG.md. apm-spec-waiver: implements existing req-rs-016 port identity; no spec text change Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Supply Chain Security Expert | 0 | 3 | 0 | No bypass found. Deny ignores the port, grants must match it exactly, and failures stay closed. Asked for grant non-leakage tests, trust-key docs, and default-port lock normalization. |
| Python Architect | 0 | 3 | 0 | One owner for the key holds. The deny port-drop should move into identity.py and the guard should pin it. |
| Test Coverage Expert | 0 | 3 | 0 | Key, dedup and #3696 traps are solid. Gaps: legacy v3 lock with a ported parent failed to read (reproduced), grant fail-closed unpinned, ported uninstall untested. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 2 follow-ups
- [Python Architect] Replace the hand-copied kwargs in the
install/plan.py_dep_ref_keyfallback with a call into the identity.py owner, and add theanchored_local_path/is_marketplacefields it is already missing. -- It is the one remaining key path outside the single owner, and it drifted before [BUG] Dependency identity key ignores the port; MCP conflict hint misreads ${CLAUDE_PROJECT_DIR:-.} #3927; the guard could pin it once it routes through identity.py. - [Supply Chain Security Expert] At the next lockfile schema revision, record the transport (or normalize scheme-default ports) so a lock row carrying :443/:22 normalizes to the manifest key. -- It fails closed today and the writer never emits default ports, but a hand-edited row causes a confusing re-resolve or re-approval.
Recommendation
Merge once CI is green on d1fe877. CI was green on the prior head 2262d6c, and the folds passed locally (2581 unit tests, 10 architecture mutation tests, lint chain clean). Every finding on the trust boundary and lockfile back-compat is folded and pinned by tests that fail under mutation. Track the _dep_ref_key single-owner cleanup as the highest-signal follow-up, and take the default-port lock normalization with the next lockfile schema revision.
Full per-persona findings
Python Architect
- [recommended] The port-blind deny identity was a second policy-identity rule computed in security/executables.py, outside identity.py at
src/apm_cli/security/executables.py:328
Folded:build_port_blind_dependency_keyin identity.py;canonical_exec_identitycalls it. - [recommended] The extended guard pinned the port on the key side but not on the deny side at
scripts/architecture_linter/checks/contracts_test_taxonomy.py
Folded: guard pins the helper body and its deny caller; mutation casesdeny-keeps-portandport-blind-key-keeps-port. - [recommended] install/plan.py
_dep_ref_keyfallback is a hand-copied list of builder arguments atsrc/apm_cli/install/plan.py:104
Deferred: pre-existing drift (anchored_local_path, is_marketplace) in a test-fake fallback predates [BUG] Dependency identity key ignores the port; MCP conflict hint misreads ${CLAUDE_PROJECT_DIR:-.} #3927; this PR only added port.
Supply Chain Security Expert
- [recommended] Add a test that a port-less grant does not approve the ported key, plus project deny and ported org deny cases at
tests/unit/security/test_executables.py
Folded:TestDenyIdentitySpellings::test_deny_ignores_the_port_and_grants_do_not(fails if the port drop is reverted). - [recommended] Document the executable-trust key rules and the re-approval upgrade at
docs/src/content/docs/enterprise/policy-reference.md
Folded: Ports note inreference/policy-schema.mdand apm-guidegovernance.md; CHANGELOG upgrade note withapm approve. - [recommended] A lock row with a default port (443/22) gets a key that never matches the manifest at
src/apm_cli/deps/lockfile.py:715
Deferred: the lockfile records no transport, so a per-row default port needs a schema change (out of scope); fails closed.
Test Coverage Expert
- [recommended] A legacy v3 lockfile whose replacement-graph parent is a ported dep failed to load at
src/apm_cli/deps/lockfile.py:1403
Folded:LockFile._rekey_port_blind_parents;test_legacy_v3_lock_with_port_blind_parent_still_loads(fails if the call is removed). - [recommended] Approval grants stay port-exact, but no test asserted it at
tests/unit/security/test_executables.py
Folded with the supply-chain test above. - [recommended] No real-binary lifecycle test of uninstall with the ported key at
tests/integration/test_same_repo_two_hosts_lifecycle.py
Folded:test_same_repo_on_another_port_is_a_different_packagenow uninstallstest/tooland keeps thegithub.com:8443package and lock entry.
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.
…7-port-identity-key
- default client is copilot; vscode is its deprecated alias (#3875) - non-default port is part of the lock identity key (#3932); the roundtrip still writes and reads port: 7990 - a partial `apm marketplace update` fails closed with exit 1 and names the failed catalog (#3910) - Claude's skill-command rewrite is an instance method that needs the project's .claude/skills copy (#3875) Co-authored-by: Copilot App <[email protected]>

Description
Root cause 1 of #3927:
build_dependency_unique_keyignored the port, sohttps://github.com:8443/acme/tool.gitandacme/tool(andgitlab.example.com:8443/...vsgitlab.example.com/...) shared one key. Lock entries, dedup, the #3696 slot check and approval keys treated two servers as one package; the second declaration was silently dropped.models/dependency/identity.py(the identity owner): a non-default port qualifies the host segment,host:port/owner/repo, on github.com too. Port-less keys and the bare default-host form are unchanged, so existing lockfiles keep their keys. Scheme-default ports are already dropped at parse, and host case-folding is unchanged.DependencyReference.get_unique_key,LockedDependency.get_unique_key(port is already persisted in the lockfile) and theinstall/plan.pyfallback passport.MaterializationSlots([BUG] The same owner/repo from two hosts collides in apm_modules with "Path already has a replacement in progress" #3696) sees two identities on oneapm_modulesdirectory and rejects the pair before fetch, naming both (github.com/acme/tool and github.com:8443/acme/tool are different packages ...);alias:installs both. Approval grants follow the ported key (fail closed).canonical_exec_identity(deny matching) drops the port, like dependency-policy host matching, so a deny cannot be bypassed by naming another port. Uninstall/audit/deps matching already route throughget_unique_key/get_identity.contracts-tooling-dependency-identityguard so the builder must handleportand both identity models must passport=self.port; three mutation tests prove its teeth.build_port_blind_dependency_key); the guard pins it and itscanonical_exec_identitycaller.dependencies.md(it stated the old "one lockfile key" behavior), policy-schema and apm-guidegovernance.md(deny ignores the port; allow/recommend/require name the ported key).Behavior note for review: two tests encoded the old "port is a transport detail" contract and are updated. One consequence: a Bitbucket DC repo reached as
ssh://host:7999/...andhttps://host/...in the same graph is now two packages (rejected on the shared directory unless aliased), and its lockfile key gains:7999on the next write (keys are recomputed on load; a v3 lock that recorded a ported parent port-blind is re-pointed at its one ported entry on read). Executable approvals for ported deps must be re-granted (apm approve); this is in the CHANGELOG upgrade notes. This matches the approved scope and req-rs-016 (identity includes explicit port).Issue and approved scope
Issue: Fixes #3927
Human scope-approval comment: #3927 (comment)
Does this PR complete the issue, or what remains? Yes. It delivers root cause 1 (port in identity key); root cause 2 (MCP conflict hint) merged in #3930, so this PR completes #3927.
Type of change
Testing
Validation evidence (HEAD merged with main bcd020f; re-merged with be0e43a, lint chain clean):
DependencyReference.parse('https://github.com:8443/acme/tool.git').get_unique_key()->acme/tool(same asacme/tool). After:github.com:8443/acme/tool.acme/tool+https://github.com:8443/acme/tool.git:.venv/bin/apm install-> exit 1,[x] github.com/acme/tool and github.com:8443/acme/tool are different packages that would both install to apm_modules/acme/tool ...(no fetch).pytest tests/unit/test_generic_git_urls.py::TestCustomPortParsing tests/unit/security/test_executables.py::TestCanonicalExecIdentityHostCase tests/unit/deps/test_replacement_resolver.py tests/integration/test_same_repo_two_hosts_lifecycle.py::test_same_repo_on_another_port_is_a_different_package-> 8 failed, 37 passed (all new port traps fail; port-less cases pass).APM_BINARY_PATH=.venv/bin/apm .venv/bin/python -m pytest -p no:xdist tests/integration/test_same_repo_two_hosts_lifecycle.py-> 4 passed (includes installed-CLI port case + alias install + lockfile replay stability)..venv/bin/python -m pytest -p no:xdist tests/unit/deps tests/unit/models tests/unit/security tests/unit/test_generic_git_urls.py tests/unit/test_canonicalization.py tests/unit/test_apm_package.py tests/unit/test_ssh_user_threading.py tests/unit/test_generic_host_error_port.py tests/unit/test_lockfile*.py-> 2917 passed (pre-merge); post-merge targeted settests/unit/test_generic_git_urls.py tests/unit/security/test_executables.py tests/unit/deps/test_replacement_resolver.py tests/unit/install/test_plan.py tests/unit/test_lockfile*.py-> 520 passed..venv/bin/python -m pytest -p no:xdist tests/integration/test_architecture_owner_rule_mutations.py -k "cannot_drop_the_port or dependency-identity or covers_every or case_order"-> 8 passed.uvx [email protected] check/format --check(CI paths) -> clean; pylint R0801 -> 10.00/10;bash scripts/lint-auth-signals.sh-> clean;bash scripts/lint-architecture-boundaries.sh-> exit 0; file-length guard: reference.py 2100 (max 2100,NR > max).Changelog
## [Unreleased]inCHANGELOG.md:user-visible effect first, 25 words or fewer, ending with
(#PR);breaking changes only under upgrade notes; no Highlights; see
.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
Implements existing req-rs-016 (repository identity includes explicit port); no normative text changes. Spec gate waived in a commit message.
docs/src/content/docs/specs/openapm-v0.1.mdupdated(new/changed
<a id="req-XXX"></a>anchor + prose + Appendix Crow).
docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.ymlupdated.
@pytest.mark.req("req-XXX")test undertests/spec_conformance/added or extended.CONFORMANCE.{md,json}regenerated viauv run --extra dev python -m tests.spec_conformance.gen_statementand committed.
apm-spec-waiver: implements existing req-rs-016 port identity; no spec text change