@@ -25,7 +25,6 @@ type cacheEntry struct {
2525
2626// turnData fetches Turn API data with caching.
2727func (app * App ) turnData (ctx context.Context , url string , updatedAt time.Time ) (* turn.CheckResponse , bool , error ) {
28- prAge := time .Since (updatedAt )
2928 hasRunningTests := false
3029 // Validate URL before processing
3130 if err := validateURL (url ); err != nil {
@@ -57,13 +56,16 @@ func (app *App) turnData(ctx context.Context, url string, updatedAt time.Time) (
5756 }
5857 } else if time .Since (entry .CachedAt ) < cacheTTL && entry .UpdatedAt .Equal (updatedAt ) {
5958 // Check if cache is still valid (10 day TTL, but PR UpdatedAt is primary check)
60- // But invalidate cache for PRs with running tests if they're fresh (< 90 minutes old)
61- if entry .Data != nil && entry .Data .PullRequest .TestState == "running" && prAge < runningTestsCacheBypass {
59+ // But invalidate cache for PRs with incomplete tests if cache entry is fresh (< 90 minutes old)
60+ cacheAge := time .Since (entry .CachedAt )
61+ testState := entry .Data .PullRequest .TestState
62+ isTestIncomplete := testState == "running" || testState == "queued" || testState == "pending"
63+ if entry .Data != nil && isTestIncomplete && cacheAge < runningTestsCacheBypass {
6264 hasRunningTests = true
63- slog .Debug ("[CACHE] Cache invalidated - PR has running tests and is fresh" ,
65+ slog .Debug ("[CACHE] Cache invalidated - tests incomplete and cache entry is fresh" ,
6466 "url" , url ,
65- "test_state" , entry . Data . PullRequest . TestState ,
66- "pr_age " , prAge .Round (time .Minute ),
67+ "test_state" , testState ,
68+ "cache_age " , cacheAge .Round (time .Minute ),
6769 "cached_at" , entry .CachedAt .Format (time .RFC3339 ))
6870 // Don't return cached data - fall through to fetch fresh data with current time
6971 } else {
@@ -160,18 +162,21 @@ func (app *App) turnData(ctx context.Context, url string, updatedAt time.Time) (
160162 }
161163
162164 // Save to cache (don't fail if caching fails) - skip if --no-cache is set
163- // Also skip caching if tests are running and PR is fresh (updated in last 90 minutes)
165+ // Don't cache when tests are incomplete - always re-poll to catch completion
164166 if ! app .noCache {
165167 shouldCache := true
166- prAge := time .Since (updatedAt )
167168
168- // Don't cache PRs with running tests unless they're older than 90 minutes
169- if data != nil && data .PullRequest .TestState == "running" && prAge < runningTestsCacheBypass {
169+ // Never cache PRs with incomplete tests - we want fresh data on every poll
170+ testState := ""
171+ if data != nil {
172+ testState = data .PullRequest .TestState
173+ }
174+ isTestIncomplete := testState == "running" || testState == "queued" || testState == "pending"
175+ if data != nil && isTestIncomplete {
170176 shouldCache = false
171- slog .Debug ("[CACHE] Skipping cache for PR with running tests" ,
177+ slog .Debug ("[CACHE] Skipping cache for PR with incomplete tests" ,
172178 "url" , url ,
173- "test_state" , data .PullRequest .TestState ,
174- "pr_age" , prAge .Round (time .Minute ),
179+ "test_state" , testState ,
175180 "pending_checks" , len (data .PullRequest .CheckSummary .PendingStatuses ))
176181 }
177182
0 commit comments