Repository navigation
fix(audit): select PACKAGE through the uninstall selector - #3968
Daniel Meppiel (danielmeppiel) merged 4 commits into
Conversation
apm audit PACKAGE now resolves plugin@marketplace and the _local/<name> key printed by apm deps list offline, through the same selector apm uninstall uses. The duplicate selector in commands/audit.py is removed and the install-deployment-uninstall-selection guard rejects a second one. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Audit can terminate with an unhandled ValueError for invalid marketplace references, and the offline-selection test can pass despite attempted registry resolution.
2 open issues
What changed in this PR
This PR addresses #3953 by routing apm audit PACKAGE through the existing uninstall selector, adding offline support for marketplace identifiers and local package keys while removing duplicate selection logic.
Changes:
- Adds a shared read-only selector and routes audit through it.
- Adds marketplace/local selection tests and architecture guard mutations.
- Updates the audit reference and changelog with the accepted identifier forms.
| File | Description |
|---|---|
tests/unit/test_audit_command.py |
Tests marketplace and local package selection. |
tests/integration/test_architecture_install_compound_mutations.py |
Adds mutations checking shared-selector routing. |
src/apm_cli/commands/uninstall/engine.py |
Exposes offline selection of installed lockfile keys. |
src/apm_cli/commands/audit.py |
Replaces audit-specific selection with the shared selector. |
scripts/architecture_linter/checks/install_uninstall_and_resolution.py |
Guards audit routing and rejects duplicate selection calls. |
docs/src/content/docs/reference/cli/audit.md |
Documents marketplace and local identifiers. |
CHANGELOG.md |
Records the audit selector fix. |
Review effort: Balanced
…ates Addresses the panel (python-architect, test-coverage-expert) and Copilot inline review on PR #3968. Audit now warns when plugin@marketplace matches a row installed via another marketplace, instead of silently auditing it. It reports an invalid marketplace ref with the parser's message and exit 1. apm uninstall and audit build their candidate list through one helper, manifest_dependency_entries, and the guard pins both routes. The tests add sibling decoys, uninstall --dry-run parity, a devDependencies entry, and assert_not_called on the registry. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…package-selector-3953
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 3 | 0 | Ship. Audit now reuses the uninstall selector. F1 and F2 are folded; F3 (move the selector to a neutral module) is carried. |
| Test Coverage Expert | 0 | 3 | 0 | All three gaps folded: decoys, provenance mismatch, uninstall parity. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 1 follow-ups
- [Python Architect] Move the read-only selector stack (
select_installed_lock_key, the_validate_uninstall_packagesselection path,_removed_lock_key,manifest_dependency_entries) out ofcommands/uninstall/engine.pyinto a neutral module such ascore/package_selection.py, and repoint the guard to it whenapm vieworapm outdatedadopts the shared selector. -- A third consumer would turn today's explicit, guarded coupling into a layering smell; moving it then is one justified change instead of speculative churn.
Recommendation
Merge once CI on the merge-of-main head (50d7dea) is green; the first head was 31 pass / 0 fail. Every in-scope panel and Copilot finding is folded. Reverting audit.py fails 9 of the 21 tests, so they prove the exact promise in #3953. Track architect F3 as a non-blocking follow-up tied to bringing apm view / apm outdated onto the shared selector.
Full per-persona findings
Python Architect
- [recommended] The silent logger hid a provenance substitution:
apm audit x@mcould audit x installed from another marketplace without a warning. Folded in bde2123: an explicit discard logger, plus aninstalled_viawarning printed by audit. - [recommended] The candidate list was built by a third reader of apm.yml. Folded: a shared
manifest_dependency_entries, used by the uninstall CLI and audit and guarded on both routes. - [recommended] A public read-only selector in
commands/uninstall/engine.pycouples audit to a sibling command's engine. Carried as a follow-up (refactor beyond the [BUG] apm audit PACKAGE rejects plugin@marketplace and _local/<name> identifiers #3953 scope).
Test Coverage Expert
- [recommended] Single-package fixtures could not prove the right package was picked. Folded: dirty sibling decoys for both the marketplace and the local package.
- [recommended] No test pinned a right plugin name with the wrong marketplace. Folded: object form exits 1 like uninstall; string form audits with an "installed via" warning.
- [recommended] No audit/uninstall parity test. Folded: every parametrized case also runs
uninstall --dry-runand asserts the same outcome.
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.

Description
apm audit PACKAGEhad its own package selector (commands/audit.py_require_installed_package_key: a raw lock key orparse_dependency_entry). It rejectedplugin@marketplaceand the_local/<name>keyapm deps listprints, thoughapm uninstallaccepts both and the #3865 CHANGELOG line says audit accepts the same forms.Audit now selects through the uninstall selector owner. A new
select_installed_lock_keyincommands/uninstall/engine.pycalls_validate_uninstall_packagesin dry-run mode (no registry fallback, so it stays offline) and maps the selection to its lock key with_removed_lock_key. A lock key, or an identifier that normalizes to one, still selects a locked transitive package. Audit's duplicate selector is removed. Theinstall-deployment-uninstall-selectionguard now requires audit to route throughselect_installed_lock_keyand rejects any selection or identity call incommands/audit.py. No new rule ID.Issue and approved scope
Issue: Fixes #3953
Human scope-approval comment: #3953 (comment)
This PR completes the issue. Out of scope, untouched: new audit options, and the
apm view/apm outdatedselectors.Type of change
Testing
New tests in
tests/unit/test_audit_command.py. They failed on main 0bb0886 with 4 failures and now pass:example-plugin@company(object form),Example-Plugin@COMPANY(case-insensitive) and a string-form declaration with adiscovered_vialock row all select the plugin.resolve_marketplace_pluginis patched to raise, which proves selection stays offline.other-plugin@companyexits 1._local/hookyand./pkgs/hookyselect the local package._local/otherexits 1.Three new compound mutations in
tests/integration/test_architecture_install_compound_mutations.pyprove the guard fires: the audit route is dropped, a second selector is added to audit, or the engine route is dropped.Validation:
.venv/bin/python -m pytest tests/unit/test_audit_command.py tests/unit/commands/ tests/unit/models/test_dependency_uninstall_selection.py tests/unit/scripts/test_architecture_runner.py -k "audit or uninstall or selection or architecture or rule": 274 passed.venv/bin/python -m pytest tests/integration/test_architecture_install_compound_mutations.py -k "uninstall or audit or selection": 43 passed, 1 failed. The failure isaudit-replay-config-modules-root, whose targetsrc/apm_cli/policy/ci_checks.pythis PR does not touch, so it already fails on main..venv/bin/python scripts/lint_architecture_boundaries.py --root .: cleanruff checkandruff format --check(0.15.12, the CI paths): cleanpylint R0801(the CI paths): 10.00/10bash scripts/lint-auth-signals.sh: cleanChangelog
## [Unreleased]inCHANGELOG.md:user-visible effect first, 25 words or fewer, ending with
(#PR);breaking changes only under upgrade notes; no Highlights; see
.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regenerated