feat(webui): reliability page

This commit is contained in:
2026-11-25 11:52:36 +00:00
parent 0ac9f5fb10
commit 31a09f5064
7 changed files with 731 additions and 378 deletions
+33
View File
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest'
import {
breakerRows,
dayRateTitle,
formatErrorRatePercent,
formatRatePercent,
@@ -182,3 +183,35 @@ describe('formatErrorRatePercent', () => {
expect(formatErrorRatePercent(null, 'no traffic')).toBe('no traffic')
})
})
describe('breakerRows', () => {
const p = (name: string, healthState: 'closed' | 'open' | 'half-open', extra: { openUntil?: string; lastErr?: string } = {}) => ({
name,
healthState,
openUntil: extra.openUntil ?? '0001-01-01T00:00:00Z',
lastErr: extra.lastErr,
})
it('open and half-open sorted first', () => {
const rows = breakerRows({
providers: [p('a-closed', 'closed'), p('b-half', 'half-open'), p('c-closed', 'closed'), p('d-open', 'open', { openUntil: '2026-01-01T00:00:00Z' })],
})
expect(rows.map((r) => r.provider)).toEqual(['d-open', 'b-half', 'a-closed', 'c-closed'])
expect(rows.map((r) => r.state)).toEqual(['open', 'half-open', 'closed', 'closed'])
})
it('sorts by name within the same state', () => {
const rows = breakerRows({ providers: [p('z', 'open'), p('m', 'open')] })
expect(rows.map((r) => r.provider)).toEqual(['m', 'z'])
})
it('carries openUntil and lastErr, blank when unset', () => {
const [row] = breakerRows({ providers: [p('x', 'open', { openUntil: '2026-01-01T00:00:00Z', lastErr: 'boom' })] })
expect(row).toEqual({ provider: 'x', state: 'open', openUntil: '2026-01-01T00:00:00Z', lastErr: 'boom' })
expect(breakerRows({ providers: [p('y', 'closed')] })[0]!.lastErr).toBe('')
})
it('returns nothing without an overview', () => {
expect(breakerRows(null)).toEqual([])
})
})
+19
View File
@@ -6,6 +6,8 @@
// ts's `test` block) exercise the threshold math directly, with no
// component mount required.
import type { AdminProviderView, ProviderHealthState } from '@/types/api'
/**
* PROVIDER_RATE_AMBER_THRESHOLD is the day-window success-rate fraction
* (0-1) at and above which a provider or model reads as healthy ("muted"
@@ -172,3 +174,20 @@ export function dayRateTitle(attemptsDay: number, failuresDay: number): string {
const pct = rate === null ? '' : ` (${formatRatePercent(rate)})`
return `${attemptsDay} ${countWord(attemptsDay, 'attempt', 'attempts')}, ${failuresDay} ${countWord(failuresDay, 'failure', 'failures')} today${pct}`
}
export interface BreakerRow {
provider: string
state: ProviderHealthState
openUntil: string
lastErr: string
}
const BREAKER_STATE_ORDER: Record<ProviderHealthState, number> = { open: 0, 'half-open': 1, closed: 2 }
/** One row per provider, open then half-open breakers first, ties by name. */
export function breakerRows(
overview: { providers: ReadonlyArray<Pick<AdminProviderView, 'name' | 'healthState' | 'openUntil' | 'lastErr'>> } | null,
): BreakerRow[] {
const rows = (overview?.providers ?? []).map((p) => ({ provider: p.name, state: p.healthState, openUntil: p.openUntil, lastErr: p.lastErr ?? '' }))
return rows.sort((a, b) => BREAKER_STATE_ORDER[a.state] - BREAKER_STATE_ORDER[b.state] || a.provider.localeCompare(b.provider))
}