Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(e2e): wait for Openbox before browser capture

Linuxdazhaoc6d14515a7f5
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a1e345dd4..47a181ba7 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -145,7 +145,7 @@ jobs:
- name: Install virtual display
run: |
sudo apt-get update
- sudo apt-get install --no-install-recommends --yes openbox xauth xvfb
+ sudo apt-get install --no-install-recommends --yes openbox xauth x11-utils xvfb
- name: Install dependencies
run: pnpm install --frozen-lockfile
@@ -178,7 +178,9 @@ jobs:
run: xvfb-run --auto-servernum pnpm test:e2e:provider-client-certificate
- name: Run browser capture/resize E2E
- run: xvfb-run --auto-servernum sh -c 'openbox >/dev/null 2>&1 & exec node scripts/e2e-browser-capture-resize.mjs'
+ run: |
+ node --test scripts/e2e/with-openbox.test.mjs
+ xvfb-run --auto-servernum sh scripts/e2e/with-openbox.sh node scripts/e2e-browser-capture-resize.mjs
- name: Run transcript rendering and disclosure E2E
run: xvfb-run --auto-servernum sh -c 'node scripts/e2e-transcript-render.mjs && node scripts/e2e-transcript-disclosure-anchor.mjs'
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 2b1f04ffd..3fd9cb2bf 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -20410,3 +20410,12 @@ Submit five references or a malformed range directly to the prompt boundary
and runtime boundary: both reject with `INVALID_ARGUMENT` before any Read.
Restore a historical attachment with range metadata and a recorded excerpt;
verify the excerpt remains a file-lines block without an assistant tool call.
+
+### E2E-BROWSER-CAPTURE-window-manager-readiness
+
+On Linux/Xvfb, start the browser capture/resize suite through
+`sh scripts/e2e/with-openbox.sh node scripts/e2e-browser-capture-resize.mjs`.
+Delay Openbox startup and verify the suite waits for its EWMH root-window
+claim before requesting maximize/restore/fullscreen. All capture, viewport,
+and lifecycle assertions must still pass. A missing or failed window manager
+fails within ten seconds. A failed native probe prints its last progress stages.
diff --git a/scripts/e2e-browser-capture-resize.mjs b/scripts/e2e-browser-capture-resize.mjs
index 6a41735f0..610d0b985 100644
--- a/scripts/e2e-browser-capture-resize.mjs
+++ b/scripts/e2e-browser-capture-resize.mjs
@@ -1,6 +1,6 @@
import assert from "node:assert/strict";
import { spawn } from "node:child_process";
-import { mkdtempSync } from "node:fs";
+import { mkdtempSync, readFileSync } from "node:fs";
import { createRequire } from "node:module";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
@@ -35,6 +35,10 @@ try {
});
} finally { clearTimeout(timeout); }
console.log(`Browser capture artifacts retained at ${artifacts}`);
+if (code !== 0) {
+ try { console.error(readFileSync(join(artifacts, "progress.log"), "utf8")); }
+ catch (error) { console.error("Could not read capture progress:", error.message); }
+}
console.log(output.trim());
assert.equal(code, 0, "native browser capture/resize regression failed");
assert.match(output, /BROWSER_CAPTURE_RESIZE {"ok":true/);
diff --git a/scripts/e2e/with-openbox.sh b/scripts/e2e/with-openbox.sh
new file mode 100644
index 000000000..016c98feb
--- /dev/null
+++ b/scripts/e2e/with-openbox.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+set -eu
+
+openbox >/dev/null 2>&1 &
+window_manager_pid=$!
+trap 'kill "$window_manager_pid" 2>/dev/null || true; wait "$window_manager_pid" 2>/dev/null || true' EXIT
+trap 'exit 130' INT
+trap 'exit 143' TERM
+
+# A live process is not yet an EWMH window manager: early maximize requests
+# can be lost before Openbox claims the root window.
+attempt=0
+while [ "$attempt" -lt 100 ]; do
+ if xprop -root _NET_SUPPORTING_WM_CHECK 2>/dev/null | grep -Eq 'window id # 0x[1-9a-fA-F]'; then
+ "$@"
+ exit
+ fi
+ if ! kill -0 "$window_manager_pid" 2>/dev/null; then
+ echo 'Openbox exited before claiming the X11 display' >&2
+ exit 1
+ fi
+ attempt=$((attempt + 1))
+ sleep 0.1
+done
+
+echo 'Openbox did not claim the X11 display within 10 seconds' >&2
+exit 1
diff --git a/scripts/e2e/with-openbox.test.mjs b/scripts/e2e/with-openbox.test.mjs
new file mode 100644
index 000000000..322f3d92d
--- /dev/null
+++ b/scripts/e2e/with-openbox.test.mjs
@@ -0,0 +1,36 @@
+import assert from "node:assert/strict";
+import { spawnSync } from "node:child_process";
+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { fileURLToPath } from "node:url";
+import test from "node:test";
+
+const launcher = fileURLToPath(new URL("./with-openbox.sh", import.meta.url));
+
+test("waits for the WM claim, forwards the probe failure and reaps Openbox", { skip: process.platform === "win32" }, (t) => {
+ const fixture = mkdtempSync(join(tmpdir(), "pi-openbox-readiness-"));
+ t.after(() => rmSync(fixture, { recursive: true, force: true }));
+ const executable = (name, source) => writeFileSync(join(fixture, name), `#!/bin/sh\n${source}\n`, { mode: 0o755 });
+ executable("openbox", 'echo "$$" > "$WM_FIXTURE/pid"\nexec sleep 60');
+ // A live WM process has not claimed the display on the first query.
+ executable("xprop", `if [ ! -e "$WM_FIXTURE/polled" ]; then
+ touch "$WM_FIXTURE/polled"
+ exit 0
+ fi
+ touch "$WM_FIXTURE/ready"
+ echo '_NET_SUPPORTING_WM_CHECK(WINDOW): window id # 0x200001'`);
+ executable("probe", '[ -e "$WM_FIXTURE/ready" ] || exit 99\nexit 37');
+ const env = { ...process.env, PATH: `${fixture}:${process.env.PATH}`, WM_FIXTURE: fixture };
+ const result = spawnSync("sh", [launcher, "probe"], { env, encoding: "utf8", timeout: 5_000 });
+ assert.equal(result.error, undefined);
+ assert.equal(result.status, 37, result.stderr);
+ const pid = Number(readFileSync(join(fixture, "pid"), "utf8"));
+ assert.throws(() => process.kill(pid, 0), { code: "ESRCH" });
+
+ executable("openbox", "exit 1");
+ executable("xprop", "exit 1");
+ const failed = spawnSync("sh", [launcher, "probe"], { env, encoding: "utf8", timeout: 5_000 });
+ assert.equal(failed.status, 1);
+ assert.match(failed.stderr, /Openbox exited before claiming/);
+});