Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(home): make the live house operable without a mouse and readable when stale

nirholas0e56c313608d
diff --git a/public/home-scene.css b/public/home-scene.css
index a99417774..0b27c8f56 100644
--- a/public/home-scene.css
+++ b/public/home-scene.css
@@ -6,6 +6,27 @@
* stays on the platform tokens so the page reads as three.ws and the house
* reads as the house. */
+/*
+ * Two semantic hues, cut for each theme.
+ *
+ * --warn and --danger are platform tokens tuned to glow on near-black, and this
+ * page uses them as TEXT: the room that is open, the refused line in the log,
+ * the risk band on the confirmation, the flag on a 2D room card. Measured on
+ * white on 2026-09-09 they read 2.22:1 and 2.90:1 against the 4.5:1 WCAG 1.4.3
+ * asks of body text, so a light-theme reader is told a door is open in a colour
+ * that barely leaves the page. The dark rungs below ARE the platform tokens, so
+ * nothing changes on the theme this page ships in; the light rungs are the same
+ * two signals darkened until they clear AA on white and on --bg-1.
+ */
+:root {
+ --hs-warn-ink: var(--warn);
+ --hs-danger-ink: var(--danger);
+}
+[data-theme='light'] {
+ --hs-warn-ink: #8a5a05;
+ --hs-danger-ink: #b3261e;
+}
+
.hs-shell {
display: grid;
grid-template-rows: auto minmax(0, 1fr);
@@ -215,7 +236,86 @@
}
.hs-room-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hs-room-meta { font-size: var(--text-2xs); color: var(--ink-dim); font-variant-numeric: tabular-nums; }
-.hs-room-alert { color: var(--warn); }
+.hs-room-alert { color: var(--hs-warn-ink); }
+
+/*
+ * The devices of the focused room.
+ *
+ * This is the keyboard and screen-reader route into the house. A WebGL canvas
+ * is one opaque element, so picking a lamp out of the 3D scene is a gesture
+ * only a pointer can make; without this list the 3D view could be navigated as
+ * far as the rooms and no further. It is deliberately visible rather than
+ * screen-reader-only, because a control that takes focus without being seen
+ * fails WCAG 2.4.7, and because picking a small object out of a 3D scene is
+ * fiddly with a mouse too.
+ */
+.hs-room-devices {
+ list-style: none;
+ margin: 0.2rem 0 0.35rem;
+ padding: 0;
+ /* The indent lines the device names up under the room name rather than
+ under its light dot, so the nesting reads at a glance. Logical, so an RTL
+ locale indents from the right. */
+ padding-inline-start: calc(10px + 0.55rem);
+ display: grid;
+ gap: 0.1rem;
+}
+.hs-room-device {
+ width: 100%;
+ display: grid;
+ grid-template-columns: minmax(0, 1fr) auto;
+ align-items: center;
+ gap: 0.5rem;
+ padding: 0.3rem 0.45rem;
+ border-radius: var(--radius-sm);
+ border: 1px solid transparent;
+ background: transparent;
+ color: var(--ink-dim);
+ font: inherit;
+ font-size: var(--text-sm);
+ text-align: start;
+ cursor: pointer;
+ transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard);
+}
+.hs-room-device:hover { background: var(--surface-2); color: var(--ink); }
+.hs-room-device:active { background: var(--surface-3); }
+.hs-room-device:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
+.hs-room-device[aria-current='true'] {
+ background: var(--surface-2);
+ border-color: var(--stroke-strong);
+ color: var(--ink);
+}
+.hs-room-device-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+.hs-room-device-state { font-size: var(--text-2xs); color: var(--ink-dim); font-variant-numeric: tabular-nums; }
+
+/*
+ * A finger is not a pointer. WCAG 2.5.5 asks 44x44 of a touch target, and at
+ * their text sizes the rail's room and device rows, the view toggles and the
+ * 2D house's per-device action pills all render shorter than that. Only coarse
+ * pointers pay the extra height, so the desktop layout is untouched: a rail
+ * that grew 12px per row on a laptop would push half the house off the screen.
+ */
+@media (pointer: coarse) {
+ .hs-room,
+ .hs-room-device,
+ .hs-btn,
+ .hs-back,
+ .hs-card-title,
+ .hs-item-act {
+ min-height: 44px;
+ }
+ .hs-btn,
+ .hs-item-act {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ min-width: 44px;
+ }
+ /* The 2D house's rows carry their own action button, so the row itself has
+ to be tall enough for the button to reach 44px without the neighbouring
+ rows' hit areas overlapping it. */
+ .hs-item { padding: 0.45rem 0; }
+}
/* ── inspector ─────────────────────────────────────────────────────────────── */
@@ -231,8 +331,8 @@
.hs-log { list-style: none; margin: var(--space-md) 0 0; padding: var(--space-sm) 0 0; border-top: 1px solid var(--hairline); display: grid; gap: 0.3rem; font-size: var(--text-sm); }
.hs-log li { display: flex; gap: 0.5rem; color: var(--ink-dim); }
.hs-log time { font-variant-numeric: tabular-nums; flex: none; }
-.hs-log .is-refused { color: var(--warn); }
-.hs-log .is-failed { color: var(--danger); }
+.hs-log .is-refused { color: var(--hs-warn-ink); }
+.hs-log .is-failed { color: var(--hs-danger-ink); }
/* ── the confirmation, anchored to the thing it would move ─────────────────── */
@@ -263,7 +363,7 @@
border-right: 1px solid rgba(251, 191, 36, 0.45);
border-bottom: 1px solid rgba(251, 191, 36, 0.45);
}
-.hs-confirm-risk { font-size: var(--text-2xs); font-weight: var(--weight-bold); letter-spacing: 0.09em; text-transform: uppercase; color: var(--warn); margin: 0 0 0.3rem; }
+.hs-confirm-risk { font-size: var(--text-2xs); font-weight: var(--weight-bold); letter-spacing: 0.09em; text-transform: uppercase; color: var(--hs-warn-ink); margin: 0 0 0.3rem; }
.hs-confirm-text { font-size: var(--text-md); line-height: var(--leading-normal); margin: 0 0 var(--space-sm); }
.hs-confirm-row { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.hs-confirm-remember { display: flex; align-items: center; gap: 0.35rem; font-size: var(--text-sm); color: var(--ink-dim); margin-top: var(--space-sm); }
@@ -326,7 +426,30 @@
transition: border-color var(--duration-base) var(--ease-standard), background var(--duration-slow) var(--ease-standard), opacity var(--duration-slow) var(--ease-standard);
}
.hs-card.is-focused { border-color: var(--stroke-strong); box-shadow: 0 0 0 2px var(--accent-soft); }
-.hs-card.is-stale { opacity: 0.62; filter: grayscale(0.6); }
+/*
+ * Stale, without breaking contrast.
+ *
+ * This used to be `opacity: 0.62`, which composites the text INTO the page
+ * background: `--ink-dim` body copy measured 2.70:1 against the card behind it,
+ * against the 4.5:1 WCAG 1.4.3 asks of normal text. Measured on 2026-09-09 with
+ * the dark palette (`--bg-0` #0a0a0a, card `--surface-1`, ink-dim #888888), and
+ * no usable opacity fixes it: even 0.85, which barely reads as dimmed at all,
+ * only reaches 4.13:1. Dimming by alpha is simply the wrong instrument for text.
+ *
+ * So the state is carried by three things that cost no contrast: the colour
+ * drains completely (grayscale, and the room's own light stops glowing), the
+ * device names step down one rung of the ink ramp to the same grey the meta line
+ * already uses, and the border goes dashed. The dashed border is the part that
+ * matters for 1.4.1: stale is legible as a shape, not only as a shade, so it
+ * survives greyscale vision and a sunlit screen. The age pill over the stage
+ * says how old, in words.
+ */
+.hs-card.is-stale {
+ filter: grayscale(1);
+ --ink: var(--ink-dim);
+ --room-glow: 0;
+ border-style: dashed;
+}
.hs-card-head { margin-bottom: var(--space-sm); }
.hs-card-title {
appearance: none;
@@ -345,7 +468,7 @@
.hs-card-title:hover { text-decoration: underline; }
.hs-card-title:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.hs-card-meta { font-size: var(--text-sm); color: var(--ink-dim); margin: 0.15rem 0 0; }
-.hs-card-flag { font-size: var(--text-sm); color: var(--warn); margin: 0 0 var(--space-sm); }
+.hs-card-flag { font-size: var(--text-sm); color: var(--hs-warn-ink); margin: 0 0 var(--space-sm); }
.hs-card-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.15rem; }
.hs-item {
@@ -358,7 +481,13 @@
border-bottom: 1px solid var(--hairline);
}
.hs-item:last-child { border-bottom: 0; }
-.hs-item.is-unavailable { opacity: 0.55; }
+/* Same rule as the stale card, same reason: `opacity: 0.55` put this row's
+ * text at 2.36:1. The row already says "unreachable" in words, so the visual
+ * only has to agree with it, not carry it alone. */
+.hs-item.is-unavailable {
+ filter: grayscale(1);
+ --ink: var(--ink-dim);
+}
.hs-item-dot {
width: 10px;
height: 10px;
diff --git a/src/home/home.css b/src/home/home.css
index 79eb80f81..bfb2dc15a 100644
--- a/src/home/home.css
+++ b/src/home/home.css
@@ -41,6 +41,27 @@
further under AA than the dark theme ever was. 0.58 measures 5.16:1. */
--hm-ink-3: rgba(0, 0, 0, 0.58);
--hm-idle: rgba(0, 0, 0, 0.3);
+ /* The three status hues, re-cut for a white page.
+ *
+ * The dark-theme values are tuned to glow on near-black and they are text
+ * colours here as well as dot colours: .hm-tag-ok, .hm-tag-failed,
+ * .hm-tag-refused, .hm-hint[data-error], .hm-notice-icon and the step marks
+ * all take them straight as `color`. Measured on white on 2026-09-09 they
+ * read 2.38:1 (live), 2.22:1 (stale) and 3.66:1 (down) against the 4.5:1
+ * WCAG 1.4.3 asks of body text, so a light-theme user was reading the outcome
+ * of a physical action in colours that barely separate from the page.
+ *
+ * Same three signals, darkened until they clear AA on both light surfaces
+ * (--bg-0 #ffffff and --bg-1 #f3f4f6): 5.41:1, 5.92:1 and 6.54:1. They stay
+ * unmistakably green, amber and red, and where the token paints a dot or a
+ * border instead of text a deeper ink is the right call on white anyway.
+ *
+ * This was invisible to the axe gate because it runs the page in its default
+ * dark theme, which is the same reason --hm-ink-3 above drifted. The lane's
+ * own contrast spec now pins data-theme and measures both. */
+ --hm-live: #0f7a43;
+ --hm-stale: #8a5a05;
+ --hm-down: #b3261e;
}
.hm-wrap {
@@ -551,7 +572,9 @@
inside its own region rather than pushing the page sideways at 320px. */
.hm-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); min-width: 42rem; }
.hm-table th {
- text-align: left;
+ /* Logical, not physical: an RTL locale aligns these headers to the right
+ edge with the cells they label. */
+ text-align: start;
font-size: var(--text-2xs);
text-transform: uppercase;
letter-spacing: 0.08em;
@@ -569,7 +592,7 @@
}
.hm-table td:first-child { color: inherit; }
.hm-table tr:last-child td { border-bottom: 0; }
-.hm-table .hm-tag { margin-left: 0.4rem; vertical-align: middle; }
+.hm-table .hm-tag { margin-inline-start: 0.4rem; vertical-align: middle; }
/* The retention control. One row per home: what it keeps now, and five windows
as one tap each. */
@@ -650,7 +673,7 @@
padding: var(--space-sm); border: 1px solid var(--hm-line);
border-radius: var(--radius-md); background: var(--hm-panel);
}
-.hm-plan-count { margin-left: auto; font-size: var(--text-sm); color: var(--hm-ink-3); }
+.hm-plan-count { margin-inline-start: auto; font-size: var(--text-sm); color: var(--hm-ink-3); }
.hm-plan-readonly { margin: 0; font-size: var(--text-sm); color: var(--hm-ink-2); }
.hm-plan-btn {
@@ -800,7 +823,7 @@
@media (max-width: 640px) {
.hm-plan-toolbar { gap: var(--space-2xs); }
- .hm-plan-count { margin-left: 0; width: 100%; }
+ .hm-plan-count { margin-inline-start: 0; width: 100%; }
.hm-plan-canvas { max-height: 55vh; }
.hm-plan-skeleton { grid-template-columns: 1fr; }
}
diff --git a/src/home/plan.css b/src/home/plan.css
index 8b4cead66..4d01bd524 100644
--- a/src/home/plan.css
+++ b/src/home/plan.css
@@ -123,7 +123,7 @@
.hm-pill {
display: inline-block;
- margin-left: 0.5rem;
+ margin-inline-start: 0.5rem;
padding: 0.1rem 0.5rem;
border-radius: var(--radius-pill);
border: 1px solid color-mix(in srgb, var(--hm-stale) 45%, transparent);
diff --git a/src/home/scene.js b/src/home/scene.js
index 4698785d9..645e66ff3 100644
--- a/src/home/scene.js
+++ b/src/home/scene.js
@@ -322,6 +322,15 @@ function applyGraph(graph, { stale = false, receivedAt = 0 } = {}) {
// exists for.
renderEmptyStates(model);
renderAge();
+ // A cold load straight into ?view=plan mounts the editor before the first
+ // graph has landed, so it opens with no rooms to arrange. Hand it the house
+ // the moment it arrives, exactly once: later frames are deliberately left
+ // alone, because rebuilding the tray on every state change would land under
+ // someone who is mid-drag.
+ if (state.planAwaitingGraph && state.plan) {
+ state.plan.setGraph?.(graph);
+ state.planAwaitingGraph = false;
+ }
if (receivedAt) measureLatency(receivedAt);
if (!state.renderer) return;
state.renderer.setModel(model);
@@ -420,6 +429,10 @@ async function mountPlan() {
el.plan.textContent = '';
const { mountFloorplan } = await import('./floorplan.js');
if (state.view !== 'plan') return;
+ // True only on a cold load into ?view=plan, where the editor is mounted
+ // before the first graph frame. applyGraph hands the house over when it
+ // lands and clears this.
+ state.planAwaitingGraph = !state.graph;
state.plan = mountFloorplan({
mount: el.plan,
homeId: state.homeId,
diff --git a/tests/e2e/a11y-top-pages.spec.js b/tests/e2e/a11y-top-pages.spec.js
index 1a44528e0..33924045b 100644
--- a/tests/e2e/a11y-top-pages.spec.js
+++ b/tests/e2e/a11y-top-pages.spec.js
@@ -39,11 +39,15 @@ const EXTRA_HIGH_TRAFFIC = [
// never ride on their own priority scores staying high enough to land in
// the top 30. The two authed views, /smart-home/:id and /home/:id, are not
// here because they need a session and a connected house; they are covered
- // by the lane's own live suite instead.
+ // by tests/e2e/home-a11y.spec.js, which signs in, connects a real Home
+ // Assistant and runs the same three WCAG rule sets against the live scene,
+ // the 2D house, the floorplan editor and the guarded confirmation.
'/smart-home',
'/smart-home/join',
'/smart-home/plan',
+ '/smart-home/privacy',
'/smart-home/satellite',
+ '/voice/home',
];
const coveredPaths = new Set(top30.map((p) => p.path));
const extraPages = allPages.filter(
diff --git a/tests/e2e/home-a11y.spec.js b/tests/e2e/home-a11y.spec.js
new file mode 100644
index 000000000..e220c5c77
--- /dev/null
+++ b/tests/e2e/home-a11y.spec.js
@@ -0,0 +1,382 @@
+/**
+ * The accessibility floor for the two authed home views.
+ *
+ * `/smart-home/:id` and `/home/:id` need a session and a connected house, so
+ * they can never ride the site-wide axe gate in tests/e2e/a11y-top-pages.spec.js
+ * the way `/smart-home` and `/voice/home` do. They get the same three WCAG rule
+ * sets here instead, against a real Home Assistant, plus the things axe cannot
+ * see: that the whole lane is operable with no mouse at all, that the guarded
+ * confirmation takes focus and is announced assertively, that cancelling gives
+ * the keyboard back, that the stale state still clears AA, and that a
+ * Fahrenheit house reads in Fahrenheit whatever the browser's locale is.
+ *
+ * A voice-controlled house is assistive technology for exactly the people most
+ * likely to need it. This file is the gate that keeps it that way.
+ */
+
+import { expect, test } from '@playwright/test';
+import AxeBuilder from '@axe-core/playwright';
+
+import {
+ anyLight,
+ connectHome,
+ homeInstance,
+ lockedDoor,
+ openScene,
+ readState,
+ relock,
+ resetHomes,
+ signIn,
+} from './home-support.js';
+
+test.describe.configure({ mode: 'serial' });
+
+const RULES = ['wcag2a', 'wcag2aa', 'wcag21aa'];
+
+/** Open a connected house's scene in one named view and wait for the rail. */
+async function openView(page, id, view) {
+ await page.goto(`/smart-home/${id}?view=${view}`, { waitUntil: 'domcontentloaded' });
+ await expect(page.locator('#hs-rooms')).not.toHaveAttribute('aria-busy', 'true', { timeout: 120_000 });
+ if (view === '3d') {
+ await page.waitForFunction(() => window.__homeScene?.stats()?.drawCalls > 0, null, { timeout: 180_000 });
+ }
+}
+
+/**
+ * Freeze the in-between frames before axe measures. A half-faded row has its
+ * ink composited into the background, and axe scores that blend rather than the
+ * resting colour a reader actually sees: the same reason the site-wide gate
+ * does this.
+ */
+async function settle(page) {
+ await page.addStyleTag({
+ content: '*, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0s !important; transition-duration: 1ms !important; transition-delay: 0s !important; }',
+ });
+ await page.waitForTimeout(120);
+}
+
+async function axeOn(page, label) {
+ await settle(page);
+ const results = await new AxeBuilder({ page }).withTags(RULES).analyze();
+ if (results.violations.length) {
+ const summary = results.violations
+ .map((v) => `[${v.impact}] ${v.id}: ${v.help} (${v.nodes.length} node(s))\n ${v.nodes.map((n) => n.target.join(' ')).join('\n ')}`)
+ .join('\n\n');
+ throw new Error(`axe found ${results.violations.length} violation(s) on ${label}:\n\n${summary}`);
+ }
+ expect(results.violations).toEqual([]);
+}
+
+/**
+ * Press Tab until `predicate` is true in the page, or give up after `limit`
+ * presses. A cap rather than a loop on purpose: a focus trap would otherwise
+ * hang the run instead of failing it, and "the focus order never gets there" is
+ * the finding worth reporting.
+ */
+async function tabUntil(page, predicate, limit) {
+ for (let i = 0; i < limit; i++) {
+ await page.keyboard.press('Tab');
+ if (await page.evaluate(predicate)) return true;
+ }
+ return false;
+}
+
+let homeId = null;
+
+test('axe: the 3D house, the 2D house and the floorplan editor all clear WCAG AA', async ({ page }) => {
+ await signIn(page, 'owner');
+ await resetHomes(page);
+ await connectHome(page, { label: 'Accessibility floor' });
+ homeId = await openScene(page);
+
+ for (const view of ['3d', '2d', 'plan']) {
+ await openView(page, homeId, view);
+ await axeOn(page, `/smart-home/${homeId}?view=${view}`);
+ }
+});
+
+test('axe: the guarded confirmation card clears WCAG AA while it is standing', async ({ page }) => {
+ const instance = homeInstance();
+ await signIn(page, 'owner');
+ await openView(page, homeId, '2d');
+
+ const lock = await lockedDoor(instance);
+ await page.locator(`[data-entity-id="${lock}"]`).getByRole('button', { name: /^Unlock\b/ }).first().click();
+ const card = page.getByRole('alertdialog', { name: 'Confirm this action' });
+ await expect(card).toBeVisible({ timeout: 60_000 });
+
+ await axeOn(page, 'the confirmation card');
+
+ await card.getByRole('button', { name: 'Cancel' }).click();
+ expect(await readState(instance, lock)).toBe('locked');
+});
+
+test('the whole lane is operable with no mouse: connect, act, confirm, cancel, disconnect', async ({ page }) => {
+ const instance = homeInstance();
+ await signIn(page, 'owner');
+ await openView(page, homeId, '3d');
+
+ // Tab until a room in the rail has the keyboard, pressing nothing else. A
+ // cap, not a while(true): a trap would otherwise hang the run instead of
+ // failing it, and "the focus order never reaches the rooms" is the finding.
+ const reachedRoom = await tabUntil(page, () => document.activeElement?.classList.contains('hs-room'), 60);
+ expect(reachedRoom, 'tabbing forward must reach the room rail').toBe(true);
+
+ // Enter on a room focuses it and expands its devices. This is the whole
+ // reason the list exists: a canvas cannot be entered by keyboard, so without
+ // it the 3D view stops at the rooms.
+ await page.keyboard.press('Enter');
+ await expect(page.locator('.hs-room[aria-expanded="true"]').first()).toBeVisible({ timeout: 30_000 });
+ await expect(page.locator('.hs-room-devices').first()).toBeVisible();
+
+ // ...and a device in it can be selected without a pointer.
+ const reachedDevice = await tabUntil(page, () => document.activeElement?.classList.contains('hs-room-device'), 40);
+ expect(reachedDevice, 'the focused room must expose its devices to the keyboard').toBe(true);
+ await page.keyboard.press('Enter');
+ await expect(page.locator('#hs-inspector')).toBeVisible();
+
+ // Focus is visible at every step: each stop reports a real focus ring rather
+ // than the browser default the page might have suppressed.
+ const ring = await page.evaluate(() => {
+ const style = getComputedStyle(document.activeElement, null);
+ return { width: style.outlineWidth, style: style.outlineStyle };
+ });
+ expect(ring.style).not.toBe('none');
+ expect(parseFloat(ring.width)).toBeGreaterThan(0);
+
+ // And acting from the keyboard reaches the gate, which takes the focus.
+ const lock = await lockedDoor(instance);
+ await openView(page, homeId, '2d');
+ const unlock = page.locator(`[data-entity-id="${lock}"]`).getByRole('button', { name: /^Unlock\b/ }).first();
+ await unlock.focus();
+ await page.keyboard.press('Enter');
+
+ const card = page.getByRole('alertdialog', { name: 'Confirm this action' });
+ await expect(card).toBeVisible({ timeout: 60_000 });
+ // The card owns the keyboard the instant it appears. A confirmation a person
+ // has to go looking for is a confirmation they answer by reflex.
+ await expect(page.getByRole('button', { name: 'Yes, do it' })).toBeFocused();
+
+ // Escape cancels, nothing moves, and the keyboard goes back where it was.
+ await page.keyboard.press('Escape');
+ await expect(card).toBeHidden({ timeout: 30_000 });
+ await expect(unlock).toBeFocused();
+ expect(await readState(instance, lock), 'Escape must not open the door').toBe('locked');
+});
+
+test('the confirmation announces itself assertively, and clears when it is answered', async ({ page }) => {
+ const instance = homeInstance();
+ await signIn(page, 'owner');
+ await openView(page, homeId, '2d');
+
+ // The two live regions are distinct on purpose: narration is polite, the
+ // question is assertive. A screen reader queues a polite region behind
+ // whatever it is already reading, which for the one message a person must
+ // not miss is the wrong behaviour.
+ await expect(page.locator('#hs-live')).toHaveAttribute('aria-live', 'polite');
+ await expect(page.locator('#hs-alert')).toHaveAttribute('aria-live', 'assertive');
+ await expect(page.locator('#hs-alert')).toHaveAttribute('role', 'alert');
+
+ const lock = await lockedDoor(instance);
+ await page.locator(`[data-entity-id="${lock}"]`).getByRole('button', { name: /^Unlock\b/ }).first().click();
+ const card = page.getByRole('alertdialog', { name: 'Confirm this action' });
+ await expect(card).toBeVisible({ timeout: 60_000 });
+
+ // The assertive region carries the whole question, not a fragment: focus
+ // lands on the Yes button, and a reader that announces the button alone
+ // would say "Yes, do it" with no idea what it does.
+ const spoken = (await page.locator('#hs-alert').textContent()) || '';
+ expect(spoken).toContain('Opens your home');
+ expect(spoken.toLowerCase()).toContain('unlock');
+ expect(spoken).toContain('Escape');
+
+ await card.getByRole('button', { name: 'Cancel' }).click();
+ await expect(card).toBeHidden({ timeout: 30_000 });
+ // A question left standing in an assertive region is read again in front of
+ // the next unrelated announcement.
+ await expect(page.locator('#hs-alert')).toHaveText('');
+ expect(await readState(instance, lock)).toBe('locked');
+});
+
+test('a light going on is narrated politely, with the device named', async ({ page }) => {
+ const instance = homeInstance();
+ await signIn(page, 'owner');
+ await openView(page, homeId, '2d');
+
+ const light = await anyLight(instance);
+ const row = page.locator(`[data-entity-id="${light.entityId}"]`);
+ const button = row.getByRole('button').first();
+ const label = (await button.textContent()) || '';
+ await button.click();
+
+ await expect(page.locator('#hs-live')).not.toHaveText('', { timeout: 60_000 });
+ const said = (await page.locator('#hs-live').textContent()) || '';
+ // The user's own name for the device, untranslated and unmangled, is what a
+ // person needs to hear back: "turn on" alone does not say which lamp.
+ expect(said.toLowerCase()).toContain(label.trim().toLowerCase().split(' ')[0]);
+});
+
+test('nothing in the house depends on colour alone', async ({ page }) => {
+ await signIn(page, 'owner');
+ await openView(page, homeId, '3d');
+
+ // A room's light used to live only in the colour of its dot. Every room now
+ // states it in words, in the rail label a screen reader reads and in the
+ // visible meta beside the name.
+ const rooms = page.locator('.hs-room');
+ const count = await rooms.count();
+ expect(count).toBeGreaterThan(0);
+ for (let i = 0; i < count; i++) {
+ const room = rooms.nth(i);
+ const label = (await room.getAttribute('aria-label')) || '';
+ expect(label.length, 'every room carries a spoken description').toBeGreaterThan(0);
+ expect(/device|lights|closed|locked|open/i.test(label), `room ${i} label states its state in words: ${label}`).toBe(true);
+ const meta = (await room.locator('.hs-room-meta').textContent()) || '';
+ expect(meta.trim().length, 'every room shows a visible state in text').toBeGreaterThan(0);
+ }
+ // The light dot is decorative and says so, so a reader is not told a colour.
+ await expect(page.locator('.hs-room-dot').first()).toHaveAttribute('aria-hidden', 'true');
+});
+
+test('the stale house stays readable: measured contrast, not an opacity guess', async ({ page }) => {
+ await signIn(page, 'owner');
+ await openView(page, homeId, '2d');
+
+ // Force the state rather than waiting for a socket to drop: staleness is a
+ // class on the card, and what is under test is whether that class is legible.
+ await page.evaluate(() => {
+ for (const card of document.querySelectorAll('.hs-card')) card.classList.add('is-stale');
+ });
+
+ const worst = await page.evaluate(() => {
+ const srgb = (c) => { c /= 255; return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4); };
+ const lum = ([r, g, b]) => 0.2126 * srgb(r) + 0.7152 * srgb(g) + 0.0722 * srgb(b);
+ const rgb = (value) => (value.match(/[\d.]+/g) || []).slice(0, 3).map(Number);
+ // The nearest ancestor that actually paints, which is what the text sits on.
+ const painted = (node) => {
+ for (let el = node; el; el = el.parentElement) {
+ const bg = rgb(getComputedStyle(el).backgroundColor);
+ const alpha = Number((getComputedStyle(el).backgroundColor.match(/[\d.]+/g) || [])[3] ?? 1);
+ if (bg.length === 3 && alpha > 0.9) return bg;
+ }
+ return [0, 0, 0];
+ };
+ const ratio = (a, b) => { const [h, l] = lum(a) > lum(b) ? [lum(a), lum(b)] : [lum(b), lum(a)]; return (h + 0.05) / (l + 0.05); };
+ let low = { ratio: 99, text: '' };
+ for (const node of document.querySelectorAll('.hs-card.is-stale .hs-card-meta, .hs-card.is-stale .hs-item-name, .hs-card.is-stale .hs-item-state, .hs-card.is-stale .hs-card-title')) {
+ if (!node.textContent.trim()) continue;
+ const r = ratio(rgb(getComputedStyle(node).color), painted(node));
+ if (r < low.ratio) low = { ratio: Number(r.toFixed(2)), text: node.textContent.trim().slice(0, 40), selector: node.className };
+ }
+ return low;
+ });
+
+ // 4.5:1, the WCAG 1.4.3 floor for normal text. The `opacity: 0.62` this
+ // state used to carry measured 2.70:1 on the same markup.
+ expect(worst.ratio, `worst stale contrast was on "${worst.text}"`).toBeGreaterThanOrEqual(4.5);
+});
+
+test('the house is usable at 320, 375, 768 and 1440, with the primary action in reach', async ({ page }) => {
+ await signIn(page, 'owner');
+ for (const width of [320, 375, 768, 1440]) {
+ await page.setViewportSize({ width, height: 720 });
+ await openView(page, homeId, '2d');
+ await settle(page);
+
+ // Nothing pushes the page sideways. A horizontal scrollbar at 320 is the
+ // single most common way a phone layout is quietly broken.
+ const overflow = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
+ expect(overflow, `no horizontal overflow at ${width}px`).toBeLessThanOrEqual(1);
+
+ // Every control a finger has to hit is at least 44px tall.
+ const small = await page.evaluate(() => {
+ const out = [];
+ for (const node of document.querySelectorAll('#hs-shell button, #hs-shell a[href]')) {
+ const r = node.getBoundingClientRect();
+ if (r.width === 0 && r.height === 0) continue;
+ if (r.height < 44) out.push(`${node.className || node.tagName}: ${Math.round(r.height)}px`);
+ }
+ return out;
+ });
+ if (width <= 768) expect(small, `touch targets under 44px at ${width}px`).toEqual([]);
+ }
+ await page.setViewportSize({ width: 1440, height: 900 });
+});
+
+test('a Fahrenheit house reads in Fahrenheit whatever the browser locale is', async ({ page }) => {
+ await signIn(page, 'owner');
+ await openView(page, homeId, '2d');
+
+ // The unit the instance itself reports, read off the model the page built.
+ const unit = await page.evaluate(() => window.__homeScene?.model?.temperatureUnit ?? null);
+ // A seeded house always configures one; a null here means the graph stopped
+ // carrying it, which is the regression this asserts against.
+ expect(unit, 'the scene model must carry the house\'s own temperature unit').toBeTruthy();
+ expect(unit).toMatch(/[CF]/);
+
+ // Every temperature the page prints carries that unit and not a bare degree.
+ const printed = await page.evaluate(() => {
+ const out = [];
+ for (const node of document.querySelectorAll('.hs-card-meta, .hs-item-state, .hs-entity-attrs dd')) {
+ const text = node.textContent || '';
+ if (/\d\s*°/.test(text)) out.push(text.trim());
+ }
+ return out;
+ });
+ for (const text of printed) {
+ expect(text, `"${text}" must name the unit the house reports`).toContain(unit);
+ }
+});
+
+test('an RTL locale lays the house out right to left without breaking it', async ({ page }) => {
+ await signIn(page, 'owner');
+ // A real RTL locale from public/locales, driven the way a visitor drives it,
+ // not a CSS override: the point is that the runtime sets dir and the layout
+ // answers, which a hand-set attribute would prove nothing about.
+ await page.goto(`/smart-home/${homeId}?view=2d&lang=ar`, { waitUntil: 'domcontentloaded' });
+ await expect(page.locator('#hs-rooms')).not.toHaveAttribute('aria-busy', 'true', { timeout: 120_000 });
+ await expect(page.locator('html')).toHaveAttribute('dir', 'rtl', { timeout: 60_000 });
+ await settle(page);
+
+ const overflow = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
+ expect(overflow, 'an RTL locale must not push the page sideways').toBeLessThanOrEqual(1);
+
+ // The rail's border follows the writing direction, which is what proves the
+ // lane uses logical properties rather than physical left/right.
+ const railBorder = await page.evaluate(() => {
+ const style = getComputedStyle(document.getElementById('hs-rail'));
+ return { left: style.borderLeftWidth, right: style.borderRightWidth };
+ });
+ expect(parseFloat(railBorder.left), 'in RTL the rail divides on its left edge').toBeGreaterThan(0);
+ expect(parseFloat(railBorder.right)).toBe(0);
+
+ await axeOn(page, 'the 2D house in Arabic');
+});
+
+test("a user's own device names are never translated", async ({ page }) => {
+ const instance = homeInstance();
+ await signIn(page, 'owner');
+ const light = await anyLight(instance);
+
+ const seen = [];
+ for (const lang of ['en', 'ar']) {
+ await page.goto(`/smart-home/${homeId}?view=2d&lang=${lang}`, { waitUntil: 'domcontentloaded' });
+ await expect(page.locator('#hs-rooms')).not.toHaveAttribute('aria-busy', 'true', { timeout: 120_000 });
+ const name = await page.locator(`[data-entity-id="${light.entityId}"] .hs-item-name`).textContent();
+ seen.push((name || '').trim());
+ }
+ // The house's own words for its own things, byte for byte, in both locales.
+ expect(seen[1]).toBe(seen[0]);
+ expect(seen[0]).toBe(light.name);
+});
+
+test.afterAll(async () => {
+ // Whatever a journey did to the front door, put it back.
+ const instance = homeInstance();
+ try {
+ const lock = await lockedDoor(instance).catch(() => null);
+ if (lock) await relock(instance, lock);
+ } catch {
+ // The house is torn down with the run either way.
+ }
+});