Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

test(puppeteer): cover accessibility visibility workflows

ldm05a877006378e
diff --git a/moli-cdp-smoke/README.md b/moli-cdp-smoke/README.md
index 4fa7bc95d..afdb6cf85 100644
--- a/moli-cdp-smoke/README.md
+++ b/moli-cdp-smoke/README.md
@@ -170,6 +170,21 @@ and old names stop matching. Removing and restoring a slot assignment must
switch the exposed fallback/assigned controls. The complete `--group puppeteer`
passed one run against each engine; use `--endpoint URL` for the Chromium run.
+The Puppeteer accessibility visibility workflow was calibrated on 2026-10-09
+with the same client and Chromium executable, then run unchanged against Moli.
+`puppeteer_accessibility_visibility.mjs` starts with a fresh Document and checks
+both snapshot modes for computed display, visibility overrides, HTML inert,
+explicit content-visibility:hidden, hidden/until-found CSS overrides, and
+hidden ARIA reference names.
+Closed shadow styles, :host rules, and assigned-slot visibility participate in
+the same checks. Two ARIA-handle clicks must emit exactly two trusted events;
+hiding and restoring a control preserves its AX and backend refs, and CSSOM
+rule edits update snapshots in both the Document and closed shadow root.
+The complete Puppeteer group passed all 24 scenarios against each engine.
+The separate Moli layout-policy group passed all 37 scenarios; AX style reads
+do not publish or refresh layout. Viewport-dependent content-visibility:auto
+display locking remains outside this visibility contract.
+
The `navigation-outcomes` group was calibrated on 2026-08-23 against Debian
`/usr/bin/chromium` 145.0.7632.116 and then run unchanged against Moli. It
directly drives `Page.navigate` and correlates the result with the matching
@@ -524,7 +539,7 @@ Runner layout:
against a Chromium CDP endpoint before validating moli.
- `groups/playwright_compat.py`: Playwright upstream derived route and CDPSession compatibility samples.
- `groups/chrome_remote_interface.py`, `groups/cdp_use.py`, and `groups/stagehand.py`: optional published-client workflows, with subprocess and JSON-result handling shared by `groups/external_process.py`.
-- `groups/puppeteer.py` and `puppeteer_smoke.mjs`: pinned Puppeteer workflows driven from the uv runner through Node. `puppeteer_shadow_accessibility.mjs` covers Shadow DOM snapshots, scoped AX refs, ARIA handle clicks, and slot/name updates.
+- `groups/puppeteer.py` and `puppeteer_smoke.mjs`: pinned Puppeteer workflows driven from the uv runner through Node. `puppeteer_shadow_accessibility.mjs` covers Shadow DOM snapshots, scoped AX refs, ARIA handle clicks, and slot/name updates. `puppeteer_accessibility_visibility.mjs` covers computed visibility, CSS overrides, stable refs, and Document/shadow CSSOM updates.
- `groups/agent_browser.py`: optional real agent-browser CLI workflows with isolated config, daemon namespace, and endpoint identity verification.
- `groups/network.py`: document/fetch/XHR routing, Network event observation, parser script and stylesheet body capture, WebSocket, and downloads.
- `groups/workers.py`: dedicated worker `postMessage`, SharedWorker port reuse, worker fetch routing/auth, and worker XHR routing.
diff --git a/moli-cdp-smoke/moli_cdp_smoke/puppeteer_accessibility_visibility.mjs b/moli-cdp-smoke/moli_cdp_smoke/puppeteer_accessibility_visibility.mjs
new file mode 100644
index 000000000..fa58d1a24
--- /dev/null
+++ b/moli-cdp-smoke/moli_cdp_smoke/puppeteer_accessibility_visibility.mjs
@@ -0,0 +1,100 @@
+import assert from 'node:assert/strict';
+
+function buttonNames(snapshot) {
+ const names = [];
+ const pending = [snapshot];
+ while (pending.length) {
+ const node = pending.pop();
+ if (node.role === 'button') names.push(node.name ?? '');
+ pending.push(...(node.children ?? []));
+ }
+ return names.sort();
+}
+
+export async function runPuppeteerAccessibilityVisibilitySmoke(page) {
+ await page.goto('about:blank');
+ await page.evaluate(() => {
+ document.body.innerHTML = `
+ <style id="visibility-sheet">.hidden-control { display:none }</style>
+ <button id="visible">Visible action</button>
+ <button hidden>Hidden action</button>
+ <button class="hidden-control">Stylesheet hidden action</button>
+ <button id="override" hidden style="display:block">CSS override action</button>
+ <span id="hidden-label" style="display:none">Hidden root<span aria-hidden="true">hidden aria child</span></span>
+ <button aria-labelledby="hidden-label"></button>
+ <div style="visibility:hidden"><button>Invisible action</button>
+ <button style="visibility:visible">Visibility override action</button></div>
+ <div inert><button>Inert action</button></div>
+ <div role="button" style="content-visibility:hidden">Hidden contents<button>CV hidden action</button></div>
+ <div hidden="until-found"><button>Until found action</button></div>
+ <div hidden="until-found" style="content-visibility:visible"><button>Until found override action</button></div>
+ <div style="display:contents;content-visibility:hidden"><button>CV contents action</button></div>
+ <button style="opacity:0">Transparent action</button>
+ <div id="visibility-host" hidden><button slot="action" style="visibility:visible">Slotted visible action</button></div>
+ `;
+ const root = document.querySelector('#visibility-host').attachShadow({mode: 'closed'});
+ root.innerHTML = `
+ <style>:host { display:block } .hidden-control { display:none } slot { visibility:hidden }</style>
+ <button class="hidden-control">Shadow hidden action</button>
+ <slot name="action"><button>Assigned fallback action</button></slot>
+ <button>Shadow visible action</button>
+ `;
+ globalThis.__visibilityRoot = root;
+ globalThis.__visibilityClicks = [];
+ for (const id of ['visible', 'override']) {
+ document.getElementById(id).addEventListener('click',
+ event => __visibilityClicks.push({id, trusted: event.isTrusted}));
+ }
+ });
+ const expected = [
+ '', 'CSS override action', 'CV contents action', 'Hidden root hidden aria child', 'Shadow visible action',
+ 'Slotted visible action', 'Transparent action', 'Until found override action',
+ 'Visibility override action', 'Visible action',
+ ];
+ for (const interestingOnly of [true, false]) {
+ assert.deepEqual(buttonNames(await page.accessibility.snapshot({interestingOnly})), expected);
+ }
+ const client = await page.createCDPSession();
+ try {
+ const initial = (await client.send('Accessibility.getFullAXTree')).nodes
+ .find(node => !node.ignored && node.name?.value === 'Visible action');
+ assert.ok(initial?.backendDOMNodeId);
+ const override = await page.$('aria/CSS override action[role="button"]');
+ assert.ok(override, 'CSS override of hidden must be selectable');
+ try { await override.click(); } finally { await override.dispose(); }
+
+ await page.evaluate(() => { document.getElementById('visible').style.display = 'none'; });
+ assert.ok(!buttonNames(await page.accessibility.snapshot()).includes('Visible action'));
+ assert.equal(await page.$('aria/Visible action[role="button"]'), null);
+ const partial = await client.send('Accessibility.getPartialAXTree', {
+ backendNodeId: initial.backendDOMNodeId, fetchRelatives: false,
+ });
+ assert.equal(partial.nodes[0].ignored, true);
+ assert.equal(partial.nodes[0].backendDOMNodeId, initial.backendDOMNodeId);
+ assert.ok(partial.nodes[0].ignoredReasons.some(reason => reason.name === 'notRendered'));
+
+ await page.evaluate(() => { document.getElementById('visible').style.removeProperty('display'); });
+ const restored = (await client.send('Accessibility.getFullAXTree')).nodes
+ .find(node => !node.ignored && node.name?.value === 'Visible action');
+ assert.equal(restored.backendDOMNodeId, initial.backendDOMNodeId);
+ assert.equal(restored.nodeId, initial.nodeId);
+ const visible = await page.$('aria/Visible action[role="button"]');
+ assert.ok(visible);
+ try { await visible.click(); } finally { await visible.dispose(); }
+ assert.deepEqual(await page.evaluate(() => __visibilityClicks), [
+ {id: 'override', trusted: true}, {id: 'visible', trusted: true},
+ ]);
+
+ await page.evaluate(() => {
+ document.getElementById('visibility-sheet').sheet.cssRules[0].style.display = 'block';
+ __visibilityRoot.querySelector('style').sheet.cssRules[1].style.display = 'block';
+ });
+ const changed = buttonNames(await page.accessibility.snapshot());
+ assert.ok(changed.includes('Stylesheet hidden action'));
+ assert.ok(changed.includes('Shadow hidden action'));
+ assert.ok(!changed.includes('Hidden action'));
+ return {trustedClicks: 2, stableReference: true, shadowMode: 'closed', cssomRuleChanges: 2};
+ } finally {
+ await client.detach();
+ }
+}
diff --git a/moli-cdp-smoke/moli_cdp_smoke/puppeteer_smoke.mjs b/moli-cdp-smoke/moli_cdp_smoke/puppeteer_smoke.mjs
index 7346976e3..85c25fe27 100644
--- a/moli-cdp-smoke/moli_cdp_smoke/puppeteer_smoke.mjs
+++ b/moli-cdp-smoke/moli_cdp_smoke/puppeteer_smoke.mjs
@@ -6,6 +6,7 @@ import path from 'node:path';
import { runPuppeteerAriaQuerySmoke } from './puppeteer_aria_queries.mjs';
import { runPuppeteerShadowAccessibilitySmoke } from './puppeteer_shadow_accessibility.mjs';
+import { runPuppeteerAccessibilityVisibilitySmoke } from './puppeteer_accessibility_visibility.mjs';
import {
activateXPathElement,
runPuppeteerDomInteractionSmoke,
@@ -451,6 +452,12 @@ async function main() {
);
record('puppeteer_shadow_accessibility_workflow', shadowAccessibilityResult);
+ const accessibilityVisibilityResult = await withTimeout(
+ 'Puppeteer accessibility visibility',
+ runPuppeteerAccessibilityVisibilitySmoke(page),
+ );
+ record('puppeteer_accessibility_visibility_workflow', accessibilityVisibilityResult);
+
const domInteractionResult = await withTimeout(
'Puppeteer DOM interaction matrix',
runPuppeteerDomInteractionSmoke(page),