Accessibility-first browser & computer use for AI agents — one MCP server for every harness (Codex, Claude Code, OpenCode, Antigravity). Instruments the DOM/accessibility tree via CDP instead of screenshot loops: diffed snapshots, stable element refs, trusted input, typed errors. Zero dependencies
JavaScript agentic-automationai-agentsbrowser-automationbrowser-usecdpchrome-devtools-protocolcomputer-usecuamcpmodel-context-protocolrpaweb-automation
Server mode round 6 — posture audit command + governance caps
CTOL Team BJ5bb81b8f97d3
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex fb85a70..259a45f 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -180,3 +180,5 @@ jobs:run: node tools/skip-audit.mjs "$RUNNER_TEMP/tap.txt"- name: Doctor smoke (server mode: headed Chrome on an auto-booted Xvfb)run: env -u DISPLAY node src/cli.js doctor+ - name: Posture audit (the full lane, machine-checked; exit 1 on failures)+ run: env -u DISPLAY node src/cli.js posture --jsondiff --git a/README.md b/README.mdindex 7efb80a..545cce4 100644--- a/README.md+++ b/README.md@@ -90,6 +90,7 @@ element refs like `[ref=e7]`. Each action returns only what changed.| `AXUSE_LANG` | `--accept-lang` for Chrome — `navigator.language(s)` and the `Accept-Language` header match the egress persona || `AXUSE_PROXY` | route every launched browser through a proxy (`http://`·`socks5://`, credentials supported — answered over CDP); `ax_open {proxy}` sets it per launch || `AXUSE_AMBIENT_MOTION` | `0` disables idle pointer park-fuzz (default: automatic in server mode — the agent's "thinking" pauses still show a live hand) |+| `AXUSE_MAX_BROWSERS` / `AXUSE_MAX_TABS` | governance caps for massive operations (defaults 8 / 48) — typed failures instead of OOM spirals || `AXUSE_NO_SANDBOX=1` | force `--no-sandbox` (auto for root/container server runs) || `AXUSE_NEUTRALIZE_WEBDRIVER=0` | disable the `navigator.webdriver` posture-fix fallback (the `AutomationControlled` launch flag already fixes it at the source) || `AXUSE_HEADLESS=1` | launch the browser without a window — **trusted internal pages only**: challenge/anti-bot pages detect headless first; servers get server mode instead |diff --git a/docs/server-mode.md b/docs/server-mode.mdindex 952823a..9a6caea 100644--- a/docs/server-mode.md+++ b/docs/server-mode.md@@ -105,6 +105,9 @@ For one-shot / cron-style runs no service is needed — `axuse solve`,| `AXUSE_PROXY` | Per-process default for the per-launch `proxy` param: `"http://host:port"`, `"socks5://user:pass@host:port"` — one browser instance per spec, credentials answered over CDP. || `AXUSE_PROXY_BYPASS` | Chrome proxy bypass list override (default: loopback bypassed so local fixtures work; `"<-loopback>"` includes localhost). || `AXUSE_AMBIENT_MOTION` | `0` disables idle pointer park-fuzz; default `auto` = on exactly in server mode. |+| `AXUSE_MAX_BROWSERS` | Governance cap: concurrent launched browsers per process (default 8) — a per-proxy fan-out fails typed at the cap instead of OOM-killing the box. |+| `AXUSE_MAX_TABS` | Governance cap: concurrent tabs per process (default 48). |+| `AXUSE_EGRESS_ECHO_URL` / `AXUSE_EGRESS_GEO_URL` | Endpoints for `axuse posture --verify-egress` (defaults: ipify + ipapi.co; `{ip}` placeholder). || `AXUSE_MANAGED_BROWSER_DIR` | Where `axuse install-browser` puts the pinned Chrome-for-Testing build (default `~/.cache/axuse/browsers`) — mount a cached volume here for fleets. || `AXUSE_NO_SANDBOX` | `1` forces `--no-sandbox`. Auto-applied anyway when running as root (containers) — Chrome refuses root otherwise. || `AXUSE_BROWSER` | Path to the browser binary (as on any host). |@@ -313,6 +316,29 @@ the smoke test), and asserted by `test/server-mode.test.js`.- **No fabricated results.** Solvers report `solved: false` honestly whena page hard-blocks; `doctor` and tests state measured numbers.+## Auditing a fleet (one command, machine-checkable)++`axuse posture` measures the live browser — the same facts the tests pin,+productized:++```bash+node src/cli.js posture # human report+node src/cli.js posture --json # CI/consumers; exit 1 on FAIL+node src/cli.js posture --verify-egress # + the exit IP's geo vs AXUSE_TIMEZONE+```++Checks (fail = exit 1): headed UA, `navigator.webdriver` false **via a+native getter**, WebGL present, PDF plugin surface; persona coherence+(clock vs `AXUSE_TIMEZONE`, navigator/Intl vs `AXUSE_LANG`, with the+`locale-gen` hint when Intl never took); audio fingerprint health. Info+lines: browser shape (virtual display / egress), fingerprint surface,+notifications. `--verify-egress` fetches the IP echo **through the+browser** (through the proxy when configured) and warns when the exit's+geography contradicts the persona clock — the misconfiguration challenge+pages would otherwise catch (caught a real one during development: a+Swiss exit behind an `America/New_York` persona). Echo/geo endpoints are+configurable (`AXUSE_EGRESS_ECHO_URL`, `AXUSE_EGRESS_GEO_URL`).+## Verify it (all commands runnable on the server)```bashdiff --git a/src/cli.js b/src/cli.jsindex 1f1f8c7..818d7f2 100644--- a/src/cli.js+++ b/src/cli.js@@ -35,6 +35,10 @@ Usage:provision a pinned Chrome forTesting under ~/.cache/axuse —no sudo, no apt repo (servers)+ axuse posture [--json] [--verify-egress] audit the live browser posture+ (UA, webdriver, WebGL, persona+ coherence, egress geo) — exit 1+ on failing checks (CI-able)axuse setup [--browser chrome|edge|chromium|chrome-for-testing]register bridge + open extension setupaxuse open-urls <file|url|-> inspect a URL list and write Markdown@@ -611,6 +615,26 @@ async function installBrowserCmd() {console.log(`managed root: ${MANAGED_ROOT_DEFAULT()} (AXUSE_MANAGED_BROWSER_DIR to relocate — mount a cached volume there for fleets)`);}+async function postureCmd() {+ const json = rest.includes("--json");+ const verifyEgress = rest.includes("--verify-egress");+ const { collectPosture, collectEgress, judgePosture, formatPosture } = await import("./workflows/posture.js");+ const c = new Controller();+ let report;+ try {+ const collected = await collectPosture(c);+ const egress = verifyEgress ? await collectEgress(c) : null;+ report = judgePosture({ ...collected, egress }, process.env);+ const browser = locateBrowser();+ let ver = "";+ try { ver = String(spawnSync(browser, ["--version"], { timeout: 15_000, encoding: "utf8" }).stdout ?? "").trim(); } catch {}+ console.log(formatPosture(report, { json, browser: ver ? `${browser} (${ver})` : browser, egress }));+ if (report.failures) process.exitCode = 1;+ } finally {+ await c.dispose();+ }+}+try {switch (command) {case "mcp":@@ -631,6 +655,9 @@ try {case "install-browser":await installBrowserCmd();break;+ case "posture":+ await postureCmd();+ break;case "solve":await solveCmd();break;diff --git a/src/core/controller.js b/src/core/controller.jsindex ac413cd..ee872eb 100644--- a/src/core/controller.js+++ b/src/core/controller.js@@ -450,6 +450,14 @@ export class Controller {}registerTab(browser, targetId, sessionId, url, openerTabId) {+ // Governance: bounded tabs per process (AXUSE_MAX_TABS, default 48) —+ // runaway popup chains must fail typed, not eat the box.+ const maxTabs = Number(process.env.AXUSE_MAX_TABS ?? 48);+ if (this.tabs.size >= maxTabs) {+ throw new AxError(Codes.COMMAND_REJECTED,+ `Tab cap reached: ${this.tabs.size}/${maxTabs} (AXUSE_MAX_TABS). Close tabs with ax_close before opening more.`,+ { retry: "retry" });+ }const tabId = `t${++this.tabSeq}`;const tab = {tabId, browserId: browser.browserId, targetId, sessionId,@@ -573,9 +581,23 @@ export class Controller {this.browserIndex.set(key, browserId);return rec;}+ // Governance (massive operations): one process, bounded browsers — an+ // unbounded fan-out of per-proxy browsers OOM-kills the box instead of+ // failing typed. AXUSE_MAX_BROWSERS (default 8) caps concurrent+ // launched browsers; reuse of an existing key is always allowed.const key = cdpUrl? `attach:${cdpUrl}`: `launch:${headless ? "headless" : "headed"}:${proxy ?? process.env.AXUSE_PROXY ?? "direct"}:${profileDir ?? "ephemeral"}`;+ const maxBrowsers = Number(process.env.AXUSE_MAX_BROWSERS ?? 8);+ const existingByKey = this.browserIndex.get(key);+ if (!cdpUrl && !existingByKey && this.browsers.size >= maxBrowsers+ && [...this.browsers.values()].some((b) => b.handle.launched)) {+ const live = [...this.browsers.keys()].join(", ");+ throw new AxError(Codes.COMMAND_REJECTED,+ `Browser cap reached: ${this.browsers.size}/${maxBrowsers} launched browsers (AXUSE_MAX_BROWSERS; live: ${live}). `+ + `Reuse tabs (ax_open opens tabs in the active browser), close one with ax_close {browser:true}, or raise the cap when the box has headroom.`,+ { retry: "retry" });+ }const existing = this.browserIndex.get(key);if (existing) {const b = this.browsers.get(existing);diff --git a/src/mcp/manifest.js b/src/mcp/manifest.jsindex ba03929..0555e4d 100644--- a/src/mcp/manifest.js+++ b/src/mcp/manifest.js@@ -250,7 +250,8 @@ export function solverTools(loaded) {`Call this whenever a page you are driving shows a verification widget, a login/form action is gated by one, or the user asks to complete/get past a challenge. ` +`Calling it needs no separate confirmation step — the operator's request for the workflow authorizes it. ` +`Loaded solvers: ${ids}; if none is loaded the result says so with an install hint. ` +- "Optionally opens url first (headed by default). Returns facts only: solved, token, attempts, rounds, elapsed_ms, notes — never a fabricated result.",+ `When an auto-detecting provider is loaded (e.g. "challenge"), prefer it — it classifies the system and routes (or returns the exact call for the specialist providers). ` ++ "Optionally opens url first (headed by default — never pass headless for challenge pages; display-less servers get a virtual display automatically). Returns facts only: solved, token, attempts, rounds, elapsed_ms, notes, posture — never a fabricated result.",inputSchema: {type: "object",properties: {diff --git a/src/workflows/posture.js b/src/workflows/posture.jsnew file mode 100644index 0000000..cfb8f3f--- /dev/null+++ b/src/workflows/posture.js@@ -0,0 +1,184 @@+/**+ * axuse — posture audit: one command that measures, in a REAL launched+ * browser, every fact the server lane promises — the same assertions the+ * test suite pins, productized for fleet operators and CI.+ *+ * node src/cli.js posture [--json] [--verify-egress]+ *+ * Design: collectPosture() gathers in-page facts through a Controller+ * (server mode boots the virtual display exactly as production would);+ * judgePosture() is PURE (facts × env → verdicts) so the rules are+ * unit-testable; formatPosture() renders human or JSON. Exit code 1 when+ * any FAIL exists — CI-able (`linux-server` lane runs it).+ *+ * `--verify-egress` closes the persona loop: it fetches an IP echo THROUGH+ * THE BROWSER (through the proxy when one is configured) and, when a geo+ * service answers, compares the exit's timezone with AXUSE_TIMEZONE — a+ * UTC server behind a US exit is the classic mismatch, caught here instead+ * of by the challenge page. Network-gated parts are INFO on failure, never+ * FAIL: an unreachable echo service says nothing about the posture.+ */++const POSTURE_EXPRESSION = `(() => {+ const g = document.createElement("canvas").getContext("webgl");+ const dbg = g && g.getExtension("WEBGL_debug_renderer_info");+ const wd = Object.getOwnPropertyDescriptor(Navigator.prototype, "webdriver") || {};+ let audioOffline = true;+ try {+ const ctx = new OfflineAudioContext(1, 4096, 44100);+ const o = ctx.createOscillator(); o.connect(ctx.destination); o.start(0);+ } catch (e) { audioOffline = false; }+ return {+ ua: navigator.userAgent,+ webdriver: navigator.webdriver,+ webdriverNative: String(wd.get ?? "").includes("[native code]"),+ languages: (navigator.languages || []).slice(0, 3),+ intl: Intl.DateTimeFormat().resolvedOptions().locale,+ tz: Intl.DateTimeFormat().resolvedOptions().timeZone,+ cores: navigator.hardwareConcurrency,+ memory: typeof navigator.deviceMemory === "number" ? navigator.deviceMemory : null,+ webgl: !!g,+ renderer: dbg ? g.getParameter(dbg.UNMASKED_RENDERER_WEBGL) : null,+ viewport: { w: innerWidth, h: innerHeight, ow: outerWidth, oh: outerHeight, dpr: devicePixelRatio },+ screen: { w: screen.width, h: screen.height, depth: screen.colorDepth, avail: screen.availHeight },+ plugins: navigator.plugins ? navigator.plugins.length : -1,+ pdfViewer: navigator.pdfViewerEnabled === true,+ notifications: (typeof Notification !== "undefined" && Notification.permission) || "unsupported",+ audioOffline,+ };+})()`;++const EGRESS_EXPRESSION = `(async () => {+ try {+ const echo = await fetch(${JSON.stringify(process.env.AXUSE_EGRESS_ECHO_URL ?? "https://api.ipify.org?format=json")}, { cache: "no-store" });+ const j = await echo.json();+ return { ip: j.ip ?? j.query ?? null };+ } catch (e) { return { ip: null, error: String(e) }; }+})()`;++const GEO_URL = (ip) => (process.env.AXUSE_EGRESS_GEO_URL ?? `https://ipapi.co/{ip}/json/`).replace("{ip}", encodeURIComponent(ip));++/** Measure the live posture of the controller's active tab (opens one when+ * none exists — the production lane, server mode included). */+export async function collectPosture(controller) {+ if (!controller.activeTabId) {+ await controller.execute("open", { url: "about:blank", settle_ms: 150 });+ }+ const facts = JSON.parse((await controller.execute("evaluate", { expression: POSTURE_EXPRESSION })).value ?? "null");+ const browser = [...controller.browsers.values()].at(-1);+ return { facts, posture: controller.browserPosture(), browserId: browser?.browserId ?? null };+}++/** In-browser egress check (opt-in): the IP the EXIT sees, and — when a geo+ * service answers — the exit's timezone for the persona comparison. */+export async function collectEgress(controller) {+ // $evaluate awaits in-page promises by contract — no extra param needed.+ const out = await controller.execute("evaluate", { expression: EGRESS_EXPRESSION });+ const echo = JSON.parse(out.value ?? "null") ?? {};+ if (!echo.ip) return { ip: null, note: echo.error ? `echo unreachable: ${String(echo.error).slice(0, 80)}` : "no ip" };+ let geo = null;+ try {+ const res = await controller.execute("evaluate", {+ expression: `(async () => { try { const r = await fetch(${JSON.stringify(GEO_URL(echo.ip))}, { cache: "no-store" }); return await r.json(); } catch (e) { return null; } })()`,+ });+ geo = JSON.parse(res.value ?? "null");+ } catch { /* geo service optional */ }+ return { ip: echo.ip, geo: geo ? { timezone: geo.timezone ?? null, country: geo.country_name ?? geo.country ?? null } : null };+}++const langPrefix = (v) => String(v ?? "").toLowerCase().split(/[-_]/)[0];+/** The REGION subtag when present ("en-GB" → "GB"; "de" → "" — a bare+ * language is legitimate and regionless). */+const regionOf = (v) => {+ const m = /[-_]([A-Za-z]{2})$/.exec(String(v ?? "").trim());+ return m ? m[1].toUpperCase() : "";+};++/** Pure: facts × env → verdicts. The rules the tests pin, in one place. */+export function judgePosture({ facts, posture, egress }, env = process.env) {+ const checks = [];+ const add = (id, status, detail) => checks.push({ id, status, detail });+ if (!facts) {+ add("facts", "fail", "no in-page facts collected — the browser lane is broken");+ return { checks, failures: 1, warnings: 0 };+ }+ // Critical: the headless class of signals.+ add("user-agent", /headless/i.test(facts.ua) ? "fail" : "pass",+ /headless/i.test(facts.ua) ? "UA contains Headless — the exact first-step detection signal" : `headed (${facts.ua.replace(/^.*?\(([^)]*\)).*$/, "$1")})`);+ const wdOk = facts.webdriver === false;+ add("navigator.webdriver", !wdOk ? "fail" : (facts.webdriverNative ? "pass" : "warn"),+ !wdOk ? "navigator.webdriver is true — automation is page-visible"+ : facts.webdriverNative ? "false via a NATIVE getter (the launch flag; zero tampering)"+ : "false via the masked fallback script — this build ignored the AutomationControlled flag");+ add("webgl", facts.webgl ? "pass" : "fail",+ facts.webgl ? `present (${String(facts.renderer).slice(0, 60)})` : "absent — a strong bot signal on GPU-less hosts (--enable-unsafe-swiftshader should restore it)");+ add("pdf-plugins", facts.pdfViewer && facts.plugins > 0 ? "pass" : "warn",+ facts.pdfViewer && facts.plugins > 0 ? `${facts.plugins} plugins, PDF viewer enabled (headed build shape)` : "no PDF plugin — headless-like plugin surface");+ // Persona coherence: clock, languages, viewport.+ const wantTz = env.AXUSE_TIMEZONE;+ if (wantTz) {+ add("timezone", facts.tz === wantTz ? "pass" : "fail",+ facts.tz === wantTz ? `${facts.tz} (matches AXUSE_TIMEZONE)` : `page reports ${facts.tz}, AXUSE_TIMEZONE=${wantTz} — persona broken`);+ } else {+ add("timezone", "info", `${facts.tz} (host default — set AXUSE_TIMEZONE to the egress persona's zone)`);+ }+ const wantLang = env.AXUSE_LANG;+ if (wantLang) {+ const langOk = langPrefix(facts.languages[0]) === langPrefix(wantLang) && regionOf(facts.languages[0] ?? "") === regionOf(wantLang);+ // Intl can legitimately drop the region (measured: LC_ALL=de_DE.UTF-8 →+ // "de"), so only mismatch when BOTH sides carry a region and they+ // differ (en-US Intl under an en-GB persona = LC_ALL never took).+ const intlRegion = regionOf(facts.intl);+ const wantRegion = regionOf(wantLang);+ const intlOk = langPrefix(facts.intl) === langPrefix(wantLang)+ && (!intlRegion || !wantRegion || intlRegion === wantRegion);+ add("language", langOk && intlOk ? "pass" : "warn",+ `navigator.languages=[${facts.languages.join(", ")}] · Intl=${facts.intl} vs AXUSE_LANG=${wantLang}`+ + (!intlOk ? " — Intl mismatch: is the locale generated on this host? (sudo locale-gen <tag>.UTF-8)" : ""));+ } else {+ add("language", "info", `navigator.languages=[${facts.languages.join(", ")}] · Intl=${facts.intl} (host defaults)`);+ }+ const vd = posture && typeof posture === "object" ? posture : {};+ add("browser-shape", "info", `${vd.posture ?? "unknown"}${vd.display ? ` on ${vd.display}` : ""}${vd.egress ? ` · egress ${vd.egress}` : ""}`);+ add("fingerprint-surface", "info",+ `cores=${facts.cores} memory=${facts.memory ?? "n/a"} viewport=${facts.viewport.w}x${facts.viewport.h}@dpr${facts.viewport.dpr} screen=${facts.screen.w}x${facts.screen.h}x${facts.screen.depth}`);+ add("audio", facts.audioOffline ? "pass" : "warn",+ facts.audioOffline ? "OfflineAudioContext renders (the audio-fingerprint vector is healthy)" : "OfflineAudioContext construction failed");+ add("notifications", "info", `Notification.permission=${facts.notifications}`);+ if (egress) {+ if (!egress.ip) {+ add("egress", "info", egress.note ?? "echo unreachable");+ } else if (egress.geo?.timezone && wantTz) {+ const geoTz = egress.geo.timezone;+ const same = geoTz === wantTz || geoTz.split("/")[0] === wantTz.split("/")[0];+ add("egress", same ? "pass" : "warn",+ `exit IP ${egress.ip} (${egress.geo.country ?? "?"}) → geo tz ${geoTz} vs AXUSE_TIMEZONE=${wantTz}${same ? "" : " — the clock does not match the exit's geography"}`);+ } else {+ add("egress", "info", `exit IP ${egress.ip}${egress.geo?.country ? ` (${egress.geo.country})` : ""} (geo ${egress.geo?.timezone ? "answered" : "unavailable"})`);+ }+ }+ const failures = checks.filter((c) => c.status === "fail").length;+ const warnings = checks.filter((c) => c.status === "warn").length;+ return { checks, failures, warnings };+}++/** Human (table-ish) or machine (JSON) rendering. */+export function formatPosture(report, { json = false, browser, egress } = {}) {+ if (json) {+ return JSON.stringify({+ ok: report.failures === 0,+ failures: report.failures,+ warnings: report.warnings,+ browser: browser ?? null,+ checks: report.checks,+ }, null, 2);+ }+ const icon = { pass: "✓", fail: "✗", warn: "!", info: "·" };+ const lines = [+ browser ? `browser: ${browser}` : null,+ ...report.checks.map((c) => `${icon[c.status] ?? "?"} ${c.id}: ${c.detail}`),+ "",+ report.failures ? `POSTURE: FAIL (${report.failures} failing, ${report.warnings} warnings)` : `POSTURE: ${report.warnings ? `OK with ${report.warnings} warning(s)` : "OK"}`,+ ].filter((l) => l !== null);+ return lines.join("\n");+}diff --git a/test/posture.test.js b/test/posture.test.jsnew file mode 100644index 0000000..2e5c1ab--- /dev/null+++ b/test/posture.test.js@@ -0,0 +1,126 @@+/**+ * Posture audit — the productized form of every posture claim, plus the+ * governance caps that keep massive-ops processes from OOM-killing the box.+ *+ * - unit (always): judgePosture is pure — every verdict path (pass/warn/+ * fail, persona matches and mismatches, egress geo vs clock) is pinned.+ * - live (browser): `axuse posture` end-to-end in full server mode — the+ * same facts the doctor smoke prints, machine-checkable; the browser cap+ * fails typed instead of launching the box into the OOM killer.+ */+import { test } from "node:test";+import assert from "node:assert/strict";+import { judgePosture } from "../src/workflows/posture.js";+import { locateBrowser } from "../src/core/cdp.js";+import { Controller } from "../src/core/controller.js";++const GOOD_FACTS = {+ ua: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36",+ webdriver: false, webdriverNative: true,+ languages: ["en-US", "en"], intl: "en-US", tz: "America/New_York",+ cores: 8, memory: 8,+ webgl: true, renderer: "ANGLE (SwiftShader)",+ viewport: { w: 1919, h: 992, ow: 1920, oh: 1080, dpr: 1 },+ screen: { w: 1920, h: 1080, depth: 24, avail: 1080 },+ plugins: 5, pdfViewer: true, notifications: "denied", audioOffline: true,+};+const by = (report) => Object.fromEntries(report.checks.map((c) => [c.id, c.status]));++test("posture: a healthy server-lane browser passes every critical check", () => {+ const r = judgePosture({ facts: GOOD_FACTS, posture: { posture: "headed-on-virtual-display", display: ":42" }, egress: null }, { AXUSE_TIMEZONE: "America/New_York", AXUSE_LANG: "en-US" });+ const s = by(r);+ assert.equal(s["user-agent"], "pass");+ assert.equal(s["navigator.webdriver"], "pass");+ assert.equal(s["webgl"], "pass");+ assert.equal(s["timezone"], "pass");+ assert.equal(s["language"], "pass");+ assert.equal(s["pdf-plugins"], "pass");+ assert.equal(r.failures, 0);+});++test("posture: the headless class fails loudly", () => {+ const r = judgePosture({ facts: { ...GOOD_FACTS, ua: GOOD_FACTS.ua.replace("Chrome/151", "HeadlessChrome/151") }, posture: {} }, {});+ assert.equal(by(r)["user-agent"], "fail");+ assert.ok(r.failures >= 1);+ const wd = judgePosture({ facts: { ...GOOD_FACTS, webdriver: true }, posture: {} }, {});+ assert.equal(by(wd)["navigator.webdriver"], "fail");+ const noWebgl = judgePosture({ facts: { ...GOOD_FACTS, webgl: false, renderer: null }, posture: {} }, {});+ assert.equal(by(noWebgl)["webgl"], "fail");+});++test("posture: the masked-fallback script is a warn (build ignored the flag), never a silent pass", () => {+ const r = judgePosture({ facts: { ...GOOD_FACTS, webdriverNative: false }, posture: {} }, {});+ assert.equal(by(r)["navigator.webdriver"], "warn");+ assert.match(r.checks.find((c) => c.id === "navigator.webdriver").detail, /fallback script/);+});++test("posture: persona mismatches are diagnosed, not just failed", () => {+ const tz = judgePosture({ facts: { ...GOOD_FACTS, tz: "UTC" }, posture: {} }, { AXUSE_TIMEZONE: "America/New_York" });+ assert.equal(by(tz)["timezone"], "fail");+ assert.match(tz.checks.find((c) => c.id === "timezone").detail, /persona broken/);+ // Intl mismatch carries the locale-gen hint (the LC_ALL mechanism).+ const lang = judgePosture({ facts: { ...GOOD_FACTS, intl: "en-US", languages: ["en-GB"] }, posture: {} }, { AXUSE_LANG: "en-GB" });+ assert.equal(by(lang)["language"], "warn");+ assert.match(lang.checks.find((c) => c.id === "language").detail, /locale-gen/);+});++test("posture: egress geo vs clock — the fleet misconfiguration detector", () => {+ // Same area: pass.+ const ok = judgePosture({ facts: GOOD_FACTS, posture: {}, egress: { ip: "1.2.3.4", geo: { timezone: "America/Chicago", country: "United States" } } }, { AXUSE_TIMEZONE: "America/New_York" });+ assert.equal(by(ok)["egress"], "pass");+ // Different area: warn with both facts (caught live during development:+ // a Swiss exit behind an America/New_York persona).+ const bad = judgePosture({ facts: GOOD_FACTS, posture: {}, egress: { ip: "1.2.3.4", geo: { timezone: "Europe/Zurich", country: "Switzerland" } } }, { AXUSE_TIMEZONE: "America/New_York" });+ assert.equal(by(bad)["egress"], "warn");+ assert.match(bad.checks.find((c) => c.id === "egress").detail, /does not match the exit/);+ // Echo unreachable: info, never fail — the network says nothing about posture.+ const offline = judgePosture({ facts: GOOD_FACTS, posture: {}, egress: { ip: null, note: "echo unreachable: x" } }, {});+ assert.equal(by(offline)["egress"], "info");+});++const hasBrowser = !!locateBrowser();+const linux = process.platform === "linux";+const xvfb = linux && (await import("node:child_process")).spawnSync("which", ["Xvfb"]).status === 0;+const liveGate = hasBrowser && linux && xvfb;+const liveSkip = liveGate ? false : "requires Linux + Xvfb + a Chromium-family browser (the server-mode audit lane)";++test("posture: the live command audits the full server lane (json mode)", { skip: liveSkip }, async (t) => {+ const saved = { DISPLAY: process.env.DISPLAY, TZ: process.env.TZ };+ process.env.DISPLAY = ":988"; // dead → server mode boots the virtual display+ process.env.AXUSE_TIMEZONE = "America/New_York";+ t.after(() => {+ process.env.DISPLAY = saved.DISPLAY;+ delete process.env.AXUSE_TIMEZONE;+ if (saved.TZ === undefined) delete process.env.TZ; else process.env.TZ = saved.TZ;+ });+ const { collectPosture, judgePosture } = await import("../src/workflows/posture.js");+ const c = new Controller();+ t.after(() => c.dispose());+ const collected = await collectPosture(c);+ const report = judgePosture(collected, process.env);+ const s = by(report);+ assert.equal(collected.posture.posture, "headed-on-virtual-display");+ assert.match(collected.posture.display, /^:\d+$/);+ assert.equal(s["user-agent"], "pass");+ assert.equal(s["navigator.webdriver"], "pass", "native getter, zero tampering");+ assert.equal(s["webgl"], "pass", "SwiftShader on the virtual display");+ assert.equal(s["timezone"], "pass");+ assert.equal(report.failures, 0, JSON.stringify(report.checks.filter((x) => x.status === "fail")));+});++test("governance: the browser cap fails typed instead of OOM-killing the box", { skip: !hasBrowser ? "live-gate-browser: needs any Chromium-family browser" : false }, async (t) => {+ const prev = process.env.AXUSE_MAX_BROWSERS;+ process.env.AXUSE_MAX_BROWSERS = "1";+ t.after(() => { if (prev === undefined) delete process.env.AXUSE_MAX_BROWSERS; else process.env.AXUSE_MAX_BROWSERS = prev; });+ const c = new Controller();+ t.after(() => c.dispose());+ await c.execute("open", { url: "about:blank", headless: true, settle_ms: 100 });+ // Same launch key → reuse, never capped.+ const again = await c.execute("open", { url: "about:blank", headless: true, settle_ms: 100 });+ assert.ok(again.tab_id);+ // A DIFFERENT key (different proxy) at the cap → typed rejection.+ await assert.rejects(+ () => c.execute("open", { url: "about:blank", headless: true, proxy: "http://127.0.0.1:9", settle_ms: 100 }),+ (e) => e.code === "COMMAND_REJECTED" && /Browser cap reached/.test(e.message),+ );+});diff --git a/test/skip-allowlist.json b/test/skip-allowlist.jsonindex 5b33198..90c1f6a 100644--- a/test/skip-allowlist.json+++ b/test/skip-allowlist.json@@ -28,6 +28,8 @@"browser flow": "live-gate-browser: needs any Chromium-family browser (auto-detect or AXUSE_BROWSER)","human input: typing and clicking land as human-shaped trusted events": "live-gate-browser: needs any Chromium-family browser (headless hermetic)","proxy: browser egress": "live-gate-browser: needs any Chromium-family browser (local fixture proxy — no external service)",+ "posture: the live command": "platform-linux-xvfb: the server-mode audit lane (sudo apt install xvfb + a browser)",+ "governance: the browser cap": "live-gate-browser: needs any Chromium-family browser (headless hermetic)","fill: ARIA and native sliders via trusted Arrow keys": "live-gate-browser: needs any Chromium-family browser","fill: foreign-tab refs fail with a hint naming the owning tab": "live-gate-browser: needs any Chromium-family browser","mcp: handshake, tools/list, tools/call end-to-end": "live-gate-browser: needs any Chromium-family browser",