Repository navigation
fix(policy): judge the declared constraint, accept package release tags - #3381
Kaustubh Arora (Kaustubh1235) wants to merge 9 commits into
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 a semver range selected, and the install gate runs after that,
so a bounded range such as `pkg-a#^1.0.0` was classified as whatever tag
it resolved to. The resolve phase now records the manifest-declared refs
of the direct dependencies before any rewrite, and the gate and the
post-targets re-check classify those. The resolved reference is left in
place for download, drift and lockfile work; preflight and audit already
hold the manifest view and are unchanged.
The literal-tag classifier only knew the `v{version}` layout, while the
resolver selects from `v{version}`, `{name}--v{version}` and
`{name}-v{version}` and the dependency guide recommends pinning the
package-qualified forms. The classifier now accepts those layouts for
the dependency's own package name, using the resolver's tag patterns and
regex builder, so `pkg-a-v1.1.0` on a `pkg-a` dependency is pinned while
`pkg-b-v1.1.0`, `pkg-a-v1.1` or `release-pkg-a-v1.1.0` stay bare
branches. Missing refs, moving branches, wildcards and open-upper ranges
are classified as before, and a selected tag or SHA never launders an
unbounded declaration.
Refs microsoft#3224.
There was a problem hiding this comment.
🟡 Changes recommended
Duplicate dependency identities can overwrite declared constraints and let a branch pass the pinned-constraint gate; package-name derivation also needs one shared owner.
2 open issues
What changed in this PR
This PR addresses #3224 by making pinned-constraint policy checks evaluate declared references rather than resolved tags, and recognize package-qualified release tags.
Changes:
- Capture direct dependency declarations and forward them to install policy checks.
- Accept release tags matching the dependency's own package name.
- Add regression coverage and clarify policy behavior in documentation.
| File | Description |
|---|---|
| tests/unit/policy/test_pinned_constraint_declared.py | Tests declared-ref precedence and package-qualified tags. |
| tests/integration/policy/test_require_pinned_constraint_e2e.py | Checks declaration forwarding to the policy gate. |
| tests/integration/policy/test_require_pinned_constraint_declared_e2e.py | Adds real-binary install, replay, update, and audit coverage. |
| src/apm_cli/policy/policy_checks.py | Passes declared refs into classification and diagnostics. |
| src/apm_cli/policy/_help_text.py | Clarifies accepted tags and declared-constraint semantics. |
| src/apm_cli/policy/_constraint_pinning.py | Recognizes package-qualified tags and declared-ref overrides. |
| src/apm_cli/install/phases/resolve.py | Snapshots direct refs before resolution rewrites them. |
| src/apm_cli/install/phases/policy_target_check.py | Forwards declarations during target checks. |
| src/apm_cli/install/phases/policy_gate.py | Forwards declarations to the install gate. |
| src/apm_cli/install/context.py | Stores the declared-reference snapshot. |
| docs/src/content/docs/reference/policy-schema.md | Updates policy semantics and examples. |
| docs/src/content/docs/enterprise/policy-reference.md | Clarifies direct-only evaluation and accepted tags. |
| 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 | Clarifies that policy judges direct declarations. |
Review effort: Balanced
|
Thank you for contributing this policy repair. Issue #3224 has an explicit maintainer-approved scope, and this PR appears to implement it. The requested reviewers include Daniel Meppiel (@danielmeppiel) and Sergio Sisternes (@sergio-sisternes-epam). The license/cla check is currently queued. This is a recommendation for human review only, not merge approval. Generated by autopilot-pr-triage-worker. This comment is AI-generated and may contain errors. |
|
Hi Kaustubh Arora (@Kaustubh1235), thanks for this fix for #3224. The scope has been accepted, so the next step is on the Contributor License Agreement: CI cannot run on this PR until the CLA is signed. Please follow the instructions in the CLA comment above (reply with Generated by autopilot-pr-ready-worker. This comment is AI-generated and may contain errors. |
Brings the PR up to current main (includes microsoft#3571, which touched install/phases/resolve.py) before folding review follow-ups. Co-authored-by: Copilot App <[email protected]>
The declared-ref map was keyed by unique key, which excludes the ref, so a package declared under both dependencies and devDependencies kept only the last declaration and a bounded one could cover a branch; a missing ref was dropped and fell back to the rewritten reference. collect_declared_refs now keeps every declaration (None included) and the check classifies each one. The snapshot moves to InstallContext construction in the pipeline, before any phase can rewrite a reference, which also keeps install/phases/resolve.py within its LOC budget after merging main. The policy no longer re-derives the git-tag package name: _is_package_literal_tag calls ref_reuse.git_semver_package_name (the git-semver owner, now public) and requires the captured version to parse like the resolver does. A static guard in transport-platform-git-semver-preflight and a mutation test keep the policy on that owner. Addresses Copilot inline on src/apm_cli/install/phases/resolve.py:421 (P1) and src/apm_cli/policy/_constraint_pinning.py:139 (P2), and the matching panel follow-ups; also asserts the policy_target_check wiring and drops a non-ASCII ellipsis from a docstring. Co-authored-by: Copilot App <[email protected]>
On current main a no-op apm update returns before the install pipeline, so the contract's update step evaluated no policy. The contract now publishes pkg-a-v1.2.0 and asserts update selects it through the gate while the declared range stays the judged constraint. Adds the object-form declaration and the dependencies/devDependencies collision negative control from the approved scope, and injects apm_binary_path per test instead of through a module fixture (architecture lint AC9). Co-authored-by: Copilot App <[email protected]>
The approved scope requires packaged usage guidance to describe the bounded-choice rule; the apm-guide governance remediation still listed only vX.Y.Z tags. Adds the Unreleased Fixed entry crediting the author and trims a duplicated paragraph in policy-reference (addresses doc-writer panel follow-ups). Co-authored-by: Copilot App <[email protected]>
Picks up microsoft#3598 (preflight gate revert) and the other changes on main since the previous merge. Co-authored-by: Copilot App <[email protected]>
…cies apm audit evaluates the dependencies block only (unchanged on main), so the entry no longer implies audit also checks devDependencies. Addresses doc-writer delta-panel follow-up. Co-authored-by: Copilot App <[email protected]>
Resolves the conflicting state after microsoft#2506 and microsoft#3534 landed on main. Co-authored-by: Copilot App <[email protected]>
Keeps the PR current with main before landing. Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 0 | 0 | Prior findings resolved: canonical owner routed, dual guardrail shipped, every declaration kept including None. |
| Test Coverage Expert | 0 | 0 | 0 | Duplicate-declaration trap (unit + e2e), target-check wiring and e2e verified at head; no new gaps. |
| Doc Writer | 0 | 1 | 0 | Prior findings resolved; CHANGELOG audit/devDependencies wording folded in d186200. |
| Performance Expert | 0 | 0 | 0 | O(N) collector, K~1-2 refs per key, lazy imports deferred; no hot-path regression. |
| Supply Chain Security Expert | 0 | 0 | 0 | Laundering and .git-suffix findings resolved with tests; no remaining bypass path found. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 3 follow-ups
- [Supply Chain Security Expert] Extend
apm auditto evaluate devDependencies against pinned-constraint policy. -- Pre-existing gap on main: audit reads onlydependencies, so an unbounded devDependencies ref passes audit while install rejects it. - [Python Architect] Consolidate
deps/revision_pins.package_namewith the canonicalref_reuse.git_semver_package_name. -- Install and policy now route through the owner; update/outdated keeps its own derivation with different .git handling. - [Performance Expert] Evaluate whether the
DEFAULT_TAG_PATTERNSimport can avoid the full resolver graph on a cold audit. -- One-time ~10-30ms cost; declined here to keep the resolver's constant as the single source of truth.
Recommendation
The PR delivers the full approved scope for #3224 with zero open required findings across all five panelists. The two deferrals are pre-existing on main and outside scope. Recommended next action: Kaustubh Arora (@Kaustubh1235) signs the CLA, and Daniel Meppiel (@danielmeppiel) / Sergio Sisternes (@sergio-sisternes-epam) complete their CODEOWNERS review. The audit devDependencies follow-up is the highest-signal item to track after merge.
Folded in this run
- (copilot) Keep every direct declaration when dependency identities collide; a missing ref stays NO_REF -- resolved in cbb15de.
- (copilot) Take the git-tag package name from the resolver owner
ref_reuse.git_semver_package_name, guarded by a static check -- resolved in cbb15de. - (panel) Move the declared-ref snapshot to InstallContext construction (keeps
install/phases/resolve.pywithin its LOC budget after merging main) -- resolved in cbb15de. - (panel) Regression traps for duplicate declarations, declared None, owner routing, and policy_target_check wiring -- resolved in cbb15de.
- (panel) Real-binary contract:
apm updatenow selects a newly publishedpkg-a-v1.2.0through the policy check (a no-op update on current main returns before the pipeline), plus object-form and dependencies/devDependencies collision controls -- resolved in 395767e. - (panel) Packaged apm-guide governance guidance, CHANGELOG entry, trimmed policy-reference paragraph -- resolved in 7816250.
- (panel) Scope the CHANGELOG audit claim to
dependencies-- resolved in d186200. - PR body now ends with
Closes #3224(append-only); both Copilot threads answered and resolved; branch merged with current main.
Copilot signals reviewed
src/apm_cli/install/phases/resolve.py:421-- LEGIT: last-wins dict keyed by a ref-less unique key let a bounded devDependencies ref cover a branch (resolved in cbb15de).src/apm_cli/policy/_constraint_pinning.py:139-- LEGIT: package-name rule duplicated the git-semver owner with different .git handling (resolved in cbb15de).
Deferred (out-of-scope follow-ups)
- (panel) Extend
apm auditto evaluate devDependencies -- 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 on main in update/outdated, which this PR does not touch. - (panel) Lighter import for
DEFAULT_TAG_PATTERNS-- scope boundary: import-graph refactor of the resolver constants; current cost is one-time and noise-level.
Regression-trap evidence (mutation-break gate)
tests/unit/policy/test_pinned_constraint_declared.py::test_bounded_declaration_does_not_cover_an_unbounded_one-- deleted the per-key accumulation incollect_declared_refs; test FAILED as expected; guard restored.tests/unit/policy/test_pinned_constraint_declared.py::test_declared_missing_ref_stays_no_ref_after_a_tag_was_selected-- deleted the declared-None sentinel; test FAILED as expected; guard restored.tests/unit/policy/test_pinned_constraint_declared.py::test_tag_name_comes_from_the_resolver_owner-- replaced the owner call with a local derivation; test FAILED as expected; guard restored.tests/integration/policy/test_require_pinned_constraint_e2e.py::TestDeclaredRefsWiring-- deleted the pipeline snapshot; test FAILED as expected; guard restored.tests/integration/test_architecture_owner_rule_mutations.py::test_pinned_constraint_tag_name_must_use_resolver_owner-- deleted the new static subchecks; test FAILED as expected; guard restored.
Lint contract
ruff check and ruff format --check (src, tests, architecture linter scripts), pylint R0801 (10.00/10), lint-auth-signals.sh and lint-architecture-boundaries.sh all silent on the merged head.
CI
All 23 required checks green on 903968e (CI, Merge Gate, CodeQL, Spec conformance, NOTICE Drift, Deploy Docs, lifecycle smoke, Windows compatibility); license/cla pending until the author signs (after 0 CI fix iteration(s)).
Mergeability status
| PR | head SHA | CEO stance | iters | folds | defers | Copilot rounds | CI | mergeable | mergeStateStatus | notes |
|---|---|---|---|---|---|---|---|---|---|---|
| #3381 | 903968e |
ship_with_followups | 2 | 7 | 3 | 2 | green | MERGEABLE | BLOCKED | CLA unsigned; awaiting CODEOWNERS review |
Convergence
2 outer iteration(s); 2 Copilot round(s). Final panel stance: ship_with_followups. Ready for maintainer review.
Full per-persona findings
Python Architect
- [recommended] (iteration 1, resolved in cbb15de)
package_tag_nameduplicated_git_semver_package_namewith .git/rstrip divergence atsrc/apm_cli/policy/_constraint_pinning.py:128 - [recommended] (iteration 1, resolved in cbb15de)
declared_direct_refskeyed byget_unique_key()dropped duplicate declarations atsrc/apm_cli/install/phases/resolve.py:417 - Delta: no findings.
Test Coverage Expert
- [recommended] (iteration 1, resolved in cbb15de) no regression trap for the dependencies/devDependencies key collision.
- Delta: no findings.
Doc Writer
- [recommended] (iteration 1, resolved in 7816250) packaged apm-guide governance row still listed only
vX.Y.Ztags. - [recommended] (iteration 1, resolved in 7816250) missing CHANGELOG Fixed entry.
- [recommended] (delta, resolved in d186200) CHANGELOG implied
apm auditchecks devDependencies atCHANGELOG.md:16
Suggested: narrow the claim, or make audit read all apm dependencies (deferred above).
Performance Expert
- Iteration 1 import-weight remark declined (single source of truth). Delta: no findings.
Supply Chain Security Expert
- [recommended] (iteration 1, resolved in cbb15de) duplicate unique key across dependencies/devDependencies laundered an unbounded ref at
src/apm_cli/install/phases/resolve.py:421 - Delta: no findings.
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.
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]>
|
Thank you Kaustubh Arora (@Kaustubh1235) for this fix for #3224 -- the diagnosis, the declared-ref approach and the real-binary contract are excellent work. The Contributor License Agreement on this PR has stayed pending for more than 6 days, and we want this repair to ship in 0.36.0. So we rebuilt the same converged change (head 903968e) onto current main as #3652. Your authorship is credited via Closing this PR in favor of #3652. If anything there diverges from your intent, please say so on #3652 -- we would value your review. Generated by autopilot-pr-merge-worker. This comment is AI-generated and may contain errors. |
…gs (supersedes #3381) (#3652) * fix(policy): judge the declared constraint, accept package release tags 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]> * docs(policy): describe the bounded-choice pinned-constraint rule 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]> * docs(changelog): point the #3224 entry at successor PR #3652 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]> * fix(policy): snapshot declared deps after replace selection 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]> * fix(policy): apm audit judges replace: rules like the install gate 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: danielmeppiel <[email protected]> Co-authored-by: Kaustubh1235 <[email protected]> Co-authored-by: Copilot App <[email protected]>
|
sorry was delay was occupied with some urgent work |
|
@microsoft-github-policy-service agree |


Description
require_pinned_constraintnow judges the constraint the author declared, and recognises a package's own release tags.Two things were wrong. The resolve phase rewrites a direct dependency's in-memory reference to the tag its semver range selected, and the install gate runs after that, so
pkg-a#^1.0.0was judged aspkg-a-v1.1.0. The literal-tag classifier also only knewv{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.The resolve phase now snapshots the manifest-declared refs of the direct dependencies before any rewrite (
ctx.declared_direct_refs), andpolicy_gateandpolicy_target_checkpass that map torun_dependency_policy_checks, which classifies it in place of the rewritten reference. Nothing else sees a different reference: download, drift and lockfile work keep the resolved tag, and preflight and audit already held the manifest view. The classifier accepts{name}-v{version}and{name}--v{version}for the dependency's own package name only, reusing the resolver'sDEFAULT_TAG_PATTERNSandbuild_tag_regex, sopkg-b-v1.1.0,pkg-a-v1.1,release-pkg-a-v1.1.0andpkg-a_v1.1.0remain bare branches. The package name follows the resolver's rule (final virtual-path segment, else repository name), with a unit test asserting parity against_git_semver_package_name.Docs updated where the rule is described (
policy-reference.md,policy-schema.md,governance-on-the-consumer-ramp.md,manage-dependencies.md, and theREQUIRE_PINNED_CONSTRAINT_HELPtext), including correcting two places that said transitive deps are classified; the check has been direct-only since #1494.Issue and approved scope
Issue: #3224
Human scope-approval comment: #3224 (comment)
This PR completes the accepted issue scope. It does not request merge approval.
Type of change
Testing
Unit (
tests/unit/policy/test_pinned_constraint_declared.py, 13 tests): package-qualified forms for subdirectory and repository deps, prerelease and build suffixes, other-package and near-miss negatives, name parity with the resolver,declared_refprecedence (a declaredmainstays a violation after resolution replaced it with a tag; a declared>=1.0.0stays open-upper when the reference is a SHA), and_check_pinned_constraintswith and withoutdeclared_refs.Gate wiring (
TestDeclaredRefsWiringintest_require_pinned_constraint_e2e.py): pinned to the gate's own call. Verified it fails when either the gate stops forwardingdeclared_refsor the resolve phase stops recording them.Real binary (
tests/integration/policy/test_require_pinned_constraint_declared_e2e.py,e2e+requires_apm_binary): one local bare monorepo with a subdirectory package taggedpkg-a-v1.1.0/pkg-a--v1.1.0and the root taggedv1.0.0only, so^1.0.0resolves to the package-qualified tag the old gate rejected. Policy reachesinstallthe way the Govern contract does (ADO-shaped origin, leaf extending the strict policy at the cache-key path,policy statuswarm), and every governed command asserts the(cacheddiagnostic. Covers fresh install, frozen replay, repeat install,update --yesand audit for the range; the two literal forms; the repository-level range; andmain,pkg-b-v1.1.0,>=1.0.0blocked at install and failed by audit with the same hints. Audits are judged by thedependency-pinned-constraintcheck in the JSON, not the exit code.Local validation:
tests/unit/policy tests/unit/install tests/integration/policy tests/integration/test_policy_pinned_constraint_e2e.py: 4360 passed, 7 skipped, 1 xfailed.tests/spec_conformance/test_policy_reqs.pypasses. The real-binary contract passed on three consecutive runs. Ruff check and format clean on every changed file.Observed while writing the contract, out of scope here and identical on unmodified main (same scenario, same binary build, byte-for-byte the same lock and deployed state at every step): on this package shape,
install --frozenright after a fresh install redeploys the 1.0.0 skill while the lock still recordspkg-a-v1.1.0, and a plain repeatinstalldropsconstraintandresolved_tagand writes the raw range intoresolved_ref;update --yesrestores them. I'll file that separately with the probe script. The contract therefore asserts the policy verdict on those steps and not what they record.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 enumerates forms that MUST count as pinned and is unchanged. If the maintainers want req-pl-008 to list the package-qualified layouts explicitly, that would be a separate spec proposal under normal review.
Closes #3224