98 lines
2.8 KiB
TypeScript
98 lines
2.8 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
cacheHitRates,
|
|
compareStatusMonitors,
|
|
formatCacheHitRate,
|
|
getOverallStatus,
|
|
getProbeInterval,
|
|
statusKind,
|
|
} from '../lib/status'
|
|
|
|
describe('group status mapping', () => {
|
|
it('prioritizes normal and degraded groups together, then Astra', () => {
|
|
const rows = [
|
|
{ name: 'down-astra', status: 0, uptime: 0, models: ['gpt-6-astra'] },
|
|
{ name: 'normal-luna', status: 1, uptime: 1, models: ['gpt-6-luna'] },
|
|
{
|
|
name: 'partial-astra',
|
|
status: 2,
|
|
uptime: 0.8,
|
|
models: ['gpt-6-astra'],
|
|
},
|
|
{ name: 'normal-astra', status: 1, uptime: 1, models: ['gpt-6-astra'] },
|
|
{ name: 'degraded-luna', status: 3, uptime: 0.8, models: ['gpt-6-luna'] },
|
|
{ name: 'unknown-luna', status: -1, uptime: 0, models: ['gpt-6-luna'] },
|
|
]
|
|
expect(
|
|
[...rows].sort(compareStatusMonitors).map((row) => row.name)
|
|
).toEqual([
|
|
'partial-astra',
|
|
'normal-astra',
|
|
'normal-luna',
|
|
'degraded-luna',
|
|
'down-astra',
|
|
'unknown-luna',
|
|
])
|
|
})
|
|
|
|
it('maps down monitors to error', () => {
|
|
expect(statusKind(0)).toBe('error')
|
|
})
|
|
|
|
it('uses the most severe monitor state for the summary', () => {
|
|
expect(getOverallStatus([1, 2, 0])).toBe('error')
|
|
})
|
|
|
|
it('derives the probe interval from recent heartbeats', () => {
|
|
expect(
|
|
getProbeInterval([
|
|
{ status: 1, time: '2026-09-05 10:05:00' },
|
|
{ status: 1, time: '2026-09-05 10:11:00' },
|
|
])
|
|
).toBe(6)
|
|
})
|
|
|
|
it('keeps missing samples unknown instead of reporting an outage', () => {
|
|
expect(statusKind(-1)).toBe('unknown')
|
|
expect(cacheHitRates()).toEqual({ request: null, token: null })
|
|
})
|
|
|
|
it('does not replace the normal interval with one restart sample', () => {
|
|
expect(
|
|
getProbeInterval([
|
|
{ status: 1, time: '2026-09-05 10:00:00' },
|
|
{ status: 1, time: '2026-09-05 10:06:00' },
|
|
{ status: 1, time: '2026-09-05 10:12:00' },
|
|
{ status: 1, time: '2026-09-05 10:13:00' },
|
|
])
|
|
).toBe(6)
|
|
})
|
|
|
|
it('uses request counts and total input tokens as different denominators', () => {
|
|
expect(
|
|
cacheHitRates({
|
|
requests: 4,
|
|
cached_requests: 3,
|
|
input_tokens: 1000,
|
|
cached_tokens: 900,
|
|
})
|
|
).toEqual({ request: 0.75, token: 0.9 })
|
|
expect(
|
|
cacheHitRates({
|
|
requests: 4,
|
|
cached_requests: 0,
|
|
input_tokens: 1000,
|
|
cached_tokens: 0,
|
|
})
|
|
).toEqual({ request: 0, token: 0 })
|
|
})
|
|
|
|
it('does not round a near-perfect cache rate up to 100 percent', () => {
|
|
expect(formatCacheHitRate(381763 / 381785)).toBe('99.99%')
|
|
expect(formatCacheHitRate(706457 / 706572)).toBe('99.98%')
|
|
expect(formatCacheHitRate(2 / 3)).toBe('66.7%')
|
|
expect(formatCacheHitRate(1)).toBe('100.0%')
|
|
})
|
|
})
|