Files
traefik-llmgateway/webui/vite.config.ts
T
lukaszraczylo a25ebf0567 fix(webui): resilient dashboard polling (SF7)
useDashboardStore.refresh() used Promise.all across overview/usage/
targets: one route rejecting threw before any of the three state
fields were assigned, so a single flaky GET /admin/api/targets blanked
the already-working Providers and Usage views too.

Switched to Promise.allSettled with per-section assignment: a
fulfilled result updates its own field, a rejected one leaves the
PREVIOUS value in place rather than nulling it. lastUpdated still
advances on a partial success (some fresh data did arrive); error
names which section(s) failed. A 401/403 on any section still defers
to the auth store exactly as before (AdminApiError check unchanged).

Added dashboard.spec.ts — the first Pinia store under vitest in this
package (a store needs no DOM, so it fits the existing 'node'
environment without pulling in jsdom); vite.config.ts's own test-scope
comment updated to say so.
2026-08-21 19:16:32 +01:00

50 lines
2.3 KiB
TypeScript

import { fileURLToPath, URL } from 'node:url'
import tailwindcss from '@tailwindcss/vite'
import vue from '@vitejs/plugin-vue'
// vitest/config's defineConfig is vite's own, augmented with the `test`
// field's types — importing from here (not 'vite') is what lets the
// `test` block below type-check under vue-tsc -b without a separate
// vitest.config.ts or a triple-slash type reference.
import { defineConfig } from 'vitest/config'
// https://vite.dev/config/
export default defineConfig({
// admin.go serves this build's index.html at GET /admin and every hashed
// asset at GET /admin/assets/{hashedname} — the base must match so the
// emitted index.html's own <script>/<link> references resolve correctly
// regardless of what path the browser first loaded the page from.
base: '/admin/',
plugins: [vue(), tailwindcss()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
build: {
// No inline bootstrap script in the emitted index.html (admin.go's CSP
// ships script-src 'self' with no 'unsafe-inline' — see the Go-side
// asset-serving comment for the full rationale): Vite's module-preload
// polyfill is otherwise inlined as a <script> tag, which that CSP would
// block. Disabling it leaves only <link rel="modulepreload"> hints,
// which need no script-src allowance at all. The admin panel only ever
// targets current evergreen browsers (native ES module support), so the
// polyfill has nothing to do here anyway.
modulePreload: { polyfill: false },
},
test: {
// Deliberately narrow: lib/'s pure modules (search-expand.ts,
// usage-search.ts) plus, since review round 2 (v0.21), stores/
// dashboard.ts's own refresh() action — a Pinia store is plain
// reactive state and actions, no DOM or component mount involved, so
// it fits this same environment. Still no snapshot/DOM/component
// (.vue mount) testing. 'node' is enough since nothing under test
// touches a real browser global — dashboard.spec.ts mocks lib/api.ts
// entirely, so even sessionStorage access (auth.ts) never actually
// runs; jsdom is not pulled in as a dependency for modules that don't
// need it.
environment: 'node',
include: ['src/**/*.spec.ts'],
},
})