mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-09 18:59:50 +08:00
Merge remote-tracking branch 'origin/main' into codex/usage-pending-reasoning-reset-expiry-20260712
# Conflicts: # crates/aether-ai-formats/src/formats/openai/responses/mod.rs # crates/aether-usage/runtime/src/runtime.rs # frontend/src/features/usage/components/UsageRecordsTable.vue # frontend/src/features/usage/components/__tests__/UsageRecordsTable.spec.ts
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { parseProviderKeyBatchImport } from '../providerKeyBatchImport'
|
||||
|
||||
describe('provider key batch import parser', () => {
|
||||
it('parses required names and keys separated by four hyphens', () => {
|
||||
const result = parseProviderKeyBatchImport([
|
||||
'primary----sk-primary',
|
||||
'backup----sk-backup',
|
||||
'night----sk-night----suffix',
|
||||
'# ignored comment',
|
||||
].join('\n'))
|
||||
|
||||
expect(result.errors).toEqual([])
|
||||
expect(result.items).toEqual([
|
||||
{ lineNumber: 1, name: 'primary', apiKey: 'sk-primary' },
|
||||
{ lineNumber: 2, name: 'backup', apiKey: 'sk-backup' },
|
||||
{ lineNumber: 3, name: 'night', apiKey: 'sk-night----suffix' },
|
||||
])
|
||||
})
|
||||
|
||||
it('reports invalid format, missing fields and duplicates', () => {
|
||||
const result = parseProviderKeyBatchImport([
|
||||
'one----sk-1',
|
||||
'two----sk-1',
|
||||
'one----sk-2',
|
||||
'----sk-3',
|
||||
'three----',
|
||||
'sk-without-name',
|
||||
].join('\n'))
|
||||
|
||||
expect(result.items).toHaveLength(1)
|
||||
expect(result.errors.map(error => error.message)).toEqual([
|
||||
'Key 与前面行重复',
|
||||
'名称与前面行重复',
|
||||
'名称不能为空',
|
||||
'Key 不能为空',
|
||||
'格式应为 名称----Key',
|
||||
])
|
||||
})
|
||||
|
||||
it('does not impose a client-side item limit', () => {
|
||||
const input = Array.from({ length: 750 }, (_, index) => `key-${index}----sk-${index}`).join('\n')
|
||||
const result = parseProviderKeyBatchImport(input)
|
||||
|
||||
expect(result.items).toHaveLength(750)
|
||||
expect(result.errors).toEqual([])
|
||||
})
|
||||
})
|
||||
@@ -1,52 +0,0 @@
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
|
||||
import {
|
||||
AUTO_QUOTA_REFRESH_COOLDOWN_SECONDS,
|
||||
isProviderQuotaAutoRefreshCoolingDown,
|
||||
markProviderQuotaAutoRefreshAttempt,
|
||||
resetProviderQuotaAutoRefreshCooldownForTests,
|
||||
} from '../quotaAutoRefreshCooldown'
|
||||
|
||||
describe('quota auto refresh cooldown', () => {
|
||||
afterEach(() => {
|
||||
resetProviderQuotaAutoRefreshCooldownForTests()
|
||||
})
|
||||
|
||||
it('starts cooldown after recording an auto refresh attempt', () => {
|
||||
markProviderQuotaAutoRefreshAttempt('provider-1', 1_000)
|
||||
|
||||
expect(isProviderQuotaAutoRefreshCoolingDown('provider-1', 1_000)).toBe(true)
|
||||
expect(
|
||||
isProviderQuotaAutoRefreshCoolingDown(
|
||||
'provider-1',
|
||||
1_000 + AUTO_QUOTA_REFRESH_COOLDOWN_SECONDS - 1,
|
||||
),
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('expires cooldown after the configured window', () => {
|
||||
markProviderQuotaAutoRefreshAttempt('provider-1', 1_000)
|
||||
|
||||
expect(
|
||||
isProviderQuotaAutoRefreshCoolingDown(
|
||||
'provider-1',
|
||||
1_000 + AUTO_QUOTA_REFRESH_COOLDOWN_SECONDS,
|
||||
),
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('tracks cooldown independently per provider', () => {
|
||||
markProviderQuotaAutoRefreshAttempt('provider-1', 1_000)
|
||||
markProviderQuotaAutoRefreshAttempt('provider-2', 1_200)
|
||||
|
||||
expect(isProviderQuotaAutoRefreshCoolingDown('provider-1', 1_301)).toBe(false)
|
||||
expect(isProviderQuotaAutoRefreshCoolingDown('provider-2', 1_301)).toBe(true)
|
||||
})
|
||||
|
||||
it('ignores empty provider ids', () => {
|
||||
markProviderQuotaAutoRefreshAttempt('', 1_000)
|
||||
|
||||
expect(isProviderQuotaAutoRefreshCoolingDown('', 1_001)).toBe(false)
|
||||
expect(isProviderQuotaAutoRefreshCoolingDown(null, 1_001)).toBe(false)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user