mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-07 18:07:47 +08:00
fix(pool): 配额倒计时归零后进度条与列表恢复显示 100%
- 后端读取层 provider_key_status_snapshot_payload 复用调度侧同一判定 provider_pool_reset_deadline_elapsed,对已到期的 Codex 配额窗口归一化为 used_ratio=0 / remaining_ratio=1,并清除窗口级耗尽标记;跳过 window_minutes=0 与无用量观测的窗口 - 前端展示层在倒计时归零(isExpired)时兜底显示 100%,并隐藏重置前的旧用量 文本,保证归零瞬间即时恢复,与后端读取口径、调度口径一致 - 补充后端 2 个单测(到期归一化、遗留耗尽状态清理)与前端 1 个回归用例 (负向验证可复现旧行为) 验证:aether-provider-pool 71/71;aether-gateway lib 回归通过(仅 3 个依赖 PostgreSQL 服务端的用例因本机环境缺失失败,与本改动无关);前端 222 文件 / 1718 用例全部通过;clippy -D warnings、cargo fmt、vue-tsc、eslint 均通过。
This commit is contained in:
@@ -2061,17 +2061,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
|
||||
})
|
||||
@@ -3544,10 +3550,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: {
|
||||
|
||||
Reference in New Issue
Block a user