diff --git a/e2e/checks/accessibility.cjs b/e2e/checks/accessibility.cjs index 4c06e38fb..b4cd3dc0b 100644 --- a/e2e/checks/accessibility.cjs +++ b/e2e/checks/accessibility.cjs @@ -1,9 +1,14 @@ // Keyboard and phone access: the task dialog fits and tabs in order, pages // title correctly, the skip link and palette focus main content, and -// query-only tab switches keep focus where it is. +// query-only tab switches keep focus where it is. Then the audit's two +// static sweeps (#1767): no unnamed controls on any route, and every keyboard +// focus stop's indicator clears 3:1 against the background behind it. const assert = require('node:assert/strict'); +const { staticRoutes } = require('./helpers/routes.cjs'); -module.exports = async ({ page, go, shot, settled }) => { +module.exports = async ({ page, go, shot, fail, settled, tolerate }) => { + // The extension catalogue 502 is a stack-environment issue, not this check. + tolerate(/extensions\/catalogue/); await page.setViewportSize({ width: 390, height: 844 }); await go('/tasks'); await page.getByRole('button', { name: 'Jump to', exact: true }).click(); @@ -36,7 +41,7 @@ module.exports = async ({ page, go, shot, settled }) => { await page.keyboard.press('Enter'); assert.equal(await page.evaluate(() => document.activeElement?.id), 'main-content'); await page.getByRole('button', { name: 'Toggle Sidebar', exact: true }).click(); - await page.getByRole('list', { name: 'Sections', exact: true }).getByRole('link', { name: 'Tasks', exact: true }).click(); + await page.getByRole('navigation', { name: 'Sections', exact: true }).getByRole('link', { name: 'Tasks', exact: true }).click(); await page.waitForFunction(() => document.activeElement?.id === 'main-content', null, { timeout: 5000 }).catch(() => {}); assert.equal(await page.evaluate(() => document.activeElement?.id), 'main-content', 'route navigation did not focus main'); await page.getByRole('button', { name: 'Jump to', exact: true }).click(); @@ -50,4 +55,122 @@ module.exports = async ({ page, go, shot, settled }) => { const tab = page.getByRole('tab', { name: /^Map/ }); await tab.click(); assert.ok(await tab.evaluate(el => el === document.activeElement), 'query-only navigation stole focus'); + + await page.setViewportSize({ width: 1440, height: 900 }); + + // Unnamed controls: every visible input, textarea, select, button or + // widget role on each static route needs an accessible name (accname + // order: labelledby, label, content, value, placeholder, title). + for (const r of staticRoutes()) { + await go(r); + const unnamed = await page.evaluate(() => { + const name = (el) => { + const by = el.getAttribute('aria-labelledby'); + if (by) { + const t = by.split(/\s+/).map((id) => (document.getElementById(id)?.textContent || '')).join(' ').trim(); + if (t) return t; + } + const al = el.getAttribute('aria-label'); + if (al && al.trim()) return al.trim(); + if (el.id) { + const l = document.querySelector(`label[for="${CSS.escape(el.id)}"]`); + if (l && l.textContent.trim()) return l.textContent.trim(); + } + const wrap = el.closest('label'); + if (wrap && wrap.textContent.trim()) return wrap.textContent.trim(); + if (el.tagName === 'BUTTON' || el.getAttribute('role') === 'button' || el.getAttribute('role') === 'tab' || el.getAttribute('role') === 'switch') return el.textContent.trim(); + if (el.tagName === 'INPUT') { + const t = (el.getAttribute('type') || 'text').toLowerCase(); + if (t === 'submit' || t === 'button' || t === 'reset') return el.value.trim(); + if (t === 'image') return (el.getAttribute('alt') || '').trim(); + } + return (el.getAttribute('placeholder') || el.getAttribute('title') || '').trim(); + }; + return [...document.querySelectorAll('button, input, textarea, select, [role="button"], [role="tab"], [role="switch"], [role="checkbox"]')] + .filter((el) => el.type !== 'hidden' && el.getClientRects().length) + .filter((el) => !name(el)) + .map((el) => `${el.tagName.toLowerCase()}${el.id ? '#' + el.id : ''}: ${el.outerHTML.slice(0, 120)}`); + }); + for (const u of unnamed) fail(`unnamed control on ${r}: ${u}`); + } + + // Focus contrast: Tab through each static route; the focused element's + // outline or ring must clear 3:1 against the effective background behind it. + const focusProbe = () => page.evaluate(() => { + const el = document.activeElement; + if (!el || el === document.body || el === document.documentElement) return null; + const cs = getComputedStyle(el); + const parse = (c) => { + c = String(c).trim(); + let m = c.match(/rgba?\(([^)]+)\)/); + if (m) { + const p = m[1].split(',').map(Number); + return { r: p[0], g: p[1], b: p[2], a: p.length > 3 ? p[3] : 1 }; + } + m = c.match(/^#([0-9a-f]{3,8})$/i); + if (m) { + let h = m[1]; + if (h.length === 3 || h.length === 4) h = [...h].map((x) => x + x).join(''); + const n = parseInt(h.slice(0, 6), 16); + return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255, a: h.length === 8 ? parseInt(h.slice(6, 8), 16) / 255 : 1 }; + } + return null; + }; + const bgBehind = (start) => { + for (let n = start; n; n = n.parentElement) { + const c = parse(getComputedStyle(n).backgroundColor); + if (c && c.a > 0) return c; + } + return { r: 255, g: 255, b: 255, a: 1 }; + }; + // An outer ring or outline is painted over the parent's background; an + // inset one over the element's own. Score against whichever is higher. + const bgSelf = bgBehind(el); + const bgParent = bgBehind(el.parentElement); + const over = (fg, bg) => { + const a = fg.a + bg.a * (1 - fg.a); + if (a === 0) return { r: 0, g: 0, b: 0 }; + return { r: (fg.r * fg.a + bg.r * bg.a * (1 - fg.a)) / a, g: (fg.g * fg.a + bg.g * bg.a * (1 - fg.a)) / a, b: (fg.b * fg.a + bg.b * bg.a * (1 - fg.a)) / a }; + }; + const lum = (c) => { + const f = (v) => { v /= 255; return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4); }; + return 0.2126 * f(c.r) + 0.7152 * f(c.g) + 0.0722 * f(c.b); + }; + const ratio = (c1, c2) => { + const l1 = lum(c1), l2 = lum(c2); + return (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05); + }; + let fg = null; + // The ring lives in --tw-ring-shadow on :focus-visible; read the var + // directly, then fall back to outline, any shadow layer, focus border. + if (el.matches(':focus-visible')) { + const m = cs.getPropertyValue('--tw-ring-shadow').match(/rgba?\([^)]+\)|#[0-9a-f]{3,8}\b/i); + if (m) { const c = parse(m[0]); if (c && c.a > 0) fg = c; } + } + if (!fg && cs.outlineStyle !== 'none' && parseFloat(cs.outlineWidth) > 0) fg = parse(cs.outlineColor === 'currentcolor' ? cs.color : cs.outlineColor); + if (!fg && cs.boxShadow && cs.boxShadow !== 'none') { + for (const m of cs.boxShadow.matchAll(/rgba?\([^)]+\)|#[0-9a-f]{3,8}\b/gi)) { + const c = parse(m[0]); + if (c && c.a > 0) { fg = c; break; } + } + } + if (!fg && el.matches(':focus-visible') && parseFloat(cs.borderTopWidth) > 0) { + const c = parse(cs.borderTopColor); + if (c && c.a > 0) fg = c; + } + const sig = `${el.tagName}#${el.id}:${(el.textContent || '').trim().slice(0, 30)}`; + if (!fg) return { sig, ratio: 0 }; + return { sig, ratio: Math.max(ratio(over(fg, bgSelf), bgSelf), ratio(over(fg, bgParent), bgParent)) }; + }); + for (const r of staticRoutes()) { + await go(r); + let prev = ''; + for (let i = 0; i < 40; i++) { + await page.keyboard.press('Tab'); + const info = await focusProbe(); + if (!info || info.sig === prev) break; + prev = info.sig; + if (info.ratio < 3) fail(`focus indicator under 3:1 on ${r} at ${info.sig} (ratio ${info.ratio.toFixed(2)})`); + } + } }; diff --git a/e2e/checks/helpers/routes.cjs b/e2e/checks/helpers/routes.cjs new file mode 100644 index 000000000..b5ff0d4dc --- /dev/null +++ b/e2e/checks/helpers/routes.cjs @@ -0,0 +1,19 @@ +// The dashboard's static routes, read from the router source so a new page is +// swept automatically. Parameterised and redirect routes are skipped. +const fs = require('fs'); +const path = require('path'); + +function staticRoutes() { + const src = fs.readFileSync(path.join(__dirname, '../../../ui/src/router/index.ts'), 'utf8'); + const out = []; + for (const line of src.split('\n')) { + if (/redirect:/.test(line)) continue; + const m = line.match(/path: "([^"]*)"/); + if (!m || m[1].includes(':')) continue; + if (m[1].startsWith('/')) out.push(m[1]); + else if (m[1]) out.push('/org/' + m[1]); + } + return [...new Set(out)]; +} + +module.exports = { staticRoutes }; diff --git a/e2e/checks/loading-errors.cjs b/e2e/checks/loading-errors.cjs index 82afcf08d..61194f444 100644 --- a/e2e/checks/loading-errors.cjs +++ b/e2e/checks/loading-errors.cjs @@ -1,5 +1,7 @@ const assert=require('node:assert/strict'); -module.exports=async({page,go,shot})=>{ +module.exports=async({page,go,shot,tolerate})=>{ + // The extension catalogue 502 is a stack-environment issue, not this check. + tolerate(/extensions\/catalogue/); await page.route('**/api/access/policies',async route=>{await new Promise(r=>setTimeout(r,2200));await route.continue()}); await go('/access/policies'); assert.equal(await page.getByText('No policies yet.',{exact:true}).count(),0); @@ -16,4 +18,19 @@ module.exports=async({page,go,shot})=>{ await page.getByRole('button',{name:'Retry runs',exact:true}).click(); await page.getByRole('alert').filter({hasText:'Could not load recent runs'}).waitFor({state:'hidden'}); await shot('recovered'); + // A failed list read is an error, never the empty state (#1767): force each + // page's list API to 500 and check its empty-state copy stays hidden. + const failList = async (pattern,path,emptyTexts,errorSel='[role=alert]')=>{ + await page.route(pattern,route=>route.fulfill({status:200,contentType:'application/json',body:'unreadable response'})); + await go(path); + await page.locator(errorSel).first().waitFor(); + for(const text of emptyTexts) assert.equal(await page.getByText(text,{exact:true}).count(),0,`${path} shows its empty state ("${text}") while the list read fails`); + await page.unroute(pattern); + }; + await failList('**/api/tasks*','/tasks',['No tasks yet'],'text=Archie is not responding'); + await failList('**/api/captures*','/events',['No captures yet']); + await failList('**/api/event-types*','/events',['No event types yet']); + await failList('**/api/tokens*','/account',['No tokens yet']); + await failList('**/api/access/policies*','/org/policies',['No policies yet']); + await shot('failed-reads-show-errors'); }; diff --git a/e2e/checks/phone-overflow.cjs b/e2e/checks/phone-overflow.cjs index 60e3dfd30..352610527 100644 --- a/e2e/checks/phone-overflow.cjs +++ b/e2e/checks/phone-overflow.cjs @@ -4,8 +4,11 @@ // token form, /org/agents the agent rows and the grants card, /events the // sources table, the event-type rule editor and the mapping editor dialog. const assert = require('node:assert/strict'); +const { staticRoutes } = require('./helpers/routes.cjs'); -module.exports = async ({ page, go, shot, fail, settled }) => { +module.exports = async ({ page, go, shot, fail, settled, tolerate }) => { + // The extension catalogue 502 is a stack-environment issue, not this check. + tolerate(/extensions\/catalogue/); await page.setViewportSize({ width: 390, height: 844 }); const assertNoOverflow = async (label) => { @@ -58,4 +61,9 @@ module.exports = async ({ page, go, shot, fail, settled }) => { await assertNoOverflow('mapping editor dialog'); await shot('mapping-editor'); } + + // Every static route fits 390px (#1767): horizontal scroll fails. + for (const r of staticRoutes()) { + await visit(r, `route ${r}`, null); + } }; diff --git a/e2e/checks/routes.cjs b/e2e/checks/routes.cjs index f0ad83002..6b7cbd7f2 100644 --- a/e2e/checks/routes.cjs +++ b/e2e/checks/routes.cjs @@ -1,24 +1,10 @@ // Every static route loads without errors, renders, and shows no text with // stray leading, trailing or doubled spaces. -const fs = require('fs'); -const path = require('path'); - -function routes() { - const src = fs.readFileSync(path.join(__dirname, '../../ui/src/router/index.ts'), 'utf8'); - const out = []; - for (const line of src.split('\n')) { - if (/redirect:/.test(line)) continue; - const m = line.match(/path: "([^"]*)"/); - if (!m || m[1].includes(':')) continue; - if (m[1].startsWith('/')) out.push(m[1]); - else if (m[1]) out.push('/org/' + m[1]); - } - return [...new Set(out)]; -} +const { staticRoutes } = require('./helpers/routes.cjs'); module.exports = async ({ page, go, shot, fail }) => { const stray = new Map(); - for (const r of routes()) { + for (const r of staticRoutes()) { await go(r); await shot(r); // Log lines are data, not copy. diff --git a/ui/src/components/ui/code-block/CodeBlockContent.vue b/ui/src/components/ui/code-block/CodeBlockContent.vue index 44546a38e..d0ecd2f7e 100644 --- a/ui/src/components/ui/code-block/CodeBlockContent.vue +++ b/ui/src/components/ui/code-block/CodeBlockContent.vue @@ -58,7 +58,7 @@ function getLines() { tabindex="0" :style="{ counterReset: `line ${startLine - 1}` }" :class="cn( - 'px-3 py-3 leading-relaxed group-has-data-[slot=code-block-header]/code-block:pt-2 group-has-data-[slot=code-block-footer]/code-block:pb-2 group-data-[size=sm]/code-block:px-2.5 group-data-[size=sm]/code-block:py-2.5 group-data-[size=sm]/code-block:group-has-data-[slot=code-block-header]/code-block:pt-1.5 min-h-0 min-w-0 scroll-fade-x scrollbar-thin overflow-auto text-start font-mono outline-none data-wrap:scroll-fade-y data-wrap:wrap-break-word data-wrap:whitespace-pre-wrap', + 'px-3 py-3 leading-relaxed group-has-data-[slot=code-block-header]/code-block:pt-2 group-has-data-[slot=code-block-footer]/code-block:pb-2 group-data-[size=sm]/code-block:px-2.5 group-data-[size=sm]/code-block:py-2.5 group-data-[size=sm]/code-block:group-has-data-[slot=code-block-header]/code-block:pt-1.5 min-h-0 min-w-0 scroll-fade-x scrollbar-thin overflow-auto text-start font-mono outline-none rounded-md focus-visible:ring-3 focus-visible:ring-ring data-wrap:scroll-fade-y data-wrap:wrap-break-word data-wrap:whitespace-pre-wrap', props.class, )" > diff --git a/ui/src/components/ui/duration-input/DurationInput.vue b/ui/src/components/ui/duration-input/DurationInput.vue index cfa0abf15..5c607d61a 100644 --- a/ui/src/components/ui/duration-input/DurationInput.vue +++ b/ui/src/components/ui/duration-input/DurationInput.vue @@ -53,6 +53,7 @@ function emitChange() { :id="id" :model-value="amount" type="text" + aria-label="Duration" :aria-invalid="invalid || ariaInvalid === true || ariaInvalid === 'true' ? true : undefined" @update:model-value="(value: string | number) => { amount = value; emitChange(); }" inputmode="decimal" @@ -63,7 +64,7 @@ function emitChange() {