From 945621a3c5cf9ccef040d18173ffc55fd225cd22 Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Wed, 25 Nov 2026 11:13:15 +0000 Subject: [PATCH] fix(webui): compact config viewer, clear unknown helper sel, harness port guard --- webui/README.md | 7 +++++ webui/e2e/visual.spec.ts | 31 +++++++++++++++++-- webui/playwright.config.ts | 5 ++-- webui/src/App.vue | 4 ++- webui/src/lib/config-sections.spec.ts | 20 ++++++++++++- webui/src/lib/config-sections.ts | 11 +++++++ webui/src/lib/helper-forms.spec.ts | 13 +++++++- webui/src/lib/helper-forms.ts | 5 ++++ webui/src/pages/ConfigPage.vue | 43 ++++++++++++++++++++++----- 9 files changed, 123 insertions(+), 16 deletions(-) diff --git a/webui/README.md b/webui/README.md index 3c01dd3..8cad859 100644 --- a/webui/README.md +++ b/webui/README.md @@ -100,3 +100,10 @@ npm run build # what `make admin-ui` runs, plus webui/generate.mjs - `generate.mjs` — reads `dist/` after `vite build` and writes `../admin_assets_gen.go`; see its own header comment for why every asset is base64-encoded rather than embedded as a raw string literal. + +## Visual harness + +`npm run test:visual` starts the mock dev server on `PW_PORT` (default 5199) +and fails fast if that port is taken, so two runs cannot share one server or +the `.screenshots/` output. Set `PW_REUSE=1` to attach to a server you +already started. diff --git a/webui/e2e/visual.spec.ts b/webui/e2e/visual.spec.ts index 973c59a..b499f5d 100644 --- a/webui/e2e/visual.spec.ts +++ b/webui/e2e/visual.spec.ts @@ -183,13 +183,38 @@ test('config change helper opens from the header and Back closes it', async ({ p await expect(page.locator('[data-panel-kind="helper"]')).toHaveCount(0) }) -test('config sections fold, filter and the copied text is redacted', async ({ page }) => { +test('config page starts compact on desktop', async ({ page }) => { + await page.setViewportSize(VIEWPORTS.desktop) + await visit(page, '#config', 'live', 'light') + const height = await page.evaluate(() => document.documentElement.scrollHeight) + expect(height).toBeLessThan(2500) +}) + +test('config clears an unknown helper sel with replace', async ({ page }) => { + await page.setViewportSize(VIEWPORTS.desktop) + await visit(page, '#config', 'live', 'light') + const before = await page.evaluate(() => history.length) + await page.goto(page.url().replace(/#.*/, '#config?sel=helper:bogus')) + await expect(page).not.toHaveURL(/sel=/) + await expect(page.locator('[data-panel-kind="helper"]')).toHaveCount(0) + expect(await page.evaluate(() => history.length)).toBeLessThanOrEqual(before + 1) +}) + +// Smoke check only: the page never renders secret-shaped strings. The real redaction guard is the Go side +// (admin_config_guard_test.go, nonSecretConfigKeys); a fixture that redacts would test the mock, not the product. +test('config sections fold and filter, and the page shows no secret-shaped strings', async ({ page }) => { await page.setViewportSize(VIEWPORTS.desktop) await visit(page, '#config', 'live', 'light') const providers = page.getByRole('region', { name: 'providers', exact: true }) + const toggle = providers.getByRole('button', { name: /providers/ }).first() + await expect(toggle).toHaveAttribute('aria-expanded', 'false') + await expect(providers.getByText('baseUrl')).toHaveCount(0) + await toggle.click() await expect(providers.getByText('baseUrl').first()).toBeVisible() - await providers.getByRole('button', { name: /providers/ }).first().click() - await expect(providers.getByRole('button', { name: /providers/ }).first()).toHaveAttribute('aria-expanded', 'false') + await page.getByRole('button', { name: 'Collapse all' }).click() + await expect(toggle).toHaveAttribute('aria-expanded', 'false') + await page.getByRole('button', { name: 'Expand all' }).click() + await expect(toggle).toHaveAttribute('aria-expanded', 'true') await page.getByLabel('Filter config sections').fill('redis') await expect(page.getByRole('region', { name: 'redis', exact: true })).toBeVisible() await expect(page.getByRole('region', { name: 'providers', exact: true })).toHaveCount(0) diff --git a/webui/playwright.config.ts b/webui/playwright.config.ts index 6f2ef68..3d818b4 100644 --- a/webui/playwright.config.ts +++ b/webui/playwright.config.ts @@ -1,6 +1,7 @@ import { defineConfig } from '@playwright/test' -const PORT = 5199 +// PW_PORT sets the dev-server port; PW_REUSE=1 attaches to a running server (default: fail fast, so two runs cannot share one). +const PORT = Number(process.env.PW_PORT ?? 5199) export default defineConfig({ testDir: './e2e', @@ -14,7 +15,7 @@ export default defineConfig({ webServer: { command: `npm run dev:mock -- --port ${PORT} --strictPort`, url: `http://localhost:${PORT}/admin/`, - reuseExistingServer: !process.env.CI, + reuseExistingServer: process.env.PW_REUSE === '1', timeout: 60_000, }, }) diff --git a/webui/src/App.vue b/webui/src/App.vue index c629bba..483f12e 100644 --- a/webui/src/App.vue +++ b/webui/src/App.vue @@ -10,11 +10,13 @@ import { useHashState } from '@/composables/useHashState' import AppLayout from '@/layout/AppLayout.vue' import type { PageId } from '@/lib/pages' import { useAuthStore } from '@/stores/auth' +import { useConfigStore } from '@/stores/config' import { useDashboardStore } from '@/stores/dashboard' import { useNavStore } from '@/stores/nav' import { resetSessionData } from '@/stores/session' const auth = useAuthStore() +const config = useConfigStore() const dashboard = useDashboardStore() const nav = useNavStore() @@ -74,7 +76,7 @@ onMounted(() => { - + diff --git a/webui/src/lib/config-sections.spec.ts b/webui/src/lib/config-sections.spec.ts index 8230215..236f8aa 100644 --- a/webui/src/lib/config-sections.spec.ts +++ b/webui/src/lib/config-sections.spec.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest' -import { filterSections, splitConfigSections } from '@/lib/config-sections' +import { filterSections, initialFold, splitConfigSections } from '@/lib/config-sections' const YAML = ['admin:', ' enabled: true', 'agents:', ' a:', ' url: x', ' b:', ' url: y', '"odd/key":', ' v: 1', 'redis:', ' addr: r'].join('\n') @@ -42,3 +42,21 @@ describe('filterSections', () => { expect(filterSections(s, 'zzz')).toEqual([]) }) }) + +describe('initialFold', () => { + const big = (key: string, n: number) => [`${key}:`, ...Array.from({ length: n - 1 }, (_, i) => ` k${i}: v`)].join('\n') + const secs = splitConfigSections([big('small', 8), big('medium', 9), big('large', 40)].join('\n')) + + it('collapses sections over 8 lines and keeps small ones open', () => { + expect([...initialFold(secs, {})].sort()).toEqual(['large', 'medium']) + }) + it('keeps the hash target open', () => { + expect([...initialFold(secs, { target: 'large' })]).toEqual(['medium']) + }) + it('keeps filter matches open', () => { + expect([...initialFold(secs, { filter: 'med' })]).toEqual(['large']) + }) + it('ignores a blank filter and an unknown target', () => { + expect([...initialFold(secs, { filter: ' ', target: 'nope' })].sort()).toEqual(['large', 'medium']) + }) +}) diff --git a/webui/src/lib/config-sections.ts b/webui/src/lib/config-sections.ts index 7a65c0b..e35ff3b 100644 --- a/webui/src/lib/config-sections.ts +++ b/webui/src/lib/config-sections.ts @@ -38,3 +38,14 @@ export function filterSections(sections: ConfigSection[], query: string): Config const q = query.trim().toLowerCase() return q === '' ? sections : sections.filter((s) => s.key.toLowerCase().includes(q)) } + +const SMALL_SECTION_LINES = 8 + +/** Keys of the sections that start collapsed: all but small ones, filter matches and the jump target. */ +export function initialFold(sections: ConfigSection[], opts: { filter?: string; target?: string }): Set { + const matched = new Set(filterSections(sections, opts.filter ?? '').map((s) => s.key)) + const filtering = (opts.filter ?? '').trim() !== '' + return new Set( + sections.filter((s) => s.lineCount > SMALL_SECTION_LINES && s.key !== opts.target && !(filtering && matched.has(s.key))).map((s) => s.key), + ) +} diff --git a/webui/src/lib/helper-forms.spec.ts b/webui/src/lib/helper-forms.spec.ts index 5528d66..08168fe 100644 --- a/webui/src/lib/helper-forms.spec.ts +++ b/webui/src/lib/helper-forms.spec.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest' -import { HELPER_IDS, HELPER_LABEL, formatHelperSel, parseHelperSel } from '@/lib/helper-forms' +import { HELPER_IDS, HELPER_LABEL, formatHelperSel, isStaleHelperSel, parseHelperSel } from '@/lib/helper-forms' describe('helper selection', () => { it('round-trips every helper id', () => { @@ -22,3 +22,14 @@ describe('helper selection', () => { for (const id of HELPER_IDS) expect(HELPER_LABEL[id]).toBeTruthy() }) }) + +describe('isStaleHelperSel', () => { + it('is false when absent or a valid helper', () => { + expect(isStaleHelperSel(undefined)).toBe(false) + expect(isStaleHelperSel('helper:router')).toBe(false) + }) + it('is true for an unknown helper id or a foreign sel the Config page cannot open', () => { + expect(isStaleHelperSel('helper:bogus')).toBe(true) + expect(isStaleHelperSel('user:alice')).toBe(true) + }) +}) diff --git a/webui/src/lib/helper-forms.ts b/webui/src/lib/helper-forms.ts index f0bf248..13bab36 100644 --- a/webui/src/lib/helper-forms.ts +++ b/webui/src/lib/helper-forms.ts @@ -25,3 +25,8 @@ export function parseHelperSel(v: string | undefined): HelperId | null { const id = v.slice(PREFIX.length + 1) return (HELPER_IDS as readonly string[]).includes(id) ? (id as HelperId) : null } + +/** True when `sel` is set but opens no helper form; the Config page has no other sheet, so it clears such a value. */ +export function isStaleHelperSel(v: string | undefined): boolean { + return v !== undefined && parseHelperSel(v) === null +} diff --git a/webui/src/pages/ConfigPage.vue b/webui/src/pages/ConfigPage.vue index 3f7e163..9bebed6 100644 --- a/webui/src/pages/ConfigPage.vue +++ b/webui/src/pages/ConfigPage.vue @@ -1,11 +1,11 @@