fix(tests): use relative dates in snapshot/session retention tests (main is red) - #286
Conversation
…ain was red) Three observer tests hardcoded their snapshot observed_at / session-dir dates as 2026-06-07 and asserted retention/recency outcomes that only hold within a fixed window: - test_snapshot_repository.py::test_cleanup_retains_recent_snapshots - test_snapshot_manager.py::test_cleanup_old_snapshots - test_flaky_test_storage.py::test_storage_handles_corrupted_json As wall-clock advanced past 2026-06-14 those dates aged beyond the cutoffs (load_recent_sessions(days=7); retention_days), so cleanup deleted more / loaded fewer than the hardcoded counts and the assertions flipped — turning main's full pytest suite RED and blocking every PR from merging green. Fix: anchor the dates to `now` instead of a fixed past date — `now - 1 day + i*hours` for the loop-based snapshots (preserving the relative ordering so the sort-order tests still pass) and today's date for the flaky-session dir. Full unit suite green (7007 passed). Relative dates are the durable fix for these time-bombs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Self-review concerns — auto-fixing (up to 6 attempts; re-queued if still unresolved): test_flaky_test_storage.py uses |
|
Self-review concerns — auto-fixing (up to 6 attempts; re-queued if still unresolved):
|
test_flaky_test_storage.py uses undefined symbol |
UTC is not available directly from datetime module. Use timezone.utc instead to match Python standard library conventions and avoid NameError at runtime. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Main is red right now
Three observer tests hardcode their dates as 2026-06-07 and assert retention/recency outcomes that only hold within a fixed window:
test_snapshot_repository.py::test_cleanup_retains_recent_snapshotstest_snapshot_manager.py::test_cleanup_old_snapshotstest_flaky_test_storage.py::test_storage_handles_corrupted_jsonAs wall-clock passed 2026-06-14, those dates aged beyond the cutoffs (
load_recent_sessions(days=7),retention_days), so cleanup deletes more / loads fewer than the hardcoded counts and the assertions flip. main's full pytest suite is RED, which blocks every PR from merging green (including the campaign/state GC PRs in this series).Confirmed pre-existing: these fail on clean current main, independent of any feature branch.
Fix
Anchor the dates to
nowinstead of a fixed past date:now - 1 day + i*hours— preserves relative ordering, so the sort-order tests (test_list_snapshots_sorted_by_date, etc.) still pass while the retention windows now hold;Relative dates are the durable fix for these time-bombs.
Verification
Full
tests/unitsuite: 7007 passed, 0 failed.ruffclean; audit clean.🤖 Generated with Claude Code