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:
AAEE86
2026-09-29 16:52:26 +08:00
parent 00a315e3bf
commit 309f507ef4
5 changed files with 285 additions and 17 deletions
@@ -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: {