Skip to content

fix(test): TestSessionLog_PersistAndPrune had a fuse on it - #1012

Merged
ako merged 1 commit into
mainfrom
fix/session-log-prune-test-time-bomb
Aug 31, 2026
Merged

fix(test): TestSessionLog_PersistAndPrune had a fuse on it#1012
ako merged 1 commit into
mainfrom
fix/session-log-prune-test-time-bomb

Conversation

@ako

@ako ako commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

TestSessionLog_PersistAndPrune fails on a clean checkout of main, 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.

--- FAIL: TestSessionLog_PersistAndPrune
    sessions_test.go:53: after reload+prune: 0 records, want 1 ([])

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: NewSessionLogFile prunes inside load(), before the test can assign log2.now. So the reload prune runs against the real time.Now() whatever clock is injected afterwards. The record with LastSeenAt: base - 1h aged 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 NewSessionLog and 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 consults time.Now() before the seam is in place.

Control

With pruneLocked stubbed 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

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
@ako
ako merged commit dce56f3 into main Aug 31, 2026
13 checks passed
This was referenced Aug 31, 2026
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