Skip to content

fix(marketplace): pin plugins to a source sha - #3534

Merged
Daniel Meppiel (danielmeppiel) merged 8 commits into
microsoft:mainfrom
abhishekacharya200:fix/marketplace-source-sha
Nov 12, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 8 commits into
microsoft:mainfrom
abhishekacharya200:fix/marketplace-source-sha

Conversation

@abhishekacharya200

Copy link
Copy Markdown
Contributor

Description

A marketplace plugin whose github, url or git-subdir source declares a sha was installed unpinned. The resolver only read ref, so apm install resolved the default branch, warned 1 dependency unpinned, wrote the apm.yml entry with no ref, and the next apm update moved it. Catalogs built by apm pack hit this too: the copilot output carries a raw commit pin only as sha.

The resolver now reads sha for all three source types and for packed sources, and sha wins over ref, as the Claude Code and Copilot CLI marketplace references define. A declared sha must be a full 40 character commit; anything else raises before apm.yml, the lockfile or any deployed file is written. An empty sha falls back to ref, 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

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

tests/integration/test_marketplace_sha_pin_install.py runs the real CLI against local bare repositories (no network). Each package repo has an older pinned commit with skill body v1 and a newer branch head with v2, 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, the apm.yml entry pinned to the sha, resolved_commit equal to the sha, and the v1 skill 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 after marketplace add is unchanged, with no lockfile.
  • test_pack_copilot_commit_pin_round_trips_through_install: apm pack with the copilot output emits the commit as sha with no ref, and installing from that catalog deploys the pinned commit.

The 13 sha and pack cases fail with resolver.py from main and pass here. Unit tests in tests/unit/marketplace/test_marketplace_resolver.py cover each source type, sha over ref, packed sources, malformed shas and the empty sha fallback.

One note on the github shape: a github source always targets github.com, and install validation would call the real API, so the test sets GITHUB_HOST to the local fake host for those cases. That shape therefore runs through the GHES style path rather than github.com itself.

Verification: tests/unit/marketplace 1788 passed; the new integration file plus test_marketplace_producer_consumer_closure.py 19 passed; ruff check and ruff format --check clean on the changed files.

Spec conformance (OpenAPM v0.1)

  • N/A -- this PR does not change OpenAPM-observable behaviour.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 sha pins precedence over ref across 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 pack round 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

@danielmeppiel

Copy link
Copy Markdown
Collaborator

APM Review Panel: ship_with_followups

Community fix pins marketplace plugins to their declared SHA, closing the mutable-ref gap -- panel converges on ship with in-PR folds for one missing unit test and three stale doc pages.

panel-mode=lean; personas=supply-chain-security-expert,test-coverage-expert,doc-writer,apm-ceo

cc Abhishek Acharya (@abhishekacharya200) Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

All three panelists converge: the security surface is sound, the test matrix is thorough at e2e tier, and the CHANGELOG entry follows convention. Supply-chain-security-expert returned zero findings -- strict 40-hex validation, type-guarded untrusted catalog input, and fail-before-write on malformed SHA cover the surface this PR exists to close. That clean pass on a commit-pin integrity change is the strongest signal in the panel.

The one finding that warrants weight is test-coverage-expert's missing unit test on _extract_in_repo_path_and_ref (resolver.py L461). This path routes in-marketplace github/git-subdir/gitlab sources through _source_pin, but TestExtractInRepoPathAndRef only exercises the ref case -- reverting L461 would silently regress SHA pinning on in-marketplace plugins with no failing test. Since the merge worker can fold in-scope tests, this is an in-PR fold, not backlog.

Doc-writer's three findings are straightforward drift: three pages promise consumers receive the catalog ref, but SHA now wins. Each needs one sentence. These are also in-scope folds. No finding from any panelist rises to severity=blocking; the core implementation is clean.

Aligned with: Secure by default -- SHA pinning closes the mutable-ref gap: consumers install the exact commit the catalog declares. Portable by manifest -- the pinned SHA is persisted in apm.yml and lockfile resolved_commit. OSS community driven -- a clean, well-tested community fix for an accepted issue (#3426).

Panel summary

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

  1. [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.
  2. [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.
  3. [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.
  4. [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]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator

APM Review Panel: ship_now

All four in-PR follow-ups folded, AC9 boundary lint fixed, changelog corrected, CI 24/24 green -- delta panel converges on ship.

panel-mode=delta; personas=test-coverage-expert,doc-writer,apm-ceo

cc Abhishek Acharya (@abhishekacharya200) Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

The prior lean advisory surfaced one test-coverage gap (missing sha cases on _extract_in_repo_path_and_ref) and three stale doc pages. This delta confirms all four are resolved. test-coverage-expert reports 7 new unit cases exercising the sha path through _extract_in_repo_path_and_ref; reverting the _source_pin call at resolver L461 breaks all 7 (mutation-break). The 16 integration assertions survive the fixture refactor intact. doc-writer confirms all three pages now state that a full source sha wins over ref. Zero findings from either panelist.

Beyond the four tracked follow-ups, the merge worker fixed an AC9 architecture-boundary lint failure in the new integration test (the module fixture returned a runner built from apm_binary_path; each test now injects the binary) and moved the changelog entry from the released 0.35.1 block back to [Unreleased] after a main merge. supply-chain-security-expert was not re-spawned: resolver.py is unchanged since the prior panel head and that persona returned zero findings.

Aligned with: Secure by default -- 7 new unit cases make the sha-pin guarantee load-bearing against silent regression. Portable by manifest -- the pinned SHA is persisted in apm.yml and lockfile resolved_commit, and consumer, producer and guide pages describe the precedence rule. OSS community driven -- a community fix for an accepted issue, converged with small maintainer-side folds and no rework.

Panel summary

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, producer publish-to-a-marketplace.md and consumer installing-from-marketplaces.md say a full source sha wins over ref and a malformed sha fails 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 -- deleted ref_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.

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit f88fe4e into microsoft:main Nov 12, 2026
27 checks passed
Daniel Meppiel (danielmeppiel) added a commit to Kaustubh1235/apm that referenced this pull request Nov 12, 2026
Resolves the conflicting state after microsoft#2506 and microsoft#3534 landed on main.

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] apm install <plugin>@<marketplace> ignores a github source's sha and writes an unpinned dependency

3 participants