Skip to content

fix(audit): select PACKAGE through the uninstall selector - #3968

Merged
Daniel Meppiel (danielmeppiel) merged 4 commits into
mainfrom
danielmeppiel-fix-audit-package-selector-3953
Nov 19, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 4 commits into
mainfrom
danielmeppiel-fix-audit-package-selector-3953

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

apm audit PACKAGE had its own package selector (commands/audit.py _require_installed_package_key: a raw lock key or parse_dependency_entry). It rejected plugin@marketplace and the _local/<name> key apm deps list prints, though apm uninstall accepts 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_key in commands/uninstall/engine.py calls _validate_uninstall_packages in 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. The install-deployment-uninstall-selection guard now requires audit to route through select_installed_lock_key and rejects any selection or identity call in commands/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 outdated selectors.

Type of change

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

Testing

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

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 a discovered_via lock row all select the plugin. resolve_marketplace_plugin is patched to raise, which proves selection stays offline. other-plugin@company exits 1.
  • _local/hooky and ./pkgs/hooky select the local package. _local/other exits 1.

Three new compound mutations in tests/integration/test_architecture_install_compound_mutations.py prove 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 is audit-replay-config-modules-root, whose target src/apm_cli/policy/ci_checks.py this PR does not touch, so it already fails on main.
  • .venv/bin/python scripts/lint_architecture_boundaries.py --root .: clean
  • ruff check and ruff format --check (0.15.12, the CI paths): clean
  • pylint R0801 (the CI paths): 10.00/10
  • bash scripts/lint-auth-signals.sh: clean

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.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.
  • 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.

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>
@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 18:08
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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

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

Comment thread src/apm_cli/commands/audit.py Resolved
Comment thread tests/unit/test_audit_command.py Resolved
…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>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_with_followups

apm audit PACKAGE now goes through the same offline selector as apm uninstall, so the #3865 CHANGELOG promise holds and the duplicate selector is removed and guarded against coming back.

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 makes good on a promise the CHANGELOG already made. The #3865 entry said apm audit PACKAGE accepts the same forms as apm uninstall, but main still had a second selector in commands/audit.py. The fix stays within the approved #3953 scope. audit.py now calls select_installed_lock_key, which wraps the offline _validate_uninstall_packages(dry_run=True) path, so plugin@marketplace, _local/<name>, owner/repo and raw lock keys all resolve exactly as uninstall resolves them. The duplicate selector is deleted. The existing install-deployment-uninstall-selection guard now covers the audit, engine and CLI routes, and four new compound mutations show the guard is doing real work. It adds no new audit options and does not touch view or outdated.

Every recommended finding from python-architect (silent logger, a third reader of the manifest) and test-coverage-expert (sibling decoys, provenance mismatch, uninstall parity) was folded in bde2123. Both Copilot inline findings (unhandled ValueError on a semver ref, and an offline assertion that could be swallowed) were legitimate and folded, and their threads are resolved. The 21 package_filter tests lock the target next to dirty sibling decoys. They check uninstall --dry-run parity on every identifier and assert the registry is never called. Reverting audit.py to main fails 9 of them. Audit now warns instead of silently auditing x@m2 when you asked for x@m.

Only python-architect F3 is still open: the selector lives in commands/uninstall/engine.py, so audit depends on a sibling command's engine. This is placement, not correctness, and the guard pins the routing. Carry it until apm view or apm outdated adopts the shared selector.

Dissent. None. Both panelists returned ship, with every recommended finding folded.

Aligned with: Portable by manifest: one shared manifest_dependency_entries reader means the same identifier selects the same package in audit and uninstall. Secure by default: selection stays offline, a provenance mismatch is shown rather than silently swapped, and a bad semver ref fails closed with exit 1. Governed by policy: the duplicate selector is banned statically by the existing guard. Pragmatic as npm: any form apm uninstall takes now works with apm audit.

Panel summary

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

  1. [Python Architect] Move the read-only selector stack (select_installed_lock_key, the _validate_uninstall_packages selection path, _removed_lock_key, manifest_dependency_entries) out of commands/uninstall/engine.py into a neutral module such as core/package_selection.py, and repoint the guard to it when apm view or apm outdated adopts 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@m could audit x installed from another marketplace without a warning. Folded in bde2123: an explicit discard logger, plus an installed_via warning 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.py couples 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-run and 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.

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 9182f68 into main Nov 19, 2026
34 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-fix-audit-package-selector-3953 branch November 19, 2026 19:24
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 audit PACKAGE rejects plugin@marketplace and _local/<name> identifiers

2 participants