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.
This commit is contained in:
ozymandiashh 2026-08-04 04:11:25 +03:00
parent f9669cee33
commit 05c38dfec1

View file

@ -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'))