Skip to content

test(hrv): split flaky integration into synthetic + floor + opt-in real-data#169

Merged
neuron7xLab merged 1 commit intoneuron7xLab:mainfrom
neuron7x:fix/hrv-test-first-principles
May 1, 2026
Merged

test(hrv): split flaky integration into synthetic + floor + opt-in real-data#169
neuron7xLab merged 1 commit intoneuron7xLab:mainfrom
neuron7x:fix/hrv-test-first-principles

Conversation

@neuron7x
Copy link
Copy Markdown
Contributor

@neuron7x neuron7x commented May 1, 2026

Summary

Replaces #168 (margin bandaid n_subjects=3→5) with a first-principles split.

The previous TestHRV.test_gamma_in_range welded three orthogonal claims onto one mandatory mid-CI network call:

  1. compute_gamma mathematics recovers γ ≈ 1 from a 1/f PSD,
  2. _ensure_loaded enforces the 3-subject floor,
  3. real PhysioNet/NSR2DB data lies in the physiological band [0.5, 1.5].

When wfdb/PhysioNet flakes — as happened in run 25184505044 — claims (1) and (2) become non-testable. Bumping n_subjects only widens the absorption margin; the substrate is still the network.

Decomposition

Test Always-on Network Catches
test_compute_gamma_recovers_unity_from_synthetic_1f γ-estimator math regressing on 1/f PSD
test_floor_minimum_enforced ❌ (monkeypatched _load) floor=3 enforcement breaking
test_real_data_gamma_in_range opt-in (NEOSYNAPTEX_RUN_NETWORK_TESTS=1) full wfdb→PSD→γ on real NSR2DB

The floor constant is named (_HRV_FLOOR_MIN_SUBJECTS = 3), not magic. The CI-run-id comment from #168 is removed: the test no longer depends on transient network state, so diagnostic context lives in the commit message rather than polluting source.

Effect on CI

  • PR-blocking matrix (Verify (3.10/3.11/3.12)) becomes fully offline for the HRV substrate. wfdb/PhysioNet flake can no longer break PRs.
  • Real-data integration is preserved as an opt-in gate; running locally:
    NEOSYNAPTEX_RUN_NETWORK_TESTS=1 pytest tests/test_integrity_v2.py::TestHRV::test_real_data_gamma_in_range
    
  • Follow-up suggested (out of this PR's scope): a scheduled CI lane that sets NEOSYNAPTEX_RUN_NETWORK_TESTS=1 nightly so PhysioNet API drift is still caught.

Test plan

  • pytest tests/test_integrity_v2.py → 16 passed, 1 skipped (real-data, as designed).
  • ruff format + ruff check clean.
  • Synthetic test recovers γ within [0.7, 1.3] (deterministic seed 42).
  • Floor test asserts the documented RuntimeError("Insufficient HRV data").
  • Local pre-commit hooks pass.

Claim status

claim_status: derived

Pure test-architecture refactor — zero new measurement claims. The synthetic test recovers a textbook 1/f→γ=1 relation; the floor test exercises documented error handling; the real-data test is unchanged in intent, only gated.

Supersedes #168.

🤖 Generated with Claude Code

…al-data

The previous TestHRV.test_gamma_in_range coupled three orthogonal claims
into one mandatory mid-CI network call:

  1. compute_gamma maths recovers γ ≈ 1 from a 1/f PSD,
  2. _ensure_loaded enforces the 3-subject floor,
  3. real PhysioNet/NSR2DB data lies in the physiological band.

The single point of failure (PhysioNet/wfdb network) made (1) and (2)
non-testable when the network flaked, and forced neuron7xLab#168 to bump n_subjects
3→5 — a margin bandaid, not a fix.

This change reduces the test to first principles by splitting along the
three axes:

  • test_compute_gamma_recovers_unity_from_synthetic_1f
      Always-on. Synthesises a 1/f signal through the same VLF-band
      Welch+mask the adapter uses; no wfdb, no network. Catches the
      maths regressing.
  • test_floor_minimum_enforced
      Always-on. Monkeypatches HRVPhysioNetAdapter._load to return one
      subject below the 3-subject floor and asserts the documented
      RuntimeError. Catches floor regressions without network.
  • test_real_data_gamma_in_range
      Opt-in via NEOSYNAPTEX_RUN_NETWORK_TESTS=1. Exercises the full
      wfdb→PSD→γ pipeline on real NSR2DB data; no longer on the PR
      critical path, so PhysioNet flakes cannot block merges. Intended
      to run in a dedicated nightly/scheduled CI lane.

The floor constant (_HRV_FLOOR_MIN_SUBJECTS = 3) is named, not magic.
The CI-run-id comment from neuron7xLab#168 is removed — the test no longer
depends on transient network state, so the diagnostic context is
documented in this commit message instead of polluting the source.

Supersedes neuron7xLab#168.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@neuron7xLab neuron7xLab merged commit 220ee74 into neuron7xLab:main May 1, 2026
38 checks passed
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.

2 participants