Repository navigation
feat(install): carry the source licence with subdirectory packages - #3646
Daniel Meppiel (danielmeppiel) merged 7 commits into
Conversation
…3556) Packages materialized from a repository subdirectory now carry the nearest LICENSE, LICENSE.*, COPYING or NOTICE file found from the package path up to the repository root, verbatim, into the package in apm_modules. Every skill directory without its own licence file (also skills below the root of a whole-repo package) gets the nearest one, so the normal skill copy deploys it next to the skill and records it in deployed_files and the deployment ledger. Uninstall removes those copies and apm audit reports a missing or edited one. apm.lock.yaml records each copy under carried_licenses (path, source, hash). The copies are excluded from content_hash, using exclusions from the download result or the lock entry only, so pre-existing lockfiles keep verifying and older clients keep accepting new ones. Cached reuse requires the recorded copies to be intact, and a fresh download whose carried copies differ from the lock record fails closed. No licence detection or interpretation: APM keeps the declared-license model of #1777. apm-spec-waiver: additive optional per-entry lockfile field (carried_licenses) allowed by the lockfile schema additionalProperties and preserved by older readers; normative spec fold deferred to a spec-guardian pass. Co-authored-by: Copilot App <[email protected]>
…#3556) Moves the carried-licence hash recording and the fail-closed lock comparison into install/source_helpers so sources.py and resolve.py stay within the 1000-line install module budget, and restores the lazy verify_package_hash lookup that existing tests patch. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
A local test run left a fixture file in the worktree that was picked up by the previous commit; it is unrelated to #3556. Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved licence-handling defects can cause lockfile hash mismatches, failed skill installs, and skipped licence copies, while the new MCP configuration is invalid JSON.
3 open issues
What changed in this PR
This PR addresses #3556 by carrying source licence files into installed packages and deployed skills. It integrates licence provenance and integrity checks into APM's existing download, lockfile, cache, audit, and uninstall flows.
Changes:
- Add nearest-licence discovery, verbatim copying, and
carried_licenseslock records. - Exclude carried copies from package hashes and verify their integrity separately.
- Add lifecycle and regression coverage, documentation, and a changelog entry.
| File | Description |
|---|---|
tests/unit/install/test_branch_ref_drift.py |
Adapt hash-verification mocks for exclusions. |
tests/unit/deps/test_lockfile_field_properties.py |
Include carried licences in property tests. |
tests/unit/deps/test_lockfile_consumer_contract.py |
Extend lockfile field coverage. |
tests/unit/deps/test_carried_license.py |
Test discovery, copying, records, and integrity. |
tests/unit/deps/test_artifactory_orchestrator.py |
Cover archive-root licence carrying. |
tests/integration/test_carried_license_lifecycle.py |
Exercise install, replay, audit, and uninstall. |
tests/integration/test_architecture_native_plugin_audit.py |
Update the cache-verification guard test. |
src/apm_cli/utils/content_hash.py |
Support explicit package-hash exclusions. |
src/apm_cli/models/apm_package.py |
Add carried records to download results. |
src/apm_cli/install/sources.py |
Record and verify carried licences during acquisition. |
src/apm_cli/install/source_helpers.py |
Coordinate licence records and integrity checks. |
src/apm_cli/install/phases/resolve.py |
Capture records from resolver downloads. |
src/apm_cli/install/phases/lockfile.py |
Attach carried records to lock entries. |
src/apm_cli/install/phases/integrate.py |
Verify carried copies before cache reuse. |
src/apm_cli/install/phases/_redownload.py |
Include licence integrity in reuse decisions. |
src/apm_cli/install/native_plugin_admission.py |
Verify carried licences during native replay. |
src/apm_cli/install/legacy_plugin_compat.py |
Preserve exclusions in legacy hash checks. |
src/apm_cli/install/context.py |
Store per-install carried-licence records. |
src/apm_cli/deps/lockfile.py |
Serialize and deserialize carried records. |
src/apm_cli/deps/github_downloader.py |
Carry licences during Git materialization. |
src/apm_cli/deps/carried_license.py |
Own licence selection, copying, and verification. |
src/apm_cli/deps/artifactory_orchestrator.py |
Carry licences from archive packages. |
scripts/architecture_linter/checks/marketplace_package_and_registration.py |
Update the required cache-verification call. |
packages/apm-guide/.apm/skills/apm-usage/dependencies.md |
Document licence-carrying behavior. |
docs/src/content/docs/reference/lockfile-spec.md |
Describe carried records and hash exclusions. |
docs/src/content/docs/consumer/manage-dependencies.md |
Explain deployment and cache-refresh behavior. |
CHANGELOG.md |
Announce licence carrying. |
.github/mcp.json |
Add an unfinished MCP configuration placeholder. |
Review effort: Balanced
…pies Addresses Copilot inline review on #3646: - carried_license.py: only regular licence files satisfy "already has a licence"; never write over an existing entry (file, dir or link). - Subdirectory downloads read the repository licence before the checkout is discarded and write it after validation, so Claude plugin normalization cannot duplicate an unrecorded copy into .apm/skills (which broke pre-#3556 lockfile hashes on cold replay). - skill_adoption.render_skill_markdown never reads or rewrites licence files, so LICENSE.md deploys byte-identical and non-UTF-8 licences cannot crash install. The e2e test now covers a Claude plugin subdirectory and a LICENSE.md with a relative link, and asserts the locked content_hash equals the pre-feature hash for subdirectory packages. Co-authored-by: Copilot <[email protected]>
Addresses the test-coverage-expert panel follow-ups on #3646: direct unit tests for ensure_carried_licenses_match (fail closed, legacy, update and expected-change bypasses), record_carried_package_hash (fresh, cached intact, cached tampered), _should_skip_redownload with carried copies, and the Artifactory whole-repo carry. Co-authored-by: Copilot <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 0 | 0 | carried_license.py is a clean single owner; hash-exclusion API is minimal and backward-compatible; downloader is the correct seam. |
| Supply Chain Security Expert | 0 | 0 | 0 | Preserves content-hash integrity, uses sanctioned path guards, fails closed on tamper, constrains exclusions to licence-named basenames. |
| Test Coverage Expert | 0 | 3 | 0 | Done-whens covered at e2e tier; three install-pipeline glue paths lack unit regression traps. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 3 follow-ups
- [Test Coverage Expert] Add unit regression trap for ensure_carried_licenses_match and record_carried_package_hash guard branches in source_helpers.py -- fails closed on tamper, a secure-by-default surface.
- [Test Coverage Expert] Extend _should_skip_redownload unit tests with a carried-licence-aware verify_locked_package fixture -- reverting to plain verify_package_hash passes current unit tests.
- [Test Coverage Expert] Add unit assertion for carried_licenses in Artifactory whole-repo download_package -- removing the carry there fails no test.
Recommendation
Merge after the three unit regression traps land (fold-by-default: they are inside this PR's scope), prioritizing ensure_carried_licenses_match first. No rework or discussion needed.
Full per-persona findings
Python Architect
No findings.
Supply Chain Security Expert
No findings.
Test Coverage Expert
- [recommended] ensure_carried_licenses_match and record_carried_package_hash have no unit tests at
src/apm_cli/install/source_helpers.py
Guard branches (update_refs, expected_hash_change_deps, legacy no-records, carried_copies_intact fallback) have no direct regression trap.
Proof (missing at):tests/unit/install/test_source_helpers_carried.py-- proves: a fresh download whose carried licences differ from the lockfile record fails closed [secure-by-default] - [recommended] _should_skip_redownload unit tests do not exercise carried-licence-aware verify_locked_package at
src/apm_cli/install/phases/_redownload.py
TestHashRedownloadGuard uses SimpleNamespace without carried_licenses.
Proof (missing at):tests/unit/test_install_command.py-- proves: warm reinstall re-downloads when an on-disk carried licence copy is tampered [secure-by-default] - [recommended] Artifactory download_package (whole-repo) has no test asserting carried_licenses at
src/apm_cli/deps/artifactory_orchestrator.py:256
Removing carry_licenses from the whole-repo path fails no test.
Proof (missing at):tests/unit/deps/test_artifactory_orchestrator.py-- proves: Artifactory whole-repo download carries the root licence to skill directories [secure-by-default,portability-by-manifest]
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.
…556-subdir-licence
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 0 | 0 | Read/write split keeps carried_license.py the single owner; skill_adoption imports the canonical licence-name rule in the correct direction. |
| Supply Chain Security Expert | 0 | 0 | 0 | In-memory RepositoryLicense, lexists no-overwrite, regular-file-only detection and render-skip add no new attack surface. |
| Test Coverage Expert | 0 | 0 | 0 | All three prior findings resolved by 7cf53ac; C1/C2/C3 folds have dedicated unit traps plus lifecycle coverage. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Recommendation
All three prior follow-ups are resolved with mutation-checked unit traps. The three Copilot inline folds are covered by the same trap suite. CI is green on 43f57cc (27 pass, 0 fail, license/cla pass), and zero review threads remain open. No panelist raised a finding. Recommend merge at maintainer discretion.
Full per-persona findings
Python Architect
No findings.
Supply Chain Security Expert
No findings.
Test Coverage Expert
No findings.
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.
Clean merge of eight main commits (#3408, #2231, #2602, #3640, #3611, #3645, #3602, #3646); no lockfile or autopilot package conflicts and apm audit --ci passes with no drift. Co-authored-by: sergio-sisternes-epam <[email protected]> Co-authored-by: Copilot App <[email protected]>
Resolve docs/src/content/docs/reference/lockfile-spec.md content_hash row: keep this PR's core.autocrlf/core.eol pin wording (#3270) and main's carried_licenses exclusion (#3646). Co-authored-by: Copilot App <[email protected]>
* fix(tests): restore release-gate lanes for 0.36.0 Main's tag-gate lanes (build-release push + manual-build-release) were red on runs 43381609442, 43381682871 and 43394173235. PR CI never runs them. Product regressions (Windows/real installs), fixed: - Hook cleanup removed nothing on Windows: remove_stale_deployed_files looked up recorded hashes with POSIX keys while callers passed native backslash keys, so content proof failed closed (#3672, Refs #3649). - describe_path_obstruction returned None on Windows, which reports a directory-for-file as EACCES and a file-for-parent as ENOENT instead of EISDIR/ENOTDIR (#3709, Refs #3678). - Skill preflight refused claimed members of an unclaimed, populated skill directory that materialization leaves alone, failing a local bundle install (Refs #3625). Stale tests (behaviour changed intentionally), updated: - policy chain mocks now return real PolicyFetchResult (#2933, Refs #2753) - bare-cache/downloader/anonymous-https fixtures use real Git checkouts (#3603, Refs #3457) - mcp install help, registry error wording, deps why -g help (#3633 Refs #3588, #2803 Refs #2478, #3614 Refs #2884) - downloader stub carries carried_licenses (#3646, Refs #3556) - frozen-hash lifecycle uses a generic git host so -g URL validation uses git ls-remote instead of a live api.github.com 404 (#3672) New Windows-shaped regression tests are marked windows_compat. Co-authored-by: Copilot App <[email protected]> * chore: spec waiver for release-gate repair apm-spec-waiver: restores pre-existing behaviour on Windows and in skill preflight; no OpenAPM-observable change Co-authored-by: Copilot App <[email protected]> --------- Co-authored-by: danielmeppiel <[email protected]> Co-authored-by: Copilot App <[email protected]>
0.36.0 includes microsoft/apm#3638, which adopts unchanged committed skills when the local deployment receipts are missing, but only for `apm update`. After a manifest edit, `apm install` on a fresh checkout still refuses every committed file of the changed package ("no trustworthy local deployment baseline") and fails, so the dependabot#3625 workaround and the edited-file check are still needed. With them, every end-to-end scenario matches a fresh install of the new version and passes `apm install --frozen`. 0.36 also copies the source licence into subdirectory packages (microsoft/apm#3646). The copied LICENSE is recorded in `deployed_files` and `deployed_file_hashes` like any other deployed file, so the updater handles it without change. The checksums come from the release's `.sha256` files and match both downloaded archives.

Description
feat(install): carry the source licence with subdirectory packages
TL;DR. A dependency installed from a repository subdirectory now brings the repository's nearest
LICENSE/LICENSE.*/COPYING/NOTICE, byte-for-byte, intoapm_modulesand next to every deployed skill that has none. Whole-repo skills below the root get the root licence too. Each copy is recorded inapm.lock.yamlundercarried_licenses. Uninstall removes the copies andapm auditreports a missing or edited one. APM never reads or interprets the file.Problem (WHY)
path:dependency materializes only its subdirectory, so the repository-root licence never reachesapm_modules, the deployed skill, or the lockfile (repro in [FEATURE] Carry the source licence with packages installed from a repository subdirectory #3556:mattpocock/skills,skills/productivity/grilling).skills/<name>/.content_hash. Every existing lockfile would then hit the hard "supply-chain attack" mismatch, and older clients would reject new lockfiles.Approach (WHAT)
LICENSE,LICENSE.*,COPYING,NOTICE(case-insensitive, that precedence) from the package path up to the repo root; regular files only, symlinks never followedapm_modules(subdirectory packages), plus everySKILL.mddirectory lacking a licence; the existing skill copy then deploys itcarried_licenses: [{path, source, hash}]per entry; omitted when emptycontent_hashusing exclusions from the download result or lock entry only (never from disk), and verified against their ownhashdeployed_files+ ledger rows, so existing uninstall,deployed-files-present, andcontent-integritycover themImplementation (HOW)
deps/carried_license.py(new)CarriedLicenserecord, lock (de)serialization with strict validation,verify_locked_packageutils/content_hash.pycompute_package_hash/verify_package_hashtakeexclude=deps/github_downloader.py,deps/artifactory_orchestrator.pyPackageInfo.carried_licensesintegration/skill_adoption.pyLICENSE.mddeploys byte-identical and non-UTF-8 licences cannot crash installinstall/phases/resolve.py,install/sources.py,install/source_helpers.pyctx.package_carried_licenses; hash with exclusions; fail closed when fresh copies differ from the lock recordinstall/phases/integrate.py,install/phases/_redownload.py,install/native_plugin_admission.py,install/legacy_plugin_compat.pydeps/lockfile.py,install/phases/lockfile.py,install/context.py,models/apm_package.pycarried_licensesfield, attach step, ctx map,PackageInfofieldscripts/architecture_linter/.../marketplace_package_and_registration.pyverify_locked_package(candidate, expected_hash, carried)(which callsverify_package_hash)consumer/manage-dependencies.md,reference/lockfile-spec.md,packages/apm-guide/.../dependencies.mdDiagram
Legend: where the licence comes from and how each later step treats the copy (new behaviour boxed in green).
flowchart LR R["repo @ locked commit<br/>LICENSE at root"] -->|"sparse clone / archive"| D["downloader"] D --> C["carry_licenses()"] C -->|"verbatim copy"| M["apm_modules/.../grilling/LICENSE"] C -->|"records"| L["apm.lock.yaml<br/>carried_licenses"] M -->|"normal skill copy"| S[".agents/skills/grilling/LICENSE"] S --> A["apm audit<br/>deployed-files + content-integrity"] S --> U["apm uninstall removes it"] M -.->|"excluded from content_hash"| H["content_hash unchanged"] classDef new fill:#e6ffed,stroke:#2da44e class C,M,L,S newTrade-offs
content_hash. Including them is simpler but breaks every existing lockfile and makes new lockfiles fail on older clients. Excluding them, with a separate per-copy hash checked fail-closed, keeps both directions compatible.apm_modulesreuses that machinery unchanged. The cost: unselected skills in the cache also get a copy (harmless; not deployed).LICENSEandNOTICEcarriesLICENSEonly. Carrying ApacheNOTICEalongside would be a follow-up.apm_modules/to force it. Otherwise every licence-less subdirectory package would re-download on each install.LICENSE.md. Licence text should travel verbatim, and rendering would crash on non-UTF-8 bytes. A non-UTF-8LICENSE.mdstill audits as "incomplete coverage" under the existing hidden-Unicode scanner policy for any non-UTF-8 Markdown.hashuses the existing line-ending-normalizedcompute_file_hash, matchingdeployed_file_hashes, so lockfiles stay portable acrossautocrlfcheckouts. The copy itself is byte-for-byte.Benefits
LICENSEbyte-identical inapm_modulesand in.agents/skills/grilling/.content_hashkeeps its legacy value, asserted in the e2e test).apm install/apm auditclosed.Issue and approved scope
Issue: Fixes #3556
Human scope-approval comment: #3556 (comment) (Daniel Meppiel (@danielmeppiel),
apm-scope:v1,Decision: approve).Completes the issue per the record's Done when. Out of scope honoured: no SPDX detection, no licence policy, no aggregated notices file, no lock export format change.
Overlap: touches the same install/materialization area as #3602 (GitCache sparse retry), #3612 (subdirectory orphans) and #3640 (cache remote), but no shared hunks;
download_subdirectory_packagegains one call after the copy loop.Note
Local preflight skipped by maintainer instruction (2026-11-12); CI is the gate.
Type of change
Testing
Scenario evidence
apm_modulesand next to the deployed skill, recorded in the locktests/integration/test_carried_license_lifecycle.py::test_licence_is_carried_recorded_audited_and_uninstalledalpha/betaassertions);tests/unit/deps/test_carried_license.pycontent_hashunchangedcompute_package_hashassertions);test_carried_copies_keep_the_legacy_package_content_hashtest_symlinked_license_is_never_followed,test_untrusted_lock_data_is_droppedtests/unit/deps/test_artifactory_orchestrator.py(test_archive_root_licence_is_carried_into_subdirectory_package,test_whole_repo_download_carries_root_licence_next_to_skills)content_hash;LICENSE.mdwith a link deploys byte-identical_pre_feature_hashon the plugin,LICENSE.mdbytes)tests/unit/install/test_carried_license_install.pyMutation-break: removing any of these fails a test:
integrate.py_should_skip_redownloadensure_carried_licenses_matchCommands and results
How to test
APM_BINARY_PATH=.venv/bin/apm uv run --extra dev pytest -p no:xdist tests/integration/test_carried_license_lifecycle.pyapm.yml, thencmp .agents/skills/grilling/LICENSE <(curl -s https://raw.githubusercontent.com/mattpocock/skills/4ae2317ddb22b046e26455e4f9c9b3aaaf62212d/LICENSE)carried_licensesunder thegrillingentry inapm.lock.yaml; edit.agents/skills/grilling/LICENSEand runapm audit --ci:content-integrityfailsapm uninstall mattpocock/skills/skills/productivity/grillingremoves the deployed copySpec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regeneratedlockfile-v0.1.schema.json(additionalProperties: true) and preserved by older readers. Mode B waived with anapm-spec-waiver:commit trailer; a normative fold can follow via a spec-guardian pass.Co-authored-by: Copilot [email protected]