mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-07 18:07:47 +08:00
Fix usage records filtering and pool trace display
This commit is contained in:
@@ -175,6 +175,34 @@ describe('poolTrace', () => {
|
||||
expect(attempts[1].extra_data?.pool_group_id).toBe('provider-1')
|
||||
})
|
||||
|
||||
it('infers pool membership from runtime pool key metadata', () => {
|
||||
const attempts = buildPoolParticipatedCandidates([
|
||||
buildCandidate({
|
||||
id: 'cand-pool-skipped',
|
||||
candidate_index: 0,
|
||||
provider_id: 'provider-1',
|
||||
provider_name: 'CodexFree2',
|
||||
key_id: 'pool-group',
|
||||
key_name: 'CodexFree2',
|
||||
status: 'skipped',
|
||||
extra_data: { pool_group_id: 'provider-1' },
|
||||
}),
|
||||
buildCandidate({
|
||||
id: 'cand-pool-success',
|
||||
candidate_index: 1,
|
||||
provider_id: 'provider-1',
|
||||
provider_name: 'CodexFree2',
|
||||
key_id: 'key-success',
|
||||
key_name: 'Success Key',
|
||||
status: 'success',
|
||||
extra_data: { pool_key_index: 0 },
|
||||
}),
|
||||
], null, 'req-1')
|
||||
|
||||
expect(attempts).toHaveLength(2)
|
||||
expect(attempts.map(item => item.key_id)).toEqual(['pool-group', 'key-success'])
|
||||
})
|
||||
|
||||
it('treats only real execution statuses as attempted', () => {
|
||||
expect(isAttemptedCandidate(buildCandidate({ status: 'success' }))).toBe(true)
|
||||
expect(isAttemptedCandidate(buildCandidate({ status: 'failed' }))).toBe(true)
|
||||
|
||||
@@ -74,14 +74,40 @@ export const parseTimelineStatus = (value: unknown): CandidateRecord['status'] |
|
||||
}
|
||||
|
||||
export const extractPoolGroupId = (
|
||||
candidate: Pick<CandidateRecord, 'extra_data'>,
|
||||
candidate: Pick<CandidateRecord, 'extra_data' | 'provider_id'>,
|
||||
): string | null => {
|
||||
const extra = candidate.extra_data
|
||||
if (!extra || typeof extra !== 'object' || Array.isArray(extra)) return null
|
||||
const value = (extra as Record<string, unknown>).pool_group_id
|
||||
if (typeof value !== 'string') return null
|
||||
const text = value.trim()
|
||||
return text || null
|
||||
const raw = extra as Record<string, unknown>
|
||||
|
||||
for (const key of ['pool_group_id', 'candidate_group_id']) {
|
||||
const value = raw[key]
|
||||
if (typeof value === 'string') {
|
||||
const text = value.trim()
|
||||
if (text) return text
|
||||
}
|
||||
}
|
||||
|
||||
const routingTrace = raw.routing_trace
|
||||
if (routingTrace && typeof routingTrace === 'object' && !Array.isArray(routingTrace)) {
|
||||
const poolExpansion = (routingTrace as Record<string, unknown>).pool_expansion
|
||||
if (Array.isArray(poolExpansion)) {
|
||||
for (const item of poolExpansion) {
|
||||
if (!item || typeof item !== 'object' || Array.isArray(item)) continue
|
||||
const value = (item as Record<string, unknown>).pool_group_id
|
||||
if (typeof value !== 'string') continue
|
||||
const text = value.trim()
|
||||
if (text) return text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (raw.pool_key_index !== undefined && raw.pool_key_index !== null) {
|
||||
const providerId = String(candidate.provider_id || '').trim()
|
||||
if (providerId) return providerId
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function buildPoolParticipatedCandidates(
|
||||
|
||||
Reference in New Issue
Block a user