Repository navigation
fix(policy): judge the declared constraint, accept package release tags (supersedes #3381) - #3652
Conversation
require_pinned_constraint judged the wrong string in two ways. The
resolve phase rewrites a direct dependency's in-memory reference to the
tag its semver range selected, and the install gate ran after that, so
pkg-a#^1.0.0 was judged as pkg-a-v1.1.0. The literal-tag classifier also
only knew v{version}, while the resolver selects from v{version},
{name}--v{version} and {name}-v{version}.
InstallContext now snapshots every manifest-declared ref of each direct
dependency before any rewrite; policy_gate and policy_target_check pass
that map to run_dependency_policy_checks, which classifies each
declaration instead of the rewritten reference, so a bounded
devDependencies declaration cannot hide an unbounded one. The classifier
accepts {name}-v{version} and {name}--v{version} for the dependency's
own package name only, taking the name from the resolver owner
ref_reuse.git_semver_package_name and the patterns from
DEFAULT_TAG_PATTERNS; a static architecture check guards that routing.
Unit, wiring and real-binary lifecycle tests cover fresh install, locked
replay, repeat install, update and audit, with negative branch, range
and other-package controls.
Rebuilt from #3381 by @Kaustubh1235 to ship in 0.36.0 (CLA pending).
Refs #3224
Co-authored-by: Kaustubh1235 <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Policy reference, schema, consumer governance and dependency guides, the packaged apm-guide governance usage file and the CHANGELOG now say that require_pinned_constraint judges each direct dependency's declared constraint and counts a package's own release tags as pinned. Two places that said transitive dependencies are classified are corrected; the check is direct-only. Rebuilt from #3381 by @Kaustubh1235 to ship in 0.36.0 (CLA pending). Refs #3224 Co-authored-by: Kaustubh1235 <[email protected]> Co-authored-by: Copilot App <[email protected]>
The entry ships through #3652, which rebuilds #3381; the changelog convention ends each bullet with the merging PR number. Credit to the original author is kept in the bullet. Refs #3224 Co-authored-by: Kaustubh1235 <[email protected]> Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The policy checks can incorrectly accept an unbounded replacement for a bounded dependency and reject valid pinned declarations whose repository names differ only in casing.
2 open issues
What changed in this PR
Fixes require_pinned_constraint to evaluate declared constraints rather than resolved tags, addressing #3224 and superseding #3381.
Changes:
- Snapshots direct dependency declarations before resolution and forwards them to policy checks.
- Recognizes package-qualified release tags using the resolver’s package-name rules.
- Adds regression coverage and updates policy documentation, CLI help, and the changelog.
| File | Description |
|---|---|
tests/unit/policy/test_pinned_constraint_declared.py |
Tests declared refs, package tags, and duplicate declarations. |
tests/integration/test_architecture_owner_rule_mutations.py |
Tests enforcement of shared package-name ownership. |
tests/integration/policy/test_require_pinned_constraint_e2e.py |
Verifies declared-ref forwarding to policy checks. |
tests/integration/policy/test_require_pinned_constraint_declared_e2e.py |
Covers install, replay, update, and audit scenarios. |
src/apm_cli/policy/policy_checks.py |
Checks each captured declaration and deduplicates diagnostics. |
src/apm_cli/policy/_help_text.py |
Explains declared constraints and package-qualified tags. |
src/apm_cli/policy/_constraint_pinning.py |
Adds declaration collection and package-tag classification. |
src/apm_cli/install/pipeline.py |
Captures direct refs before resolution. |
src/apm_cli/install/phases/policy_target_check.py |
Forwards declared refs during target checks. |
src/apm_cli/install/phases/policy_gate.py |
Forwards declared refs to the install gate. |
src/apm_cli/install/helpers/ref_reuse.py |
Exposes the shared package-name helper. |
src/apm_cli/install/context.py |
Stores the declared-ref snapshot. |
scripts/architecture_linter/checks/transport_network_and_runtime.py |
Guards reuse of the package-name helper. |
packages/apm-guide/.apm/skills/apm-usage/governance.md |
Updates policy usage guidance. |
docs/src/content/docs/reference/policy-schema.md |
Clarifies direct-only checks and accepted tag forms. |
docs/src/content/docs/enterprise/policy-reference.md |
Documents declared-constraint behavior and direct-only scope. |
docs/src/content/docs/consumer/manage-dependencies.md |
Explains policy acceptance of ranges and package tags. |
docs/src/content/docs/consumer/governance-on-the-consumer-ramp.md |
Updates the consumer-facing policy summary. |
CHANGELOG.md |
Records the fix and contributor credit. |
Review effort: Balanced
Copilot review on #3652 found two gaps in the declared-ref snapshot. It was taken from the raw manifest before replace: rules, and a replacement keeps the original unique key, so a bounded original such as acme/widget#^1.0.0 covered an unbounded fork ref; the docs say policy uses the selected source and original refs are provenance only. It also stored bare ref strings, so declarations sharing a case-folded key (acme/Widget, acme/widget) were matched against the resolved dep's package name instead of their own. The pipeline now snapshots project_manifest_dependencies(), and collect_declared_refs keeps a shallow copy of each declaration, which the check classifies directly. classify_unbounded_reason and humanize_reason no longer need ref overrides and return to their main signatures. Regressions cover a replaced dep at unit and pipeline-wiring level and the case-colliding declarations; each was mutation-checked. apm-spec-waiver: classification repair under existing req-pl-007; declared-constraint snapshot, no new normative behaviour (#3224) Refs #3224 Co-authored-by: Kaustubh1235 <[email protected]> Co-authored-by: Copilot App <[email protected]>
The #3652 review panel (doc-writer, supply-chain-security-expert) found that run_policy_checks still passed the raw manifest to the pinned constraint check, so apm audit judged a bounded original while install judged the unbounded ref a replace: rule selects; the docs promise the two agree. collect_manifest_declarations(manifest) is now the single owner of the source-selected declaration snapshot; the install pipeline and run_policy_checks both use it (this also keeps pipeline.py within its LOC budget). Unit, wiring and a real-binary replace: scenario (fork tag passes, fork branch is blocked at install and fails audit) were each mutation-checked against both call sites. Policy reference and the packaged governance guide note that a replace: rule is judged by the ref it selects. Refs #3224 Co-authored-by: Kaustubh1235 <[email protected]> Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 0 | 0 | Fold aligns snapshot source with canonical project_manifest_dependencies; shallow copy is sound; no dead code remains. |
| Test Coverage Expert | 0 | 1 | 0 | Fold adds regression traps at unit + wiring tier for both Copilot findings; replace: scenario lacked real-binary e2e coverage (folded). |
| Supply Chain Security Expert | 0 | 1 | 0 | Fold is security-correct: replacement refs are judged, shallow copy is safe, no laundering path; audit path gap for replace: (folded). |
| Performance Expert | 0 | 0 | 0 | No perf regression: fold adds O(N+R) in-memory work (<0.1ms) to a pipeline dominated by network resolve/fetch. |
| Doc Writer | 0 | 1 | 0 | Docs, guide, help text and CHANGELOG accurate and succinct; install/audit agreement under replace: needed code or a clause (both folded). |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 5 follow-ups
- [Test Coverage Expert] Real-binary e2e test for replace: through the declared-constraint contract -- FOLDED in 0aaad3a with mutation-break coverage. -- Evidence outcome=missing on a governed-by-policy surface; now resolved.
- [Supply Chain Security Expert]
apm auditnow applies replace: rules to the pinned-constraint check via the sharedcollect_manifest_declarations-- FOLDED in 0aaad3a. -- Audit/install agreement is a core policy contract; the gap is closed. - [Doc Writer] policy-reference.md and the packaged governance guide say a replace: rule is judged by the ref it selects -- FOLDED in 0aaad3a. -- Docs now match the code.
- [Supply Chain Security Expert]
apm auditover devDependencies-only packages (deferred from fix(policy): judge the declared constraint, accept package release tags #3381, out of [BUG] require_pinned_constraint flags git semver ranges as bare branches: checks the resolved tag and rejects {name}-v{version} literal tags #3224 scope). -- Pre-existing gap, not a regression. - [Python Architect] Consolidate
deps/revision_pins.package_name(deferred from fix(policy): judge the declared constraint, accept package release tags #3381, out of [BUG] require_pinned_constraint flags git semver ranges as bare branches: checks the resolved tag and rejects {name}-v{version} literal tags #3224 scope). -- Abstraction hygiene; no user-facing risk.
Recommendation
Every panel finding was folded with test-proven evidence. At the final head 4b90dc3 (current main merged, including hotfix #3651), all CI checks are green and license/cla passes. Recommended next action: Sergio Sisternes (@sergio-sisternes-epam) completes the CODEOWNERS review; the deferred items can ride the backlog.
Folded in this run
- (rebuild) Net diff of fix(policy): judge the declared constraint, accept package release tags #3381 at 903968e re-applied on main as 66953c7, 94e6f8c; CHANGELOG entry points at fix(policy): judge the declared constraint, accept package release tags (supersedes #3381) #3652 (cae92bf).
- (copilot) Snapshot declared deps after
replace:source selection, so a bounded original no longer covers an unbounded fork ref -- resolved in 8b470a2. - (copilot) Keep each declaration's own package name (shallow-copy snapshots), so case-colliding keys are matched against their own tags -- resolved in 8b470a2.
- (ci)
install/pipeline.pyback within its 1000-line budget by moving the projection into one policy-side owner -- resolved in 0aaad3a. - (panel)
apm auditjudges replace: rules like the install gate viacollect_manifest_declarations-- resolved in 0aaad3a. - (panel) Real-binary replace: scenario (fork tag installs and audits green; fork branch rejected at install and failing audit) -- resolved in 0aaad3a.
- (panel) One-clause doc note in policy-reference.md and packaged governance guidance -- resolved in 0aaad3a.
- (ci) Spec conformance Mode B:
apm-spec-waiver(classification repair under existing req-pl-007) in 8b470a2.
Copilot signals reviewed
src/apm_cli/install/pipeline.py:542-- LEGIT: snapshot taken beforereplace:rules let a bounded original cover an unbounded replacement ref (resolved in 8b470a2).src/apm_cli/policy/policy_checks.py:1118-- LEGIT: case-folded key shared by differently cased repos judged both tags against one package name (resolved in 8b470a2).
Deferred (out-of-scope follow-ups)
- (panel)
apm auditover devDependencies-only packages -- scope boundary: changes which dependency set audit evaluates; pre-existing on main, outside the declared-vs-resolved repair. - (panel) Consolidate
deps/revision_pins.package_name-- scope boundary: pre-existing split in update/outdated, which this PR does not touch. - (panel) Lighter import for
DEFAULT_TAG_PATTERNS-- scope boundary: import-graph refactor of resolver constants; current cost is one-time and noise-level.
Regression-trap evidence (mutation-break gate)
TestDeclaredRefsWiring::test_policy_gate_forwards_the_replacement_ref-- reverted the pipeline snapshot to rawall_apm_deps; test FAILED as expected; guard restored.test_snapshot_is_not_rewritten_with_the_reference,test_check_still_fails_declared_branch_after_resolution-- droppedcopy.copyincollect_declared_refs; tests FAILED as expected; guard restored.test_each_declaration_keeps_its_own_package_name-- judged each declaration with the resolved dep's context; test FAILED as expected; guard restored.test_audit_judges_a_replacement_by_its_selected_ref-- removeddeclared_refsfromrun_policy_checks; test FAILED as expected; guard restored.test_replacement_is_judged_by_the_ref_it_selects(real binary) -- removed the audit wiring, then reverted the pipeline snapshot; the branch case FAILED each time; guards restored.
Lint contract
ruff check and ruff format --check (src, tests, architecture linter and probe scripts; ruff 0.15.12 per uv.lock), pylint R0801 (10.00/10), lint-auth-signals.sh and lint-architecture-boundaries.sh all silent on the merged head.
CI
All 23 checks green on 4b90dc3 (CI build/test shards, lifecycle smoke, Windows compatibility, CodeQL, Spec conformance, NOTICE Drift, Deploy Docs); license/cla success (after 2 CI fix iteration(s): pipeline LOC budget, and merging main for the #3651 hotfix).
Mergeability status
| PR | head SHA | CEO stance | iters | folds | defers | Copilot rounds | CI | mergeable | mergeStateStatus | notes |
|---|---|---|---|---|---|---|---|---|---|---|
| #3652 | 4b90dc3 |
ship_now | 2 | 7 | 3 | 1 | green | MERGEABLE | BLOCKED | awaiting CODEOWNERS review |
Convergence
2 outer iteration(s); 1 Copilot round(s). Final panel stance: ship_now. Ready for maintainer review.
Full per-persona findings
Python Architect
No findings.
Test Coverage Expert
- [recommended] No real-binary lifecycle test for replace: through the declared-constraint contract at
tests/integration/policy/test_require_pinned_constraint_declared_e2e.py
The wiring test mocks the runner, so it proves the snapshot is forwarded but not the end-to-end outcome through the real binary. (Folded in 0aaad3a.)
Suggested: Parametrize a replace: scenario (fork branch rejected, fork tag passes) in the module-scoped monorepo fixture.
Proof (missing at):tests/integration/policy/test_require_pinned_constraint_declared_e2e.py::test_replacement_is_judged_by_selected_source-- proves: a replace: rule with an unbounded fork ref is rejected even though the original dep had a bounded range [governed-by-policy,secure-by-default]
Supply Chain Security Expert
- [recommended] run_policy_checks (apm audit) does not apply replace: rules to the pinned-constraint check at
src/apm_cli/policy/policy_checks.py:1415
Audit judged the original bounded ref while install judged the unbounded fork ref; a CI pipeline relying only on apm audit would not flag it. (Folded in 0aaad3a.)
Suggested: Pass the source-selected declarations to run_dependency_policy_checks in run_policy_checks.
Proof (passed):tests/integration/policy/test_require_pinned_constraint_e2e.py::TestDeclaredRefsWiring::test_policy_gate_forwards_the_replacement_ref-- proves: the install gate judges the replacement source ref, not the original bounded constraint [secure-by-default,governed-by-policy]
Performance Expert
No findings.
Doc Writer
- [recommended] The install/audit agreement claim did not hold for a dependency redirected by a replace: rule at
docs/src/content/docs/enterprise/policy-reference.md:191
The approved scope promises consistency across audit, so fixing the code is preferred over weakening the docs. (Folded in 0aaad3a: code fix plus one clause.)
Suggested: Use project_manifest_dependencies in run_policy_checks; add a clause that a replace: rule is judged by the ref it selects.
Proof (missing at):tests/unit/policy/test_pinned_constraint_declared.py::audit path judges a replace: rule by its selected ref-- proves: apm audit and apm install give the same result for a dependency redirected by a replace: rule [governed-by-policy]
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.
…tterns Resolve policy_checks.py and policy-schema.md conflicts with #3652 by keeping both sides: source_deps (host-qualified allow/deny over effective direct + locked transitive sources) and declared_refs (authored constraint for require_pinned_constraint); both doc paragraphs kept. Co-authored-by: Copilot App <[email protected]>
Main's pipeline.py reached exactly 1000 lines (#3652), so the CI merge commit put it at 1002 with this PR's import and reporter call (test_no_install_module_exceeds_loc_budget). The finally block's exit sequence -- deactivate Copilot plugin registration, close the TUI, then report failed-install residue -- now lives in finalization.close_pipeline_attempt, beside close_install_contexts, in the same order. pipeline.py is 999 lines, one under main. Co-authored-by: Copilot App <[email protected]>
#3641) * fix(install): name native target files a failed install leaves on disk InstallTransaction restores apm.yml and apm_modules staging only; native target integrations run outside it. A failure after integration now lists every deployed path that apm.lock.yaml does not track, gives one next step (remove the files, or re-run apm install with --force when skipped as not managed by APM), and the FAILED summary no longer says "No install transaction changes were committed" when such files remain. Reporting only: no rollback, deletion, or ownership tracking of native target files, and no InstallTransaction or resolution staging changes. apm-spec-waiver: failure-output wording only; no install, lockfile or staging semantics change (#3525) Fixes #3525 Co-authored-by: Copilot App <[email protected]> * docs(changelog): note failed-install residue report (#3641) Co-authored-by: Copilot App <[email protected]> * fix(install): keep residue report from masking the install error The residue report runs in the pipeline finally block while the original failure propagates. A crash while rendering it must never replace that error, so the call is suppressed and a regression test proves a raising reporter still surfaces DirectDependencyError. Addresses panel python-architect finding on src/apm_cli/install/pipeline.py. Co-authored-by: Copilot <[email protected]> * refactor(install): own the never-raise guard in failure_residue The residue reporter now suppresses its own errors instead of the pipeline wrapping the call, so the guard lives with the report owner and pipeline.py stays within the 1000-line install module budget enforced by test_architecture_invariants (CI Build & Test Shard 1 failed at 1001). Co-authored-by: Copilot <[email protected]> * fix(install): report only removable residue, scope-correct next step Address Copilot review on the failed-install residue report: - skill directory claims are dropped when their members are claimed, so the "remove these files" advice never targets a directory that may hold unrelated user files; - user-scope (-g) residue renders home-rooted paths and suggests 'apm install -g'; - file-backed target locators (cowork://) resolve through their owning target for display, and non-file locators (copilot-app-db://) are listed as entries, not files; - lockfile claim membership routes through the canonical DeploymentLedgerCodec.legacy_deployed_file_claims owner. Co-authored-by: Copilot <[email protected]> * chore(changelog): place #3641 entry away from the section head Avoids landing-order conflicts with other queued PRs. Co-authored-by: Copilot App <[email protected]> * refactor(install): keep the residue outcome check out of pipeline.py After merging main, pipeline.py reached 1007 lines and failed the 1000-line install module budget (test_no_install_module_exceeds_loc_budget, CI run 43279911187). The finished-vs-failed decision now lives in failure_residue.record_install_outcome, which records it on the install context; report_failed_install_residue returns early once the install finished. pipeline.py keeps one import and one call (1000 lines). Two regression traps cover the guard and the pipeline wiring. Co-authored-by: Copilot App <[email protected]> * refactor(install): move pipeline exit teardown into finalization Main's pipeline.py reached exactly 1000 lines (#3652), so the CI merge commit put it at 1002 with this PR's import and reporter call (test_no_install_module_exceeds_loc_budget). The finally block's exit sequence -- deactivate Copilot plugin registration, close the TUI, then report failed-install residue -- now lives in finalization.close_pipeline_attempt, beside close_install_contexts, in the same order. pipeline.py is 999 lines, one under main. Co-authored-by: Copilot App <[email protected]> * test(install): trap the pipeline exit sequence order close_pipeline_attempt must deactivate Copilot plugin registration, close the TUI, then report residue. No test asserted those calls or their order, so a later refactor could drop or reorder them silently. Addresses the CEO follow-up from the delta panel on 11f286b. Co-authored-by: Copilot App <[email protected]> --------- Co-authored-by: danielmeppiel <[email protected]> Co-authored-by: Copilot App <[email protected]>


Description
fix(policy): judge the declared constraint, accept package release tags
Note
Rebuilt from #3381 by Kaustubh Arora (@Kaustubh1235) to ship in 0.36.0; original authorship credited via
Co-authored-byon every commit. The contributor's CLA stayed pending for 6+ days, so the converged diff of #3381 (head903968e) was re-applied onto currentmainas new commits. Supersedes #3381.TL;DR
require_pinned_constraintnow judges the constraint the author declared inapm.yml, not the tag the resolver selected, and it recognises a package's own release tags (pkg-a-v1.2.3,pkg-a--v1.2.3). A bounded range such aspkg-a#^1.0.0therefore passes on fresh install, locked reinstall, update and audit alike, while branches, wildcards, open-upper ranges, missing refs and other packages' tags still fail.Problem (WHY)
referenceto the tag its semver range selected, and the install policy gate runs after it, sopkg-a#^1.0.0was judged aspkg-a-v1.1.0and reported as a moving bare branch.v{version}, while the resolver selects fromv{version},{name}--v{version}and{name}-v{version}, and the dependency guide tells people to pin the package-qualified forms.apm auditdisagreed on the sameapm.yml([BUG] require_pinned_constraint flags git semver ranges as bare branches: checks the resolved tag and rejects {name}-v{version} literal tags #3224).get_unique_key()alone would let a boundeddevDependenciesdeclaration hide an unboundeddependenciesone for the same package (caught on fix(policy): judge the declared constraint, accept package release tags #3381 by Copilot and the panel).Approach (WHAT)
InstallContext.declared_direct_refssnapshots every manifest ref per direct dep before resolution;policy_gateandpolicy_target_checkpass it to the checkcollect_declared_refskeeps all refs per unique key (includingNone); each is classified, so one bounded declaration never covers an unbounded one{name}-v{version}/{name}--v{version}count as pinned only for the dependency's own name, via the resolver'sDEFAULT_TAG_PATTERNS,build_tag_regexandgit_semver_package_nameref_reuse.git_semver_package_name(was private) is the only package-name rule; a static architecture check forbids re-deriving it underpolicy/Implementation (HOW)
src/apm_cli/policy/_constraint_pinning.pycollect_declared_refs,_is_package_literal_tag,declared_ref=onclassify_unbounded_reason,ref=onhumanize_reasonsrc/apm_cli/policy/policy_checks.py_check_pinned_constraints/run_dependency_policy_checksacceptdeclared_refsand classify each declarationsrc/apm_cli/install/{context,pipeline}.pyInstallContextconstructionsrc/apm_cli/install/phases/policy_gate.py,policy_target_check.pydeclared_refssrc/apm_cli/install/helpers/ref_reuse.py_git_semver_package_name-> publicgit_semver_package_namesrc/apm_cli/policy/_help_text.pyscripts/architecture_linter/checks/transport_network_and_runtime.pypackages/apm-guide+CHANGELOG.mdDiagram
Where the policy check reads its input before and after this change.
flowchart LR M[apm.yml declared refs] --> S[collect_declared_refs snapshot] M --> R[resolve phase rewrites dep.reference to selected tag] S --> G[policy_gate / policy_target_check] R --> D[download, lockfile, drift] G --> C[classify each declared ref]Trade-offs
dep.reference: download, drift and lockfile code keep the resolved tag unchanged; only the policy check reads the declared view.*-vX.Y.Zexemption (per the [BUG] require_pinned_constraint flags git semver ranges as bare branches: checks the resolved tag and rejects {name}-v{version} literal tags #3224 scope).Benefits
^1.0.0resolving topkg-a-v1.1.0passes underenforcement: blockinstead of failing install.pkg-a#pkg-a-v1.1.0pin is accepted.dependencies.Validation
Lint (ruff 0.15.12 check + format on changed files): clean. Targeted tests and CI evidence are recorded in the review advisory comment on this PR.
Scenario evidence
tests/unit/policy/test_pinned_constraint_declared.pyNonestaysNO_REFtests/unit/policy/test_pinned_constraint_declared.pytests/integration/policy/test_require_pinned_constraint_e2e.py::TestDeclaredRefsWiringtests/integration/policy/test_require_pinned_constraint_declared_e2e.pytests/integration/test_architecture_owner_rule_mutations.pyHow to test
uv run pytest tests/unit/policy/test_pinned_constraint_declared.py -quv run pytest tests/integration/policy/test_require_pinned_constraint_e2e.py -qAPM_BINARY_PATH=.venv/bin/apm uv run pytest tests/integration/policy/test_require_pinned_constraint_declared_e2e.py -qIssue and approved scope
Issue: Closes #3224
Human scope-approval comment: #3224 (comment)
This PR completes the accepted issue scope. Out-of-scope follow-ups from the #3381 panel (audit over
devDependencies, consolidatingdeps/revision_pins.package_name) remain separate.Type of change
Testing
Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}req-pl-007 flags "a bare branch name"; a dependency's own release tag in a layout the resolver selects from is a tag, not a branch, so recognising it is a classification repair under the existing rule. req-pl-008 is unchanged.
Supersedes #3381. Credit: Kaustubh Arora (@Kaustubh1235).