Skip to content

fix(marketplace): explicit refresh revalidates catalogs or fails (#3279) - #3910

Merged
Daniel Meppiel (danielmeppiel) merged 11 commits into
mainfrom
danielmeppiel-marketplace-refresh-cli-version-gate
Nov 19, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 11 commits into
mainfrom
danielmeppiel-marketplace-refresh-cli-version-gate

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Description

apm install --refresh and apm update resolved marketplace plugins from a catalog cache up to 1 h old, and apm marketplace update cleared the last valid cache before fetching and printed success even when catalogs failed. A publisher's fix was not visible when a consumer explicitly asked for it.

Now:

  • Explicit freshness revalidates or fails. apm install --refresh, apm install --update and apm update revalidate each catalog they actually resolve. They send a conditional request (If-None-Match/If-Modified-Since, so 304 is cheap) and make one request per source per invocation, however many plugins come from that source. If a catalog is unreachable or invalid, the command fails with Could not verify that marketplace '<name>' is current ... nothing was changed. It does not fall back to stale data, and it does not report the plugin as removed.
  • Ordinary installs are unchanged. A plain apm install still uses the TTL cache, and browse/view keep their stale fallback. Frozen replay gets no live-catalog requirement. Local catalogs are still read locally.
  • The last valid cache is kept. A response is validated before it replaces the cache, so an invalid body never overwrites a good one.
  • apm marketplace update [NAME] revalidates through the same owner instead of clearing the cache first. On a partial batch it names every failed catalog and exits 1. Catalogs that did refresh stay refreshed.
  • Selected updates work for catalog declarations. Before this change, apm update foo@acme quietly said everything was current even after foo was re-pinned. The resolver now carries the selection through to the Git coordinate the declaration resolves to.

Canonical owners:

  • marketplace/client.py owns revalidation (fetch_marketplace(require_fresh=True)) and the per-invocation answer (catalog_freshness_scope / fetch_or_cache). Shadow detection reads catalogs in advisory mode, so a refresh never revalidates unrelated catalogs.
  • InstallService.catalog_freshness maps command intent through the existing RefFreshnessPolicy.for_install_intent. The install and update commands enter it once.

Static guard: marketplace-integrations-catalog-freshness, with an owner record and a mutation case.

Positional apm install plugin@marketplace saves a Git dependency, so later apm update runs do not follow the catalog. That matches the boundary in the scope; durable catalog-following is #2903.

izidormaklary offered to implement this in October and no PR followed. Daniel Meppiel (@danielmeppiel) asked for it to land in 0.37, so it is delivered here. Thanks for the precise report.

Issue and approved scope

Issue: Fixes #3279

Human scope-approval comment: #3279 (comment) (apm-scope:v1 by Daniel Meppiel (@danielmeppiel), 2026-10-20). Delivery for 0.37 was re-confirmed by Daniel Meppiel (@danielmeppiel) via the issue-triage coordinator.

This PR completes the bounded scope. Out-of-scope items (configurable TTL, new flags, always-online default install, #2903) are not touched.

Type of change

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

Testing

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

I reproduced the bug first with the real CLI on main (0.36.1 fec774d). I removed foo from a hosted catalog, and apm install --refresh foo@acme still succeeded with 0 catalog requests.

tests/integration/test_marketplace_explicit_refresh_lifecycle.py (installed CLI, loopback HTTPS with a private CA, url catalogs, plugins in a local Git repo) covers:

  • a fresh-but-outdated cache is bypassed and a removed entry is rejected
  • one request per source when several plugins are selected
  • a re-pinned entry is picked up by apm update through the object-form route, selected apm update foo@acme changes only foo, and a 304 follows
  • unavailable and invalid responses fail --refresh (positional and object routes) and apm update, leaving the manifest, lockfile, deployed files and cache byte-identical, while ordinary install still works
  • frozen replay makes 0 requests during an outage
  • named and all-catalog marketplace update, including 304, partial failure with exit 1, retained cache, and browse fallback

With src/ reverted, 4 of the 6 lifecycle cases fail; the frozen-preservation case passes by design, and the selection case had been dropped when that check ran. It was then re-added and failed until the resolver fix.

Command Result
APM_E2E_TESTS=1 APM_BINARY_PATH=.venv/bin/apm pytest tests/integration/test_marketplace_explicit_refresh_lifecycle.py tests/unit/marketplace/{test_marketplace_client,test_marketplace_commands_phase3,test_marketplace_commands_surface,test_marketplace_resolver}.py tests/integration/test_marketplace_{catalog_path,update_provenance}_lifecycle.py (after merging main) 401 passed
pytest tests/unit/marketplace tests/unit/install tests/unit/commands tests/unit/deps tests/unit/test_outdated_marketplace*.py 8904 passed. 4 shell-installer timeouts in test_unix_install_ownership.py/test_install_safety.py happened under host load average 68 and pass in isolation
pytest tests/unit/scripts/test_architecture_runner.py and tests/integration/test_architecture_{owner,semantic}_rule_mutations.py (new guard cases) passed
pytest tests/quality; check_test_assertions.py; check_exact_test_duplicates.py 206 passed; clean; clean
uvx [email protected] check and format --check on the CI paths clean
pylint R0801, bash scripts/lint-auth-signals.sh, bash scripts/lint-architecture-boundaries.sh clean

Changelog

  • One line under ## [Unreleased] in CHANGELOG.md: user-visible
    effect first, 25 words or fewer, ending with (#PR); see
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour. Catalog cache freshness is CLI-local; there is no manifest, lockfile or wire change. A waiver is recorded in a commit message.

apm install --refresh, apm update and apm marketplace update now revalidate
each needed marketplace catalog once per invocation and fail closed instead
of serving a still-in-TTL or stale cached catalog. Invalid responses never
replace the last valid cache; marketplace update reports partial failures
and exits nonzero. Selected 'apm update plugin@marketplace' now re-checks
the package the declaration resolves to.

Co-authored-by: Copilot App <[email protected]>
…nielmeppiel-marketplace-refresh-cli-version-gate
Co-authored-by: Copilot App <[email protected]>
apm-spec-waiver: CLI-local marketplace catalog cache freshness and update selection; no OpenAPM manifest, lockfile or wire contract change (#3279)

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 09:23

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.

🟡 Changes recommended

Required-refresh handling still allows partial installs to succeed during catalog outages and malformed catalog data to overwrite valid caches.

3 open issues
What changed in this PR

This PR addresses #3279 by connecting explicit install and update intent to marketplace catalog revalidation, while retaining cached reads for ordinary installs. Durable marketplace identity remains outside scope under #2903.

Changes:

  • Adds invocation-scoped catalog freshness handling and cache-preserving refresh failures.
  • Carries selected marketplace dependencies through to resolved Git coordinates and reports partial marketplace-update failures.
  • Adds lifecycle tests, architecture guards, and documentation for the refresh behavior.
File Description
tests/​unit/​scripts/​test_architecture_runner.py Registers the freshness guard in the expected inventory.
tests/​unit/​marketplace/​test_marketplace_commands_surface.py Expects nonzero exit on partial refresh failure.
tests/​unit/​marketplace/​test_marketplace_commands_phase3.py Checks partial-failure output and exit status.
tests/​unit/​marketplace/​test_marketplace_client.py Tests strict refresh, retained caches, and shared answers.
tests/​integration/​test_marketplace_explicit_refresh_lifecycle.py Adds installed-CLI catalog refresh scenarios.
tests/​integration/​test_architecture_owner_rule_mutations.py Adds a freshness-guard mutation case.
src/​apm_cli/​marketplace/​shadow_detector.py Marks shadow lookups as advisory.
src/​apm_cli/​marketplace/​errors.py Introduces a catalog freshness error.
src/​apm_cli/​marketplace/​client.py Implements strict refresh and invocation-scoped results.
src/​apm_cli/​install/​service.py Maps install intent to catalog freshness policy.
src/​apm_cli/​install/​phases/​resolve.py Transfers resolved marketplace selection keys.
src/​apm_cli/​deps/​apm_resolver.py Tracks Git coordinates selected through catalogs.
src/​apm_cli/​commands/​update.py Wraps dependency updates in a freshness scope.
src/​apm_cli/​commands/​marketplace/​__init__.py Revalidates without clearing caches and reports failures.
src/​apm_cli/​commands/​install.py Opens the install catalog freshness scope.
scripts/​architecture_linter/​checks/​marketplace_integration_analyzers.py Includes the new freshness rule.
scripts/​architecture_linter/​checks/​marketplace_catalog_freshness.py Guards canonical freshness routing.
packages/​apm-guide/​.apm/​skills/​apm-usage/​commands.md Updates command guidance for catalog refresh.
docs/​src/​content/​docs/​reference/​cli/​update.md Documents catalog revalidation and selection syntax.
docs/​src/​content/​docs/​reference/​cli/​marketplace.md Describes cache retention and partial failures.
docs/​src/​content/​docs/​reference/​cli/​install.md Expands the documented --refresh behavior.
docs/​src/​content/​docs/​consumer/​update-and-refresh.mdx Explains explicit marketplace refresh behavior.
docs/​src/​content/​docs/​consumer/​manage-dependencies.md Updates the catalog dependency refresh workflow.
CHANGELOG.md Records the user-visible freshness change.
.apm/​architecture/​owners/​marketplace-plugins.json Registers catalog freshness ownership and its guard.

Review effort: Balanced

Comment thread src/apm_cli/commands/install.py Resolved
Comment thread src/apm_cli/marketplace/client.py Resolved
Comment thread src/apm_cli/marketplace/client.py Resolved
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 19, 2026
…nrelated catalogs

Addresses the three Copilot inline threads on #3910:
- install.py: an unverifiable catalog in a mixed positional batch now fails
  the whole command instead of installing the healthy packages.
- client.py: an explicit refresh rejects catalogs with structural errors so a
  malformed response cannot replace the last valid cache; ordinary and add
  parsing stay tolerant; local catalogs stay ordinary reads.
- client.py: during a required-freshness scope, advisory (shadow-detection)
  reads use only cached data, keeping one request per needed source.

Co-authored-by: Copilot <[email protected]>
…pinned advisory contract

Addresses lean-panel follow-ups on #3910:
- python-architect: MarketplaceFreshnessError routes through the base
  __init__ with a command-neutral retry hint; one _manifest_from_cache helper
  owns cache-to-manifest projection for fresh, stale and advisory reads; an
  explicit MarketplaceNotCachedError pins the advisory contract under
  required scopes (unit-tested per mode).
- test-coverage-expert: lifecycle now exercises install --frozen --refresh
  during an outage (mutation-proven against the frozen guard) and proves a
  local catalog stays a local read under --refresh.

Co-authored-by: Copilot <[email protected]>
…nielmeppiel-marketplace-refresh-cli-version-gate

# Conflicts:
#	scripts/architecture_linter/checks/marketplace_integration_analyzers.py
Addresses the apm-ceo follow-up on #3910: when an explicit refresh leaves
uncached (for example generic-git) catalogs out of shadow detection, the
resolver now warns which catalogs were not checked instead of narrowing the
supply-chain signal silently.

Co-authored-by: Copilot <[email protected]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_with_followups

--refresh now revalidates the marketplace catalogs it needs, or fails clearly, so it can no longer hand back stale cached data. Ordinary cached installs, browse fallback, frozen replay and local catalogs are unchanged.

panel-mode=lean; personas=python-architect,test-coverage-expert,apm-ceo

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

This PR delivers the #3279 apm-scope:v1 contract and puts freshness in one place. marketplace/client.py owns require_fresh, catalog_freshness_scope and fetch_or_cache. InstallService.catalog_freshness maps the user's intent through the existing RefFreshnessPolicy, and the marketplace-integrations-catalog-freshness static guard keeps it that way. Both panelists agree: the ownership is centralized and scoped once per command, and installed-CLI scenario tests cover the Done-when list.

Every finding is folded with test evidence:

  • The frozen guard is exercised by install --frozen --refresh during an outage, and removing the guard makes that test fail.
  • A local catalog stays a local read under --refresh, with zero HTTP requests.
  • MarketplaceFreshnessError gives a hint that fits any command.
  • One _manifest_from_cache projection replaces three copies.
  • The advisory behaviour per scope mode is pinned by a test.

The three Copilot threads (mixed positional batch, malformed entries overwriting the cache, advisory reads spending requests) were real bugs. Each was folded with a regression trap that fails when its fix is removed.

The one deliberate trade-off: during --refresh, shadow detection checks only catalogs that are already cached, because it must not spend requests on catalogs the command does not need. That residual follow-up is now folded too. The resolver warns which catalogs it did not check instead of narrowing the signal silently.

Aligned with: Portable by manifest: frozen replay and local catalogs are untouched and pinned by installed-CLI tests. Secure by default: an explicit refresh fails closed, and malformed entries cannot overwrite the last valid cache. Governed by policy: freshness intent flows through RefFreshnessPolicy and is enforced by a static guard. Pragmatic as npm: a refresh either refreshes or says it could not, with one request per source and a nonzero exit on partial failure.

Panel summary

Persona B R N Takeaway
Python Architect 0 3 0 Freshness ownership is correctly centralized in client.py, scoped once per command, and reuses RefFreshnessPolicy; three cohesion and fidelity gaps worth folding.
Test Coverage Expert 0 2 0 Real-binary scenario tests cover most of #3279; frozen+refresh and local catalogs needed regression-catching tests.

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Top 1 follow-ups

  1. [Python Architect] Track the shadow-detection coverage trade-off during explicit refresh. -- Shadowing between catalogs is a supply-chain signal, so narrowing it must be visible. Folded in a663b1d: the resolver now warns which uncached catalogs were not checked, and test_uncached_catalogs_skipped_during_explicit_refresh_are_reported pins this.

Recommendation

Ready for maintainer merge once CI is green on a663b1d. All panel and Copilot findings are folded with mutation-proven or installed-CLI regression tests. The CI-mirror lint chain and the architecture lint are clean after merging current main, and CHANGELOG has the user-visible line.


Full per-persona findings

Python Architect

  • [recommended] MarketplaceFreshnessError hardcodes install-only remediation and skips the base init at src/apm_cli/marketplace/errors.py
    The remediation named apm install --refresh even when raised from apm update or apm marketplace update, and the class bypassed MarketplaceFetchError.__init__. Folded: base init plus a command-neutral hint.
  • [recommended] Cache-to-manifest decision written out three times at src/apm_cli/marketplace/client.py
    Split-authority risk for digest/provenance handling. Folded: _manifest_from_cache owns it.
  • [recommended] Advisory shadow detection silently goes blind for git-kind and uncached catalogs during explicit refresh at src/apm_cli/marketplace/client.py
    The advisory contract changed by mode without a written contract. Folded: MarketplaceNotCachedError, a per-mode unit test, and a user-visible skipped-catalog warning.

Test Coverage Expert

  • [recommended] Frozen-replay lifecycle test could not catch removal of the and not frozen guard at tests/integration/test_marketplace_explicit_refresh_lifecycle.py
    Folded: object-form seed plus install --frozen --refresh during an outage; mutation-proven.
    Proof (passed): tests/integration/test_marketplace_explicit_refresh_lifecycle.py::test_frozen_replay_needs_no_live_catalog -- proves: a locked CI replay never needs a live marketplace, even with --refresh.
  • [recommended] No explicit-refresh test against a local catalog at src/apm_cli/marketplace/client.py
    Folded: installed-CLI test asserting a local read, zero HTTP requests, and a not-found result for a removed entry.
    Proof (passed): tests/integration/test_marketplace_explicit_refresh_lifecycle.py::test_local_catalog_stays_a_local_read_under_refresh -- proves: --refresh against a local catalog still installs from the local file.

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.

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit d604dbb into main Nov 19, 2026
34 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-marketplace-refresh-cli-version-gate branch November 19, 2026 11:31
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 19, 2026
Skip the version-range tag lookup for a resolution admission will refuse,
so no request reaches the ambiguous package remote. Move
DependencyConfusionError into marketplace/errors.py and name it in the
resolver's except tuple. Harden the static guard against nested defs,
getattr reads, aliased imports and direct resolve_plugin_source calls.
Serve the enterprise catalog from an SSH-registered Git fixture so
apm update revalidates offline (#3910) and reaches admission; add a
version-range case, a host-qualified positive control and unit traps.
Narrow docs to type: github sources and fix the producer example.

Addresses panel follow-ups (python-architect, test-coverage-expert,
supply-chain-security-expert, doc-writer) on #3923.

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 19, 2026
… install path (#3923)

* fix(marketplace): apply the #1326 dependency-confusion check on every install path

Route apm install NAME@MARKETPLACE, apm.yml marketplace entries, transitive
marketplace dependencies and apm update through one admission owner,
marketplace/dependency_confusion.py admit_marketplace_resolution, before any
fetch or write. A new architecture guard rejects resolver calls that skip it.

Closes #3913

Co-authored-by: Copilot App <[email protected]>

* docs(changelog): record #3913 dependency-confusion fix

Co-authored-by: Copilot App <[email protected]>

* fix(marketplace): fold panel review into the #1326 admission

Skip the version-range tag lookup for a resolution admission will refuse,
so no request reaches the ambiguous package remote. Move
DependencyConfusionError into marketplace/errors.py and name it in the
resolver's except tuple. Harden the static guard against nested defs,
getattr reads, aliased imports and direct resolve_plugin_source calls.
Serve the enterprise catalog from an SSH-registered Git fixture so
apm update revalidates offline (#3910) and reaches admission; add a
version-range case, a host-qualified positive control and unit traps.
Narrow docs to type: github sources and fix the producer example.

Addresses panel follow-ups (python-architect, test-coverage-expert,
supply-chain-security-expert, doc-writer) on #3923.

Co-authored-by: Copilot App <[email protected]>

* test(marketplace): prove apm update re-admits ambiguous locked entries

Plain installs replay lock rows without the catalog (#3911), so apm update
is the remediation for entries an older APM locked; a lifecycle case locks
a host-qualified entry, flips the catalog to the bare form, and asserts
apm update refuses without touching the lock. Document the remediation.

Addresses CEO follow-up on #3923.

Co-authored-by: Copilot App <[email protected]>

---------

Co-authored-by: danielmeppiel <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
- 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]>
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.

[FEATURE]: apm install resolves marketplace plugins from a cache up to 1h old; --refresh doesn't bypass it

2 participants