mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-11-26 10:06:31 +00:00
fix(webui): router fixture consistency and panel screenshots
Router escalation fixtures now scale tiers, reasons and outcomes with requests, and the shadow classifier differs from live. The harness captures each panel's full scroll height, runs checks on the expanded panel, and samples smartrouter/uni. RoutersPage no longer refetches on range change. The breaker State column sorts by severity.
This commit is contained in:
@@ -223,6 +223,27 @@ export async function noLiteralNaNUndefined(page: Page): Promise<CheckResult> {
|
||||
return { name: 'no-literal-NaN-undefined', ok: !m, detail: ctx }
|
||||
}
|
||||
|
||||
const PANEL_SCROLL = '[data-panel-scroll]'
|
||||
const MAX_EXPANDED_VIEWPORT_PX = 8000
|
||||
|
||||
/**
|
||||
* Grows the viewport by the panel's hidden scroll height so the whole panel is on screen.
|
||||
* A fullPage screenshot misses the Sheet's inner scroll, and axe and the geometry checks skip
|
||||
* content clipped by a scroller, so every panel check runs after this. Returns the remaining
|
||||
* hidden height (0 when the whole panel fits), or null when no panel is open.
|
||||
*/
|
||||
export async function expandPanelViewport(page: Page): Promise<number | null> {
|
||||
const box = page.locator(PANEL_SCROLL)
|
||||
if ((await box.count()) === 0) return null
|
||||
const { hidden } = await box.evaluate((el) => ({ hidden: el.scrollHeight - el.clientHeight }))
|
||||
const size = page.viewportSize()
|
||||
if (hidden > 0 && size) {
|
||||
await page.setViewportSize({ width: size.width, height: Math.min(size.height + hidden, MAX_EXPANDED_VIEWPORT_PX) })
|
||||
await page.waitForTimeout(300)
|
||||
}
|
||||
return box.evaluate((el) => Math.max(0, el.scrollHeight - el.clientHeight))
|
||||
}
|
||||
|
||||
async function guarded(name: CheckName, run: () => Promise<CheckResult>): Promise<CheckResult> {
|
||||
try {
|
||||
return await run()
|
||||
|
||||
@@ -5,7 +5,7 @@ import { expect, test } from '@playwright/test'
|
||||
import type { Page } from '@playwright/test'
|
||||
|
||||
import { PAGE_IDS } from '../src/lib/pages'
|
||||
import { collectConsoleErrors, runChecks } from './checks'
|
||||
import { collectConsoleErrors, expandPanelViewport, runChecks } from './checks'
|
||||
|
||||
const SCENARIOS = ['live', 'empty', 'limits-hot', 'breaker-open', 'redis-down', 'auth-401', 'huge'] as const
|
||||
const VIEWPORTS = {
|
||||
@@ -43,7 +43,8 @@ async function sampleIds(page: Page, scenario: string): Promise<Record<string, s
|
||||
'provider-degraded': `provider:${encodeURIComponent('amd')}`,
|
||||
'provider-open': `provider:${encodeURIComponent('alibaba')}`,
|
||||
router: `router:${encodeURIComponent(catalog.routers[0].name)}`,
|
||||
target: `target:${encodeURIComponent((targets.mcpServers[0] ?? targets.agents[0]).name)}`,
|
||||
'router-uni': `router:${encodeURIComponent(catalog.routers[1].name)}`,
|
||||
target: `target:${encodeURIComponent(targets.mcpServers[0] ? `mcp/${targets.mcpServers[0].name}` : `agent/${targets.agents[0].name}`)}`,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +58,7 @@ const PANEL_PAGES: Array<{ page: (typeof PAGE_IDS)[number]; kind: string; scenar
|
||||
{ page: 'models', kind: 'provider-open', scenario: 'breaker-open' },
|
||||
{ page: 'routers', kind: 'router' },
|
||||
{ page: 'routers', kind: 'router', scenario: 'router-escalations' },
|
||||
{ page: 'routers', kind: 'router-uni' },
|
||||
{ page: 'targets', kind: 'target' },
|
||||
]
|
||||
|
||||
@@ -83,6 +85,12 @@ async function exercise(page: Page, label: string, hash: string, scenario: strin
|
||||
mkdirSync(OUT, { recursive: true })
|
||||
const name = `${label}-${scenario}-${viewport}-${theme}`
|
||||
await page.screenshot({ path: join(OUT, `${name}.png`), fullPage: true })
|
||||
// Panels are measured and captured whole: a Sheet scrolls inside the viewport, which fullPage cannot see.
|
||||
const hiddenAfterExpand = await expandPanelViewport(page)
|
||||
if (hiddenAfterExpand !== null) {
|
||||
await page.locator('[data-panel-scroll]').screenshot({ path: join(OUT, `${name}-full.png`) })
|
||||
expect.soft(hiddenAfterExpand, `${name}: panel still scrolls after expanding the viewport`).toBe(0)
|
||||
}
|
||||
const results = await runChecks(page, errors())
|
||||
mkdirSync(join(OUT, 'results'), { recursive: true })
|
||||
writeFileSync(join(OUT, 'results', `${name}.json`), JSON.stringify({ label, scenario, viewport, theme, results, diag }))
|
||||
@@ -185,3 +193,44 @@ for (const theme of THEMES) {
|
||||
await expect(page.getByTestId('clamped-range')).toBeVisible()
|
||||
})
|
||||
}
|
||||
|
||||
// Events with a filter set in the hash: the chips show and the feed narrows. Also the Reliability handoff param.
|
||||
const EVENT_FILTER_HASHES = { 'events-filter': '#events?kind=upstream&route=chat', 'events-provider': '#events?provider=alibaba' } as const
|
||||
for (const [label, hash] of Object.entries(EVENT_FILTER_HASHES)) {
|
||||
for (const [vp, size] of Object.entries(VIEWPORTS)) {
|
||||
for (const theme of THEMES) {
|
||||
test(`${label} live ${vp} ${theme}`, async ({ page }) => {
|
||||
await page.setViewportSize(size)
|
||||
await exercise(page, label, hash, 'live', vp as keyof typeof VIEWPORTS, theme)
|
||||
await expect(page.getByRole('group', { name: /filter/i }).first()).toBeVisible()
|
||||
await expect(page.getByText(label === 'events-filter' ? /Kind.*Upstream error/i : /Provider.*alibaba/i).first()).toBeVisible()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test('events pause and resume the live tail', async ({ page }) => {
|
||||
await page.setViewportSize(VIEWPORTS.desktop)
|
||||
let polls = 0
|
||||
page.on('request', (r) => r.url().includes('/admin/api/events') && polls++)
|
||||
await visit(page, '#events', 'live', 'light')
|
||||
const status = page.getByTestId('events-live-status')
|
||||
await expect(status).toContainText('Live')
|
||||
await page.getByRole('button', { name: 'Pause' }).click()
|
||||
await expect(status).toContainText('Paused')
|
||||
const paused = polls
|
||||
await page.waitForTimeout(6500)
|
||||
expect(polls, 'no events request while paused').toBe(paused)
|
||||
await page.getByRole('button', { name: 'Resume' }).click()
|
||||
await expect(status).toContainText('Live')
|
||||
await expect.poll(() => polls).toBeGreaterThan(paused)
|
||||
})
|
||||
|
||||
test('events rows are capped and show more', async ({ page }) => {
|
||||
await page.setViewportSize(VIEWPORTS.desktop)
|
||||
await visit(page, '#events', 'huge', 'light')
|
||||
const rows = page.getByRole('list', { name: 'Events' }).locator('li')
|
||||
expect(await rows.count()).toBeLessThanOrEqual(50)
|
||||
await page.getByRole('button', { name: /Show \d+ more/ }).click()
|
||||
expect(await rows.count()).toBeGreaterThan(50)
|
||||
})
|
||||
|
||||
+21
-2
@@ -131,6 +131,17 @@ function configWarnings(path: string, body: Obj) {
|
||||
}
|
||||
}
|
||||
|
||||
const ROUTER_MIN_REQUESTS = 120
|
||||
const SHADOW_CLASSIFIER = 'v3'
|
||||
|
||||
/** Scales counts by `factor`; with `total`, the rounding remainder lands on the largest row so the rows still sum to it. */
|
||||
function scaleCounts(rows: Obj[], factor: number, total?: number) {
|
||||
for (const row of rows) row.count = Math.round(row.count * factor)
|
||||
if (total === undefined || rows.length === 0) return
|
||||
const largest = rows.reduce((a, b) => (b.count > a.count ? b : a))
|
||||
largest.count += total - rows.reduce((sum, row) => sum + row.count, 0)
|
||||
}
|
||||
|
||||
function routerEscalations(path: string, body: Obj) {
|
||||
if (path !== '/admin/api/overview' && path !== '/admin/api/catalog') return
|
||||
eachRouter(body, (r) => {
|
||||
@@ -140,9 +151,13 @@ function routerEscalations(path: string, body: Obj) {
|
||||
stats.escalations = tiers.slice(0, -1).map((from, i) => ({ from, to: tiers[i + 1], count: 14 - i * 5 }))
|
||||
if (tiers.length > 2) stats.escalations.push({ from: tiers[0], to: tiers[tiers.length - 1], count: 3 })
|
||||
stats.shadow = tiers.flatMap((live, i) => tiers.map((shadow, j) => ({ live, shadow, count: i === j ? 40 - i * 9 : 4 + ((i + j) % 3) * 3 })))
|
||||
stats.requests = Math.max(stats.requests ?? 0, 120)
|
||||
const target = Math.max(stats.requests ?? 0, ROUTER_MIN_REQUESTS)
|
||||
const factor = target / Math.max(stats.requests ?? 0, 1)
|
||||
stats.requests = target
|
||||
for (const list of [stats.tiers, stats.reasons]) scaleCounts(list ?? [], factor, target)
|
||||
scaleCounts(stats.outcomes ?? [], factor)
|
||||
r.shadowEnabled = true
|
||||
r.shadowClassifier ??= 'v2'
|
||||
r.shadowClassifier = SHADOW_CLASSIFIER
|
||||
r.fellBack = 7
|
||||
})
|
||||
}
|
||||
@@ -312,6 +327,10 @@ function huge(path: string, body: Obj) {
|
||||
body.rows = expandRows(body.rows, body.kind === 'provider' ? (id) => copies(HUGE_FACTOR, (n) => hugeProvider(id, n)) : hugeModelIds)
|
||||
} else if (path === '/admin/api/usage/totals' && body.kind === 'usermodel') {
|
||||
body.rows = expandRows(body.rows, hugeModelIds)
|
||||
} else if (path === '/admin/api/targets') {
|
||||
for (const key of ['mcpServers', 'agents']) {
|
||||
body[key] = (body[key] as Obj[]).flatMap((t) => copies(HUGE_USER_FACTOR, (n) => (n === 0 ? t : { ...t, name: `${t.name}-${n + 1}` })))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { statusRank } from './breaker-severity'
|
||||
import { sortThenSlice } from './table-sort'
|
||||
|
||||
describe('statusRank', () => {
|
||||
it('ranks open > half-open > degraded > closed', () => {
|
||||
expect(statusRank('open')).toBeGreaterThan(statusRank('half-open'))
|
||||
expect(statusRank('half-open')).toBeGreaterThan(statusRank('degraded'))
|
||||
expect(statusRank('degraded')).toBeGreaterThan(statusRank('closed'))
|
||||
})
|
||||
it('ranks an unknown state below closed so it never reads as severe', () => {
|
||||
expect(statusRank('mystery')).toBeLessThan(statusRank('closed'))
|
||||
})
|
||||
it('sorts severity-first, not alphabetically', () => {
|
||||
const rows = ['closed', 'open', 'degraded', 'half-open'].map((s) => ({ s, rank: statusRank(s) }))
|
||||
expect(sortThenSlice(rows, { key: 'rank', direction: 'desc' }, 10, 0).map((r) => r.s)).toEqual(['open', 'half-open', 'degraded', 'closed'])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,6 @@
|
||||
const SEVERITY: Record<string, number> = { open: 3, 'half-open': 2, degraded: 1, closed: 0 }
|
||||
|
||||
/** Sort rank of a breaker status, most severe highest; unknown states rank below closed. */
|
||||
export function statusRank(status: string): number {
|
||||
return SEVERITY[status] ?? -1
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { loadState } from '@/lib/load-state'
|
||||
import { pageWindow } from '@/lib/paging'
|
||||
import { sortThenSlice } from '@/lib/table-sort'
|
||||
import type { SortSpec } from '@/lib/table-sort'
|
||||
import { statusRank } from '@/lib/breaker-severity'
|
||||
import { breakerRows, ratePercentSeries } from '@/lib/provider-rate'
|
||||
import type { BreakerRow } from '@/lib/provider-rate'
|
||||
import { scopeId } from '@/lib/scope'
|
||||
@@ -31,6 +32,7 @@ const MAX_AXIS_LABELS = 6
|
||||
interface BreakerView extends BreakerRow {
|
||||
until: string
|
||||
status: string
|
||||
statusRank: number
|
||||
}
|
||||
|
||||
const dashboard = useDashboardStore()
|
||||
@@ -137,6 +139,7 @@ const breakers = computed<BreakerView[]>(() => {
|
||||
...r,
|
||||
until: r.state === 'open' ? formatUntil(r.openUntil) || 'due' : '',
|
||||
status: r.degraded ? 'degraded' : r.state,
|
||||
statusRank: statusRank(r.degraded ? 'degraded' : r.state),
|
||||
}))
|
||||
})
|
||||
const phone = ref(false)
|
||||
@@ -148,7 +151,8 @@ const breakerPageSize = computed(() => (phone.value ? BREAKER_PAGE_SIZE_PHONE :
|
||||
const breakerPage = ref(1)
|
||||
const breakerWindow = computed(() => pageWindow(breakers.value.length, breakerPageSize.value, breakerPage.value - 1))
|
||||
const breakerSort = ref<SortSpec | null>(null)
|
||||
const breakerPaged = computed(() => sortThenSlice(breakers.value, breakerSort.value, breakerPageSize.value, breakerWindow.value.index))
|
||||
const breakerSortSpec = computed<SortSpec | null>(() => (breakerSort.value?.key === 'status' ? { ...breakerSort.value, key: 'statusRank' } : breakerSort.value))
|
||||
const breakerPaged = computed(() => sortThenSlice(breakers.value, breakerSortSpec.value, breakerPageSize.value, breakerWindow.value.index))
|
||||
function onBreakerSort(next: SortSpec | null): void {
|
||||
breakerSort.value = next
|
||||
breakerPage.value = 1
|
||||
|
||||
@@ -10,7 +10,6 @@ import { sortThenSlice } from '@/lib/table-sort'
|
||||
import type { SortSpec } from '@/lib/table-sort'
|
||||
import { wbColumns } from '@/lib/wb-columns'
|
||||
import RouterPanel from '@/panels/RouterPanel.vue'
|
||||
import { useFiltersStore } from '@/stores/filters'
|
||||
import { useModelsStore } from '@/stores/models'
|
||||
import { useNavStore } from '@/stores/nav'
|
||||
import StateView from '@/widgets/StateView.vue'
|
||||
@@ -30,15 +29,10 @@ interface Row {
|
||||
escalations: number | null
|
||||
}
|
||||
|
||||
const filters = useFiltersStore()
|
||||
const models = useModelsStore()
|
||||
const nav = useNavStore()
|
||||
|
||||
onMounted(() => void models.fetch())
|
||||
watch(
|
||||
() => filters.range,
|
||||
() => void models.fetch(),
|
||||
)
|
||||
|
||||
const rows = computed<Row[]>(() =>
|
||||
models.routers.map((r) => ({
|
||||
|
||||
@@ -18,7 +18,7 @@ function onOpen(open: boolean): void {
|
||||
<SheetTitle class="truncate">{{ title }}</SheetTitle>
|
||||
<SheetDescription class="sr-only">{{ kind }} details for {{ title }}</SheetDescription>
|
||||
</SheetHeader>
|
||||
<div class="min-w-0 flex-1 overflow-y-auto">
|
||||
<div class="min-w-0 flex-1 overflow-y-auto" data-panel-scroll>
|
||||
<slot />
|
||||
</div>
|
||||
</SheetContent>
|
||||
|
||||
Reference in New Issue
Block a user