Repository navigation
test(policy): drive install-time policy enforcement through the installed CLI - #4129
Merged
Daniel Meppiel (danielmeppiel) merged 5 commits intoNov 20, 2026
Merged
Conversation
…lled CLI Add test_policy_install_enforcement_lifecycle.py: 13 installed-CLI rows against a real org policy served from a local contoso/.github repository (policy discovered from the git remote, nothing patched). Each row checks the exit code, output and a before/after LifecycleStateSnapshot; refused installs must leave the project byte-identical. Part of #4081 Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 20, 2026 08:14
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The warn-mode test cannot detect premature stopping after the first failed check because all three packages fail the same rule; it needs a second independently failing rule and an assertion for its diagnostic.
1 open issue
What changed in this PR
Adds installed-CLI coverage for install-time organization policy enforcement, addressing the first part of #4081 while preserving the existing in-process routing tests.
Changes:
- Adds 13 lifecycle cases using real policy discovery through a local HTTPS fixture.
- Covers blocking, warnings, bypasses, inheritance, dry runs, and non-enforcing outcomes.
- Checks exit codes, diagnostics, deployment state, rollback integrity, and warn-mode repeat-install stability.
| File | Description |
|---|---|
tests/integration/test_policy_install_enforcement_lifecycle.py |
Adds installed-CLI policy enforcement tests with filesystem snapshots and output assertions. |
Review effort: Balanced
Merged
6 of 10 tasks
…t rows Part of #4081 Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Resolve the duration seed conflict by keeping main's seeds and adding the new module's entries. Rename the opt-out test so its name matches the documented --no-policy / APM_POLICY_DISABLE opt-out. Co-authored-by: Copilot App <[email protected]>
The warn row now also requires a package that the manifest lacks, so a regression that stops warn-mode evaluation after the first failed check loses the required-package warning and fails the test. Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
deleted the
danielmeppiel-didactic-umbrella
branch
November 20, 2026 11:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
tests/integration/test_policy_install_e2e.pyis named and inventoried as end-to-end. Its rows driveCliRunnerin-process, though, and patch policy discovery at both entry points (_patch_both_discover,_PATCH_DISCOVER_GATE,_PATCH_DISCOVER_PREFLIGHT). They prove that a fixed discovery result routes correctly through the install pipeline. They cannot notice when the shipped CLI stops finding or applying the org policy.This PR adds
tests/integration/test_policy_install_enforcement_lifecycle.py. It holds 13 rows that run the installedapmCLI against a real org policy. The policy lives in a localcontoso/.githubgit repository, served over the loopback GitHub HTTPS fixture. The consumer'soriginpoints atcontoso, so the CLI discovers the policy on its own. Nothing in discovery or enforcement is patched. Each row asserts:LifecycleStateSnapshotplus a whole-project byte snapshot.A refused install must leave the project byte-identical. Successful rows also check that every lockfile deployment record exists on disk. The warn row also checks that a second install changes no bytes.
Note
Part of #4081 part (1). Renaming the old module to a component-marked routing module is separate follow-up work, after an in-flight change to its
TestI8TransitiveMCPDeniedrow lands. This PR does not touch the old module.Issue and approved scope
Issue: Part of #4081
Human scope-approval comment: #4081 (comment)
Does this PR complete the issue, or what remains? Partial. This PR delivers the installed-CLI rows and their red/green evidence. Remaining for part (1): rename the old module and add the
componentmarker (separate follow-up). Parts (2) and (3), moving and classifying modules, are separate.Approved by the test-corpus steward
Type of change
Testing
Red-before / green-after (mutation evidence)
Each mutation was applied to
src/. Both modules were then run withAPM_BINARY_PATH=$PWD/.venv/bin/apm APM_E2E_TESTS=1 uv run --extra dev pytest -v -n 4 tests/integration/test_policy_install_e2e.py tests/integration/test_policy_install_enforcement_lifecycle.py, and the mutation was reverted afterwards.discover_policyreturnsabsent(fetch path)policy/discovery.py(cached-policy-shape owner module)Nonepolicy/_remote.py(policy-remote-origin-reader)install/phases/policy_gate.pyThe two discovery-path mutations silently turn off install-time enforcement in the shipped CLI, and every old row stays green. Even the gate-level control is caught by only one old row (I20). The other rows still pass because their assertions accept any non-zero exit or any mention of a dependency name.
Mutation diffs
New rows failing under the origin-read and fetch-path mutations (identical set for both)
The five rows that still pass (
enforcement-off,absent-policy,no-git-remote, and the two rows for the documented--no-policy/APM_POLICY_DISABLEopt-out) assert outcomes that must not block, so a disabled gate cannot fail them.Gate early-return control
Old row -> installed-CLI home
No old node is removed or renamed in this PR. The table maps each old row to the installed-CLI row that now proves it end to end.
test_policy_install_e2e.pytest_block_policy_refuses_denied_dependency_without_writingtest_allowlist_refuses_unlisted_dependency_without_writinginstall <pkg>manifest rollbacktest_refused_package_install_restores_manifest_bytestest_dry_run_previews_blocked_dependencies_without_writingtest_warn_policy_installs_and_reports_every_violationextends:chaintest_three_level_extends_chain_enforces_root_deny--no-policy, I9APM_POLICY_DISABLE=1test_policy_bypass_installs_denied_dependency_with_loud_warning[no-policy-flag / policy-disable-env](executes the documented opt-out hint the refusal prints)test_non_enforcing_policy_outcomes_install[enforcement-off / absent-policy / malformed-policy / garbage-policy / no-git-remote]test_mcp_transport_policy_lifecycle.pytest_target_declaration_install_lifecycle.pyCommands run
Duration seeds
.github/ci-durations/linux-x86_64.json(the Lifecycle Smoke seed) gains the 13 node weights, measured with-p scripts.ci_sharding --shard-store-durationsunder-n 4 --dist loadgroupand compacted withcompact_durations. The max node is 5.79s locally. On CI no node appears in any Lifecycle Smoke shard's slowest-20 list, whose 20th entries top out at 11.06s.CI lanes
The module carries
integration, e2e, lifecycle_smoke, requires_apm_binary, requires_e2e_modeand an opensslskipif, the same set astest_gitlab_subgroup_policy_lifecycle.py.Lifecycle Smoke Shard 1-3 (Linux)jobs inci.ymlselect-m 'lifecycle_smoke and not lifecycle_merge_group'withAPM_E2E_TESTS=1.requires_apm_binaryresolves theuv syncconsole script on PATH, so the rows run and are not skipped.Integration Tests Shard 1-4 (Linux)jobs inci-integration.ymlrun the module against the frozen PyInstaller binary indist/.Promises
policy-remote-origin-reader,policy-violation-subjects(.apm/architecture/owners/install-deployment.json);cached-policy-shape(.apm/architecture/owners/contracts-tooling.json).transaction.failed_command_preserves_state,outcome.status_matches_state.Changelog
## [Unreleased]inCHANGELOG.mdSpec conformance (OpenAPM v0.1)
Trade-offs
How to test
APM_BINARY_PATH="$(uv run which apm)" APM_E2E_TESTS=1 uv run --extra dev pytest -q tests/integration/test_policy_install_enforcement_lifecycle.py-> 13 passed.return Noneas the first statement of_git_remote_origin_urlinsrc/apm_cli/policy/_remote.py, then rerun step 1 -> 8 failed.uv run --extra dev pytest -q tests/integration/test_policy_install_e2e.py-> 23 passed.Co-authored-by: Copilot [email protected]