Skip to content

test(freshness): pin against calendar-day regression in freshness functions#298

Merged
cipher813 merged 1 commit into
mainfrom
test/freshness-regression-pin
May 24, 2026
Merged

test(freshness): pin against calendar-day regression in freshness functions#298
cipher813 merged 1 commit into
mainfrom
test/freshness-regression-pin

Conversation

@cipher813
Copy link
Copy Markdown
Owner

Summary

AST-walk regression pin: production functions whose name matches fresh|stale|preflight|postflight must not contain .days calendar arithmetic. Closes the cross-repo defect class surfaced by the 2026-05-24 Sunday SF recovery and the migration arc that followed.

Why

The 2026-05-24 incident: validators/postflight.py::_check_macro_spy_fresh used (run_date - last_date).days > 1 and blocked the Sunday redrive even though macro.SPY carried Friday's close (the most recent NYSE session). Audit found the same pattern in 7 sites across data/predictor/research. All migrated to alpha_engine_lib.dates.{trading_days_stale, is_fresh_in_trading_days} in lib v0.27.0 + the migration arc (data #297, predictor #191, research #222).

Without this pin, a future bug fix that introduces (today - last_date).days > N inside check_X_fresh / validate_stale_Y / _check_Z_preflight would slip past code review and rediscover the gate-trips-on-redrive failure mode.

Mechanism

  1. Walk all .py files under the repo root (skip .venv, __pycache__, tests, .claude, .git, build).
  2. For each FunctionDef whose lowercased name matches (fresh|stale|preflight|postflight), scan the function body for any .days attribute access.
  3. Fail the test if any are found, unless the line carries an inline # noqa: trading-day marker.

Per-repo allowlists exist for documented exceptions (only alpha-engine-data has one: collectors/prices._find_stale_fast is a write-recency check on S3 LastModified, correctly calendar-day).

Test plan

  • Pin passes on current clean state in each repo (all freshness sites migrated)
  • test_allowlist_entries_are_real ensures any allowlisted (file, function) tuple actually exists — drift-detector for the allowlist itself

Composes with

🤖 Generated with Claude Code

…ctions

AST-walk regression pin: every production function whose name matches
fresh|stale|preflight|postflight must not contain ``.days`` calendar
arithmetic. Closes the cross-repo defect class surfaced by the
2026-05-24 Sunday SF recovery: calendar-day gates trip on every
post-Saturday redrive even when data carries the most recent NYSE close.

Escape hatch: inline ``# noqa: trading-day`` marker on the same line
documents calendar-day correctness at that specific call site.

Explicit allowlist: ``collectors/prices._find_stale_fast`` checks S3
LastModified timestamp (write-recency, not data-freshness) and is
correctly calendar-day; allowlist verified by a second test that
ensures the named function actually exists in the named file.

Pin passes on current clean state (all 5 freshness sites migrated to
``alpha_engine_lib.dates.{trading_days_stale, is_fresh_in_trading_days}``
in PR #297). Would catch any future PR that adds calendar-day
arithmetic to a freshness-named function.

Composes with the lib v0.27.0 chokepoint (lib #59) + the cross-repo
migration arc (predictor #191, research #222).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@cipher813 cipher813 marked this pull request as draft May 24, 2026 15:00
@cipher813 cipher813 marked this pull request as ready for review May 24, 2026 15:01
@cipher813 cipher813 merged commit 6525b6a into main May 24, 2026
1 check passed
@cipher813 cipher813 deleted the test/freshness-regression-pin branch May 24, 2026 15:02
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