Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/main/rate-limits/codex-fetcher-pty-settle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,40 @@ describe('fetchCodexRateLimits PTY settle timers', () => {
status: 'ok'
})
})

it('keeps the reset text on the weekly window for weekly-only plans', async () => {
const ptyHandlers: { onData?: (data: string) => void } = {}

childSpawnMock.mockImplementation(() => {
throw new Error('rpc unavailable')
})
ptySpawnMock.mockReturnValue({
onData: vi.fn((callback) => {
ptyHandlers.onData = callback
return makeDisposable()
}),
onExit: vi.fn(() => makeDisposable()),
write: vi.fn(),
kill: vi.fn()
})

const resultPromise = fetchCodexRateLimits()
await vi.advanceTimersByTimeAsync(0)

const onPtyData = ptyHandlers.onData
if (!onPtyData) {
throw new Error('PTY data handler was not registered')
}

onPtyData('>')
onPtyData('Weekly limit: 76%\nResets in 5d 23h\n')

await vi.advanceTimersByTimeAsync(500)

await expect(resultPromise).resolves.toMatchObject({
session: null,
weekly: { usedPercent: 76, resetDescription: '5d 23h' },
status: 'ok'
})
})
})
8 changes: 5 additions & 3 deletions src/main/rate-limits/codex-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,10 +827,12 @@ function parsePtyStatus(output: string): {
}
: null

// Try to extract reset time from surrounding text
// Try to extract reset time from surrounding text. Weekly-only plans have
// no session window, so fall back to the weekly one instead of dropping it.
const resetMatch = RESET_TEXT_RE.exec(output)
if (resetMatch && session) {
session.resetDescription = resetMatch[1].trim()
const resetTarget = session ?? weekly
if (resetMatch && resetTarget) {
resetTarget.resetDescription = resetMatch[1].trim()
}

return { session, weekly }
Expand Down
Loading