Repository navigation
fix(marketplace): pin plugins to a source sha - #3534
Daniel Meppiel (danielmeppiel) merged 8 commits into
Conversation
github, url and git-subdir sources can pin a commit with sha, but only ref was read, so the entry resolved the default branch and was written unpinned. sha now wins over ref, as it does in Claude Code.
…d to end A declared sha must be a full 40-character commit, so a typo fails before apm.yml, the lockfile or any deployed file is written. Installed-CLI tests cover sha-only, ref-plus-sha and ref-only entries for github, url and git-subdir sources, malformed shas, and an apm pack copilot catalog that carries the commit only as sha.
99de0f4 to
a0f49a4
Compare
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the change to preserve marketplace commit pins during dependency resolution.
No open issues 🎉
What changed in this PR
Fixes #3426 by preserving marketplace source commit pins during dependency resolution, so installation uses the declared commit rather than the default branch.
Changes:
- Gives valid full-length
shapins precedence overrefacross GitHub, URL, git-subdir, and packed sources. - Rejects malformed SHAs while preserving empty-SHA fallback and ref-only behavior.
- Adds unit and local-repository integration coverage, including an
apm packround trip.
| File | Description |
|---|---|
tests/unit/marketplace/test_marketplace_resolver.py |
Tests SHA selection, validation, packed sources, and fallback behavior. |
tests/integration/test_marketplace_sha_pin_install.py |
Verifies pinned deployments, unchanged projects on invalid input, and pack/install compatibility. |
src/apm_cli/marketplace/resolver.py |
Centralizes SHA validation and precedence across source-resolution paths. |
CHANGELOG.md |
Documents the marketplace commit-pinning fix. |
Review effort: Balanced
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Supply Chain Security Expert | 0 | 0 | 0 | Sha-pin implementation is sound: strict 40-hex validation, type-guarded untrusted catalog input, fail-before-write on malformed sha, all resolver paths covered. Ship. |
| Test Coverage Expert | 0 | 1 | 0 | Six sha-install scenarios plus malformed-sha rejection are covered at e2e tier; _extract_in_repo_path_and_ref sha path has no test at any tier. |
| Doc Writer | 0 | 3 | 0 | The CHANGELOG entry follows the conventions. Three marketplace pages still say install keeps the catalog ref; each needs one sentence saying a declared full sha wins. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 4 follow-ups
- [Test Coverage Expert] Add sha-only and sha-over-ref unit cases to TestExtractInRepoPathAndRef asserting ref == SHA. -- Reverting resolver.py L461 would silently regress SHA pinning on in-marketplace plugins with no failing test. In-scope fold.
- [Doc Writer] Update packages/apm-guide/.apm/skills/apm-usage/dependencies.md (~L356) to note that a full 40-char sha wins over ref. -- The guide says url/git-subdir sources keep their ref; after this PR it contradicts what apm.yml shows. In-scope fold.
- [Doc Writer] Update docs/src/content/docs/producer/publish-to-a-marketplace.md (~L154) to note consumers record source.sha when present. -- The producer guide promises consumers receive the generated ref, which is now stale for sha-pinned entries. In-scope fold.
- [Doc Writer] Update docs/src/content/docs/consumer/installing-from-marketplaces.md (~L190) to list sha precedence and malformed-sha failure. -- The consumer guide lists ref among preserved fields and omits malformed sha from its fail-before-write list. In-scope fold.
Recommendation
The security surface is clean (zero supply-chain findings) and the e2e test matrix covers the sha-install and malformed-sha scenarios mandated by the accepted scope. Fold the missing _extract_in_repo_path_and_ref unit test and the three doc-page corrections into this PR before merge; all four are squarely in scope. No rework needed on the production code.
Full per-persona findings
Supply Chain Security Expert
No findings.
Test Coverage Expert
- [recommended] _extract_in_repo_path_and_ref changed to use _source_pin but no test at any tier exercises sha through this path. at
tests/unit/marketplace/test_marketplace_resolver.py
The diff (resolver.py L461) routes in-marketplace github/git-subdir/gitlab sources through _source_pin, but TestExtractInRepoPathAndRef::test_dict_with_ref only passes ref; grep found no sha case.
Suggested: Add sha-only and sha-over-ref cases to TestExtractInRepoPathAndRef asserting ref == SHA.
Proof (missing at):tests/unit/marketplace/test_marketplace_resolver.py::TestExtractInRepoPathAndRef::test_dict_source_sha_wins_over_ref-- proves: When an in-marketplace plugin source declares a sha, sha wins over ref in path-and-ref extraction. [secure-by-default,portability-by-manifest]
Doc Writer
- [recommended] The apm-usage guide says url/git-subdir sources keep their ref in apm.yml and the lockfile, but a declared full sha now replaces it at
packages/apm-guide/.apm/skills/apm-usage/dependencies.md:356
Repo rule: update packages/apm-guide/.apm/skills/apm-usage/ when dependency resolution changes. - [recommended] The producer guide says install 'preserves the generated path and ref', but install now pins to source.sha when it is present at
docs/src/content/docs/producer/publish-to-a-marketplace.md:154
apm pack emits a tag ref plus a peeled sha; consumers now record the sha. - [recommended] The consumer guide lists ref among the identity fields APM preserves and omits malformed sha from its fail-before-write list at
docs/src/content/docs/consumer/installing-from-marketplaces.md:190
Consumers checking why apm.yml shows a commit instead of a tag will find these sentences contradict what they see.
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.
Merging main after the 0.35.1 cut left the entry in a second Fixed section of the released 0.35.1 block. Keep one release block per version and list the fix under [Unreleased]. Co-authored-by: Copilot App <[email protected]>
_extract_in_repo_path_and_ref now reads the pin through _source_pin, but no test exercised a sha there, so reverting it would silently drop sha pins for in-marketplace github, git-subdir and gitlab plugins. Mutation-break checked: reverting the call fails all 7 new cases. Addresses panel follow-up FU-1 (test-coverage-expert). Co-authored-by: Copilot App <[email protected]>
The consumer and producer marketplace pages and the apm-usage dependencies guide still said install keeps the catalog ref. A full 40-character sha on github, url or git-subdir sources now wins, is written to apm.yml and the lockfile, and a malformed sha fails before writes. Addresses panel follow-ups FU-2..FU-4 (doc-writer). Co-authored-by: Copilot App <[email protected]>
The module fixture took apm_binary_path and returned a runner built from it, which the AC9 executable-contract guard in scripts/lint-architecture-boundaries.sh rejects as a local binary facade, failing the CI Lint job. Build only the hermetic repositories in the module fixture and give each test the injected binary. Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Test Coverage Expert | 0 | 0 | 0 | FU-1 resolved: 7 unit cases now exercise sha through _extract_in_repo_path_and_ref; fixture refactor preserves all 16 integration assertions. |
| Doc Writer | 0 | 0 | 0 | FU-2..4 are resolved: all three pages say a full source sha wins over ref. The #3534 entry is in the [Unreleased] Fixed block at head 8ff11e0. Ship. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Recommendation
All four in-scope follow-ups from the prior advisory are resolved with zero new findings. The sha-pin surface is covered end to end (unit, real-CLI integration, SSH marketplace install), the three doc pages match the new behavior, and CI is fully green. No remaining action items.
Folded in this run
- (panel) FU-1: sha-only, sha-over-ref and malformed-sha unit cases for
_extract_in_repo_path_and_ref(github, git-subdir, gitlab) -- resolved in 8053411. - (panel) FU-2..FU-4: apm-usage
dependencies.md, producerpublish-to-a-marketplace.mdand consumerinstalling-from-marketplaces.mdsay a full sourceshawins overrefand a malformedshafails before writes -- resolved in 1ab9024. - (panel) Lint on touched file: AC9 boundary lint rejected the sha-pin module fixture as an apm binary facade; tests now inject
apm_binary_path-- resolved in 8583097. - (panel) CHANGELOG entry moved from the released 0.35.1 block back under [Unreleased] -- resolved in 13297b6.
Copilot signals reviewed
- Overview review 5846460812 -- NOT-LEGIT (nothing to fold): "no open issues", zero inline comments; round 2 after push produced no new items.
Regression-trap evidence (mutation-break gate)
TestSourceShaPin::test_in_marketplace_source_uses_sha/test_in_marketplace_source_rejects_malformed_sha-- deletedref_val = _source_pin(src)in_extract_in_repo_path_and_ref; 7 tests FAILED as expected; guard restored.
Lint contract
ruff check, ruff format --check, pylint R0801, lint-auth-signals.sh and lint-architecture-boundaries.sh all silent at 8ff11e0.
CI
gh pr checks 3534 at 8ff11e0: 24 pass, 3 skipping, 0 fail (after 0 CI fix iteration(s)). license/cla: pass.
Mergeability status
| PR | head SHA | CEO stance | iters | folds | defers | Copilot rounds | CI | mergeable | mergeStateStatus | notes |
|---|---|---|---|---|---|---|---|---|---|---|
| #3534 | 8ff11e0 |
ship_now | 2 | 6 | 0 | 2 | green | MERGEABLE | BLOCKED | pending required review |
Convergence
2 outer iteration(s); 2 Copilot round(s). Final panel stance: ship_now. Ready for maintainer review.
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-merge-worker. This comment is AI-generated and may contain errors.
f88fe4e
into
microsoft:main
Resolves the conflicting state after microsoft#2506 and microsoft#3534 landed on main. Co-authored-by: Copilot App <[email protected]>
Description
A marketplace plugin whose
github,urlorgit-subdirsource declares ashawas installed unpinned. The resolver only readref, soapm installresolved the default branch, warned1 dependency unpinned, wrote theapm.ymlentry with noref, and the nextapm updatemoved it. Catalogs built byapm packhit this too: the copilot output carries a raw commit pin only assha.The resolver now reads
shafor all three source types and for packed sources, andshawins overref, as the Claude Code and Copilot CLI marketplace references define. A declaredshamust be a full 40 character commit; anything else raises beforeapm.yml, the lockfile or any deployed file is written. An emptyshafalls back toref, and ref-only entries are unchanged.Issue and approved scope
Issue: #3426
Human scope-approval comment: #3426 (comment)
This PR completes the approved scope. The out of scope items listed there (#2903, #3458, #3048, catalog freshness, new source types) are not touched.
Fixes #3426
Type of change
Testing
tests/integration/test_marketplace_sha_pin_install.pyruns the real CLI against local bare repositories (no network). Each package repo has an older pinned commit with skill bodyv1and a newer branch head withv2, so a pin is observable in the deployed file.test_sha_bearing_entry_installs_pinned_commit: sha-only and ref-plus-sha entries for github, url and git-subdir (6 cases). Each checks exit 0, no unpinned warning, theapm.ymlentry pinned to the sha,resolved_commitequal to the sha, and thev1skill deployed.test_ref_only_entry_still_resolves_branch_head: ref-only entries for the three shapes still resolve the branch head (3 cases, pass on main too).test_malformed_sha_fails_before_project_writes: a short sha and a 40 character non hex value for each shape (6 cases). Install fails, mentions the sha, and the project snapshot taken aftermarketplace addis unchanged, with no lockfile.test_pack_copilot_commit_pin_round_trips_through_install:apm packwith the copilot output emits the commit asshawith noref, and installing from that catalog deploys the pinned commit.The 13 sha and pack cases fail with
resolver.pyfrom main and pass here. Unit tests intests/unit/marketplace/test_marketplace_resolver.pycover each source type, sha over ref, packed sources, malformed shas and the empty sha fallback.One note on the github shape: a
githubsource always targets github.com, and install validation would call the real API, so the test setsGITHUB_HOSTto the local fake host for those cases. That shape therefore runs through the GHES style path rather than github.com itself.Verification:
tests/unit/marketplace1788 passed; the new integration file plustest_marketplace_producer_consumer_closure.py19 passed;ruff checkandruff format --checkclean on the changed files.Spec conformance (OpenAPM v0.1)