Repository navigation
test(audit): patch run_replay where audit_replay uses it (#4876) - #4881
Closed
Daniel Meppiel (danielmeppiel) wants to merge 1 commit into
Closed
Daniel Meppiel (danielmeppiel) wants to merge 1 commit into
Daniel Meppiel (danielmeppiel) wants to merge 1 commit into
Conversation
Import apm_cli.install.audit_replay at test-module top so its run_replay binding is the real function before any test patches drift.run_replay, and assert the binding is intact after each patched block. Co-authored-by: Copilot App <[email protected]> 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 23, 2026 01:15
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the test-isolation change.
No open issues 🎉
What changed in this PR
Addresses the audit CI test-isolation flake in #4876 by preventing a patched run_replay mock from persisting in audit_replay module globals. Production behavior is unchanged.
Changes:
- Imports
audit_replaybefore test patches can capture a mock during lazy loading. - Adds binding-identity assertions after the affected patch blocks while retaining the patch target used by the CI drift checks.
| File | Description |
|---|---|
| tests/unit/test_audit_ci_command.py | Eagerly imports replay modules and checks that patched tests leave the real run_replay binding intact. |
Review effort: Balanced
Merged
6 of 10 tasks
Collaborator
Author
|
Superseded by #4884 (conftest preload of apm_cli.install.audit_replay). This PR's approach trips AQ004_patches_owner_it_imports in scripts/check_test_assertions.py (tests/unit/test_audit_ci_command.py:228,257). |
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
Fixes #4876
Cause:
audit_replay.pybindsrun_replayat import time (from apm_cli.install.drift import run_replay). Whentest_audit_ci_command.pypatchedapm_cli.install.drift.run_replayandaudit_replaywas first imported lazily inside that patch (viacommands/audit.py), the Mock was captured inaudit_replay's module globals for good, tripping the session-end leak guard. Order-dependent under xdist.Fix: import
apm_cli.install.audit_replayat test-module top so the binding is the real function before any patch, and assertaudit_replay.run_replay is drift.run_replayafter each patched block (fails deterministically without the import). The patch target staysapm_cli.install.drift.run_replay: for this fixture the drift check runs viapolicy/ci_checks._check_drift, which looksrun_replayup lazily fromdrift; retargeting toaudit_replay.run_replaymakes the three tests exit 0. The otherdrift.run_replaymonkeypatch sites (test_ci_checks,test_export_patch,test_drift_checke10) never importaudit_replay, so they are not affected.Issue and approved scope
Issue: Fixes #4876
Human scope-approval comment: none on the issue yet; fix requested via the maintainer's QL session as a bounded test-only change.
Completes the issue.
Type of change
Testing
Tested locally
All existing tests pass
Added tests for new functionality (if applicable)
uv run --extra dev ruff check tests/unit/test_audit_ci_command.py-- passeduv run --extra dev ruff format --check tests/unit/test_audit_ci_command.py-- passeduv run --extra dev pytest tests/unit/test_audit_ci_command.py -q -p no:xdist-- 17 passedRegression check: with the assertion but without the top-level import,
-k "native_drift_boundary or policy_blocked_drift"-- 3 failed (leak reproduced)Full suites not run.
Changelog
changelog.d/<pr>.<section>.md.Spec conformance (OpenAPM v0.1)