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.

chore(audit): overlay audit sweep and report

nirholas68fc70cfc3f8
diff --git a/docs/overlay-audit.md b/docs/overlay-audit.md
new file mode 100644
index 000000000..6ebd32a4a
--- /dev/null
+++ b/docs/overlay-audit.md
@@ -0,0 +1,135 @@
+# The overlay audit
+
+`npm run audit:overlays` drives a real browser over real pages and proves that no
+floating widget covers another.
+
+## Why this exists
+
+three.ws has a lot of persistent, viewport-anchored UI. The Walk Companion. The
+corner stack, with its "Getting started" pill, feature-discovery prompt and
+language switcher. Sticky headers, CTA rails, chat launchers, the command
+palette. Every one of them is correct on its own.
+
+They are only wrong together, and only sometimes. A collision needs the right
+page, the right viewport, and the right combination of widgets to be switched on
+at the same time. That is a state no unit test reaches and neither widget's
+author ever sees. So these bugs shipped, were found by a person squinting at a
+screenshot, and were fixed with a magic offset that the next widget then broke.
+
+The audit replaces the squinting. It finds every painted `position: fixed` or
+`position: sticky` overlay on a page, intersects them pairwise, and reports the
+ones that hide each other, with a screenshot of the offence.
+
+## Running it
+
+```bash
+npm run audit:overlays # curated routes, 3 viewports
+npm run audit:overlays -- --all # every public HTML route
+npm run audit:overlays -- --routes /,/examples,/docs
+npm run audit:overlays -- --base https://three.ws # audit production
+npm run audit:overlays -- --viewport mobile
+npm run audit:overlays -- --json # machine-readable findings
+```
+
+It targets `http://localhost:3000` (`npm run dev`) by default, so a run reflects
+your working tree. It exits `1` if it finds a collision or fails to render a
+route, which makes it usable as a release gate.
+
+Results land in `reports/overlays/` (gitignored):
+
+| File | What it is |
+| --- | --- |
+| `index.html` | The browsable report: one card per failing route with the annotated screenshot |
+| `report.json` | Every finding, with boxes and overlap areas, for tooling |
+| `shots/` | The annotated PNGs |
+
+In the screenshots, dashed boxes are the two offenders and the filled box is the
+region one hides of the other.
+
+## What counts as a collision
+
+Precision matters more than recall here. A report with one false positive in it
+is a report nobody reads, so the rules are deliberately narrow:
+
+- **Both parties paint something.** A transparent positioning wrapper hides
+ nothing. Backgrounds, borders, shadows, backdrop filters, and any
+ `canvas`/`img`/`video`/`svg` inside all count as painting.
+- **The party underneath is interactive or carries text.** The defect is losing
+ something you could have clicked or read. The Walk Companion is drawn over its
+ own footprint-trail canvas on purpose, and calling that a bug would train
+ everyone to ignore the report.
+- **The overlap clears both thresholds:** `--min-area` (default 900 px²) *and*
+ `--min-ratio` of the smaller party's area (default 6%). Ratio alone flags
+ hairline seams between two full-width bars; area alone flags a 1% clip of two
+ huge rails.
+- **Neither party contains the other.** A widget's own dropdown is allowed to sit
+ on the widget.
+- **Neither is a dialog.** A modal is supposed to cover things while it is open.
+
+Full-viewport layers (90% or more of the viewport) are not treated as collisions.
+They are classified separately: a modal backdrop covering the page is correct, a
+stray one that survived its modal is a serious bug, and neither is an
+overlay-versus-overlay problem.
+
+## The part that is easy to get wrong
+
+The audit does **not** just collect fixed and sticky elements. That was the first
+version, and it found almost nothing.
+
+The corner stack is a transparent, `pointer-events: none` flex column. It paints
+nothing, and its members are `position: relative` inside it. An audit that only
+looked at fixed and sticky boxes would have declared that entire family
+invisible, and missed the exact bug it was written to catch.
+
+So a viewport anchor that paints nothing is treated as a positioning shell rather
+than an overlay, and is replaced by its outermost painted descendants, each
+audited in its own right. That is what makes "the companion covers the Getting
+started pill" a finding instead of a blind spot.
+
+## First-visit state
+
+Persistent widgets are off by default for a returning visitor who dismissed them,
+and a page with every widget off has no collisions to find. So each context is
+seeded with the state a **first-time** visitor gets: the Walk Companion enabled,
+the getting-started checklist not dismissed, feature discovery unseen. Pass
+`--no-widgets` to audit only a page's own chrome.
+
+Because the companion is a lazily-injected Three.js module that can take ten
+seconds to appear on an unbundled dev server, the audit waits for it to finish
+animating in before measuring, rather than guessing a settle time.
+
+## Fixing what it finds
+
+Corner widgets belong in the shared corner stack
+([`public/corner-stack.js`](../public/corner-stack.js)), which flows its members
+vertically by priority so they cannot overlap each other:
+
+```js
+window.twsCornerStack.mount(el, { priority: 60 }); // higher = nearer the corner
+```
+
+A widget that genuinely cannot join the flow, because it is a fixed-size canvas
+the visitor interacts with directly, declares the corner height it occupies
+instead, and the stack lifts clear of it:
+
+```js
+window.twsCornerStack.reserve('walk-companion', bottom + height);
+window.twsCornerStack.release('walk-companion'); // on unmount
+```
+
+Reservations are keyed and independent, and the tallest wins, so two of them
+never fight. Measure from `getComputedStyle`, not `getBoundingClientRect`: a
+widget that animates in with a transform reports a short box mid-transition, and
+the stack would settle into it.
+
+If the corner stack has not booted yet when your widget mounts, listen once for
+`tws-corner-stack:ready` and claim then. Load order between these modules is not
+guaranteed.
+
+## Related
+
+- [`public/corner-stack.js`](../public/corner-stack.js): the shared container and the reservation API
+- [`tests/corner-stack.test.js`](../tests/corner-stack.test.js): the contract, exercised in JSDOM
+- `npm run audit:mobile-touch`: touch-target sizes, the other half of "can I actually hit this"
+- `npm run audit:a11y`: keyboard and screen-reader coverage on the top pages
+- `npm run snapshot`: the daily full-page visual record of every route
diff --git a/scripts/audit-overlays.mjs b/scripts/audit-overlays.mjs
index c70849ff9..463ca7a55 100644
--- a/scripts/audit-overlays.mjs
+++ b/scripts/audit-overlays.mjs
@@ -25,9 +25,10 @@
* • Both parties are painted (they have a background, border, shadow, or a
* canvas/img/video/svg inside). A transparent positioning wrapper hides
* nothing and is not a finding.
- * • At least one party is interactive (focusable, or contains something
- * focusable that can receive pointer events). Two decorative layers
- * overlapping is a design choice.
+ * • The party UNDERNEATH is interactive or carries text: something a visitor
+ * could have clicked or read, and now cannot. A decorative layer losing
+ * pixels is not a defect: the Walk Companion is drawn over its own
+ * footprint-trail canvas on purpose.
* • The overlap clears both thresholds: --min-area px² and --min-ratio of the
* SMALLER party's area. Ratio alone flags hairline seams on huge bars;
* area alone flags a 1% clip of two full-width rails.
@@ -240,6 +241,7 @@ function collectOverlays() {
zIndex: c.cs.zIndex === 'auto' ? null : Number(c.cs.zIndex),
pointerEvents: c.cs.pointerEvents,
interactive: interactive(c.el, c.cs),
+ hasText: (c.el.innerText || '').trim().length > 1,
box: c.box,
area: Math.round(c.area),
coverage: +(c.area / (vw * vh)).toFixed(3),
@@ -266,8 +268,6 @@ function findCollisions(overlays) {
for (let j = i + 1; j < widgets.length; j++) {
const a = widgets[i];
const b = widgets[j];
- // Decorative-on-decorative is a design decision, not a defect.
- if (!a.interactive && !b.interactive) continue;
// A dialog is meant to sit on everything while it is open.
if (a.isDialog || b.isDialog) continue;
if (a.ariaHidden && b.ariaHidden) continue;
@@ -280,11 +280,17 @@ function findCollisions(overlays) {
const az = a.zIndex ?? 0;
const bz = b.zIndex ?? 0;
const top = az === bz ? (a.index > b.index ? a : b) : az > bz ? a : b;
+ const under = top === a ? b : a;
+ // The defect is losing something you could have read or clicked. A
+ // decorative layer underneath loses nothing: the Walk Companion is
+ // deliberately drawn over its own footprint-trail canvas, and calling
+ // that a bug would train everyone to ignore this report.
+ if (!under.interactive && !under.hasText) continue;
out.push({
a: a.label,
b: b.label,
covering: top.label,
- covered: (top === a ? b : a).label,
+ covered: under.label,
zIndexA: a.zIndex,
zIndexB: b.zIndex,
overlapPx: Math.round(hit.area),
@@ -333,15 +339,35 @@ async function auditRoute(browser, route, viewport) {
const page = await ctx.newPage();
const result = { route, viewport: viewport.id, collisions: [], scrims: [], error: null };
try {
- const res = await page.goto(BASE + route, {
- waitUntil: 'domcontentloaded',
- timeout: 45000,
- });
+ // One retry: a dev server restarting mid-sweep (or a cold serverless
+ // route) refuses a single connection, and an audit that reports that as
+ // a finding is worse than useless.
+ let res = null;
+ for (let attempt = 0; attempt < 2; attempt++) {
+ try {
+ res = await page.goto(BASE + route, { waitUntil: 'domcontentloaded', timeout: 45000 });
+ break;
+ } catch (err) {
+ if (attempt === 1) throw err;
+ await page.waitForTimeout(4000);
+ }
+ }
if (res && res.status() >= 400) {
result.error = `HTTP ${res.status()}`;
await ctx.close();
return result;
}
+ // The companion is a lazily-injected Three.js module; on an unbundled dev
+ // server it can take ten seconds to appear. Waiting for it (rather than
+ // guessing a settle) is the difference between auditing the widget-heavy
+ // page a visitor sees and auditing a page with the widgets still absent.
+ if (WITH_WIDGETS) {
+ await page
+ .waitForSelector('.walk-companion.is-in', { timeout: 20000 })
+ .catch(() => {
+ /* excluded route, no WebGL, or the visitor already dismissed it */
+ });
+ }
await page.waitForTimeout(SETTLE_MS);
const overlays = await page.evaluate(collectOverlays);
result.overlayCount = overlays.length;
@@ -569,7 +595,9 @@ async function main() {
`\n${collisions} collision(s) across ${results.length} renders. Report: reports/overlays/index.html`,
);
}
- process.exit(collisions > 0 ? 1 : 0);
+ // A route that would not render is not a pass. Silently exiting 0 on a dead
+ // dev server is how an audit starts lying about coverage.
+ process.exit(collisions > 0 || errored.length > 0 ? 1 : 0);
}
main().catch((err) => {