Repository navigation
[0.37] fix(audit): required-package matching follows source replacement (#4038) - #4069
Merged
Daniel Meppiel (danielmeppiel) merged 4 commits intoNov 20, 2026
Merged
Conversation
`apm audit --ci` (run_policy_checks) passed the raw manifest declarations to the required-package checks, while the install gate passes the declarations projected through the manifest `replace:` rules. The two commands therefore matched `dependencies.require` entries against different packages when a root replacement was present. run_policy_checks now passes the production declarations through the same projection (project_manifest_dependencies, which gains an include_dev switch), so required-packages, required-packages-deployed, required-package-version and required-executable-untrusted identify the selected package (req-rpl-002) and read the lock entry under the original's lockfile identity (req-pl-018 clause (g)) through the existing RequiredPackageMatch key. Projects without `replace:` are unchanged. Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…#4038) Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…4038) Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-require-replace-4038
branch
from
November 20, 2026 03:52
15c096c to
be1338c
Compare
Daniel Meppiel (danielmeppiel)
marked this pull request as ready for review
November 20, 2026 03:52
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 20, 2026 03:52
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 20, 2026
Daniel Meppiel (danielmeppiel)
deleted the
danielmeppiel-require-replace-4038
branch
November 20, 2026 06:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
apm installandapm audit --cidisagreed on which package adependencies.requireentry identifies when the project has a rootreplace:rule.Take a consumer that declares
example-org/app, with a rootreplace:that selectsfork-org/app-fork:fork-org/app-fork), as req-rpl-002 requires.apm audit --cimatched them against the original package (example-org/app).Root cause:
run_policy_checks(src/apm_cli/policy/policy_checks.py, theapm audit --cipath) passed the rawmanifest.get_apm_dependencies()to the required-package checks.ctx.deps_to_install, whose declarations are already projected throughreplace:._audit_source_dependencies. Only the required-package checks used the raw declarations.Fix:
run_policy_checkspasses the production declarations through the same projection,project_manifest_dependencies. That function gains aninclude_devswitch, so the audit keeps its production-only scope.required-packages,required-packages-deployed,required-package-versionandrequired-executable-untrustedidentify the selected package (req-rpl-002).RequiredPackageMatchkey. For a bound reference,DependencyReference.get_unique_key()already returns the original's key, so there is no new key logic.dependency-sourcesfailure path is used.registry-sourcereads the same declaration list, soapm audit --cinow also judgesregistry_sourceagainst the selected source, asapm installdoes.Unchanged: lockfile keys and format, replacement binding, install-gate behaviour, the production-only scope of the audit's require checks, allow/deny matching, and projects without
replace:.Issue and approved scope
Issue: Fixes #4038
Human scope-approval comment: #4038 (comment)
Stacked on #4008 (base
danielmeppiel-scaling-potatoat 3560d7f); it must merge after #4008. Because the base is stacked, CI does not run on this PR; local evidence is below. It does not overlap #4067 (#4037), which changesRequiredPackageMatch.locked_inanddeps/lockfile.py.Type of change
Testing
The new installed-CLI lifecycle test,
tests/integration/policy/test_required_packages_source_replacement_lifecycle.py, sets up the following:enforcement: block) is discovered through the project'soriginremote and served onapi.github.combylocal_scripted_https_proxy;example-org/app#v1.0.0with a rootreplace:tofork-org/app-fork.Each scenario runs
apm install(the gate), thenapm audit --ci:example-org/app): failsrequired-packagesinapm install, and failsrequired-packagesandrequired-packages-deployedinapm audit --ci. This holds for a github.com fork, for a GHES fork, and for a GHES fork with the qualifiedgithub.com/example-org/appentry.fork-org/app-fork, orghes.example.test/fork-org/app-fork):apm installpasses, andapm audit --ciexits 0 with both presence checks passing. The lock entry stays keyedexample-org/appand records the fork.fork-org/app-fork#v9.9.9,require_resolution: block): a freshapm installpasses the gate, since there is no locked ref to compare yet.required-package-versionin the audit then reportsexpected ref 'v9.9.9', got 'v1.0.0'.replace:, a require on the declared package passes both commands, andapm audit --ciexits 0.The conformance test in
tests/spec_conformance/test_policy_reqs.py, markedreq("req-rpl-002", "req-pl-018"), runsrun_policy_checkson disk: the selected entry passes both presence checks and the original entry fails both.CONFORMANCE.{md,json}are regenerated.Red/green: with the
src/change reverted at 3560d7f, the 6 replacement lifecycle cases fail and the control passes. The conformance test fails with(False, False) == (True, True).APM_BINARY_PATH=.venv/bin/apm pytest -q -n 4 tests/integration/policy/test_required_packages_source_replacement_lifecycle.pysrc/change reverted (3560d7f)pytest -q -p no:randomly tests/spec_conformance/test_policy_reqs.py -k follows_source_replacementpytest -q -n 8 tests/unit/policy tests/unit/models tests/unit/install tests/spec_conformance tests/integration/policytest_unix_install_ownership, plus git signing intest_mode_b_detector,test_cache_pinandtest_resolution_reqs), identical with the fix reverted, apart from the new conformance testpytest -q -n 8 tests/unit -k "doc or guide or changelog or governance"ruff check/ruff format --check/pylint R0801/lint-auth-signals.sh/lint_architecture_boundaries.py --root .python -m tests.spec_conformance.orphan_checkChangelog
## [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)
docs/src/content/docs/specs/openapm-v0.1.mdupdated(new/changed
<a id="req-XXX"></a>anchor + prose + Appendix Crow).
docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.ymlupdated.
@pytest.mark.req("req-XXX")test undertests/spec_conformance/added or extended.CONFORMANCE.{md,json}regenerated viauv run --extra dev python -m tests.spec_conformance.gen_statementand committed.
There is no spec text change. req-rpl-002 already says policy matching "evaluates the selected package, not the original package". req-pl-018 clause (g), as revised by #4008 (0.1.67), already requires reading the lock entry by the dependency's own lockfile identity.
Docs re-home after #3996
The docs are in the last commit, by themselves.
dependencies.requireand source replacementdocs/src/content/docs/reference/policy-schema.mdpackages/apm-guide/.apm/skills/apm-usage/governance.md