fix(ui): improve keyboard access and add headed checks

This commit is contained in:
sam committed 2026-10-19 01:45:20 +11:00
1 parent e202d250ea
commit cfd4afd894
14 files changed
+123 -20

No files matched your search

+8 -1
View File
@@ -9,7 +9,7 @@ park, which is useful data for the dashboard.
| --- | --- |
| `stack.sh` | Starts PostgreSQL 18 (port 55432) and the five services as local processes, then Vite on 5173 |
| `seed.sh` | Seeds the stack through the dashboard API; safe to rerun |
| `run.cjs` | Runs `checks/*.cjs` in headless Chromium; screenshots to `out/` |
| `run.cjs` | Runs `checks/*.cjs` in Chromium; screenshots to `out/` |
| `checks/` | One module per behaviour |
| `results/` | One committed report per release |
@@ -21,9 +21,16 @@ task e2e:check # list available checks (no stack needed)
task e2e:check -- list # explicitly list checks
task e2e:check -- workflow-phone # one check
task e2e:check -- all # all checks
task e2e:check -- --headed accessibility # watch a check in Chromium
task e2e:check -- --headed all # watch every check
task e2e:down # stop; e2e/stack.sh reset also deletes the data
```
Headless is the default. `--headed` opens visible Chromium and slows browser
actions to 150ms so you can follow them; assertions and saved evidence are the
same in both modes. The terminal prints each check before it starts. Headed mode
requires a graphical desktop.
Nothing reads the installed config: `stack.sh` points the XDG directories at
`${ARCHIE_DEV_DIR:-~/.local/state/archie-dev}` and writes its overlay from
`deployments/dev.toml`. Logs are in its `logs/`. `e2e/stack.sh restart archied`
+68
View File
@@ -0,0 +1,68 @@
const assert = require('node:assert/strict');
module.exports = async ({ page, go, shot }) => {
await page.setViewportSize({ width: 360, height: 700 });
await go('/tasks');
await page.getByRole('button', { name: 'Jump to', exact: true }).click();
await page.getByRole('option', { name: 'New task', exact: true }).click();
const dialog = page.getByRole('dialog');
await dialog.waitFor();
await page.waitForTimeout(200);
const bounds = await dialog.boundingBox();
assert.ok(bounds.y >= 0 && bounds.y + bounds.height <= 700, 'New task dialog extends outside viewport');
await shot('phone-task-dialog-top');
const start = dialog.getByRole('button', { name: 'Start task', exact: true });
await start.scrollIntoViewIfNeeded();
const button = await start.boundingBox();
assert.ok(button.y >= 0 && button.y + button.height <= 700, 'Start task cannot be reached by scrolling');
await shot('phone-task-dialog');
const close = dialog.getByRole('button', { name: 'Close', exact: true });
await dialog.getByRole('button', { name: 'Cancel', exact: true }).focus();
await page.keyboard.press('Tab');
assert.ok(await close.evaluate(el => el === document.activeElement), 'Close is missing from keyboard tab order');
const closeBounds = await close.boundingBox();
assert.ok(closeBounds.y >= 0 && closeBounds.y + closeBounds.height <= 700, 'Close cannot be reached by keyboard');
await page.keyboard.press('Escape');
for (const [path, title] of [['/tasks', 'Tasks'], ['/events', 'Events'], ['/account', 'Your account'], ['/settings/models', 'Models | Instance'], ['/org/models', 'Models | Organisation']]) {
await go(path);
assert.equal(await page.title(), `${title} | Archie`);
}
await page.keyboard.press('Tab');
const skip = page.getByRole('link', { name: 'Skip to main content', exact: true });
assert.ok(await skip.evaluate(el => el === document.activeElement), 'Skip link is not the first keyboard stop');
await page.keyboard.press('Enter');
assert.equal(await page.evaluate(() => document.activeElement?.id), 'main-content');
await page.getByRole('button', { name: 'Sections', exact: true }).click();
await page.getByRole('navigation', { name: 'Sections', exact: true }).getByRole('link', { name: 'Tasks', exact: true }).click();
await page.waitForTimeout(300);
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();
await page.getByRole('option', { name: 'Events', exact: true }).click();
await page.waitForTimeout(300);
assert.equal(await page.evaluate(() => document.activeElement?.id), 'main-content', 'palette navigation did not focus main');
await page.getByRole('button', { name: 'Chat with Archie', exact: true }).click();
const composer = page.getByRole('textbox', { name: 'Message Archie', exact: true });
await composer.fill('Composition in progress');
const sent = [];
await page.route('**/api/chat/stream', async route => {
sent.push(route.request().postDataJSON().text);
await route.fulfill({ contentType: 'text/event-stream', body: 'data: {"type":"done","text":"Test response"}\n\n' });
});
for (const event of [{ isComposing: true }, { keyCode: 229 }]) {
await composer.dispatchEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true, ...event });
assert.equal(await composer.inputValue(), 'Composition in progress', 'IME confirmation submitted the draft');
}
assert.equal(sent.length, 0);
await composer.press('Shift+Enter');
assert.ok((await composer.inputValue()).includes('\n'), 'Shift+Enter no longer inserts a newline');
await composer.fill('Ordinary Enter submits');
const request = page.waitForRequest('**/api/chat/stream');
await composer.press('Enter');
assert.equal((await request).postDataJSON().text, 'Ordinary Enter submits');
assert.equal(await composer.inputValue(), '');
await shot('chat-composition');
await page.getByRole('button', { name: 'Close chat', exact: true }).click();
const tab = page.getByRole('tab', { name: /^Map/ });
await tab.click();
assert.ok(await tab.evaluate(el => el === document.activeElement), 'query-only navigation stole focus');
};
+7 -5
View File
@@ -1,8 +1,7 @@
// Drive the dashboard of a running local stack (e2e/stack.sh) in headless
// Chromium. Each module in checks/ exports async ({ page, go, shot, fail }).
// Drive the dashboard of a running local stack (e2e/stack.sh) in Chromium. Each module in checks/ exports async ({ page, go, shot, fail }).
// A check fails on a thrown error or any console or page error.
//
// node e2e/run.cjs [--record VERSION] [list | all | check ...]
// node e2e/run.cjs [--headed] [--record VERSION] [list | all | check ...]
//
// Screenshots and results.json go to e2e/out/<stamp>/. --record also writes
// e2e/results/VERSION.md, the committed evidence for a release.
@@ -11,6 +10,8 @@ const path = require('path');
const base = process.env.ARCHIE_E2E_URL || 'http://localhost:5173';
const args = process.argv.slice(2);
const headed = args.includes('--headed');
if (headed) args.splice(args.indexOf('--headed'), 1);
let record = '';
if (args[0] === '--record') {
record = args[1];
@@ -22,7 +23,7 @@ if (args[0] === '--record') {
}
const available = fs.readdirSync(path.join(__dirname, 'checks')).filter((f) => f.endsWith('.cjs')).map((f) => f.slice(0, -4)).sort();
if (!args.length || (args.length === 1 && args[0] === 'list')) {
console.log(`Available browser checks:\n${available.map(name => ` ${name}`).join('\n')}\n\nRun: task e2e:check -- <check ...>\nAll: task e2e:check -- all`);
console.log(`Available browser checks:\n${available.map(name => ` ${name}`).join('\n')}\n\nRun: task e2e:check -- <check ...>\nAll: task e2e:check -- all\nWatch: task e2e:check -- --headed <check ...>`);
process.exit(0);
}
const names = args.length === 1 && args[0] === 'all' ? available : args;
@@ -37,7 +38,7 @@ const out = path.join(__dirname, 'out', stamp);
fs.mkdirSync(out, { recursive: true });
(async () => {
const browser = await chromium.launch();
const browser = await chromium.launch({ headless: !headed, slowMo: headed ? 150 : 0 });
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } });
const login = await context.request.post(base + '/api/auth/login', {
headers: { 'X-Archie-CSRF': '1', Origin: base },
@@ -52,6 +53,7 @@ fs.mkdirSync(out, { recursive: true });
await context.close();
const results = [];
for (const name of names) {
console.log(`run ${name}`);
const check = require(path.join(__dirname, 'checks', name + '.cjs'));
// A fresh page per check: open event streams pile up across navigations.
const page = await browser.newPage({ viewport: { width: 1440, height: 900 }, storageState });