Repository navigation
test: pre-load install.audit_replay so run_replay patches cannot leak (MAIN-RED FIX, #4876) - #4884
Conversation
apm audit --ci imports audit_replay on first use, so a test that patches drift.run_replay and then runs the verb bound the module to the mock. Fixes #4876 Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The change only modifies the leak guard’s preload list, leaving the approved test-local patches and required real-function regression check unimplemented.
1 open issue
What changed in this PR
This test-only change aims to prevent an order-dependent mock leak reported by the session-end guard, particularly in Windows unit-test shards.
Changes:
- Adds
apm_cli.install.audit_replayto the session-start preload list so it imports before tests patchdrift.run_replay. - Leaves production code unchanged.
| File | Description |
|---|---|
tests/conftest.py |
Preloads audit_replay to prevent its module globals from retaining a patched function. |
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The reviewed diff still shows the conftest preload that the author reports reverting, so a refreshed diff is needed to assess the unavailable test-local replacement.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
7ea41dc to
92d4704
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
The available snapshot still contains the conftest preload reportedly reverted in 7ea41dc, while the replacement test-local fix and regression fixture are unavailable for review.
No open issues 🎉
Review effort: Balanced
7ea41dc to
92d4704
Compare
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
c4de3ba
into
main
Co-authored-by: Copilot App <[email protected]>

Description
Main is red on Windows unit tests: the conftest mock-leak guard reports
apm_cli.install.audit_replay.run_replayleft bound to aunittest.mockobject.apm audit --ciimportsaudit_replaylazily. That module bindsrun_replayfromdriftat import, so a test that patchesdrift.run_replayand then runs the verb can first-importaudit_replayinside the patch.This adds
apm_cli.install.audit_replayto_LAZY_CONSUMERSintests/conftest.py. The module now loads at session start, so every later patch stays transient. It is the same one-line preload as commit b9f7fd0 on #4827. OPS VP chose this over the patch-where-used approach (#4881), which fails the AQ004 test-assertion ratchet (see the PR comment).Issue and approved scope
Issue: Fixes #4876
Human scope-approval comment: #4876 (comment) (approach revised by OPS VP in the reopen comment on this PR: conftest preload instead of patch-where-used, which fails AQ004)
Does this PR complete the issue, or what remains? Completes it.
Type of change
Testing
Validation:
uv run --extra dev pytest -q -p no:randomly <every tests/unit file from git grep -l run_replay tests/>(9 files, one process, guard active at sessionfinish): 281 passed, 1 skipped.uv run --extra dev ruff check tests/conftest.py: passed.uv run --extra dev ruff format --check tests/conftest.py: passed.Lintcurrently fails on main too:src/apm_cli/core/deployment_ledger.pyis 2101 lines (limit 2100) after the docs(policy): user-scope org policy is still absent in 0.38; #3703 targets 0.39 #4806 merge. This PR does not touch it.Changelog
changelog.d/<pr>.<section>.md, holdingone line: user-visible effect first, 25 words or fewer, ending with
(#PR); breaking changes only under upgrade notes; no Highlights; nonew lines under
## [Unreleased]. Seechangelog.d/README.mdand.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)