Skip to content

fix(logging): close flow-doctor import-time pytest-guard gap (v0.59.3)#114

Merged
cipher813 merged 1 commit into
mainfrom
fix/flow-doctor-pytest-import-guard
Jun 11, 2026
Merged

fix(logging): close flow-doctor import-time pytest-guard gap (v0.59.3)#114
cipher813 merged 1 commit into
mainfrom
fix/flow-doctor-pytest-import-guard

Conversation

@cipher813

Copy link
Copy Markdown
Owner

Problem

The flow-doctor 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. 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_TEST set OR "pytest" in sys.modules (true from the moment the runner starts, including collection). Explicit opt-ins unchanged: FLOW_DOCTOR_ENABLED=1 still wins over the test guard, and FLOW_DOCTOR_ALLOW_IN_TESTS=1 still 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=1 in 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

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>
@cipher813 cipher813 merged commit 55ffa09 into main Jun 11, 2026
6 checks passed
@cipher813 cipher813 deleted the fix/flow-doctor-pytest-import-guard branch June 11, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant