Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Map the X11 smoke's test window again when openbox drops it (#4886)

Milind Soni593b78c0a546
diff --git a/scripts/smoke-cua-x11-input.mjs b/scripts/smoke-cua-x11-input.mjs
index 9f745deb07..ab27eb91d7 100644
--- a/scripts/smoke-cua-x11-input.mjs
+++ b/scripts/smoke-cua-x11-input.mjs
@@ -29,7 +29,14 @@ chmodSync(home, 0o700);
// A real Xorg desktop always runs a window manager, and Cua Driver 0.41 sends foreground input only to the window the
// manager reports active (_NET_ACTIVE_WINDOW). A bare Xvfb has none, so start a small EWMH one first.
-const windowManager = spawn("openbox", ["--sm-disable"], { env: process.env, stdio: "ignore" });
+const windowManager = spawn("openbox", ["--sm-disable"], { env: process.env, stdio: ["ignore", "pipe", "pipe"] });
+let windowManagerOutput = "";
+for (const stream of [windowManager.stdout, windowManager.stderr]) {
+ stream.setEncoding("utf8");
+ stream.on("data", (chunk) => {
+ windowManagerOutput += chunk;
+ });
+}
windowManager.once("error", (error) => {
console.error(`[smoke-cua-x11-input] openbox could not start (install it): ${error.message}`);
process.exit(1);
@@ -108,7 +115,13 @@ async function until(probe, description, timeout = 10_000) {
}
await delay(25);
}
- throw new Error(`timed out waiting for ${description}\n${driverError}\n${xevOutput}`);
+ const x11 = async (command, args) => (await execFileAsync(command, args).catch((error) => ({ stdout: String(error) }))).stdout;
+ const pid = windowManager.pid;
+ const proc = async (file) => (await import("node:fs/promises")).readFile(`/proc/${pid}/${file}`, "utf8").catch((error) => String(error));
+ const state = `${await x11("ps", ["-o", "pid,stat,wchan:32,pcpu,etime,args", "-p", String(pid)])}\nwchan ${await proc("wchan")}\n` +
+ `syscall ${await proc("syscall")}\n${(await proc("status")).split("\n").filter((line) => /^(State|Threads|SigBlk|SigPnd)/.test(line)).join("\n")}`;
+ throw new Error(`timed out waiting for ${description}\n${driverError}\n${xevOutput}\nopenbox:\n${windowManagerOutput}\n${state}\n` +
+ `${await x11("xprop", ["-root"])}\n${await x11("xwininfo", ["-root", "-tree"])}`);
}
function driverRequest(method) {
@@ -200,18 +213,26 @@ async function stop(child) {
}
try {
+ let remapped = false;
const windowId = await until(async () => {
if (xev.exitCode !== null || xev.signalCode !== null) {
throw new Error(`xev exited before its test window appeared:\n${xevOutput}`);
}
- const { stdout } = await execFileAsync("xdotool", [
- "search",
- "--onlyvisible",
- "--name",
- `^${title}$`,
- ]);
- return stdout.trim().split(/\s+/)[0] || null;
- }, "the unrelated X11 test window");
+ if (windowManager.exitCode !== null || windowManager.signalCode !== null) {
+ throw new Error(`openbox exited before the test window appeared: ${windowManager.exitCode ?? windowManager.signalCode}`);
+ }
+ const { stdout } = await execFileAsync("xdotool", ["search", "--name", `^${title}$`]);
+ const id = stdout.trim().split(/\s+/)[0];
+ if (!id) return null;
+ const { stdout: info } = await execFileAsync("xwininfo", ["-id", id]);
+ if (/Map State:\s+IsViewable/.test(info)) return id;
+ // openbox 3.6 on a loaded runner can drop the map request of a window opened while it finishes starting; ask again once.
+ if (!remapped) {
+ remapped = true;
+ await execFileAsync("xdotool", ["windowmap", id]);
+ }
+ return null;
+ }, "the unrelated X11 test window", 20_000);
if (!windowId) throw new Error("xev test window did not appear");
const metadata = await until(