fix(test): TestSessionLog_PersistAndPrune had a fuse on it - #1012
Merged
Conversation
The test pinned base := time.Date(2026, 8, 1) against a 30-day retention window, so it started failing on 2026-08-31 -- exactly 30 days later -- on every branch at once, turning every open PR red on a package none of them touched. The reason a fixed base cannot work here specifically: NewSessionLogFile prunes inside load(), before the caller can assign log2.now, so the reload prune runs against the real time.Now() no matter what clock the test injects afterwards. The 1-hour-old record aged past the window in wall-clock terms and was pruned, leaving 0 records where the test wants 1. The fixture is now relative to time.Now(), so the record ages decide the outcome rather than the calendar: 40 days old is outside a 30-day window and 1 hour old is inside it, whenever this runs. The other tests in the file keep their fixed base legitimately -- they use NewSessionLog and inject the clock before recording anything. Controlled: with pruneLocked stubbed to a no-op the repaired test still fails (2 records, want 1), so it has not merely stopped testing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DufwPkjFimB8BoTm7bWbik
This was referenced Aug 31, 2026
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
TestSessionLog_PersistAndPrunefails on a clean checkout ofmain, which is turning every open PR red on a package none of them touch. It is a time bomb in the test, not a regression.Why it went off today
The fixture pinned
base := time.Date(2026, 8, 1, 12, 0, 0, 0, time.UTC)against a 30-day retention window. Today is 2026-08-31 — exactly 30 days later.What makes a fixed base unusable here specifically:
NewSessionLogFileprunes insideload(), before the test can assignlog2.now. So the reload prune runs against the realtime.Now()whatever clock is injected afterwards. The record withLastSeenAt: base - 1haged past the 30-day window in wall-clock terms and was pruned, leaving 0 records.It passed for 30 days and then failed permanently, on every branch simultaneously.
Fix
The fixture is relative to
time.Now(), so the record ages decide the outcome rather than the calendar: 40 days old is outside a 30-day window and 1 hour old is inside it, whenever this runs.The other four fixed-date fixtures in the file are left alone — they use
NewSessionLogand inject the clock before recording, so no code path reads the real clock. That is the actual rule: a date fixture is safe only where nothing consultstime.Now()before the seam is in place.Control
With
pruneLockedstubbed to a no-op the repaired test still fails (2 records, want 1), so it has not quietly stopped testing anything.Unblocks #1009, #1010 and #1011, which are red for this reason alone.
🤖 Generated with Claude Code
https://claude.ai/code/session_01DufwPkjFimB8BoTm7bWbik