mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-23 06:46:02 +00:00
feat(addons): add a CurseForge source to the addon browser (#3028)
* feat(addons): add a CurseForge source to the addon browser Search and install CurseForge addons from the Download addons window by driving the installed CurseForge app in the background: it starts minimized on the session's X display with its inspector bound to 127.0.0.1, and the window's own renderer services handle game detection, search, install and shutdown. Sign-in stays inside the CurseForge app. The Install buttons in the addon list now size to their label, so the label is centered and the button matches the other compact buttons. * fix(curseforge): secret inspector URL, hold mode and serialised starts - Start CurseForge with its Node inspector on 127.0.0.1:0 and publish only the UUID websocket URL, kept in the 0700 state directory, so no fixed unauthenticated debug port is exposed. - The agent evaluates through that URL instead of a fixed port. - Add a hold mode that runs as a session program and stops the app on exit, and a lock so hold and start never launch twice. * feat(addons): run CurseForge in a hidden session when none is running - Opening the CurseForge source with no session starts one headlessly (offscreen compositor output, shared start path with SessionActivity via CompositorHost) running the CurseForge hold helper; leaving the dialog stops the app and that session. A session the user already had is reused and left running. - Drop the "start a session" notice from every locale. - Addon browser link: cleanup shares the link's lock off the UI thread, stops the app at once on close, refuses work after close and stops a launch that finishes after close. - CurseForgeApp.start stops the app before every failed return. - instanceFor returns no instance when the populated list has no match. * Harden headless CurseForge session and helper lifecycle Scope the hidden session to its id, roll back partial starts, release the offscreen reader once the session ends, re-acquire the inspector when its endpoint goes away, bound DevTools calls by one deadline, key the installed snapshot by target, track the helper launch by pid start time and directory, fail on lock errors, and update the HDR gate test to its new location. * Map DevTools send failures and recheck the hidden session id * fix(addons): bind the hidden session to the id it claims at launch * Keep the CurseForge helper quiet when no launch is recorded
This commit is contained in:
1 parent
234e40157e
commit
210c127446
48 files changed
+1162
-67
No files matched your search
@@ -432,7 +432,7 @@ class FocusWatcher(threading.Thread):
|
||||
|
||||
class WebSocket:
|
||||
|
||||
def __init__(self, url, timeout):
|
||||
def __init__(self, url, timeout, bounded=False):
|
||||
target = urllib.parse.urlsplit(url)
|
||||
if (target.scheme != "ws" or target.hostname not in ("127.0.0.1", "::1", "localhost")
|
||||
or target.username is not None or target.password is not None or target.fragment):
|
||||
@@ -442,6 +442,7 @@ class WebSocket:
|
||||
if target.query:
|
||||
path += "?" + target.query
|
||||
host = "127.0.0.1" if target.hostname == "localhost" else target.hostname
|
||||
self.deadline = time.monotonic() + timeout if bounded else None
|
||||
self.s = socket.create_connection((host, target.port or 80), timeout=timeout)
|
||||
try:
|
||||
self._handshake(path, hostport)
|
||||
@@ -457,6 +458,7 @@ class WebSocket:
|
||||
).encode())
|
||||
head = b""
|
||||
while b"\r\n\r\n" not in head:
|
||||
self._wait()
|
||||
chunk = self.s.recv(4096)
|
||||
if not chunk:
|
||||
raise OSError("DevTools closed the connection during the handshake")
|
||||
@@ -468,8 +470,17 @@ class WebSocket:
|
||||
raise OSError("DevTools refused the WebSocket: " + status.decode(errors="replace"))
|
||||
self.buffer = head.split(b"\r\n\r\n", 1)[1]
|
||||
|
||||
def _wait(self):
|
||||
if self.deadline is None:
|
||||
return
|
||||
left = self.deadline - time.monotonic()
|
||||
if left <= 0:
|
||||
raise socket.timeout("DevTools did not answer in time")
|
||||
self.s.settimeout(left)
|
||||
|
||||
def _read(self, n):
|
||||
while len(self.buffer) < n:
|
||||
self._wait()
|
||||
chunk = self.s.recv(65536)
|
||||
if not chunk:
|
||||
raise OSError("DevTools closed the connection")
|
||||
@@ -547,22 +558,51 @@ def cdp_targets(agent_dir, timeout=5):
|
||||
raise AgentError("DEVTOOLS_UNREACHABLE", "Could not reach the client's DevTools at %s: %s" % (url, e))
|
||||
|
||||
|
||||
def cdp_eval(agent_dir, expression, target=None, await_promise=True, timeout=15):
|
||||
targets = [t for t in cdp_targets(agent_dir) if t.get("webSocketDebuggerUrl")]
|
||||
want = target or "SharedJSContext"
|
||||
match = [t for t in targets if want in (t.get("title") or "") or want in (t.get("url") or "")]
|
||||
if not match:
|
||||
names = ", ".join(sorted({t.get("title") or t.get("url") or "?" for t in targets}))
|
||||
raise AgentError("NO_TARGET", "No DevTools target matches '%s' (have: %s)" % (want, names))
|
||||
ws = WebSocket(match[0]["webSocketDebuggerUrl"], timeout)
|
||||
INSPECTOR_URL = re.compile(r"ws://127\.0\.0\.1:([0-9]{4,5})/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")
|
||||
|
||||
|
||||
def inspector_url(url):
|
||||
found = INSPECTOR_URL.fullmatch(url) if isinstance(url, str) else None
|
||||
if not found or not 1024 <= int(found.group(1)) <= 65535:
|
||||
raise AgentError("INVALID_REQUEST", "inspector must be a ws://127.0.0.1 inspector URL with its session id")
|
||||
return url
|
||||
|
||||
|
||||
def cdp_eval(agent_dir, expression, target=None, await_promise=True, timeout=15, inspector=None,
|
||||
command_line_api=False):
|
||||
if inspector is not None:
|
||||
url, name = inspector_url(inspector), "inspector"
|
||||
else:
|
||||
targets = [t for t in cdp_targets(agent_dir) if t.get("webSocketDebuggerUrl")]
|
||||
want = target or "SharedJSContext"
|
||||
match = [t for t in targets if want in (t.get("title") or "") or want in (t.get("url") or "")]
|
||||
if not match:
|
||||
names = ", ".join(sorted({t.get("title") or t.get("url") or "?" for t in targets}))
|
||||
raise AgentError("NO_TARGET", "No DevTools target matches '%s' (have: %s)" % (want, names))
|
||||
url, name = match[0]["webSocketDebuggerUrl"], match[0].get("title")
|
||||
try:
|
||||
ws.send(json.dumps({"id": 1, "method": "Runtime.evaluate", "params": {
|
||||
"expression": expression, "returnByValue": True, "awaitPromise": await_promise,
|
||||
"userGesture": True,
|
||||
}}))
|
||||
deadline = time.monotonic() + timeout
|
||||
while time.monotonic() < deadline:
|
||||
message = json.loads(ws.recv())
|
||||
ws = WebSocket(url, timeout, bounded=True)
|
||||
except socket.timeout:
|
||||
raise AgentError("TIMEOUT", "No answer from DevTools in %ss" % timeout)
|
||||
except OSError as e:
|
||||
raise AgentError("DEVTOOLS_UNREACHABLE", "Could not reach DevTools: %s" % e)
|
||||
try:
|
||||
try:
|
||||
ws.send(json.dumps({"id": 1, "method": "Runtime.evaluate", "params": {
|
||||
"expression": expression, "returnByValue": True, "awaitPromise": await_promise,
|
||||
"userGesture": True, "includeCommandLineAPI": command_line_api,
|
||||
}}))
|
||||
except socket.timeout:
|
||||
raise AgentError("TIMEOUT", "No answer from DevTools in %ss" % timeout)
|
||||
except OSError as e:
|
||||
raise AgentError("DEVTOOLS_UNREACHABLE", "DevTools went away: %s" % e)
|
||||
while True:
|
||||
try:
|
||||
message = json.loads(ws.recv())
|
||||
except socket.timeout:
|
||||
raise AgentError("TIMEOUT", "No answer from DevTools in %ss" % timeout)
|
||||
except OSError as e:
|
||||
raise AgentError("DEVTOOLS_UNREACHABLE", "DevTools went away: %s" % e)
|
||||
if message.get("id") != 1:
|
||||
continue
|
||||
if "error" in message:
|
||||
@@ -573,9 +613,8 @@ def cdp_eval(agent_dir, expression, target=None, await_promise=True, timeout=15)
|
||||
text = (details.get("exception") or {}).get("description") or details.get("text") or "exception"
|
||||
raise AgentError("JS_EXCEPTION", text)
|
||||
value = result.get("result", {})
|
||||
return {"target": match[0].get("title"), "type": value.get("type"),
|
||||
return {"target": name, "type": value.get("type"),
|
||||
"value": value.get("value"), "description": value.get("description")}
|
||||
raise AgentError("TIMEOUT", "No answer from DevTools in %ss" % timeout)
|
||||
finally:
|
||||
ws.close()
|
||||
|
||||
@@ -1157,7 +1196,7 @@ def handle(agent_dir, req):
|
||||
if not isinstance(expression, str) or not expression:
|
||||
raise AgentError("INVALID_REQUEST", "cdp eval needs an expression")
|
||||
return cdp_eval(agent_dir, expression, req.get("target"), bool(req.get("awaitPromise", True)),
|
||||
request_timeout(req, 15))
|
||||
request_timeout(req, 15), req.get("inspector"), req.get("commandLineApi") is True)
|
||||
if kind == "steam-selection":
|
||||
return steam_selection(agent_dir, request_timeout(req, 5))
|
||||
if kind == "quit":
|
||||
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
#!/bin/bash
|
||||
set -u
|
||||
umask 077
|
||||
self=${BASH_SOURCE[0]}
|
||||
proc=${DD_PROC:-/proc}
|
||||
state=${DD_CURSEFORGE_STATE:-${XDG_RUNTIME_DIR:-/tmp}/droiddeck-curseforge}
|
||||
runner=${DD_APPIMAGE_RUN:-${self%/*}/droiddeck-appimage-run}
|
||||
wait_s=${DD_CURSEFORGE_WAIT:-60}
|
||||
cmd=${1:-}
|
||||
dir=${2:-}
|
||||
flag=--inspect-publish-uid=stderr
|
||||
case $cmd in start|hold|stop|display) ;; *) echo "usage: droiddeck-curseforge start|hold|stop|display <imported AppImage directory>" >&2; exit 2 ;; esac
|
||||
if [ "$cmd" != display ] && [ ! -d "$dir/app" ]; then
|
||||
echo "droiddeck-curseforge: $dir is not an imported AppImage" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
x_display() {
|
||||
if [ -n "${DISPLAY:-}" ]; then
|
||||
printf '%s\n%s\n' "$DISPLAY" "${XAUTHORITY:-}"
|
||||
return 0
|
||||
fi
|
||||
local p name a prev display auth
|
||||
for p in "$proc"/[0-9]*; do
|
||||
name=$(tr '\0' '\n' 2>/dev/null < "$p/cmdline" | head -n 1)
|
||||
case ${name##*/} in Xwayland|Xorg|Xvfb) ;; *) continue ;; esac
|
||||
display= auth= prev=
|
||||
while IFS= read -r a; do
|
||||
case $a in :[0-9]*) [ -z "$display" ] && display=$a ;; esac
|
||||
[ "$prev" = -auth ] && auth=$a
|
||||
prev=$a
|
||||
done < <(tr '\0' '\n' 2>/dev/null < "$p/cmdline")
|
||||
if [ -n "$display" ]; then
|
||||
printf '%s\n%s\n' "$display" "$auth"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
running() {
|
||||
local p
|
||||
for p in "$proc"/[0-9]*; do
|
||||
tr '\0' '\n' 2>/dev/null < "$p/cmdline" | grep -qF -- "$dir/app/" && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
started_at() {
|
||||
local stat
|
||||
stat=$(cat "/proc/$1/stat" 2>/dev/null) || return 1
|
||||
stat=${stat##*) }
|
||||
set -- $stat
|
||||
echo "${20}"
|
||||
}
|
||||
|
||||
tracked() {
|
||||
local pid at launched
|
||||
read -r pid at launched 2>/dev/null < "$state/pid" || return 1
|
||||
case $pid in ''|*[!0-9]*) return 1 ;; esac
|
||||
kill -0 "$pid" 2>/dev/null && [ "$(started_at "$pid")" = "$at" ] || return 1
|
||||
printf '%s %s\n' "$pid" "$launched"
|
||||
}
|
||||
|
||||
ours() {
|
||||
local pid launched
|
||||
read -r pid launched <<<"$(tracked)"
|
||||
[ -n "$pid" ] && [ "$launched" = "$dir" ] && echo "$pid"
|
||||
}
|
||||
|
||||
lock() {
|
||||
mkdir -p "$state" && chmod 700 "$state" || return 1
|
||||
exec 9>"$state/lock" || return 1
|
||||
flock 9
|
||||
}
|
||||
|
||||
inspector() {
|
||||
grep -aom1 'ws://127\.0\.0\.1:[0-9]*/[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}' "$state/log" 2>/dev/null
|
||||
}
|
||||
|
||||
start() {
|
||||
local shown display auth url pid
|
||||
lock || { echo "droiddeck-curseforge: cannot lock $state" >&2; return 5; }
|
||||
if ! ours >/dev/null; then
|
||||
if tracked >/dev/null || running; then
|
||||
exec 9>&-
|
||||
echo busy
|
||||
return 3
|
||||
fi
|
||||
shown=$(x_display) || { exec 9>&-; echo "no X display" >&2; return 4; }
|
||||
display=$(sed -n 1p <<<"$shown")
|
||||
auth=$(sed -n 2p <<<"$shown")
|
||||
env -u DBUS_SESSION_BUS_ADDRESS -u WAYLAND_DISPLAY -u GAMESCOPE_WAYLAND_DISPLAY DISPLAY="$display" ${auth:+XAUTHORITY="$auth"} \
|
||||
setsid "$runner" "$dir" --minimized --inspect=127.0.0.1:0 "$flag" </dev/null >"$state/log" 2>&1 9>&- &
|
||||
pid=$!
|
||||
printf '%s %s %s\n' "$pid" "$(started_at "$pid")" "$dir" > "$state/pid"
|
||||
fi
|
||||
exec 9>&-
|
||||
for _ in $(seq 1 $((wait_s * 2))); do
|
||||
if url=$(inspector); then
|
||||
echo "$url"
|
||||
return 0
|
||||
fi
|
||||
ours >/dev/null || break
|
||||
sleep 0.5
|
||||
done
|
||||
tail -n 20 "$state/log" >&2
|
||||
return 5
|
||||
}
|
||||
|
||||
stop() {
|
||||
local pid p
|
||||
lock || return 1
|
||||
pid=$(ours) || { tracked >/dev/null || rm -f "$state/pid"; exec 9>&-; return 0; }
|
||||
kill -TERM -- "-$pid" 2>/dev/null
|
||||
for _ in $(seq 1 20); do
|
||||
kill -0 -- "-$pid" 2>/dev/null || break
|
||||
sleep 0.5
|
||||
done
|
||||
kill -KILL -- "-$pid" 2>/dev/null
|
||||
for p in "$proc"/[0-9]*; do
|
||||
tr '\0' '\n' 2>/dev/null < "$p/cmdline" | grep -qF -- "$dir/app/" && kill -KILL "${p##*/}" 2>/dev/null
|
||||
done
|
||||
rm -f "$state/pid"
|
||||
exec 9>&-
|
||||
return 0
|
||||
}
|
||||
|
||||
case $cmd in
|
||||
display)
|
||||
x_display || exit 4
|
||||
;;
|
||||
start)
|
||||
start
|
||||
exit $?
|
||||
;;
|
||||
hold)
|
||||
start >/dev/null || exit $?
|
||||
trap 'stop; exit 0' TERM INT HUP
|
||||
while ours >/dev/null; do
|
||||
sleep 1 &
|
||||
wait $!
|
||||
done
|
||||
exit 0
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,173 @@
|
||||
import os
|
||||
import shlex
|
||||
import shutil
|
||||
import signal
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
HELPER = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-curseforge"
|
||||
URL = "ws://127.0.0.1:43117/0f8fad5b-d9cb-469f-a165-70867728950e"
|
||||
|
||||
|
||||
class CurseForgeHelperTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = Path(tempfile.mkdtemp())
|
||||
self.addCleanup(shutil.rmtree, self.tmp, True)
|
||||
self.proc = self.tmp / "proc"
|
||||
self.proc.mkdir()
|
||||
self.dir = self.tmp / "curseforge"
|
||||
(self.dir / "app").mkdir(parents=True)
|
||||
self.state = self.tmp / "state"
|
||||
self.runner = self.tmp / "runner"
|
||||
self.seen = self.tmp / "seen"
|
||||
self.runner.write_text(
|
||||
"#!/bin/bash\n"
|
||||
"printf '%%s\\n' \"DISPLAY=$DISPLAY\" \"XAUTHORITY=${XAUTHORITY-}\" \"WAYLAND=${WAYLAND_DISPLAY-}\" "
|
||||
"\"DBUS=${DBUS_SESSION_BUS_ADDRESS-}\" \"$@\" > %s\n"
|
||||
"mkdir -p %s/$$ && printf '%%s\\0' bash \"$0\" \"$@\" > %s/$$/cmdline\n"
|
||||
"echo 'Debugger listening on %s'\n"
|
||||
"echo 'For help, see: https://nodejs.org/en/docs/inspector'\n"
|
||||
"exec sleep 60\n"
|
||||
% (shlex.quote(str(self.seen)), shlex.quote(str(self.proc)), shlex.quote(str(self.proc)), URL))
|
||||
self.runner.chmod(0o755)
|
||||
|
||||
def fake(self, pid, *argv):
|
||||
d = self.proc / str(pid)
|
||||
d.mkdir()
|
||||
(d / "cmdline").write_bytes(b"".join(a.encode() + b"\0" for a in argv))
|
||||
|
||||
def env(self, extra=None):
|
||||
base = {k: v for k, v in os.environ.items() if k not in ("DISPLAY", "XAUTHORITY")}
|
||||
base.update(DD_PROC=str(self.proc), DD_CURSEFORGE_STATE=str(self.state), DD_APPIMAGE_RUN=str(self.runner),
|
||||
DD_CURSEFORGE_WAIT="10", WAYLAND_DISPLAY="wayland-0", DBUS_SESSION_BUS_ADDRESS="unix:path=/x")
|
||||
base.update(extra or {})
|
||||
return base
|
||||
|
||||
def run_helper(self, *args, env=None):
|
||||
return subprocess.run(["bash", str(HELPER), *args], env=self.env(env), capture_output=True, text=True, timeout=60)
|
||||
|
||||
def stop(self):
|
||||
self.run_helper("stop", str(self.dir))
|
||||
|
||||
def pid(self):
|
||||
return int((self.state / "pid").read_text().split()[0])
|
||||
|
||||
def gone(self, pid):
|
||||
for _ in range(50):
|
||||
try:
|
||||
os.kill(pid, 0)
|
||||
except ProcessLookupError:
|
||||
return True
|
||||
time.sleep(0.1)
|
||||
return False
|
||||
|
||||
def test_the_desktop_x_display_is_found_from_xwayland(self):
|
||||
self.fake(40, "/usr/bin/kwin_wayland", ":9")
|
||||
self.fake(41, "/usr/bin/Xwayland", ":0", "-rootless", "-auth", "/run/droiddeck/xauth_abc", "-listenfd", "5")
|
||||
out = self.run_helper("display", "")
|
||||
self.assertEqual(0, out.returncode, out.stderr)
|
||||
self.assertEqual([":0", "/run/droiddeck/xauth_abc"], out.stdout.splitlines())
|
||||
|
||||
def test_the_session_display_wins(self):
|
||||
self.fake(41, "/usr/bin/Xwayland", ":3")
|
||||
out = self.run_helper("display", "", env={"DISPLAY": ":0"})
|
||||
self.assertEqual(":0", out.stdout.splitlines()[0])
|
||||
|
||||
def test_no_display_is_reported(self):
|
||||
out = self.run_helper("start", str(self.dir))
|
||||
self.assertEqual(4, out.returncode)
|
||||
|
||||
def test_a_running_instance_without_the_inspector_is_busy(self):
|
||||
self.fake(50, "/usr/bin/FEX", str(self.dir) + "/app/curseforge", "--no-sandbox")
|
||||
out = self.run_helper("start", str(self.dir), env={"DISPLAY": ":0"})
|
||||
self.assertEqual(3, out.returncode)
|
||||
self.assertEqual("busy", out.stdout.strip())
|
||||
self.stop()
|
||||
self.assertTrue((self.proc / "50").exists())
|
||||
|
||||
def test_start_uses_a_random_port_and_a_secret_inspector_url_kept_private(self):
|
||||
self.fake(41, "/usr/bin/Xwayland", ":0", "-auth", "/run/droiddeck/xauth_abc")
|
||||
out = self.run_helper("start", str(self.dir))
|
||||
self.addCleanup(self.stop)
|
||||
self.assertEqual(0, out.returncode, out.stderr)
|
||||
self.assertEqual(URL, out.stdout.strip())
|
||||
seen = self.seen.read_text().splitlines()
|
||||
self.assertEqual(["DISPLAY=:0", "XAUTHORITY=/run/droiddeck/xauth_abc", "WAYLAND=", "DBUS=", str(self.dir),
|
||||
"--minimized", "--inspect=127.0.0.1:0", "--inspect-publish-uid=stderr"], seen)
|
||||
self.assertEqual(0o700, self.state.stat().st_mode & 0o777)
|
||||
self.assertEqual(0o600, (self.state / "log").stat().st_mode & 0o777)
|
||||
again = self.run_helper("start", str(self.dir))
|
||||
self.assertEqual(URL, again.stdout.strip())
|
||||
pid = self.pid()
|
||||
self.stop()
|
||||
self.assertFalse((self.state / "pid").exists())
|
||||
self.assertTrue(self.gone(pid), "the started instance is still running")
|
||||
|
||||
def test_hold_keeps_the_app_until_it_is_signalled(self):
|
||||
held = subprocess.Popen(["bash", str(HELPER), "hold", str(self.dir)], env=self.env({"DISPLAY": ":0"}),
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
self.addCleanup(self.end, held)
|
||||
for _ in range(100):
|
||||
if (self.state / "pid").exists() and self.seen.exists():
|
||||
break
|
||||
time.sleep(0.1)
|
||||
pid = self.pid()
|
||||
time.sleep(1)
|
||||
self.assertIsNone(held.poll())
|
||||
held.send_signal(signal.SIGTERM)
|
||||
self.assertEqual(0, held.wait(timeout=30))
|
||||
self.assertTrue(self.gone(pid), "hold left the app running")
|
||||
self.assertFalse((self.state / "pid").exists())
|
||||
|
||||
def end(self, held):
|
||||
if held.poll() is None:
|
||||
held.send_signal(signal.SIGTERM)
|
||||
try:
|
||||
held.wait(timeout=15)
|
||||
except subprocess.TimeoutExpired:
|
||||
held.kill()
|
||||
held.wait()
|
||||
record = self.state / "pid"
|
||||
if record.exists():
|
||||
try:
|
||||
os.killpg(self.pid(), signal.SIGKILL)
|
||||
except (ProcessLookupError, PermissionError):
|
||||
pass
|
||||
|
||||
def test_a_launch_for_another_directory_is_busy(self):
|
||||
other = self.tmp / "other"
|
||||
(other / "app").mkdir(parents=True)
|
||||
first = self.run_helper("start", str(self.dir), env={"DISPLAY": ":0"})
|
||||
self.addCleanup(self.stop)
|
||||
self.assertEqual(0, first.returncode, first.stderr)
|
||||
out = self.run_helper("start", str(other), env={"DISPLAY": ":0"})
|
||||
self.assertEqual(3, out.returncode)
|
||||
self.assertEqual("busy", out.stdout.strip())
|
||||
pid = self.pid()
|
||||
self.run_helper("stop", str(other))
|
||||
self.assertEqual(pid, self.pid())
|
||||
os.kill(pid, 0)
|
||||
|
||||
def test_hold_ends_when_the_app_exits(self):
|
||||
proc = shlex.quote(str(self.proc))
|
||||
self.runner.write_text("#!/bin/bash\nmkdir -p %s/$$ && printf '%%s\\0' bash \"$0\" \"$@\" > %s/$$/cmdline\n"
|
||||
"echo 'Debugger listening on %s'\nsleep 2\nrm -r %s/$$\n" % (proc, proc, URL, proc))
|
||||
out = subprocess.run(["bash", str(HELPER), "hold", str(self.dir)], env=self.env({"DISPLAY": ":0"}),
|
||||
capture_output=True, text=True, timeout=60)
|
||||
self.assertEqual(0, out.returncode, out.stderr)
|
||||
|
||||
def test_stop_without_a_launch_is_quiet(self):
|
||||
out = self.run_helper("stop", str(self.dir))
|
||||
self.assertEqual(0, out.returncode)
|
||||
self.assertEqual("", out.stderr)
|
||||
|
||||
def test_bad_arguments_are_refused(self):
|
||||
self.assertEqual(2, self.run_helper("start", str(self.tmp / "missing")).returncode)
|
||||
self.assertEqual(2, self.run_helper("launch", str(self.dir)).returncode)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -348,6 +348,23 @@ class AgentTest(unittest.TestCase):
|
||||
self.assertEqual("INVALID_TARGET", caught.exception.code)
|
||||
connect.assert_not_called()
|
||||
|
||||
def test_a_devtools_endpoint_lost_while_sending_is_reported_as_gone(self):
|
||||
class Lost:
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def send(self, text):
|
||||
raise BrokenPipeError("closed")
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
with patch.object(agent, "WebSocket", Lost), patch.object(
|
||||
agent, "cdp_targets", return_value=[{"title": "SharedJSContext", "webSocketDebuggerUrl": "ws://127.0.0.1:1/x"}]):
|
||||
with self.assertRaises(agent.AgentError) as caught:
|
||||
agent.cdp_eval(str(self.dir), "1")
|
||||
self.assertEqual("DEVTOOLS_UNREACHABLE", caught.exception.code)
|
||||
|
||||
def test_cdp_without_a_port(self):
|
||||
os.environ.pop("DD_CDP_PORT", None)
|
||||
self.assertEqual("NO_DEVTOOLS", self.ask({"kind": "cdp", "expression": "1"})["error"]["code"])
|
||||
@@ -368,6 +385,22 @@ class AgentTest(unittest.TestCase):
|
||||
missing = self.ask({"kind": "cdp", "expression": "1", "target": "Nope"})
|
||||
self.assertEqual("NO_TARGET", missing["error"]["code"])
|
||||
|
||||
def test_cdp_eval_on_a_secret_inspector_url(self):
|
||||
server = FakeDevTools({"result": {"result": {"type": "string", "value": "ok"}}})
|
||||
server.start()
|
||||
self.addCleanup(server.server.close)
|
||||
os.environ.pop("DD_CDP_PORT", None)
|
||||
url = "ws://127.0.0.1:%d/0f8fad5b-d9cb-469f-a165-70867728950e" % server.port
|
||||
answer = self.ask({"kind": "cdp", "expression": "require('electron')", "inspector": url, "commandLineApi": True})
|
||||
self.assertTrue(answer["ok"], answer)
|
||||
self.assertEqual("inspector", answer["target"])
|
||||
self.assertTrue(server.seen[0]["params"]["includeCommandLineAPI"])
|
||||
|
||||
def test_cdp_refuses_inspector_urls_without_a_session_id(self):
|
||||
for url in ("ws://127.0.0.1:9229/", "ws://127.0.0.1:9229/json/list", "ws://10.0.0.2:9229/0f8fad5b-d9cb-469f-a165-70867728950e",
|
||||
"ws://127.0.0.1:80/0f8fad5b-d9cb-469f-a165-70867728950e", "ws://127.0.0.1:9229/0f8fad5b-d9cb-469f-a165-70867728950e/x", 9229):
|
||||
self.assertEqual("INVALID_REQUEST", self.ask({"kind": "cdp", "expression": "1", "inspector": url})["error"]["code"])
|
||||
|
||||
def test_steam_selection(self):
|
||||
with patch.object(agent, "cdp_eval", return_value={"value": "3180310"}) as evaluate:
|
||||
answer = self.ask({"kind": "steam-selection"})
|
||||
|
||||
@@ -43,11 +43,15 @@ class HdrLiveSwitchTest(unittest.TestCase):
|
||||
def test_the_gate_follows_the_display_not_the_setting(self):
|
||||
text = (APP / "SessionActivity.kt").read_text()
|
||||
start = text.index("val attached = CompositorHost.isStarted")
|
||||
block = text[start:text.index("DriverSetupLog.write", start)]
|
||||
block = text[start:text.index("CompositorHost.start(", start)]
|
||||
request = block[block.index("nativeSetHdrRequest("):block.index("Log.i", block.index("nativeSetHdrRequest("))]
|
||||
self.assertNotIn("SessionPrefs.hdr", block[:block.index("if (!SessionState.running)")])
|
||||
self.assertNotIn("SessionPrefs.hdr", block)
|
||||
self.assertIn("capable, false", request)
|
||||
self.assertIn("SessionState.hdrCapable && SessionPrefs.hdr(this, mode)", block)
|
||||
self.assertIn("if (!SessionState.running) CompositorHost.applyHdr(this, mode)", block)
|
||||
host = (APP / "wayland/CompositorHost.kt").read_text()
|
||||
gate = host[host.index("fun applyHdr("):]
|
||||
gate = gate[:gate.index("\n }")]
|
||||
self.assertIn("SessionState.hdrCapable && SessionPrefs.hdr(context, mode)", gate)
|
||||
|
||||
def test_both_switches_apply_to_the_running_session(self):
|
||||
helper = (APP / "session/SessionHdr.kt").read_text()
|
||||
|
||||
Reference in new issue
Block a user