Repository navigation
fix(uninstall): remove object-form marketplace entries by plugin@marketplace - #3933
Daniel Meppiel (danielmeppiel) merged 5 commits into
Conversation
…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]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 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]>
APM Review Panel:
|
| 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
- [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.
- [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.
- [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.
- [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.
- [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]>
…meppiel-uninstall-object-form-3928


TL;DR
apm uninstall plugin@marketplaceexited 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 fromapm.ymldirectly and removes the entry, its lock row, itsapm_modules/checkout and its deployed files. It never contacts the marketplace, and--dry-runbehaves the same way. The string form is unchanged.Fixes #3928
Description
Reproduced on
main09af2b1 with the real CLI, using a hermetic Git catalogcompanylistingexample-pluginandapm.ymldeclaring{name: example-plugin, marketplace: company}:Root cause.
_resolve_marketplace_packagesmapsplugin@aliasto 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.cjsreportsrecord-present).Does this PR complete the issue? Yes. Every "Done when" item is covered (see Scenario evidence). It adds no new
apm.ymlor lockfile fields, does not touch the #2903marketplaces:map, and makes no other uninstall-selection changes.Type of change
Approach
plugin@aliasnamesmodels/dependency/selection.pyselect_marketplace_declaration(plugin, alias, deps). It matches object-form entries case-insensitively, as the registry does, and reads only the manifest.commands/uninstall/engine.py_validate_uninstall_packagesengine._removal_target/_removed_lock_keyLockFile.get_dependency(the existing association owner), to its locked coordinate for the lock row, theapm_modules/path and the orphan-edge scan. Survivor seeding still uses manifest identity, so #3915's reachability is untouched.install-deployment-uninstall-selection_removal_target), with three compound mutations.Trade-offs
cli.py. Passing resolved references through everycli.pycall would have broken the survivor subtraction that_read_survivor_direct_refsdoes by manifest identity.Testing
Scenario evidence
plugin@aliasremoves the apm.yml entry, lock row, checkout and deployed files with the marketplace unregistered and unreachabletests/integration/test_uninstall_marketplace_object_form_lifecycle.py::test_uninstall_selects_object_form_marketplace_declaration_offline(fails on main)--dry-runpreviews the same removal and changes nothing@COMPANY);tests/unit/models/test_dependency_uninstall_selection.py::test_marketplace_ref_selects_object_form_declaration_case_insensitivelytests/integration/test_uninstall_marketplace.py(unchanged, passes)tests/unit/models/test_dependency_uninstall_selection.py::test_object_form_removal_targets_the_locked_coordinatetests/integration/test_architecture_install_compound_mutations.py(uninstall-object-form-*)test_removing_one_of_two_declarations_of_one_package_fails_closedtest_recased_alias_still_targets_the_locked_row,test_ambiguous_lock_rows_for_one_declaration_fail_closed-g --dry-runuses the scoped lockfiletest_object_form_removal_seeds_the_orphan_scan_from_the_locked_plugin,test_dry_run_previews_object_form_checkout_from_the_scoped_lockfileBoth 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)
Review history: two Copilot inline points (shared coordinate fail-closed;
-gdry-run uses the scoped lockfile) and the lean panel follow-ups (advisory) are folded. The panel's fail-open finding is fixed by case-insensitivemarketplace_rowsresolution that refuses ambiguity. Deferred, because it crosses into #3915'sdeps/reachabilitycode: extracting a sharedLockFile.locked_reference_forused byreachability._locked_marketplace_form, and moving_resolve_marketplace_packagesStage 1 ontoLockFile(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{name: x, marketplace: company}, runapm install, thenapm marketplace remove company --yes, thenapm uninstall x@company. The entry, lock row and files should be gone.Changelog
## [Unreleased]inCHANGELOG.md(Fixed).Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regeneratedCo-authored-by: Copilot [email protected]