diff --git a/webui/e2e/visual.spec.ts b/webui/e2e/visual.spec.ts index 70e0766..973c59a 100644 --- a/webui/e2e/visual.spec.ts +++ b/webui/e2e/visual.spec.ts @@ -145,6 +145,58 @@ for (const [vp, size] of Object.entries(VIEWPORTS)) { } } +// The Change helper sheet, deep-linked onto a form: captured whole like the entity panels. +for (const form of ['router', 'limits'] as const) { + for (const [vp, size] of Object.entries(VIEWPORTS)) { + for (const theme of THEMES) { + test(`config helper ${form} live ${vp} ${theme}`, async ({ page }) => { + await page.setViewportSize(size) + await exercise(page, `config-helper-${form}`, `#config?sel=helper:${form}`, 'live', vp as keyof typeof VIEWPORTS, theme) + await expect(page.locator('[data-panel-kind="helper"]')).toHaveAttribute('data-panel-id', form) + await expect(page.getByRole('button', { name: 'Smart router', pressed: form === 'router' })).toBeVisible() + }) + } + } +} + +// Config warnings show as callouts above the viewer; the global banner steps aside on this page. +for (const [vp, size] of Object.entries(VIEWPORTS)) { + for (const theme of THEMES) { + test(`config warnings config-warnings ${vp} ${theme}`, async ({ page }) => { + await page.setViewportSize(size) + await exercise(page, 'config-warnings', '#config', 'config-warnings', vp as keyof typeof VIEWPORTS, theme) + await expect(page.getByTestId('config-warnings').getByText('Config warning')).toHaveCount(5) + await expect(page.getByRole('button', { name: /configuration warning details/ })).toHaveCount(0) + }) + } +} + +// Opening and closing the helper from the header moves the hash, and Back closes it. +test('config change helper opens from the header and Back closes it', async ({ page }) => { + await page.setViewportSize(VIEWPORTS.desktop) + await visit(page, '#config', 'live', 'light') + await page.getByRole('button', { name: 'Change helper' }).click() + await expect(page).toHaveURL(/#config\?.*sel=helper(%3A|:)limits/) + await page.getByRole('button', { name: 'Smart router' }).click() + await expect(page).toHaveURL(/sel=helper(%3A|:)router/) + await page.goBack() + await expect(page.locator('[data-panel-kind="helper"]')).toHaveCount(0) +}) + +test('config sections fold, filter and the copied text is redacted', async ({ page }) => { + await page.setViewportSize(VIEWPORTS.desktop) + await visit(page, '#config', 'live', 'light') + const providers = page.getByRole('region', { name: 'providers', exact: true }) + 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.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) + const body = await page.locator('main').innerText() + expect(body).not.toMatch(/sk-[A-Za-z0-9]{8,}/) +}) + // Compare mode: tiles show a delta and the chart adds a dashed previous-period series. for (const theme of THEMES) { test(`overview-cmp live desktop ${theme}`, async ({ page }) => { diff --git a/webui/src/App.vue b/webui/src/App.vue index 3898eb6..c629bba 100644 --- a/webui/src/App.vue +++ b/webui/src/App.vue @@ -74,7 +74,7 @@ onMounted(() => { - + diff --git a/webui/src/components/ChangeHelper.vue b/webui/src/components/ChangeHelper.vue index 7a8f163..a4693c8 100644 --- a/webui/src/components/ChangeHelper.vue +++ b/webui/src/components/ChangeHelper.vue @@ -8,21 +8,10 @@ import PricingForm from '@/components/forms/PricingForm.vue' import RouterForm from '@/components/forms/RouterForm.vue' import UserForm from '@/components/forms/UserForm.vue' import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs' +import { HELPER_IDS, HELPER_LABEL } from '@/lib/helper-forms' +import type { HelperId } from '@/lib/helper-forms' import { useNavStore } from '@/stores/nav' -/** HELPER_IDS mirrors the Config page's own `helper` hash param (redesign-plan.md section 3.1: `helper=limits|grant|pricing|model|router|user`) — the single source of truth for which tab is selected and which form renders. */ -const HELPER_IDS = ['limits', 'grant', 'pricing', 'model', 'router', 'user'] as const -type HelperId = (typeof HELPER_IDS)[number] - -const HELPER_LABEL: Record = { - limits: 'Limits', - grant: 'Access grant', - pricing: 'Pricing', - model: 'Model metadata', - router: 'Smart router', - user: 'New user', -} - /** * ChangeHelper (redesign-plan.md section 3.4) is the Config page's * snippet-building surface: six forms (LimitsForm, GrantForm, diff --git a/webui/src/lib/config-sections.spec.ts b/webui/src/lib/config-sections.spec.ts new file mode 100644 index 0000000..8230215 --- /dev/null +++ b/webui/src/lib/config-sections.spec.ts @@ -0,0 +1,44 @@ +import { describe, expect, it } from 'vitest' + +import { filterSections, 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') + +describe('splitConfigSections', () => { + it('splits at each top-level key with 1-based start lines and line counts', () => { + const s = splitConfigSections(YAML) + expect(s.map((x) => [x.key, x.startLine, x.lineCount])).toEqual([ + ['admin', 1, 2], + ['agents', 3, 5], + ['odd/key', 8, 2], + ['redis', 10, 2], + ]) + }) + + it('keeps each section text verbatim so the sections join back to the document', () => { + expect(splitConfigSections(YAML).map((x) => x.text).join('\n')).toBe(YAML) + }) + + it('returns no sections for empty text', () => { + expect(splitConfigSections('')).toEqual([]) + }) + + it('does not treat list items or comments at column 0 as keys', () => { + const s = splitConfigSections(['a:', '- x: 1', '# note', 'b: 2'].join('\n')) + expect(s.map((x) => x.key)).toEqual(['a', 'b']) + expect(s[0].lineCount).toBe(3) + }) +}) + +describe('filterSections', () => { + const s = splitConfigSections(YAML) + it('returns all sections for a blank query', () => { + expect(filterSections(s, ' ')).toHaveLength(4) + }) + it('matches keys case-insensitively by substring', () => { + expect(filterSections(s, 'AG').map((x) => x.key)).toEqual(['agents']) + }) + it('returns none when nothing matches', () => { + expect(filterSections(s, 'zzz')).toEqual([]) + }) +}) diff --git a/webui/src/lib/config-sections.ts b/webui/src/lib/config-sections.ts new file mode 100644 index 0000000..7a65c0b --- /dev/null +++ b/webui/src/lib/config-sections.ts @@ -0,0 +1,40 @@ +export interface ConfigSection { + key: string + /** 1-based line of the key in the full document. */ + startLine: number + lineCount: number + text: string +} + +const TOP_KEY = /^([^\s#-][^:]*|"[^"]*"|'[^']*'):/ + +function unquote(raw: string): string { + const q = raw[0] + return (q === '"' || q === "'") && raw.endsWith(q) ? raw.slice(1, -1) : raw +} + +/** Splits a block-style YAML document at its column-0 keys; joining the section texts with newlines gives the document back. */ +export function splitConfigSections(yaml: string): ConfigSection[] { + if (yaml === '') return [] + const out: ConfigSection[] = [] + const lines = yaml.split('\n') + let current: { key: string; startLine: number; lines: string[] } | null = null + const flush = (): void => { + if (current) out.push({ key: current.key, startLine: current.startLine, lineCount: current.lines.length, text: current.lines.join('\n') }) + } + lines.forEach((line, i) => { + const m = TOP_KEY.exec(line) + if (m) { + flush() + current = { key: unquote(m[1]), startLine: i + 1, lines: [line] } + } else current?.lines.push(line) + }) + flush() + return out +} + +/** Sections whose key contains the query, case-insensitively; a blank query keeps all. */ +export function filterSections(sections: ConfigSection[], query: string): ConfigSection[] { + const q = query.trim().toLowerCase() + return q === '' ? sections : sections.filter((s) => s.key.toLowerCase().includes(q)) +} diff --git a/webui/src/lib/helper-forms.spec.ts b/webui/src/lib/helper-forms.spec.ts new file mode 100644 index 0000000..5528d66 --- /dev/null +++ b/webui/src/lib/helper-forms.spec.ts @@ -0,0 +1,24 @@ +import { describe, expect, it } from 'vitest' + +import { HELPER_IDS, HELPER_LABEL, formatHelperSel, parseHelperSel } from '@/lib/helper-forms' + +describe('helper selection', () => { + it('round-trips every helper id', () => { + for (const id of HELPER_IDS) expect(parseHelperSel(formatHelperSel(id))).toBe(id) + }) + it('formats as helper:', () => { + expect(formatHelperSel('router')).toBe('helper:router') + }) + it('rejects absent, unknown and non-helper values', () => { + expect(parseHelperSel(undefined)).toBeNull() + expect(parseHelperSel('helper:nope')).toBeNull() + expect(parseHelperSel('helper:')).toBeNull() + expect(parseHelperSel('user:router')).toBeNull() + }) + it('opens the first form for a bare "helper" selection', () => { + expect(parseHelperSel('helper')).toBe(HELPER_IDS[0]) + }) + it('has a label for every id', () => { + for (const id of HELPER_IDS) expect(HELPER_LABEL[id]).toBeTruthy() + }) +}) diff --git a/webui/src/lib/helper-forms.ts b/webui/src/lib/helper-forms.ts new file mode 100644 index 0000000..f0bf248 --- /dev/null +++ b/webui/src/lib/helper-forms.ts @@ -0,0 +1,27 @@ +/** The ChangeHelper forms, in picker order; the single source for the Config page's `sel=helper:` hash and the form switch. */ +export const HELPER_IDS = ['limits', 'grant', 'pricing', 'model', 'router', 'user'] as const + +export type HelperId = (typeof HELPER_IDS)[number] + +export const HELPER_LABEL: Record = { + limits: 'Limits', + grant: 'Access grant', + pricing: 'Pricing', + model: 'Model metadata', + router: 'Smart router', + user: 'New user', +} + +const PREFIX = 'helper' + +export function formatHelperSel(id: HelperId): string { + return `${PREFIX}:${id}` +} + +/** A bare `helper` opens the first form; an unknown id or foreign kind is null. */ +export function parseHelperSel(v: string | undefined): HelperId | null { + if (v === PREFIX) return HELPER_IDS[0] + if (!v?.startsWith(`${PREFIX}:`)) return null + const id = v.slice(PREFIX.length + 1) + return (HELPER_IDS as readonly string[]).includes(id) ? (id as HelperId) : null +} diff --git a/webui/src/pages/ConfigPage.vue b/webui/src/pages/ConfigPage.vue index 2d8dcc2..3f7e163 100644 --- a/webui/src/pages/ConfigPage.vue +++ b/webui/src/pages/ConfigPage.vue @@ -1,64 +1,128 @@ diff --git a/webui/src/panels/ChangeHelperPanel.vue b/webui/src/panels/ChangeHelperPanel.vue new file mode 100644 index 0000000..be03f04 --- /dev/null +++ b/webui/src/panels/ChangeHelperPanel.vue @@ -0,0 +1,53 @@ + + + diff --git a/webui/src/stores/nav.spec.ts b/webui/src/stores/nav.spec.ts index 43127bb..7d29341 100644 --- a/webui/src/stores/nav.spec.ts +++ b/webui/src/stores/nav.spec.ts @@ -92,6 +92,27 @@ describe('useNavStore panels', () => { }) }) +describe('useNavStore raw sheet selection', () => { + it('openSheet sets an opaque sel, pushes history and lets close go Back', () => { + const nav = useNavStore() + nav.goTo('config', { q: 'x' }) + nav.openSheet('helper:router') + expect(nav.params).toEqual({ q: 'x', sel: 'helper:router' }) + expect(nav.pushPending).toBe(true) + expect(nav.panelPushed).toBe(true) + }) + + it('swapSheet changes sel in place and keeps the pushed marker', () => { + const nav = useNavStore() + nav.openSheet('helper:router') + nav.pushPending = false + nav.swapSheet('helper:limits') + expect(nav.params.sel).toBe('helper:limits') + expect(nav.pushPending).toBe(false) + expect(nav.panelPushed).toBe(true) + }) +}) + describe('useNavStore no-op navigation', () => { it('goTo to the identical page and params with replace:false does not leave a push pending', () => { const nav = useNavStore() diff --git a/webui/src/stores/nav.ts b/webui/src/stores/nav.ts index 15f3d12..4967f02 100644 --- a/webui/src/stores/nav.ts +++ b/webui/src/stores/nav.ts @@ -59,12 +59,21 @@ export const useNavStore = defineStore('nav', { }, /** Opens a detail panel and pushes a history entry, so Back closes it. */ openPanel(kind: PanelKind, id: string): void { - const sel = formatSel(kind, id) + this.openSheet(formatSel(kind, id)) + }, + /** Opens a sheet whose `sel` is not an entity panel (e.g. `helper:router`), pushing a history entry like openPanel. */ + openSheet(sel: string): void { if (this.params.sel === sel) return this.params = { ...this.params, sel } this.pushPending = true this.panelPushed = true }, + /** Switches the open sheet's `sel` in place: no new history entry, and Back still closes it. */ + swapSheet(sel: string): void { + if (this.params.sel === sel) return + this.params = { ...this.params, sel } + this.pushPending = false + }, /** Goes Back when the panel owns the last history entry; otherwise drops `sel` in place. */ closePanel(): void { if (this.panelPushed && typeof window !== 'undefined') {