test(freshness): pin against calendar-day regression in freshness functions#298
Merged
Conversation
…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>
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.
Summary
AST-walk regression pin: production functions whose name matches
fresh|stale|preflight|postflightmust not contain.dayscalendar 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_freshused(run_date - last_date).days > 1and 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 toalpha_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 > Ninsidecheck_X_fresh/validate_stale_Y/_check_Z_preflightwould slip past code review and rediscover the gate-trips-on-redrive failure mode.Mechanism
.pyfiles under the repo root (skip.venv,__pycache__,tests,.claude,.git,build).FunctionDefwhose lowercased name matches(fresh|stale|preflight|postflight), scan the function body for any.daysattribute access.# noqa: trading-daymarker.Per-repo allowlists exist for documented exceptions (only
alpha-engine-datahas one:collectors/prices._find_stale_fastis a write-recency check on S3LastModified, correctly calendar-day).Test plan
test_allowlist_entries_are_realensures any allowlisted (file, function) tuple actually exists — drift-detector for the allowlist itselfComposes with
🤖 Generated with Claude Code