fix(logging): close flow-doctor import-time pytest-guard gap (v0.59.3)#114
Merged
Conversation
The activation guard keyed only on PYTEST_CURRENT_TEST, which pytest sets per-test — but every entrypoint calls setup_logging at module top, so under pytest the FlowDoctorHandler attaches at COLLECTION time, before that var exists. 2026-06-11: an alpha-engine-data test run leaked REAL alert emails + GitHub issues + S3 changelog entries for synthetic fixture tickers (T0/T1/BAD) through exactly this window. Rule 3 of the activation precedence now treats EITHER signal as test context: PYTEST_CURRENT_TEST set OR 'pytest' in sys.modules. Explicit opt-ins are unchanged (FLOW_DOCTOR_ENABLED=1 still wins; suites that deliberately exercise activation keep FLOW_DOCTOR_ALLOW_IN_TESTS=1). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
The flow-doctor activation guard keyed only on
PYTEST_CURRENT_TEST, which pytest sets per-test — but every entrypoint callssetup_loggingat module top, so under pytest theFlowDoctorHandlerattaches at collection time, before that var exists. On 2026-06-11 an alpha-engine-data test run leaked REAL alert emails + GitHub issues + S3 changelog entries for synthetic fixture tickers (T0/T1/BAD) through exactly this window.Fix
Rule 3 of the activation precedence now treats EITHER signal as test context:
PYTEST_CURRENT_TESTset OR"pytest" in sys.modules(true from the moment the runner starts, including collection). Explicit opt-ins unchanged:FLOW_DOCTOR_ENABLED=1still wins over the test guard, andFLOW_DOCTOR_ALLOW_IN_TESTS=1still opts a suite back in.Regression test simulates collection time (env var deleted, pytest in
sys.modules) and asserts suppression.Companion: alpha-engine-data#414 adds a belt-and-suspenders
FLOW_DOCTOR_DISABLED=1in its conftest and fixes the 10-emails-per-EOD-run quality-gate alert storm at the emitting site.Tests
Full suite: 1238 passed (pythonpath=src — worktree code verified under test).
🤖 Generated with Claude Code