fix(linux): improve Hopper reliability and CachyOS support (#963)
* fix(linux): support CachyOS Hopper hosts * fix(config): reuse user-local Hopper launcher * fix(hopper): harden Linux demo dialog handling * chore: retrigger CI after PR title fix * fix(linux): align Hopper defaults and support docs --------- Co-authored-by: Ysopwnable <161784452+N0zoM1z0@users.noreply.github.com>
This commit is contained in:
@@ -25,6 +25,12 @@ const helperPath = fileURLToPath(
|
||||
const hangingHelperPath = fileURLToPath(
|
||||
new URL("../../../fixtures/x11ProbeHang.py", import.meta.url),
|
||||
);
|
||||
const dialogDetectionFixturePath = fileURLToPath(
|
||||
new URL("../../../fixtures/hopperDialogDetection.py", import.meta.url),
|
||||
);
|
||||
const cleanupTimeoutFixturePath = fileURLToPath(
|
||||
new URL("../../../fixtures/hopperCleanupTimeout.py", import.meta.url),
|
||||
);
|
||||
|
||||
type DiagnosticOverrides = Partial<
|
||||
Omit<HopperStartupDiagnostic, "failure_code" | "status">
|
||||
@@ -81,6 +87,46 @@ const failureExit = (code: HopperStartupFailureCode): number =>
|
||||
? 79
|
||||
: 70;
|
||||
|
||||
describe("Hopper demo dialog detection", () => {
|
||||
it.skipIf(process.platform !== "linux")(
|
||||
"uses the Hopper transient-parent relation instead of exact dialog geometry",
|
||||
() => {
|
||||
const result = spawnSync(
|
||||
"/usr/bin/python3",
|
||||
[dialogDetectionFixturePath, helperPath],
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
expect(result.status).toBe(0);
|
||||
expect(JSON.parse(result.stdout)).toEqual({
|
||||
dialog: [10, 20, 100, 1200, 284],
|
||||
click: [136, 362],
|
||||
wrong_parent_rejected: true,
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("Hopper process cleanup", () => {
|
||||
it.skipIf(process.platform !== "linux")(
|
||||
"kills a child that ignores SIGTERM after the bounded timeout",
|
||||
() => {
|
||||
const result = spawnSync(
|
||||
"/usr/bin/python3",
|
||||
[cleanupTimeoutFixturePath, helperPath],
|
||||
{ encoding: "utf8", timeout: 5_000 },
|
||||
);
|
||||
expect(result.status).toBe(0);
|
||||
const parsed = JSON.parse(result.stdout) as {
|
||||
readonly returncode: number;
|
||||
readonly elapsed_ms: number;
|
||||
};
|
||||
expect(parsed.returncode).toBe(-9);
|
||||
expect(parsed.elapsed_ms).toBeGreaterThanOrEqual(1_800);
|
||||
expect(parsed.elapsed_ms).toBeLessThan(4_000);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("Linux private display selection", () => {
|
||||
it("prefers a successful direct Xvfb probe", async () => {
|
||||
const calls: LinuxPrivateDisplayRunnableStrategy[] = [];
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
defaultHopperLauncherPath,
|
||||
parseConfig,
|
||||
} from "../../src/config/parseConfig.js";
|
||||
|
||||
describe("Hopper launcher defaults", () => {
|
||||
it("prefers an executable system Hopper on Linux", () => {
|
||||
const executable = (path: string) => path === "/opt/hopper/bin/Hopper";
|
||||
expect(defaultHopperLauncherPath("linux", "/home/test", executable)).toBe(
|
||||
"/opt/hopper/bin/Hopper",
|
||||
);
|
||||
});
|
||||
|
||||
it("falls back to the legacy user-local Hopper on Linux", () => {
|
||||
const executable = (path: string) =>
|
||||
path === "/home/test/.local/share/rea/hopper/bin/Hopper";
|
||||
expect(defaultHopperLauncherPath("linux", "/home/test", executable)).toBe(
|
||||
"/home/test/.local/share/rea/hopper/bin/Hopper",
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps the system path as the diagnostic fallback when neither exists", () => {
|
||||
expect(defaultHopperLauncherPath("linux", "/home/test", () => false)).toBe(
|
||||
"/opt/hopper/bin/Hopper",
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps explicit HOPPER_LAUNCHER_PATH authoritative", () => {
|
||||
const parsed = parseConfig({
|
||||
HOPPER_LAUNCHER_PATH: "/custom/Hopper",
|
||||
});
|
||||
expect(parsed.ok).toBe(true);
|
||||
if (parsed.ok)
|
||||
expect(parsed.value.hopperLauncherPath).toBe("/custom/Hopper");
|
||||
});
|
||||
});
|
||||
@@ -45,6 +45,7 @@ describe("localized README product facts", () => {
|
||||
expect(content).toContain("Ubuntu 24.04");
|
||||
expect(content).toContain("Fedora 41");
|
||||
expect(content).toContain("Arch Linux");
|
||||
expect(content).toContain("CachyOS");
|
||||
for (const client of SUPPORTED_CLIENT_DEFINITIONS)
|
||||
expect(content).toContain(client.displayName);
|
||||
expect(content).toContain("MCP-tool_catalog");
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
import importlib.util
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
helper_path = sys.argv[1]
|
||||
spec = importlib.util.spec_from_file_location("hopper_demo_x11", helper_path)
|
||||
if spec is None or spec.loader is None:
|
||||
raise SystemExit("unable to load helper")
|
||||
helper = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(helper)
|
||||
|
||||
child = subprocess.Popen(
|
||||
[
|
||||
sys.executable,
|
||||
"-c",
|
||||
(
|
||||
"import signal,time;"
|
||||
"signal.signal(signal.SIGTERM, signal.SIG_IGN);"
|
||||
"print('ready', flush=True);"
|
||||
"time.sleep(100)"
|
||||
),
|
||||
],
|
||||
stdout=subprocess.PIPE,
|
||||
text=True,
|
||||
)
|
||||
assert child.stdout is not None
|
||||
if child.stdout.readline().strip() != "ready":
|
||||
raise SystemExit("child did not become ready")
|
||||
|
||||
started = time.monotonic()
|
||||
helper.stop_process(child)
|
||||
elapsed = time.monotonic() - started
|
||||
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"returncode": child.returncode,
|
||||
"elapsed_ms": round(elapsed * 1000),
|
||||
},
|
||||
separators=(",", ":"),
|
||||
)
|
||||
)
|
||||
|
||||
if child.returncode != -9:
|
||||
raise SystemExit(f"expected SIGKILL fallback, got {child.returncode}")
|
||||
if not 1800 <= elapsed * 1000 < 4000:
|
||||
raise SystemExit(f"unexpected cleanup duration: {elapsed}")
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python3
|
||||
import importlib.util
|
||||
import json
|
||||
import sys
|
||||
|
||||
helper_path = sys.argv[1]
|
||||
spec = importlib.util.spec_from_file_location("hopper_demo_x11", helper_path)
|
||||
if spec is None or spec.loader is None:
|
||||
raise SystemExit("unable to load helper")
|
||||
helper = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(helper)
|
||||
|
||||
|
||||
class FakeX11:
|
||||
def __init__(self, titles, transients):
|
||||
self.titles = titles
|
||||
self.transients = transients
|
||||
|
||||
def XFetchName(self, _display, window, target):
|
||||
value = self.titles.get(window)
|
||||
if value is None:
|
||||
return 0
|
||||
target._obj.value = value.encode("utf-8")
|
||||
return 1
|
||||
|
||||
def XGetTransientForHint(self, _display, window, target):
|
||||
value = self.transients.get(window)
|
||||
if value is None:
|
||||
return 0
|
||||
target._obj.value = value
|
||||
return 1
|
||||
|
||||
def XFree(self, _value):
|
||||
return 1
|
||||
|
||||
|
||||
x11 = FakeX11(
|
||||
{
|
||||
10: "Registration",
|
||||
11: "Hopper Disassembler",
|
||||
20: "Registration",
|
||||
21: "Unrelated application",
|
||||
30: "Other window",
|
||||
},
|
||||
{
|
||||
10: 11,
|
||||
20: 21,
|
||||
},
|
||||
)
|
||||
|
||||
observed = [
|
||||
(20, 189, 370, 901, 284),
|
||||
(30, 0, 0, 1280, 1024),
|
||||
(10, 20, 100, 1200, 284),
|
||||
]
|
||||
|
||||
dialog = helper.find_demo_dialog(x11, 0, observed)
|
||||
if dialog is None:
|
||||
raise SystemExit("expected Hopper registration dialog was not detected")
|
||||
if dialog[0] != 10:
|
||||
raise SystemExit(f"wrong dialog detected: {dialog!r}")
|
||||
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"dialog": dialog,
|
||||
"click": helper.demo_click(dialog),
|
||||
"wrong_parent_rejected": helper.find_demo_dialog(
|
||||
x11,
|
||||
0,
|
||||
[observed[0], observed[1]],
|
||||
)
|
||||
is None,
|
||||
},
|
||||
separators=(",", ":"),
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user