Skip to content

fix(uninstall): remove object-form marketplace entries by plugin@marketplace - #3933

Merged
Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-uninstall-object-form-3928
Nov 19, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
danielmeppiel-uninstall-object-form-3928

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

TL;DR

apm uninstall plugin@marketplace exited 1 ("was not found in apm.yml") for a dependency declared in object form, {name: plugin, marketplace: alias}, even though its lock row existed. It now selects that declaration from apm.yml directly and removes the entry, its lock row, its apm_modules/ checkout and its deployed files. It never contacts the marketplace, and --dry-run behaves the same way. The string form is unchanged.

Fixes #3928

Description

Reproduced on main 09af2b1 with the real CLI, using a hermetic Git catalog company listing example-plugin and apm.yml declaring {name: example-plugin, marketplace: company}:

$ apm install --target codex --no-policy        # ok, lock row discovered_via: company
$ apm uninstall example-plugin@company [--dry-run]
[x] example-plugin@company (gitlab.example.invalid/team/catalog-a/plugins/example-plugin) was not found in apm.yml. ...
[x] Uninstall aborted: 1 requested package(s) could not be selected. ... no changes were made.

Root cause. _resolve_marketplace_packages maps plugin@alias to the concrete lock key. select_manifest_dependency(canonical, ...) then compares that key against the object-form identity _marketplace/<alias>/<plugin>, so it never matches. The removal steps after it also keyed on the manifest identity, so even a selected object-form entry would have left its lock row and checkout behind.

Issue and approved scope

Issue: Fixes #3928

Human scope-approval comment: #3928 (comment) (apm-scope:v1, approver and review contact Daniel Meppiel (@danielmeppiel); eligibility.cjs reports record-present).

Does this PR complete the issue? Yes. Every "Done when" item is covered (see Scenario evidence). It adds no new apm.yml or lockfile fields, does not touch the #2903 marketplaces: map, and makes no other uninstall-selection changes.

Type of change

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

Approach

Concern Owner Change
Which manifest entry plugin@alias names models/dependency/selection.py New select_marketplace_declaration(plugin, alias, deps). It matches object-form entries case-insensitively, as the registry does, and reads only the manifest.
Offline selection commands/uninstall/engine.py _validate_uninstall_packages Refs that name an object-form declaration are selected before, and instead of, lock/registry resolution. The registry fallback and its lock-recorded supply-chain guard stay as they are for every other ref.
What a removed declaration owns engine._removal_target / _removed_lock_key An object-form declaration maps, through LockFile.get_dependency (the existing association owner), to its locked coordinate for the lock row, the apm_modules/ path and the orphan-edge scan. Survivor seeding still uses manifest identity, so #3915's reachability is untouched.
Static guard install-deployment-uninstall-selection New required routes (validator → declaration selection → owner; lock key, disk, dry-run and orphan scan → _removal_target), with three compound mutations.

Trade-offs

  • Selection is declaration-first. When an object-form entry is declared, the lock and the registry are not consulted to choose it. That keeps the command offline and avoids a stale or rebound alias picking another package. String-form behaviour, including the registry guard, is unchanged.
  • The removal-target mapping lives inside the engine, not in cli.py. Passing resolved references through every cli.py call would have broken the survivor subtraction that _read_survivor_direct_refs does by manifest identity.
  • The case-insensitive alias match applies only to the object-form path. It mirrors registry lookup; string-form matching is unchanged, as the scope requires.

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality

Scenario evidence

# Scenario Principle(s) Test Type
1 Uninstalling an object-form marketplace dep by plugin@alias removes the apm.yml entry, lock row, checkout and deployed files with the marketplace unregistered and unreachable DevX, Governed by policy tests/integration/test_uninstall_marketplace_object_form_lifecycle.py::test_uninstall_selects_object_form_marketplace_declaration_offline (fails on main) e2e
2 --dry-run previews the same removal and changes nothing DevX same test (dry-run step: manifest, lock and checkout unchanged) e2e
3 The alias matches case-insensitively DevX same test (@COMPANY); tests/unit/models/test_dependency_uninstall_selection.py::test_marketplace_ref_selects_object_form_declaration_case_insensitively e2e, unit
4 String form unchanged Governed by policy tests/integration/test_uninstall_marketplace.py (unchanged, passes) integration
5 A removed object-form declaration targets its locked coordinate Governed by policy tests/unit/models/test_dependency_uninstall_selection.py::test_object_form_removal_targets_the_locked_coordinate unit
6 The guard catches bypasses of selection and removal-target routing Governed by policy tests/integration/test_architecture_install_compound_mutations.py (uninstall-object-form-*) component
7 Removing one of two declarations of the same package fails closed with nothing changed Secure by default lifecycle test (shared-coordinate step, exit 1, bytes unchanged); test_removing_one_of_two_declarations_of_one_package_fails_closed e2e, unit
8 A recased alias or ambiguous lock rows cannot leave lock rows and files behind Secure by default test_recased_alias_still_targets_the_locked_row, test_ambiguous_lock_rows_for_one_declaration_fail_closed unit
9 The removed plugin's own dependencies are orphan candidates; -g --dry-run uses the scoped lockfile Governed by policy test_object_form_removal_seeds_the_orphan_scan_from_the_locked_plugin, test_dry_run_previews_object_form_checkout_from_the_scoped_lockfile unit

Both lifecycle and unit traps were checked against main or with the guard removed: the lifecycle test fails on main with not found in apm.yml; the recased-alias, ambiguous-rows and dry-run unit tests fail with their fixes reverted.

Validation commands and results (exact head 50dadcb, main d46ce76 merged in)
$ APM_E2E_TESTS=1 APM_BINARY_PATH=.venv/bin/apm pytest tests/unit/models/test_dependency_uninstall_selection.py \
    tests/integration/test_uninstall_marketplace_object_form_lifecycle.py tests/integration/test_uninstall_marketplace.py \
    tests/unit/commands/test_uninstall_atomic_selection.py -n 4
42 passed
$ ... tests/integration/test_uninstall_skill_selection_lifecycle.py tests/unit/test_uninstall_reintegration.py \
    tests/integration/test_profile_uninstall_runtime_scope_lifecycle.py -n 4
12 passed
$ ... every tests/**/test_*uninstall* file + tests/unit/models + marketplace replay/origin lifecycles -n 4
613 passed, 4 skipped
$ ... architecture compound mutations + owner-rule mutations + runner
997 passed
$ uvx [email protected] check / format --check (CI paths)        -> clean
$ pylint R0801 (CI paths)                                    -> 10.00/10, rc=0
$ bash scripts/lint-auth-signals.sh                          -> clean
$ bash scripts/lint-architecture-boundaries.sh               -> rc=0
$ gh pr checks 3933                                          -> 31 pass, 3 skipping

Review history: two Copilot inline points (shared coordinate fail-closed; -g dry-run uses the scoped lockfile) and the lean panel follow-ups (advisory) are folded. The panel's fail-open finding is fixed by case-insensitive marketplace_rows resolution that refuses ambiguity. Deferred, because it crosses into #3915's deps/reachability code: extracting a shared LockFile.locked_reference_for used by reachability._locked_marketplace_form, and moving _resolve_marketplace_packages Stage 1 onto LockFile (one lock-association rule for string-form refs).

How to test

  • APM_E2E_TESTS=1 APM_BINARY_PATH=.venv/bin/apm uv run --extra dev pytest tests/integration/test_uninstall_marketplace_object_form_lifecycle.py -p no:xdist
  • Manually: declare {name: x, marketplace: company}, run apm install, then apm marketplace remove company --yes, then apm uninstall x@company. The entry, lock row and files should be gone.

Changelog

  • One line under ## [Unreleased] in CHANGELOG.md (Fixed).
  • 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 (uninstall selection only).

Co-authored-by: Copilot [email protected]

…etplace

`apm uninstall plugin@alias` resolved the ref to the concrete lock key and
then looked for that key in apm.yml, so an object-form
`{name, marketplace}` declaration (identity `_marketplace/<alias>/<plugin>`)
was never found and the command exited 1.

- models/dependency/selection.py: select_marketplace_declaration selects
  object-form declarations case-insensitively from the manifest alone.
- uninstall engine: declared refs skip lock/registry resolution entirely
  (offline, --dry-run identical); _removal_target maps a removed
  declaration to its locked coordinate for the lock row, apm_modules
  checkout and transitive edges. The registry supply-chain guard is
  unchanged for refs that are not declared in object form.
- Guard: install-deployment-uninstall-selection now requires these routes.

Closes #3928

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 19, 2026
Copilot AI balanced review requested due to automatic review settings November 19, 2026 14:30

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

Uninstall can delete a shared checkout, deployed files, and lock entry still owned by a surviving Git declaration, leaving that dependency declared but missing.

2 open issues
What changed in this PR

This PR addresses #3928 by enabling apm uninstall plugin@marketplace to select object-form marketplace dependencies directly from the manifest, without catalog access.

Changes:

  • Adds case-insensitive marketplace declaration selection while preserving string-form behavior.
  • Maps selected declarations to locked coordinates for checkout, lock-row and orphan cleanup.
  • Adds lifecycle tests, architecture guards and documentation for offline uninstall and dry-run behavior.
File Description
tests/​unit/​models/​test_dependency_uninstall_selection.py Tests declaration selection and locked removal targets.
tests/​integration/​test_uninstall_marketplace_object_form_lifecycle.py Covers offline uninstall and dry-run through the real CLI.
tests/​integration/​test_architecture_install_compound_mutations.py Adds mutations checking required selection and removal routes.
src/​apm_cli/​models/​dependency/​selection.py Adds object-form marketplace declaration selection.
src/​apm_cli/​commands/​uninstall/​engine.py Resolves declarations to concrete removal targets.
src/​apm_cli/​commands/​uninstall/​cli.py Uses mapped targets during uninstall planning and cleanup.
scripts/​architecture_linter/​checks/​install_uninstall_and_resolution.py Enforces routing through selection and removal helpers.
packages/​apm-guide/​.apm/​skills/​apm-usage/​commands.md Documents offline object-form uninstall support.
docs/​src/​content/​docs/​reference/​cli/​uninstall.md Explains declaration-first selection and lock-based cleanup.
CHANGELOG.md Records the user-visible uninstall fix.

Review effort: Balanced

…file

- Removing one of two declarations that own the same locked package (an
  object-form entry and its Git form) now fails closed and names both,
  instead of deleting the checkout, files and lock row the survivor needs.
- `--dry-run` uses the scoped lockfile (global `-g` included) for the
  object-form removal target and orphan preview, not ./apm.lock.yaml.

Addresses Copilot inline review on engine.py:65 and engine.py:817.

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

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_with_followups

Makes apm uninstall plugin@alias work for object-form {name, marketplace} declarations offline, closing the 0.37 marketplace slice gap left after #3917, with a lifecycle test that fails on main.

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

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

This PR delivers the approved scope from #3928. Object-form marketplace declarations can now be uninstalled by alias, case-insensitively and offline. --dry-run previews the same plan, and the lock-recorded supply-chain guard is unchanged. The lifecycle test fails on main and passes on this head; test-coverage-expert ran it and confirmed the offline behavior. Both Copilot inline points (fail closed on a shared coordinate, -g dry-run reading the scoped lockfile) are already folded, and deletions stay inside apm_modules.

The finding weighted above the rest comes from two panelists independently. _removal_target looks up the lock with the case-sensitive LockFile.get_dependency. If the alias in apm.yml is recased after install, or two lock rows share a label, the lookup misses: uninstall removes the manifest entry but leaves the lock row, checkout and deployed files, and still reports success. That is a fail-open on a secure-by-default surface, and case-insensitive selection is in the approved scope, so it should be folded before landing.

The remaining findings are lower risk and mostly in scope: two missing tests (transitive orphan cleanup for an object-form plugin, a CLI-level nothing-changed check for the shared-coordinate refusal), a negative route guard, and a stronger dry-run assertion. The shared locked_reference_for helper would also change deps/reachability (#3915's code); fold it only as a pure extraction, otherwise defer it.

Dissent. None. The supply-chain and architecture findings on the lock lookup describe the same problem; the security framing is taken as the top fold.

Aligned with: Secure by default: the registry guard and apm_modules containment hold; requiring exactly one case-insensitive lock row and failing closed otherwise closes the fail-open. Portable by manifest: object-form declarations become first-class for uninstall. Pragmatic as npm: uninstall by alias works offline and the dry-run matches the real plan.

Panel summary

Persona B R N Takeaway
Supply Chain Security Expert 0 1 0 Deletions stay inside apm_modules and the registry guard is unchanged. A lock miss for an object-form entry should fail closed.
Test Coverage Expert 0 3 0 Object-form uninstall works offline and is proven by a test I ran. No functional test covers object-form transitive orphan cleanup or the CLI-level shared-coordinate refusal.
Python Architect 0 3 0 Sound split: selection stays manifest-only, the lock association goes through LockFile.get_dependency. Three non-blocking seams.

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

Top 5 follow-ups

  1. [Supply Chain Security Expert] Resolve the object-form lock row through the case-insensitive LockFile.marketplace_rows and require exactly one match; fail closed atomically on several matches; fall back to the manifest only when no row exists. Add regression tests for a recased alias and a shared label. -- A lock miss today removes the apm.yml entry but leaves the lock row, checkout and deployed files, and reports success.
  2. [Test Coverage Expert] Add a CLI-level test that a shared-coordinate uninstall exits 1 and leaves apm.yml, the lockfile and apm_modules unchanged. -- The fail-closed refusal is only unit-tested.
  3. [Test Coverage Expert] Add a functional test of transitive orphan cleanup for an object-form plugin. -- Orphan pruning is new on this path and nothing would catch it breaking.
  4. [Python Architect] Add a negative guard so cli.py cannot reintroduce parsed-entry get_unique_key() for removed entries; assert the lifecycle dry-run names the apm_modules checkout. -- Cheap guards against the exact regression class behind [BUG] apm uninstall plugin@marketplace cannot remove an object-form {name, marketplace} dependency from apm.yml #3928.
  5. [Python Architect] Extract a shared LockFile.locked_reference_for used by _removal_target and reachability._locked_marketplace_form, with one index snapshot. Defer it if it changes reachability behavior. -- One lock-association rule removes the drift behind the fail-open.

Recommendation

Fold the fail-closed lock resolution and its regression tests before landing, together with the two missing tests and the cheap guards; all are inside #3928's scope. Defer the reachability helper extraction and moving Stage 1 onto LockFile if they touch #3915's behavior. Verify the fail-closed resolution on the final head.


Full per-persona findings

Supply Chain Security Expert

  • [recommended] _removal_target silently falls back to manifest identity when an object-form declaration has no unique case-exact lock association. at src/apm_cli/commands/uninstall/engine.py:66
    A recased alias or duplicate-label rows make get_dependency miss; the manifest entry goes but the lock row, checkout and integrations stay, and success is reported. safe_rmtree still blocks deletion outside apm_modules.
    Suggested: case-insensitive marketplace_rows with exactly one match; fail closed on several; regression tests.

Test Coverage Expert

  • [recommended] No functional test covers transitive orphan cleanup when an object-form plugin is uninstalled. at src/apm_cli/commands/uninstall/engine.py:1119
    Proof (missing at): tests/integration/test_uninstall_marketplace_object_form_lifecycle.py -- proves: the plugin's own dependencies are removed too.
  • [recommended] The shared-coordinate refusal has only unit coverage. at src/apm_cli/commands/uninstall/engine.py:85
    Proof (missing at): tests/integration/test_uninstall_marketplace_object_form_lifecycle.py -- proves: uninstalling one of two entries for one package is refused and nothing is deleted.
  • [recommended] The dry-run step should assert the preview names the checkout removal. at tests/integration/test_uninstall_marketplace_object_form_lifecycle.py
    Proof (passed): test_uninstall_selects_object_form_marketplace_declaration_offline -- 13 passed in 49.63s.

Python Architect

  • [recommended] _removal_target re-implements reachability._locked_marketplace_form and rebuilds the marketplace index per declaration. at src/apm_cli/commands/uninstall/engine.py:52
  • [recommended] Two lock-association rules in uninstall, and a silent fallback on a miss. at src/apm_cli/commands/uninstall/engine.py:66
  • [recommended] The route table is positive-only; add a negative guard for cli.py. at scripts/architecture_linter/checks/install_uninstall_and_resolution.py:128

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.

- Resolve an object-form declaration's lock row through the case-insensitive
  LockFile.marketplace_rows and require exactly one; several rows for one
  alias/plugin pair fail closed atomically instead of removing the apm.yml
  entry while leaving the lock row and files behind.
- Rename the validator refusal to _refuse_unsafe_marketplace_removals; it
  covers ambiguous rows and shared coordinates.
- Tests: recased alias, ambiguous rows, orphan scan seeded from the locked
  plugin, CLI-level shared-coordinate refusal (exit 1, nothing changed),
  dry-run preview names the apm_modules checkout.
- Guard: negative half forbids cli.py from deriving lock keys itself.

Addresses the lean panel advisory on #3933 (supply-chain F1,
test-coverage F1-F3, python-architect F2-F3).

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 94b0c69 into main Nov 19, 2026
35 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-uninstall-object-form-3928 branch November 19, 2026 15:56
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 uninstall plugin@marketplace cannot remove an object-form {name, marketplace} dependency from apm.yml

2 participants