Merge pull request #869 from AAEE86/fix-pool-quota-reset-display

fix(pool): 配额倒计时归零后进度条与列表恢复显示 100%
This commit is contained in:
ZheFox
2026-10-05 12:05:03 +08:00
committed by GitHub
6 changed files with 672 additions and 29 deletions
+25 -14
View File
@@ -2063,17 +2063,23 @@ const quotaProgressMap = computed<Record<string, QuotaProgressItem[]>>(() => {
const quotaProgressDisplayMap = computed<Record<string, QuotaProgressDisplayItem[]>>(() => {
const map: Record<string, QuotaProgressDisplayItem[]> = {}
for (const key of keyPage.value.keys) {
map[key.key_id] = (quotaProgressMap.value[key.key_id] || []).map(item => ({
label: getQuotaProgressLabel(item.label),
remainingPercent: item.remainingPercent,
resetText: getQuotaProgressResetDisplayText(item),
meterText: item.numericOnly
? item.detail || formatQuotaValue(item.remainingPercent)
: getQuotaProgressMeterDisplayText(item),
barClass: getQuotaRemainingBarColorByRemaining(item.remainingPercent),
meterClass: getQuotaRemainingClassByRemaining(item.remainingPercent),
numericOnly: item.numericOnly,
}))
map[key.key_id] = (quotaProgressMap.value[key.key_id] || []).map(item => {
// 倒计时归零表示窗口已越过重置时间点:按“已重置”展示 100%,
// 不再显示重置前的旧用量文本,与后端读取口径、调度口径保持一致。
const expired = !item.numericOnly && getQuotaProgressCountdown(item)?.isExpired === true
const remainingPercent = expired ? 100 : item.remainingPercent
return {
label: getQuotaProgressLabel(item.label),
remainingPercent,
resetText: getQuotaProgressResetDisplayText(item),
meterText: item.numericOnly
? item.detail || formatQuotaValue(remainingPercent)
: getQuotaProgressMeterDisplayText(item, remainingPercent, expired),
barClass: getQuotaRemainingBarColorByRemaining(remainingPercent),
meterClass: getQuotaRemainingClassByRemaining(remainingPercent),
numericOnly: item.numericOnly,
}
})
}
return map
})
@@ -3563,10 +3569,15 @@ function getQuotaProgressResetDisplayText(item: QuotaProgressItem): string {
return ''
}
function getQuotaProgressMeterDisplayText(item: QuotaProgressItem): string {
const detail = item.detail?.trim() || ''
function getQuotaProgressMeterDisplayText(
item: QuotaProgressItem,
remainingPercent = item.remainingPercent,
suppressDetail = false,
): string {
// 窗口已重置时忽略重置前的旧用量文本,直接显示归一化后的剩余百分比。
const detail = suppressDetail ? '' : (item.detail?.trim() || '')
if (!shouldHideQuotaProgressDetailText(detail) && detail) return detail
return `${item.remainingPercent.toFixed(1)}%`
return `${remainingPercent.toFixed(1)}%`
}
function getQuotaFallbackText(key: PoolKeyDetail): string | null {
@@ -35,6 +35,10 @@ const routeMocks = vi.hoisted(() => ({
}),
}))
const countdownMocks = vi.hoisted(() => ({
isExpired: false,
}))
const proxyStoreMocks = vi.hoisted(() => ({
ensureLoaded: vi.fn(),
}))
@@ -106,7 +110,7 @@ vi.mock('@/composables/useCountdownTimer', async () => {
start: vi.fn(),
}),
getCodexResetCountdown: () => ({
isExpired: false,
isExpired: countdownMocks.isExpired,
text: '1h',
}),
}
@@ -604,6 +608,7 @@ beforeEach(() => {
window.sessionStorage.clear()
routeMocks.patchQuery.mockClear()
proxyStoreMocks.ensureLoaded.mockClear()
countdownMocks.isExpired = false
endpointMocks.getPoolOverview.mockReset()
endpointMocks.getPoolSchedulingPresets.mockReset()
@@ -736,6 +741,44 @@ describe('PoolManagement Codex cycle stats mode', () => {
expect(root.textContent).toContain('生图')
})
it('shows expired Codex quota windows as fully restored', async () => {
countdownMocks.isExpired = true
const expiredKey = createPoolKey('codex', {
status_snapshot: {
oauth: { code: 'valid' },
account: { code: 'ok', blocked: false },
quota: {
code: 'ok',
exhausted: false,
provider_type: 'codex',
windows: [
{
code: '5h',
label: '5H',
scope: 'account',
remaining_ratio: 0.12,
reset_at: 1_700_000_000,
window_minutes: 300,
},
],
},
},
})
endpointMocks.getPoolOverview.mockResolvedValue({ items: [createOverview('codex')] })
endpointMocks.listPoolKeys.mockResolvedValue(createKeyPage(expiredKey))
endpointMocks.getProvider.mockResolvedValue(createProvider('codex'))
const root = mountPoolManagement()
await settle()
// 倒计时归零后进度条与文本按“已重置”显示 100%,不再显示旧百分比。
expect(root.querySelector('[data-testid="pool-quota-meter-text"]')?.textContent?.trim()).toBe('100.0%')
const track = root.querySelector('[data-testid="pool-quota-progress-track"]')
const bar = track?.firstElementChild as HTMLElement | null
expect(bar?.style.width).toBe('100%')
expect(root.querySelector('[data-testid="pool-quota-reset-text"]')).toBeNull()
})
it('labels Codex quota by the actual refresh window duration', async () => {
const monthlyCodexKey = createPoolKey('codex', {
status_snapshot: {