Prefer formatResetDuration when resetsAt is known so the status-bar chip matches the usage popup countdown instead of the fixed window size.
This commit is contained in:
@@ -57,7 +57,7 @@ import {
|
||||
} from './tooltip'
|
||||
import { ClaudeIcon, GeminiIcon, MiniMaxIcon, OpenAIIcon, OpenCodeGoIcon } from './icons'
|
||||
import { AgentIcon } from '@/lib/agent-catalog'
|
||||
import { formatWindowLabel } from '@/lib/window-label-formatter'
|
||||
import { formatRateLimitWindowChipLabel } from '@/lib/window-label-formatter'
|
||||
import { markLiveCodexSessionsForRestart } from '@/lib/codex-session-restart'
|
||||
import { UpdateStatusSegment } from './UpdateStatusSegment'
|
||||
import { isStatusBarItemAvailable } from './status-bar-agent-gating'
|
||||
@@ -1191,7 +1191,7 @@ export function ProviderSegment({
|
||||
{visibleBuckets.length === 0 && p.session && (
|
||||
<WindowLabel
|
||||
w={p.session}
|
||||
label={formatWindowLabel(p.session.windowMinutes)}
|
||||
label={formatRateLimitWindowChipLabel(p.session)}
|
||||
display={display}
|
||||
/>
|
||||
)}
|
||||
@@ -1205,14 +1205,14 @@ export function ProviderSegment({
|
||||
? {
|
||||
key: 'session',
|
||||
window: p.session,
|
||||
label: formatWindowLabel(p.session.windowMinutes)
|
||||
label: formatRateLimitWindowChipLabel(p.session)
|
||||
}
|
||||
: null,
|
||||
p.weekly
|
||||
? {
|
||||
key: 'weekly',
|
||||
window: p.weekly,
|
||||
label: formatWindowLabel(p.weekly.windowMinutes)
|
||||
label: formatRateLimitWindowChipLabel(p.weekly)
|
||||
}
|
||||
: null,
|
||||
p.fableWeekly
|
||||
@@ -1229,7 +1229,7 @@ export function ProviderSegment({
|
||||
? {
|
||||
key: 'monthly',
|
||||
window: p.monthly,
|
||||
label: formatWindowLabel(p.monthly.windowMinutes)
|
||||
label: formatRateLimitWindowChipLabel(p.monthly)
|
||||
}
|
||||
: null
|
||||
].filter((w): w is { key: string; window: RateLimitWindow; label: string } => w !== null)
|
||||
|
||||
@@ -22,8 +22,12 @@ vi.mock('../../store', () => ({
|
||||
selector({ usagePercentageDisplay: 'used' })
|
||||
}))
|
||||
|
||||
function windowOf(usedPercent: number, windowMinutes: number): RateLimitWindow {
|
||||
return { usedPercent, windowMinutes, resetsAt: null, resetDescription: null }
|
||||
function windowOf(
|
||||
usedPercent: number,
|
||||
windowMinutes: number,
|
||||
resetsAt: number | null = null
|
||||
): RateLimitWindow {
|
||||
return { usedPercent, windowMinutes, resetsAt, resetDescription: null }
|
||||
}
|
||||
|
||||
// Grok unified-billing accounts surface a monthly window and nothing else.
|
||||
@@ -83,4 +87,34 @@ describe('ProviderSegment monthly window', () => {
|
||||
expect(markup).toContain('20% used wk')
|
||||
expect(markup).not.toContain('30d')
|
||||
})
|
||||
|
||||
// Why: #8378 — status-bar chip showed fixed window size ("5h") while the
|
||||
// usage popup showed remaining time for the same resetsAt.
|
||||
it('shows remaining session time on the chip when resetsAt is known (repro-8378)', async () => {
|
||||
const { ProviderSegment } = await import('./StatusBar')
|
||||
const now = 1_700_000_000_000
|
||||
const dateNow = vi.spyOn(Date, 'now').mockReturnValue(now)
|
||||
const remainingMs = 2 * 60 * 60_000 + 33 * 60_000
|
||||
|
||||
try {
|
||||
const limits: ProviderRateLimits = {
|
||||
provider: 'codex',
|
||||
session: windowOf(42, 300, now + remainingMs),
|
||||
weekly: windowOf(10, 10080, now + 6 * 24 * 60 * 60_000),
|
||||
updatedAt: now,
|
||||
error: null,
|
||||
status: 'ok'
|
||||
}
|
||||
const markup = renderToStaticMarkup(
|
||||
<ProviderSegment p={limits} compact={false} display="used" />
|
||||
)
|
||||
|
||||
expect(markup).toContain('42% used 2h 33m')
|
||||
expect(markup).not.toContain('5h')
|
||||
expect(markup).toContain('10% used 6d')
|
||||
expect(markup).not.toContain('wk')
|
||||
} finally {
|
||||
dateNow.mockRestore()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { formatWindowLabel } from './window-label-formatter'
|
||||
import { formatResetCountdown, formatResetDuration } from '../../../shared/rate-limit-reset-format'
|
||||
import { formatRateLimitWindowChipLabel, formatWindowLabel } from './window-label-formatter'
|
||||
|
||||
const MIN = 60_000
|
||||
const HOUR = 60 * MIN
|
||||
|
||||
describe('formatWindowLabel', () => {
|
||||
it('returns "5h" for 300 minutes', () => {
|
||||
@@ -55,3 +59,30 @@ describe('formatWindowLabel', () => {
|
||||
expect(formatWindowLabel(150)).toBe('150m')
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatRateLimitWindowChipLabel', () => {
|
||||
// Why: repro for #8378 — Codex session chip said "5h" while the popup said
|
||||
// "Resets in 2h 33m" for the same resetsAt. Both surfaces must share the
|
||||
// remaining-time duration when a reset timestamp is available.
|
||||
it('shows remaining time when resetsAt is known (repro-8378)', () => {
|
||||
const now = 1_700_000_000_000
|
||||
const remainingMs = 2 * HOUR + 33 * MIN
|
||||
const window = { windowMinutes: 300, resetsAt: now + remainingMs }
|
||||
|
||||
expect(formatRateLimitWindowChipLabel(window, now)).toBe('2h 33m')
|
||||
expect(formatRateLimitWindowChipLabel(window, now)).toBe(formatResetDuration(remainingMs))
|
||||
expect(formatResetCountdown(remainingMs)).toBe('Resets in 2h 33m')
|
||||
})
|
||||
|
||||
it('falls back to fixed window size when resetsAt is null', () => {
|
||||
expect(formatRateLimitWindowChipLabel({ windowMinutes: 300, resetsAt: null })).toBe('5h')
|
||||
expect(formatRateLimitWindowChipLabel({ windowMinutes: 10080, resetsAt: null })).toBe('wk')
|
||||
})
|
||||
|
||||
it('reports "now" when the reset timestamp has already passed', () => {
|
||||
const now = 1_700_000_000_000
|
||||
expect(formatRateLimitWindowChipLabel({ windowMinutes: 300, resetsAt: now - MIN }, now)).toBe(
|
||||
'now'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { formatResetDuration } from '../../../shared/rate-limit-reset-format'
|
||||
|
||||
/**
|
||||
* Returns a short human-readable label for a usage window duration.
|
||||
*
|
||||
@@ -28,3 +30,22 @@ export function formatWindowLabel(windowMinutes: number): string {
|
||||
}
|
||||
return `${windowMinutes}m`
|
||||
}
|
||||
|
||||
/**
|
||||
* Status-bar chip label for a rate-limit window.
|
||||
*
|
||||
* Why: the popup already shows remaining time via formatResetCountdown
|
||||
* ("Resets in 2h 33m"). The chip used fixed windowMinutes labels ("5h"),
|
||||
* so the same Codex session looked out of sync (#8378). Prefer remaining
|
||||
* duration when resetsAt is known; fall back to the fixed window size only
|
||||
* when no reset timestamp is available.
|
||||
*/
|
||||
export function formatRateLimitWindowChipLabel(
|
||||
window: { windowMinutes: number; resetsAt: number | null },
|
||||
now: number = Date.now()
|
||||
): string {
|
||||
if (window.resetsAt != null) {
|
||||
return formatResetDuration(window.resetsAt - now)
|
||||
}
|
||||
return formatWindowLabel(window.windowMinutes)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user