Skip to content

fix(policy): judge compilation-target on the canonical target set - #3774

Merged
Daniel Meppiel (danielmeppiel) merged 9 commits into
mainfrom
danielmeppiel-0361-t2-targets-policy
Nov 17, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 9 commits into
mainfrom
danielmeppiel-0361-t2-targets-policy

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Description

apm audit judged compilation.target policy from the raw target: key only, so a manifest using plural targets: passed whatever it listed (#3732). The same root cause, four call sites building four different target projections, also produced false positives and an inheritance hole.

User scenarios, before and after

Scenario Before After
targets: [claude, cursor], allow: [claude, copilot], apm audit --ci passes ("No compilation target set") fails on cursor (matches what apm install already blocked)
target: "claude,copilot" (CSV), same policy audit fails on the literal 'claude,copilot' passes
target: vscode / targets: [vscode], same policy audit and install fail on vscode pass; MCP config still lands in .vscode/mcp.json
policy allow: [all] rejects every target allows every target
target: all, narrow allow list fails on the literal 'all' fails naming the targets all actually installs
targets: [all] passes still passes (it is treated as omitted)
parent allow: [vscode, claude], child allow: [copilot] merged to "allow nothing" merged to [copilot]

How

  • One projection owner: EffectiveTargetDecision.canonical_targets (aliases resolved, all expanded, MCP-only targets mapped to their primitive profile). normalize_policy_targets is folded into it and removed.
  • canonical_policy_target_names / canonical_policy_target_name beside it canonicalize the policy side; policy/parser.py stores canonical compilation.target.allow/enforce, so inheritance intersects profiles.
  • _check_compilation_target(targets, policy, *, source) takes the canonical tuple, never a raw dict. Audit passes the manifest declaration through package_target_selection (decision A1); the install gate, apm install --mcp, and local-bundle install pass their EffectiveTargetDecision. The install gate no longer falls back to apm_package.target.
  • Static guard registry-delegation-policy-target-projection (registered on the effective-install-target-selection owner): every effective_target= handed to run_dependency_policy_checks / run_policy_preflight and every _check_compilation_target call must use .canonical_targets; no sibling normalizer may exist. One owner MutationCase plus three extra mutation tests.
  • Violation details name the selection source, e.g. targets: ['claude', 'cursor'] (source: apm.yml), allowed: ['claude', 'copilot'].

Supersedes #3739 by Mohammed Alkindi (@MohammedAlkindi): its five plural-key tests are ported to audit-level tests (real apm.yml through run_policy_checks), with Co-authored-by credit. That patch added a second raw reader and would have made targets: [all] fail as the literal all.

Follow-up PR-2 (stacked) routes every remaining package-level manifest target reader through one declaration owner on APMPackage, widens the target-vocabulary guard to deny-by-default, and rejects intellij / copilot-app in apm install before any write.

Issue and approved scope

Issue: Fixes #3732

Human scope-approval comment: #3732 (comment)

Does this PR complete the issue, or what remains? It completes the reporter's scenario (audit with plural targets:). The approved scope continues in the stacked PR-2 (declaration owner, deny-by-default guard, install pre-write rejection, compilation.target docs), which will reference #3732.

Type of change

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

Testing

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

Validation evidence (local, macOS, Python 3.12):

  • APM_E2E_TESTS=1 APM_BINARY_PATH=.venv/bin/apm pytest -p no:xdist tests/integration/policy/test_compilation_target_policy_e2e.py -- 6 passed. Against the v0.36.0 sources the same file fails L1 (plural bypass), L2 (CSV), L3 (alias audit) and the alias install case; L4 (targets: [all]) and L5 (plural install block) pass on both, as regression locks.
  • pytest -p no:xdist tests/unit/policy tests/unit/core/test_target_detection.py tests/unit/install/test_policy_target_check_phase.py tests/unit/install/test_mcp_preflight_policy.py tests/unit/install/test_install_local_bundle*.py tests/unit/install/test_policy_gate_phase.py tests/unit/install/test_no_policy_flag.py tests/unit/test_install_pipeline_*.py tests/unit/test_install_command.py tests/integration/test_intellij_target.py tests/integration/test_wave7_policy_registry_coverage.py tests/integration/test_mcp_install_flow.py -- passed (one pre-existing network-dependent failure in test_coverage_phase4.py, unrelated).
  • pytest -p no:xdist tests/integration/test_architecture_owner_rule_mutations.py -k "policy_target or test_matrix_covers or test_matrix_case_order" -- passed.
  • uvx ruff@0.15.12 check / format --check on the CI paths -- clean.
  • python -m pylint --disable=all --enable=R0801 --min-similarity-lines=10 --fail-on=R0801 src/apm_cli/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/ -- 10.00/10.
  • bash scripts/lint-auth-signals.sh -- clean. bash scripts/lint-architecture-boundaries.sh -- clean.

Behavior change for release notes: a non-compliant plural targets: manifest now fails apm audit --ci under a compilation.target policy. apm install already blocked these manifests under enforcement: block.

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-spec-waiver: compilation-target policy evaluation is APM policy behavior; OpenAPM v0.1 does not specify it

apm audit read only the singular `target:` key, so a manifest using plural
`targets:` passed compilation-target policy whatever it listed (#3732).
Audit and every install seam now hand the check the
EffectiveTargetDecision.canonical_targets projection, and the policy parser
canonicalizes compilation.target.allow/enforce through the same owner:

- plural `targets:` is judged in audit, matching the install gate;
- CSV `target: "claude,copilot"` is split instead of failing as one token;
- aliases compare as the profile they deploy (vscode/agents -> copilot,
  agy -> antigravity, intellij -> copilot) on both sides;
- `target: all` is judged as its install expansion; `targets: [all]`
  stays omitted; `all` in an allow list means unrestricted;
- inherited alias allow lists no longer intersect to "allow nothing".

normalize_policy_targets is folded into EffectiveTargetDecision and a new
registry-delegation-policy-target-projection guard keeps every
compilation-target seam on that projection.

Fixes #3732. Supersedes #3739 and reuses its plural-key tests.

apm-spec-waiver: compilation-target policy evaluation is APM policy behavior; OpenAPM v0.1 does not specify it

Co-authored-by: Mohammed Alkindi <alkndymhmd692@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 15:45
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.36.1 milestone Nov 17, 2026
Co-authored-by: Mohammed Alkindi <alkndymhmd692@gmail.com>
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

The governance guide incorrectly guarantees both constraints are satisfied, although enforce takes precedence over allow and can permit disallowed targets.

1 open issue
What changed in this PR

Fixes #3732 by making compilation-target policy checks use a shared canonical target set, closing the plural targets: audit bypass and aligning target comparisons across audit and install.

Changes:

  • Canonicalizes aliases, CSV selections, and all semantics, including policy inheritance.
  • Routes audit, standard install, direct MCP install, and local-bundle checks through the shared target projection.
  • Adds regression tests and an architecture guard, and updates policy documentation and release notes.
File Description
tests/​unit/​policy/​test_run_dependency_policy_checks.py Updates checks to canonical target tuples.
tests/​unit/​policy/​test_policy_checks.py Covers plural declarations, aliases, CSV, and all.
tests/​unit/​policy/​test_parser.py Expects canonical policy target names.
tests/​unit/​policy/​test_integration_pinned_constraint.py Updates the target-check input format.
tests/​unit/​policy/​test_inheritance.py Tests alias-aware allow-list inheritance.
tests/​unit/​install/​test_policy_target_check_phase.py Verifies shared decisions and selection sources.
tests/​unit/​install/​test_mcp_preflight_policy.py Uses canonical tuples in MCP preflight tests.
tests/​unit/​core/​test_target_detection.py Tests canonical projection and runtime destination preservation.
tests/​integration/​test_wave7_policy_registry_coverage.py Updates policy integration checks to canonical inputs.
tests/​integration/​test_architecture_owner_rule_mutations.py Adds projection-guard mutation tests.
tests/​integration/​policy/​test_compilation_target_policy_e2e.py Adds real-binary audit and install regression scenarios.
tests/​fixtures/​policy/​golden/​parsed-policies.json Refreshes canonical policy expectations.
src/​apm_cli/​policy/​policy_checks.py Evaluates canonical selections and reports their sources.
src/​apm_cli/​policy/​parser.py Canonicalizes target constraints before inheritance.
src/​apm_cli/​policy/​install_preflight.py Accepts canonical tuples and forwards source details.
src/​apm_cli/​install/​phases/​policy_target_check.py Uses the shared decision instead of raw manifest fallback.
src/​apm_cli/​install/​mcp/​command.py Passes canonical targets to MCP preflight.
src/​apm_cli/​install/​local_bundle_handler.py Projects bundle deployment targets for policy checks.
src/​apm_cli/​core/​target_detection.py Centralizes target-profile mapping and policy normalization.
scripts/​architecture_linter/​checks/​registry_owner_guards.py Guards canonical projection at policy call sites.
packages/​apm-guide/​.apm/​skills/​apm-usage/​governance.md Explains canonical policy comparisons.
docs/​src/​content/​docs/​reference/​policy-schema.md Updates target constraint descriptions.
docs/​src/​content/​docs/​enterprise/​policy-reference.md Documents declaration forms and audit/install scope.
docs/​src/​content/​docs/​enterprise/​governance-guide.md Updates target enforcement scope and guarantees.
CHANGELOG.md Records policy fixes and contributor credit.
.apm/​architecture/​owners/​core-runtime.json Registers policy projection ownership and its guard.

Review effort: Balanced

@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_with_followups

Community-reported governance-bypass fix is architecturally sound; ship after the mechanical CI fix and one doc reword.

panel-mode=lean; personas=python-architect,supply-chain-security-expert,test-coverage-expert,apm-ceo

cc Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

All three panelists converged on the same structural read: the PR closes the community-reported audit bypass (#3732) by making one canonical target tuple the unit of judgment across audit, the install gate, apm install --mcp, and local-bundle install. The python-architect confirmed single-authority ownership and a sound guard; the test-coverage-expert mapped every scenario row to a regression trap; the supply-chain-security-expert confirmed fail-closed handling of unknown spellings and tighten-only inheritance.

The one point of tension is the enforce versus allow precedence raised by the supply-chain-security-expert and the Copilot inline review. policy-reference.md already documents that enforce takes precedence (the code is if enforce ... elif allow). Changing runtime behavior to check both would be an undeclared governance behavior change riding on a patch-release bug fix, so it belongs in its own scoped issue. The governance-guide.md line 311 wording, however, implies both constraints are always checked; that doc-accuracy fix should land in this PR.

The Build & Test Shard 2 failure is mechanical: tests/unit/scripts/test_architecture_runner.py::test_registered_rule_inventory_matches_frozen_semantic_contract needs the new rule id registry_delegation.policy_target_projection in its frozen inventory. That is squarely in scope.

Dissent. No material disagreement. The only judgment call was docs-fix-now versus code-change-now for enforce/allow precedence; the panel sides with the doc fix now and a separate scoped issue for any stricter semantic.

Aligned with: Governed by policy: closes an audit bypass on an org enforcement surface. Portable by manifest: one canonical target tuple is judged in audit, install gate, MCP, and local bundle. Secure by default: unknown spellings fail closed and inheritance only narrows. OSS community driven: Jake Aitchison (@milkshakeuk)'s report is fixed and the tests from Mohammed Alkindi (@MohammedAlkindi)'s #3739 are ported with credit.

Panel summary

Persona B R N Takeaway
Python Architect 0 1 0 Single-authority centralization is sound; guard covers the right seams with mutation tests; one doc line misstates enforce/allow precedence.
Supply Chain Security Expert 0 1 0 The #3732 bypass is closed: canonical projection, fail-closed unknowns, guards, and tighten-only inheritance are sound. One doc overpromise.
Test Coverage Expert 0 1 0 Scenarios 1-7 each have regression traps at the right tier. The local-bundle seam lacks a mutation test.

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Top 4 follow-ups

  1. [Python Architect] Add registry_delegation.policy_target_projection to _EXPECTED_RULE_IDS in tests/unit/scripts/test_architecture_runner.py. -- Build & Test Shard 2 is red on the frozen rule inventory check.
  2. [Supply Chain Security Expert] Reword governance-guide.md line 311 to state that enforce takes precedence over allow. -- The current wording overpromises the security contract; python-architect and the Copilot inline review concur.
  3. [Test Coverage Expert] Add a local-bundle case to test_policy_target_projection_guard_rejects_raw_selections. -- Proves the guard fires on the fifth seam; defense in depth.
  4. [Supply Chain Security Expert] Open an issue to evaluate checking both enforce and allow in a future minor. -- A stricter semantic is a behavior change that needs its own declared scope.

Recommendation

Ship after two in-PR edits: (1) add registry_delegation.policy_target_projection to the frozen rule inventory so Build & Test Shard 2 goes green, and (2) reword governance-guide.md line 311 to state that enforce takes precedence over allow. Neither changes runtime behavior. The local-bundle mutation case is cheap and worth folding while the branch is open. A follow-up issue can evaluate checking both enforce and allow in a future minor.


Full per-persona findings

Python Architect

  • [recommended] governance-guide.md line 311 says the selection matches allow AND enforce, but the code uses elif so only one applies at docs/src/content/docs/enterprise/governance-guide.md:311
    _check_compilation_target uses if enforce ... elif allow; when enforce is set, allow is never evaluated. The doc must reflect the single code authority. Concurs with the Copilot inline thread. Other notes: lazy imports flow policy -> core only (no cycle); canonical_policy_target_names returning None for all cleanly separates unrestricted from an empty allow list; enforce: all expansion reuses the canonical authority.
    Suggested: "checked against compilation.target.enforce (if set) or compilation.target.allow (otherwise), compared after aliases resolve."

Supply Chain Security Expert

  • [recommended] governance-guide.md:311 promises both allow AND enforce are checked, but allow is skipped when enforce is set at docs/src/content/docs/enterprise/governance-guide.md:311
    Scenario: enforce: copilot, allow: [copilot, claude], targets: [copilot, cursor] passes. An admin reading the guide would believe cursor is denied; it is not.
    Suggested: Make the doc match the elif semantics, or check both in code (stricter, but a runtime behavior change).

Test Coverage Expert

  • [recommended] Local-bundle policy-projection call site has no mutation test proving the architecture guard fires there. at tests/integration/test_architecture_owner_rule_mutations.py
    local_bundle_handler.py passes deployment_decision.canonical_targets to run_policy_preflight. The static rule scans all of src/, so the seam is guarded; the gap is proof that the guard fires on this path.
    Suggested: Add pytest.param("src/apm_cli/install/local_bundle_handler.py", "effective_target=deployment_decision.canonical_targets,", "effective_target=[resolved.name for resolved in targets],", id="local-bundle-raw-names").
    Proof (missing at): tests/integration/test_architecture_owner_rule_mutations.py::test_policy_target_projection_guard_rejects_raw_selections[local-bundle-raw-names] -- proves: A regression of the local bundle install back to raw target names is caught by the architecture guard [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-review-worker. This comment is AI-generated and may contain errors.

Add registry_delegation.policy_target_projection to the frozen rule
inventory so test_registered_rule_inventory_matches_frozen_semantic_contract
matches the registered rules (Build & Test Shard 2 was red). Add the
local-bundle install seam to the policy-target projection mutation test,
and scope each case's assertion to a violation in the mutated file so an
unrelated violation elsewhere cannot satisfy it. Mutation-break: dropping
run_policy_preflight from the guard's seams fails the new case.

Addresses panel follow-ups 1 and 3 on #3774.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The install guarantees said the selection matches both
compilation.target.allow and compilation.target.enforce, but the check
evaluates enforce first and skips allow when enforce is set, as the
policy reference already documents.

Addresses Copilot inline review on governance-guide.md:311 and panel
follow-up 2 on #3774.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_now

Delta clean: all three actionable follow-ups folded, the mutation-break tightening strengthens the guard, CI green. Ready pending CODEOWNERS sign-off.

panel-mode=delta; personas=test-coverage-expert,apm-ceo

cc Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

Material delta since the last advisory (fe385f4): the three actionable items from the lean pass are resolved. The frozen rule inventory fix and the local-bundle mutation case landed in f4bdfdc, with the projection mutation test tightened to require a violation in the mutated file rather than accepting an unrelated one -- a quality uplift the mutation-break exposed. The governance-guide wording landed in 0a9af04 and the Copilot inline thread is resolved. Main was merged in cleanly (18fbe82).

The sole panelist this pass, test-coverage-expert, returned zero new findings: the local-bundle seam gap is closed and no coverage hole was introduced. Checking enforce and allow together at runtime stays deferred: it is a governance behavior change outside the accepted #3732 scope and belongs in its own issue.

Aligned with: Governed by policy: the new guard is in the frozen rule inventory and the guide states enforce precedence accurately. Secure by default: the local-bundle guard and the audit behavior are both proven by mutation-break. Pragmatic as npm: deferring the conjunctive enforce/allow question keeps this patch focused.

Panel summary

Persona B R N Takeaway
Test Coverage Expert 0 0 0 Prior local-bundle seam gap closed: mutation param added, assertion scoped to the mutated path, rule inventory updated. No new coverage holes.

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Top 1 follow-ups

  1. [Supply Chain Security Expert] Open a tracked issue to evaluate checking compilation.target.enforce and allow together. -- Today enforce takes precedence and allow is not consulted when both are set; making them conjunctive is a governance semantics change outside the compilation-target policy check ignores the plural targets: key #3732 scope.

Recommendation

Every actionable follow-up from the lean pass is folded and verified by CI and mutation-break evidence. The remaining item is a deferred design question outside #3732. The PR is implementation-complete and waits only on the required CODEOWNERS review.

Folded in this run

  • (panel) Add registry_delegation.policy_target_projection to the frozen rule inventory (Build & Test Shard 2 was red) -- resolved in f4bdfdc.
  • (panel) Local-bundle case in test_policy_target_projection_guard_rejects_raw_selections; assertions scoped to the mutated path -- resolved in f4bdfdc.
  • (copilot) governance-guide.md:311 states that enforce takes precedence over allow -- resolved in 0a9af04.
  • (panel) Same doc reword raised by supply-chain-security-expert and python-architect -- resolved in 0a9af04.

Copilot signals reviewed

  • docs/src/content/docs/enterprise/governance-guide.md:311 -- LEGIT: the bullet promised allow AND enforce; the code evaluates enforce first and skips allow, as policy-reference.md documents (resolved in 0a9af04).

Deferred (out-of-scope follow-ups)

Regression-trap evidence (mutation-break gate)

  • tests/integration/test_architecture_owner_rule_mutations.py::test_policy_target_projection_guard_rejects_raw_selections[local-bundle-raw-names] -- deleted run_policy_preflight from the guard's seams; test FAILED as expected; guard restored.
  • tests/unit/policy/test_policy_checks.py::TestAuditCompilationTargetFromManifest -- reverted audit to the raw target: key; 3 cases FAILED as expected; restored.

Lint contract

ruff check and ruff format --check (ruff 0.15.12, CI paths) both silent; pylint R0801 10.00/10; auth-signal and architecture-boundary lints clean.

CI

gh pr checks 3774: 23 pass, 3 skipping, 0 fail at 18fbe82 (CI run 44127103016, required-checks workflow 44127103153) (after 1 CI fix iteration(s)).

Mergeability status

PR head SHA CEO stance iters folds defers Copilot rounds CI mergeable mergeStateStatus notes
#3774 18fbe82 ship_now 1 4 1 1 green MERGEABLE BLOCKED pending required review

Convergence

1 outer iteration(s); 1 Copilot round(s). Final panel stance: ship_now. Ready for maintainer review.

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.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Avoids landing-order conflicts with other queued PRs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 17, 2026
apm-spec-waiver: merge of the stacked base PR only; no new spec-observable behavior in this commit

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Lane L: main merged for landing

  • Pre-merge head: 18fbe820a0f7777799d615124a3f74f76d28f8a9
  • Merged origin/main 82f8047b70b35920f8db9e02940c7e2770c566f2 (clean merge; GitHub reported DIRTY only on CHANGELOG.md, which this repo merges with merge=union).
  • New head: 4005f6bc1640effbd2f349c60c3b557fa30fcddb
  • CHANGELOG: moved 1 bullet(s) in '### Fixed' after entry Integrate copilot runtime #2 of 2, so queued PRs no longer collide at the section head while landing serially.
  • Lint: ruff check + ruff format --check silent at the new head; CI green at the new head.
  • Owner-touch report regenerated at the new head; every recorded functional test was re-run at that exact head and passed (one process at a time, no xdist).
  • Push: git push https://github.com/microsoft/apm.git HEAD:refs/heads/danielmeppiel-0361-t2-targets-policy (plain push, no force).

This comment was generated by an AI agent (Lane L landing desk) on behalf of Daniel Meppiel (@danielmeppiel).

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 59925cd into main Nov 17, 2026
26 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-0361-t2-targets-policy branch November 17, 2026 20:55
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 17, 2026
…61-t2-target-declaration

#3774 landed, so this branch now carries only the PR-2 delta. Kept the
PR-2 target-vocabulary mutation test after #3774's projection test, and
rebuilt the [Unreleased] CHANGELOG block from main plus the #3791 entry.

apm-spec-waiver: merge of main only; no new spec-observable behavior in this commit

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 17, 2026
… main

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 18, 2026
…er (#3790)

* fix(auth): route every Azure DevOps egress through one auth chain owner

AuthResolver.try_with_fallback is now the single entry for authenticated
host access. A new core/auth_outcome.py owns auth-outcome classification
(401/403, a redirect to the ADO sign-in service, an HTML sign-in page, Git
auth errors) and core/auth_chain.py walks ADO_APM_PAT -> az bearer ->
path-scoped git credential fill, recording an AuthAttemptLog that
diagnostics render.

- Route install validation, clone, ref resolution, install --update
  preflight, ADO file downloads, org policy discovery (ADO, GitHub with
  per-org PAT, GitLab) and marketplace REST/ref paths through the chain.
- Helper credentials keep their username (GitHelperCredential) and are
  sent as Basic username:password, cached per (host, port, path).
- git credential fill sets GCM_INTERACTIVE=0 when stdin is not a TTY or
  CI is set; APM never calls credential approve/reject.
- Azure DevOps requests use only the credential chosen by the auth chain.
- #3753: az token failures show the Azure CLI reason; the exhausted chain
  lists every step in order; "bearer token" is no longer redacted.
- Remove execute_with_bearer_fallback; is_ado_auth_failure_signal and
  is_public_github_auth_failure become thin classifier wrappers.
- Static guard transport-platform-auth-outcome-owner on the
  host-credential-resolution owner record, with a mutation case.

No live Azure DevOps organization was available: behavior follows the
documented contracts and is validated by hermetic tests.

Fixes #3752
Fixes #3758
Fixes #3753

apm-spec-waiver: auth chain owner refactor with no spec surface change

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* docs(changelog): reference #3790 for the ADO auth chain fixes

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(auth): cover marketplace exhausted-chain error; widen approve/reject guard

Fold panel follow-ups on #3790: RefResolver converts an exhausted ADO
chain into GitLsRemoteError naming every step (new integration test), and
transport-platform-auth-outcome-owner also rejects shell-string forms of
git credential approve/reject.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(auth): fold Copilot review on ADO helper path, tenant cache, sign-in redirects

- Legacy *.visualstudio.com remotes query the credential helper with the
  Project/_git/repo path the helper stores.
- Tenant id lookup is single-flight under a lock.
- ADO file downloads and marketplace ADO REST fetches no longer follow
  redirects; a sign-in 3xx reaches the classifier and the chain escalates.

apm-spec-waiver: review folds inside the approved auth owner scope

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* chore(lock): refresh auth skill deployed hash

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(auth): route remaining preflight and bare-clone tests through the chain

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(auth): classification never raises on non-exception error objects

The cause-chain walk follows __cause__/__context__ only through real
exceptions, and any other error value is read as text.

apm-spec-waiver: hardening inside the approved auth classifier owner

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(marketplace): ADO REST fetch sends the chain credential through the redirect owner

The ADO items fetch sends only the chain-selected Authorization header,
disables ambient credentials, and refuses the cross-origin sign-in
redirect so the auth chain classifies the 3xx and escalates.

apm-spec-waiver: adapts the approved auth owner to the redirect owner API

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(auth): carry RT1 upgrade-replay and adjacent-egress lifecycle cells; widen resolve fakes

- Add RT1's lock replay (0.35.1 / 0.36.0 locks) and ADO adjacent-egress
  installed-CLI scenarios byte-for-byte.
- Resolver test doubles accept the port/host_type keywords the chain now
  passes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(policy): drop T2 xfail now that canonical targets (#3774) are on main

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(auth): re-lock per-step credential isolation and policy env-token fallback

- Every ADO chain step's git env carries only its own Authorization header,
  suppresses credential helpers, and holds no PAT, bearer, or ambient
  GitHub token from another step (PAT -> bearer -> helper and tokenless).
- A failing AuthResolver never lets the GitHub policy fetch fall back to
  GITHUB_TOKEN, GITHUB_APM_PAT, or GH_TOKEN from the environment.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(auth): assert the narrow exhausted-chain exception

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(deps): route integration ADO download doubles through the auth chain

The TestDownloadAdoFile host doubles left auth_resolver.try_with_fallback
as a bare MagicMock, so download_ado_file returned a mock instead of
exercising 404 fallback, auth exhaustion, and network errors. They now
install the simulated chain the unit twin uses, which runs the real
AuthResolver chain against the mocked transport.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: danielmeppiel <danielmeppiel@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 18, 2026
…er (#3791)

* fix(policy): judge compilation-target on the canonical target set

apm audit read only the singular `target:` key, so a manifest using plural
`targets:` passed compilation-target policy whatever it listed (#3732).
Audit and every install seam now hand the check the
EffectiveTargetDecision.canonical_targets projection, and the policy parser
canonicalizes compilation.target.allow/enforce through the same owner:

- plural `targets:` is judged in audit, matching the install gate;
- CSV `target: "claude,copilot"` is split instead of failing as one token;
- aliases compare as the profile they deploy (vscode/agents -> copilot,
  agy -> antigravity, intellij -> copilot) on both sides;
- `target: all` is judged as its install expansion; `targets: [all]`
  stays omitted; `all` in an allow list means unrestricted;
- inherited alias allow lists no longer intersect to "allow nothing".

normalize_policy_targets is folded into EffectiveTargetDecision and a new
registry-delegation-policy-target-projection guard keeps every
compilation-target seam on that projection.

Fixes #3732. Supersedes #3739 and reuses its plural-key tests.

apm-spec-waiver: compilation-target policy evaluation is APM policy behavior; OpenAPM v0.1 does not specify it

Co-authored-by: Mohammed Alkindi <alkndymhmd692@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* docs(changelog): compilation-target policy fix (#3774)

Co-authored-by: Mohammed Alkindi <alkndymhmd692@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(arch): register policy-target-projection rule and pin local bundle

Add registry_delegation.policy_target_projection to the frozen rule
inventory so test_registered_rule_inventory_matches_frozen_semantic_contract
matches the registered rules (Build & Test Shard 2 was red). Add the
local-bundle install seam to the policy-target projection mutation test,
and scope each case's assertion to a violation in the mutated file so an
unrelated violation elsewhere cannot satisfy it. Mutation-break: dropping
run_policy_preflight from the guard's seams fails the new case.

Addresses panel follow-ups 1 and 3 on #3774.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* docs(governance): state that target enforce takes precedence over allow

The install guarantees said the selection matches both
compilation.target.allow and compilation.target.enforce, but the check
evaluates enforce first and skips allow when enforce is set, as the
policy reference already documents.

Addresses Copilot inline review on governance-guide.md:311 and panel
follow-up 2 on #3774.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* refactor(targets): route every manifest target reader through one owner

Package-level `target:` / `targets:` is now read only through
ManifestTargetDeclaration (models/manifest_targets.py), exposed as
APMPackage.target_declaration, package_target_declaration(),
read_manifest_target_declaration() and manifest_target_restriction().
Compile, the install targets phase, MCP/LSP integration, lockfile
reconciliation, the build orchestrator, the audit target hint, the
package-target filter and init re-init no longer re-read or re-parse the
raw keys.

- `apm install` rejects `target: intellij` / `copilot-app` before writing
  anything (it used to deploy files and a lockfile, then exit 2).
- singular `target: all` no longer prints "treating the field as omitted"
  while install expands it; `apm init` re-init writes its expansion
  instead of narrowing it to `targets: [all]`.
- docs: `compilation.target` is documented as ignored by `apm compile`.

The registry-delegation-target-vocabulary rule is widened to
deny-by-default over src/apm_cli with concept-named exemptions, and a new
manifest-target-declaration owner record registers its guard.

Refs #3732

apm-spec-waiver: routes existing manifest target readers through one owner; OpenAPM-observable acceptance is unchanged

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* docs(changelog): manifest target declaration owner (#3791)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(architecture): scope target exemptions to the marked statement

The deny-by-default target guard let an exemption marker cover a whole
block (marker above an if/for/try exempted its body) and the line after a
trailing marker, so a raw package.targets read placed inside an exempted
block went unflagged. A marker now covers only the innermost statement
holding the read (its header for compound statements) or sits alone on
the line directly above it. The guard also flags .pop/.setdefault on the
target keys. Existing init and compilation.target exemptions are marked
per statement. Mutation cases cover a read leaking out of an exempt block,
a trailing-marker leak, and the subscript, key-test and pop shapes.

Addresses panel follow-up 2 (test-coverage-expert, python-architect) on #3791.

apm-spec-waiver: architecture guard and exemption markers only; no OpenAPM-observable behavior change

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(targets): route compile -g and disk readers through the declaration owner

apm compile -g still re-read ~/.apm/apm.yml with its own parser and, for
target: all, printed the "treating the field as omitted" warning that
install no longer prints. read_manifest_target_declaration is now the one
disk reader (strict: refuses symlinks, empty and non-mapping documents;
lenient: returns None), and compile -g, audit's read_manifest_target and
install's declared_target_profiles go through it. read_declared_target_names
is removed; restriction() gains allow_empty_singular for strict readers.

The pre-write rejection moves into reject_undeployable_manifest_targets
(keeps install/pipeline.py under its LOC budget) and also runs before the
CLI renames a legacy apm.lock, so a rejected install writes nothing. Re-init
expands singular target: all with the install spellings, so vscode keeps its
.vscode/mcp.json destination instead of becoming copilot (.github/mcp.json).

Tests: e2e for compile -g without the warning, -g pre-write rejection,
legacy lockfile untouched on rejection, and the MCP destination after
re-init; unit tests for the strict/lenient reader; drift tests patch the
owner's parser.

Addresses panel follow-ups 1 and 3 and Copilot inline comments on
src/apm_cli/install/pipeline.py:443 and src/apm_cli/models/manifest_targets.py:155.

apm-spec-waiver: routes existing manifest target readers through one owner; OpenAPM-observable acceptance is unchanged

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(targets): close delta-panel gaps in exemption scope and strict reads

A marker on a block's first body line still exempted raw reads in the
enclosing if/for/with header, because comment lines between a header and
its body counted as header lines. Those lines now belong to the body, and
match blocks end their header at the first case. compile -g silently
compiled every harness for singular target: all,<x>, which install -g
rejects; restriction(strict=True) (renamed from allow_empty_singular) now
raises the same "all cannot be combined" error. A direct
run_install_pipeline test pins the pipeline's own pre-write gate, which
the CLI's earlier call otherwise hides.

Addresses delta panel findings (python-architect, test-coverage-expert) on #3791.

apm-spec-waiver: routes existing manifest target readers through one owner; OpenAPM-observable acceptance is unchanged

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* chore(changelog): place #3774 entry away from the section head

Avoids landing-order conflicts with other queued PRs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: danielmeppiel <danielmeppiel@users.noreply.github.com>
Co-authored-by: Mohammed Alkindi <alkndymhmd692@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 18, 2026
…3823)

* fix(auth): route every Azure DevOps egress through one auth chain owner

AuthResolver.try_with_fallback is now the single entry for authenticated
host access. A new core/auth_outcome.py owns auth-outcome classification
(401/403, a redirect to the ADO sign-in service, an HTML sign-in page, Git
auth errors) and core/auth_chain.py walks ADO_APM_PAT -> az bearer ->
path-scoped git credential fill, recording an AuthAttemptLog that
diagnostics render.

- Route install validation, clone, ref resolution, install --update
  preflight, ADO file downloads, org policy discovery (ADO, GitHub with
  per-org PAT, GitLab) and marketplace REST/ref paths through the chain.
- Helper credentials keep their username (GitHelperCredential) and are
  sent as Basic username:password, cached per (host, port, path).
- git credential fill sets GCM_INTERACTIVE=0 when stdin is not a TTY or
  CI is set; APM never calls credential approve/reject.
- Azure DevOps requests use only the credential chosen by the auth chain.
- #3753: az token failures show the Azure CLI reason; the exhausted chain
  lists every step in order; "bearer token" is no longer redacted.
- Remove execute_with_bearer_fallback; is_ado_auth_failure_signal and
  is_public_github_auth_failure become thin classifier wrappers.
- Static guard transport-platform-auth-outcome-owner on the
  host-credential-resolution owner record, with a mutation case.

No live Azure DevOps organization was available: behavior follows the
documented contracts and is validated by hermetic tests.

Fixes #3752
Fixes #3758
Fixes #3753

apm-spec-waiver: auth chain owner refactor with no spec surface change

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* docs(changelog): reference #3790 for the ADO auth chain fixes

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(auth): cover marketplace exhausted-chain error; widen approve/reject guard

Fold panel follow-ups on #3790: RefResolver converts an exhausted ADO
chain into GitLsRemoteError naming every step (new integration test), and
transport-platform-auth-outcome-owner also rejects shell-string forms of
git credential approve/reject.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(auth): fold Copilot review on ADO helper path, tenant cache, sign-in redirects

- Legacy *.visualstudio.com remotes query the credential helper with the
  Project/_git/repo path the helper stores.
- Tenant id lookup is single-flight under a lock.
- ADO file downloads and marketplace ADO REST fetches no longer follow
  redirects; a sign-in 3xx reaches the classifier and the chain escalates.

apm-spec-waiver: review folds inside the approved auth owner scope

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* chore(lock): refresh auth skill deployed hash

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(auth): route remaining preflight and bare-clone tests through the chain

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(auth): classification never raises on non-exception error objects

The cause-chain walk follows __cause__/__context__ only through real
exceptions, and any other error value is read as text.

apm-spec-waiver: hardening inside the approved auth classifier owner

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* arch: add authenticated-egress ownership guard

Add transport-platform-authenticated-egress, an AST architecture-linter
rule that keeps HTTP egress primitives (requests verbs and sessions,
urllib urlopen) and literal credential header keys in their owner
modules or in a frozen, reasoned inventory that can only shrink.

The rule carries two guard ids registered on host-credential-resolution
and credential-origin-scope. lint-auth-signals.sh drops stale Rule A
exemptions and Rule B now defers to the architecture linter.

Refs #3752, #3726

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(marketplace): ADO REST fetch sends the chain credential through the redirect owner

The ADO items fetch sends only the chain-selected Authorization header,
disables ambient credentials, and refuses the cross-origin sign-in
redirect so the auth chain classifies the 3xx and escalates.

apm-spec-waiver: adapts the approved auth owner to the redirect owner API

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(auth): carry RT1 upgrade-replay and adjacent-egress lifecycle cells; widen resolve fakes

- Add RT1's lock replay (0.35.1 / 0.36.0 locks) and ADO adjacent-egress
  installed-CLI scenarios byte-for-byte.
- Resolver test doubles accept the port/host_type keywords the chain now
  passes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(policy): drop T2 xfail now that canonical targets (#3774) are on main

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(auth): re-lock per-step credential isolation and policy env-token fallback

- Every ADO chain step's git env carries only its own Authorization header,
  suppresses credential helpers, and holds no PAT, bearer, or ambient
  GitHub token from another step (PAT -> bearer -> helper and tokenless).
- A failing AuthResolver never lets the GitHub policy fetch fall back to
  GITHUB_TOKEN, GITHUB_APM_PAT, or GH_TOKEN from the environment.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(auth): assert the narrow exhausted-chain exception

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* arch: route remaining credential egress through the owners

Policy fetches (URL, GitHub, Azure DevOps, GitLab), the Artifactory
boundary probe and the install validation GitHub probe now send through
origin_bounded_request. Policy and probe redirects away from the
requested resource stay unfollowed and are reported as before.
Literal credential headers move to AuthResolver.github_rest_headers,
AuthResolver.bearer_headers and RegistryAuthContext.headers.

The authenticated-egress inventory drops every pending entry; the
origin-bounded-redirect inventory drops the policy and Artifactory
entries; lint-auth-signals Rule B also defers auth-outcome-owner.

Refs #3752, #3726

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(marketplace): drop final-URL HTTPS recheck owned by origin_bounded_request

The origin-bounded owner sends every hop without automatic redirects and
refuses HTTPS downgrades, so the response URL check in _fetch_url_direct
could never fire. The test now drives a downgrade redirect through the
owner instead of faking a final URL.

Refs #3726

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* arch(auth): route the ADO file download through the redirect owner

DownloadDelegate.resilient_get takes redirect_base instead of
allow_redirects; when set, every retry attempt goes through
origin_bounded_request bounded to that base, with ambient netrc
excluded. download_ado_file passes its request URL, so no redirect is
followed and a sign-in 3xx still reaches the auth-outcome classifier.
The 429/503/connection retry and backoff loop is unchanged.

A shared owner helper, unfollowed_redirect_request, returns the
refused 3xx instead of raising; policy fetches and the Artifactory
boundary probe use it too. The download_strategies entry leaves the
origin-bounded-redirect inventory.

apm-spec-waiver: redirect routing inside the approved auth and redirect owners

Refs #3752, #3726

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(install): retarget the GitHub probe integration double to the owner seam

Refs #3752

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(arch): pin the urllib metadata vector in the egress mutation case

The authenticated-egress owner case now reintroduces urllib.request.urlopen
in the marketplace metadata fetch; direct requests.get egress stays covered
by the rule's unit tests.

Refs #3726

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(auth): fold review panel findings on the egress guard

- unfollowed_redirect_request now follows no redirect (max_hops=0), so a
  same-path 3xx is returned like any other; pinned with a real-socket
  test plus Artifactory and ADO download retry cases.
- The validation GitHub probe treats a refused redirect as inconclusive
  and leaves the decision to the download step, with a verbose reason.
- The egress guard reads its credential header vocabulary from
  CREDENTIAL_HEADER_NAMES (adds Proxy-Authorization) and pins an exact
  site count per inventory entry; the resilient_get reason now states
  what the code does.
- deps/registry/auth.py header ownership narrows to RegistryAuthContext;
  owner records name the new helpers and consumers.
- Tests assert the probe's token header and the REST header builders.

apm-spec-waiver: review folds inside the approved auth and redirect owners

Refs #3752, #3726

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* fix(policy): keep URL credentials on direct policy fetches; widen egress prefilter

- policy_get moves userinfo from a direct policy URL into an explicit Basic
  header through the new http_credentials.split_url_credentials owner
  helper, matching the previous requests behaviour. Redirect targets that
  embed userinfo stay refused. Covered by a transport-level test that only
  mocks the adapter send.
- The egress guard prefilter also matches 'session', so session-receiver
  calls in modules without other HTTP tokens are scanned.
- The no-follow regression test covers query and descendant-path shapes.

apm-spec-waiver: review folds inside the approved auth and redirect owners

Refs #3726

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* test(install): make the Artifactory same-path redirect trap probe a real candidate

Refs #3726

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: danielmeppiel <danielmeppiel@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 18, 2026
Re-verified the sweep's recorded findings on environment-variables,
targets-matrix, install-packages, registries, registry-http-api and
governance-guide against current main (after #3785, #3774, #3782,
#3743, #3797 merged) and fixed what is still drifted.

Refs #3800

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

compilation-target policy check ignores the plural targets: key

2 participants