From 05c38dfec1fce331c473ad30daf8ba8667c06dc9 Mon Sep 17 00:00:00 2001 From: ozymandiashh <234437643+ozymandiashh@users.noreply.github.com> Date: Tue, 4 Aug 2026 04:11:25 +0300 Subject: [PATCH] test: clamp all four relative-time fixtures to the current UTC day The shared base computation guarded hours >= 2 but its h < 2 branch still subtracted five minutes past midnight, escaping into yesterday during the first five minutes of UTC hours 0 and 1 and zeroing every 'today' assertion - which is exactly when runs #6 landed. Midnight clamp replaces the guard at all four sites. --- tests/cli-status-menubar.test.ts | 36 +++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/tests/cli-status-menubar.test.ts b/tests/cli-status-menubar.test.ts index d2186b4..292385d 100644 --- a/tests/cli-status-menubar.test.ts +++ b/tests/cli-status-menubar.test.ts @@ -63,8 +63,13 @@ describe('codeburn status --format menubar-json', () => { await mkdir(projectDir, { recursive: true }) const now = new Date() - const h = now.getUTCHours() - const base = h >= 2 ? new Date(now.getTime() - 2 * 3600_000) : new Date(now.getTime() - h * 3600_000 - 300_000) + // Two hours back, clamped inside the current UTC day (runCli pins + // TZ=UTC): a plain now-2h leaves today during the first two hours of + // the day, and the old hour-guard still escaped into yesterday during + // the first five minutes of hours 0 and 1, zeroing every "today" query + // on runs that started just past the top of those hours. + const todayUtcMidnight = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()) + const base = new Date(Math.max(todayUtcMidnight, now.getTime() - 2 * 3600_000)) const ts1 = base.toISOString().replace(/\.\d+Z$/, 'Z') const ts2 = new Date(base.getTime() + 60_000).toISOString().replace(/\.\d+Z$/, 'Z') const ts3 = new Date(base.getTime() + 120_000).toISOString().replace(/\.\d+Z$/, 'Z') @@ -425,8 +430,13 @@ describe('codeburn status --format menubar-json', () => { })) const now = new Date() - const h = now.getUTCHours() - const base = h >= 2 ? new Date(now.getTime() - 2 * 3600_000) : new Date(now.getTime() - h * 3600_000 - 300_000) + // Two hours back, clamped inside the current UTC day (runCli pins + // TZ=UTC): a plain now-2h leaves today during the first two hours of + // the day, and the old hour-guard still escaped into yesterday during + // the first five minutes of hours 0 and 1, zeroing every "today" query + // on runs that started just past the top of those hours. + const todayUtcMidnight = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()) + const base = new Date(Math.max(todayUtcMidnight, now.getTime() - 2 * 3600_000)) const ts1 = base.toISOString().replace(/\.\d+Z$/, 'Z') const ts2 = new Date(base.getTime() + 60_000).toISOString().replace(/\.\d+Z$/, 'Z') const ts3 = new Date(base.getTime() + 120_000).toISOString().replace(/\.\d+Z$/, 'Z') @@ -483,8 +493,13 @@ describe('codeburn status --format menubar-json', () => { await mkdir(projectDir, { recursive: true }) const now = new Date() - const h = now.getUTCHours() - const base = h >= 2 ? new Date(now.getTime() - 2 * 3600_000) : new Date(now.getTime() - h * 3600_000 - 300_000) + // Two hours back, clamped inside the current UTC day (runCli pins + // TZ=UTC): a plain now-2h leaves today during the first two hours of + // the day, and the old hour-guard still escaped into yesterday during + // the first five minutes of hours 0 and 1, zeroing every "today" query + // on runs that started just past the top of those hours. + const todayUtcMidnight = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()) + const base = new Date(Math.max(todayUtcMidnight, now.getTime() - 2 * 3600_000)) const ts1 = base.toISOString().replace(/\.\d+Z$/, 'Z') const ts2 = new Date(base.getTime() + 60_000).toISOString().replace(/\.\d+Z$/, 'Z') @@ -641,8 +656,13 @@ describe('codeburn status --format menubar-json', () => { const projectDir = join(home, '.claude', 'projects', 'myapp') await mkdir(projectDir, { recursive: true }) const now = new Date() - const h = now.getUTCHours() - const base = h >= 2 ? new Date(now.getTime() - 2 * 3600_000) : new Date(now.getTime() - h * 3600_000 - 300_000) + // Two hours back, clamped inside the current UTC day (runCli pins + // TZ=UTC): a plain now-2h leaves today during the first two hours of + // the day, and the old hour-guard still escaped into yesterday during + // the first five minutes of hours 0 and 1, zeroing every "today" query + // on runs that started just past the top of those hours. + const todayUtcMidnight = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()) + const base = new Date(Math.max(todayUtcMidnight, now.getTime() - 2 * 3600_000)) const ts1 = base.toISOString().replace(/\.\d+Z$/, 'Z') const ts2 = new Date(base.getTime() + 60_000).toISOString().replace(/\.\d+Z$/, 'Z') await writeFile(join(projectDir, 'session.jsonl'), [userLine('s1', ts1), assistantLine('s1', ts2, 'msg-1')].join('\n'))