chore(backup): rename WEEKLY_WINDOW_COUNT, document anchor+4 semantic
Spec reviewer flagged the weekly window keeps 5 Mondays (anchor + 4 prior), not 4 as the plan prose said. Code preserved (tests pass); constant renamed and comment made honest about the actual semantic. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const BACKUP_FILENAME_REGEX = /^inkling-(\d{4}-\d{2}-\d{2})\.sqlite$/;
|
||||
const ONE_DAY_MS = 24 * 60 * 60 * 1000;
|
||||
const DAILY_WINDOW_DAYS = 14;
|
||||
const WEEKLY_WINDOW_COUNT = 4;
|
||||
const WEEKLY_WINDOW_PRIOR_MONDAYS = 4;
|
||||
const MONTHLY_WINDOW_COUNT = 6;
|
||||
|
||||
export function parseBackupFilename(name: string): string | null {
|
||||
@@ -34,12 +34,16 @@ function isWithinWeeklyWindow(fileDate: Date, now: Date): boolean {
|
||||
// UTC-based Monday detection. UTCDay: 0=Sun, 1=Mon..6=Sat
|
||||
if (fileDate.getUTCDay() !== 1) return false;
|
||||
const today = startOfDayUtc(now);
|
||||
// Anchor to the most recent Monday on/before today, then reach back
|
||||
// WEEKLY_WINDOW_COUNT * 7 days. This keeps 4 Mondays before the anchor.
|
||||
// Weekly window: anchor on the most recent Monday on/before `now`, then reach back
|
||||
// WEEKLY_WINDOW_PRIOR_MONDAYS * 7 days from that anchor. Effective semantic:
|
||||
// up to 5 distinct Mondays kept (the anchor Monday + 4 prior). The plan's commit
|
||||
// header says "4 weekly Mondays" but the plan's test case at
|
||||
// backupRotation.test.ts requires 03-23 (5th Monday from 2026-04-26) to be kept,
|
||||
// so the test is treated as source of truth.
|
||||
const dayOfWeek = today.getUTCDay(); // 0=Sun..6=Sat
|
||||
const daysSinceMonday = (dayOfWeek + 6) % 7; // Mon=0, Sun=6
|
||||
const lastMonday = new Date(today.getTime() - daysSinceMonday * ONE_DAY_MS);
|
||||
const oldest = new Date(lastMonday.getTime() - WEEKLY_WINDOW_COUNT * 7 * ONE_DAY_MS);
|
||||
const oldest = new Date(lastMonday.getTime() - WEEKLY_WINDOW_PRIOR_MONDAYS * 7 * ONE_DAY_MS);
|
||||
return fileDate >= oldest && fileDate <= today;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user