Repository navigation
fix(policy): judge compilation-target on the canonical target set - #3774
Conversation
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>
Co-authored-by: Mohammed Alkindi <alkndymhmd692@gmail.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 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
allsemantics, 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
APM Review Panel:
|
| 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
- [Python Architect] Add
registry_delegation.policy_target_projectionto_EXPECTED_RULE_IDSintests/unit/scripts/test_architecture_runner.py. -- Build & Test Shard 2 is red on the frozen rule inventory check. - [Supply Chain Security Expert] Reword
governance-guide.mdline 311 to state thatenforcetakes precedence overallow. -- The current wording overpromises the security contract; python-architect and the Copilot inline review concur. - [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. - [Supply Chain Security Expert] Open an issue to evaluate checking both
enforceandallowin 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_targetusesif 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_namesreturningNoneforallcleanly separates unrestricted from an empty allow list;enforce: allexpansion reuses the canonical authority.
Suggested: "checked againstcompilation.target.enforce(if set) orcompilation.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 believecursoris 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.pypassesdeployment_decision.canonical_targetstorun_policy_preflight. The static rule scans all ofsrc/, so the seam is guarded; the gap is proof that the guard fires on this path.
Suggested: Addpytest.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>
APM Review Panel:
|
| 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
- [Supply Chain Security Expert] Open a tracked issue to evaluate checking
compilation.target.enforceandallowtogether. -- Todayenforcetakes precedence andallowis 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_projectionto 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:311states thatenforcetakes precedence overallow-- 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)
- (panel) Evaluate checking
compilation.targetenforce AND allow together -- scope boundary: runtime governance behavior change; accepted compilation-target policy check ignores the plural targets: key #3732 scope fixes the projection only; suggested follow-up: a scoped issue for conjunctive enforce + allow evaluation.
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]-- deletedrun_policy_preflightfrom the guard's seams; test FAILED as expected; guard restored.tests/unit/policy/test_policy_checks.py::TestAuditCompilationTargetFromManifest-- reverted audit to the rawtarget: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>
Lane L: main merged for landing
This comment was generated by an AI agent (Lane L landing desk) on behalf of Daniel Meppiel (@danielmeppiel). |
…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>
… main Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…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>
…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>
…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>
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>

Description
apm auditjudgedcompilation.targetpolicy from the rawtarget:key only, so a manifest using pluraltargets: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
targets: [claude, cursor],allow: [claude, copilot],apm audit --cicursor(matches whatapm installalready blocked)target: "claude,copilot"(CSV), same policy'claude,copilot'target: vscode/targets: [vscode], same policyvscode.vscode/mcp.jsonallow: [all]target: all, narrow allow list'all'allactually installstargets: [all]allow: [vscode, claude], childallow: [copilot][copilot]How
EffectiveTargetDecision.canonical_targets(aliases resolved,allexpanded, MCP-only targets mapped to their primitive profile).normalize_policy_targetsis folded into it and removed.canonical_policy_target_names/canonical_policy_target_namebeside it canonicalize the policy side;policy/parser.pystores canonicalcompilation.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 throughpackage_target_selection(decision A1); the install gate,apm install --mcp, and local-bundle install pass theirEffectiveTargetDecision. The install gate no longer falls back toapm_package.target.registry-delegation-policy-target-projection(registered on theeffective-install-target-selectionowner): everyeffective_target=handed torun_dependency_policy_checks/run_policy_preflightand every_check_compilation_targetcall must use.canonical_targets; no sibling normalizer may exist. One ownerMutationCaseplus three extra mutation tests.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.ymlthroughrun_policy_checks), withCo-authored-bycredit. That patch added a second raw reader and would have madetargets: [all]fail as the literalall.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 rejectsintellij/copilot-appinapm installbefore 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.targetdocs), which will reference #3732.Type of change
Testing
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 intest_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 --checkon 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 failsapm audit --ciunder acompilation.targetpolicy.apm installalready blocked these manifests underenforcement: block.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regeneratedapm-spec-waiver: compilation-target policy evaluation is APM policy behavior; OpenAPM v0.1 does not specify it