mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-06 01:17:46 +08:00
fix(providers): derive Codex primary quota label from window
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { getCodexQuotaWindowPresentation } from '../codexQuotaWindow'
|
||||
import {
|
||||
getCodexPrimaryQuotaWindow,
|
||||
getCodexQuotaWindowLimitLabel,
|
||||
getCodexQuotaWindowPresentation,
|
||||
} from '../codexQuotaWindow'
|
||||
|
||||
describe('getCodexQuotaWindowPresentation', () => {
|
||||
it.each([
|
||||
@@ -25,6 +29,22 @@ describe('getCodexQuotaWindowPresentation', () => {
|
||||
expect(windows.sort((a, b) => a.sortOrder - b.sortOrder).map(item => item.label)).toEqual(['5H', '周'])
|
||||
})
|
||||
|
||||
it('builds the provider limit label from the actual window duration', () => {
|
||||
expect(getCodexQuotaWindowLimitLabel({ code: 'weekly', window_minutes: 10_080 })).toBe('周限额')
|
||||
expect(getCodexQuotaWindowLimitLabel({ code: 'weekly', window_minutes: 43_800 })).toBe('月限额')
|
||||
})
|
||||
|
||||
it('selects a monthly primary window over a zero-minute weekly placeholder', () => {
|
||||
const monthly = { code: 'monthly', label: '月', window_minutes: 43_800, used_ratio: 0.02 }
|
||||
const selected = getCodexPrimaryQuotaWindow([
|
||||
monthly,
|
||||
{ code: 'weekly', label: '周', window_minutes: 0, used_ratio: 1 },
|
||||
])
|
||||
|
||||
expect(selected).toEqual(monthly)
|
||||
expect(getCodexQuotaWindowLimitLabel(selected!)).toBe('月限额')
|
||||
})
|
||||
|
||||
it('drops zero-minute placeholder windows', () => {
|
||||
expect(getCodexQuotaWindowPresentation({
|
||||
code: 'weekly',
|
||||
|
||||
@@ -60,3 +60,20 @@ export function getCodexQuotaWindowPresentation(
|
||||
sortOrder: (isSpark ? 10_000_000 : 0) + (hasExplicitWindowMinutes ? windowMinutes : fallbackOrder),
|
||||
}
|
||||
}
|
||||
|
||||
export function getCodexQuotaWindowLimitLabel(window: QuotaWindowSnapshot): string | null {
|
||||
const presentation = getCodexQuotaWindowPresentation(window)
|
||||
return presentation ? `${presentation.label}限额` : null
|
||||
}
|
||||
|
||||
export function getCodexPrimaryQuotaWindow(
|
||||
windows: QuotaWindowSnapshot[] | null | undefined,
|
||||
): QuotaWindowSnapshot | null {
|
||||
if (!Array.isArray(windows)) return null
|
||||
|
||||
for (const code of ['monthly', 'weekly']) {
|
||||
const window = windows.find(candidate => String(candidate.code || '').trim().toLowerCase() === code)
|
||||
if (window && getCodexQuotaWindowPresentation(window)) return window
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user