fix(fex): signal return restores syscall state; CurseForge runs headless (#3040)

* fix(fex): signal return restores the interrupted syscall state

A guest rt_sigreturn goes through FEX's syscall stub, which marks every
static register as spilled. Returning to unchanged JIT code skipped the
stub's reset, so later asynchronous signals skipped the register spill
and guest handlers read stale registers. CoreCLR's GC suspension reads
and redirects that context, which made x86-64 .NET programs fail with
random access violations. Restore the value saved at signal entry.

* fix(addons): run CurseForge headless from the addon browser, without a session

- The CurseForge source starts the app in its own headless gamescope
  (droiddeck-headless, shared with the Battle.net Agent) instead of a hidden
  session: no SessionService, compositor output or ImageReader.
- The helper's start keeps running until the app exits, so the app lives
  for as long as the addon browser holds that guest command; closing the
  dialog asks the app to quit, stops its process group and cancels the
  command, which ends the app, its gamescope and the guest.
- An app the user already has open is reported busy and left alone.
- Removes BackgroundSession and the CompositorHost start path it shared with
  SessionActivity, with their tests.

* fix(addons): bind each CurseForge stop to its launch and keep the inspector URL out of logs

A stop now only acts on the launch that registered it, so a late stop
from a closed browser cannot end a newer launch, and the browser stops
once. Command logs redact the inspector URL. The signal probe reports a
sender thread that cannot start, sets ECX before the measured region and
its test accepts a valid overshoot of the target count.

* fix(fex): unblock the probe signal before sampling
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-22 20:40:30 -05:00
1 parent 6ef8e2274e
commit 527cb85867
21 files changed
+663 -415

No files matched your search

+4 -15
View File
@@ -1413,7 +1413,8 @@ class AgentJobTest(Harness):
self.assertEqual(code, 0)
self.assertTrue(os.path.isdir(folder))
cmd = self.started[0]
self.assertEqual(cmd[:6], ["gamescope", "--backend", "headless", "-w", "640", "-h"])
self.assertEqual(cmd[:4], ["/usr/local/bin/droiddeck-headless", str(self.tmp / "cache" / "agent-runtime"), "--log",
str(self.tmp / "cache" / "agent.log")])
self.assertEqual(cmd[cmd.index("--") + 2:-1], ["agent-serve", "install", "gryphon", "gryphon", "Z:" + folder, "enUS", "USA", "US"])
self.assertEqual([kind for kind, _ in self.lines], ["STATE", "PROGRESS", "DONE"])
self.assertEqual(json.loads(self.lines[-1][1]), {"install_dir": "Z:" + folder, "exe": "WarcraftRumble.exe", "version": "16.1.2.119725"})
@@ -1641,16 +1642,6 @@ class AgentJobTest(Harness):
path.write_bytes(json.dumps({"state": 1004}).encode("utf-8"))
self.assertEqual(BNET["read_status"](str(path)), {"state": 1004})
def test_a_large_agent_log_is_rotated_before_a_job(self):
self.install()
os.makedirs(self.tmp / "cache")
log = self.tmp / "cache" / "agent.log"
log.write_bytes(b"x" * (BNET["AGENT_LOG_LIMIT"] + 1))
self.files = {".game": json.dumps({"installed": False})}
BNET["agent_job"](self.root, "uninstall", "gryphon", poll=0)
self.assertEqual((self.tmp / "cache" / "agent.log.1").stat().st_size, BNET["AGENT_LOG_LIMIT"] + 1)
self.assertEqual(log.stat().st_size, 0)
def test_it_queues_behind_another_battle_net_job(self):
self.install()
self.files = {".game": json.dumps({"installed": False})}
@@ -1681,13 +1672,11 @@ class AgentJobTest(Harness):
self.assertEqual(self.lines[0], ("STATE", "waiting"))
self.assertEqual(self.lines[1], ("STATE", "starting"))
def test_gamescope_gets_no_display_but_the_agent_keeps_the_one_gamescope_gives_it(self):
def test_the_agent_keeps_the_display_gamescope_gives_it_and_launches_through_the_shared_headless_helper(self):
self.install()
os.environ.update(DISPLAY=":5", WAYLAND_DISPLAY="wayland-1")
self.files = {".game": json.dumps({"installed": False})}
BNET["agent_job"](self.root, "uninstall", "gryphon", poll=0)
self.assertNotIn("DISPLAY", self.envs[0])
self.assertNotIn("WAYLAND_DISPLAY", self.envs[0])
self.assertEqual(self.started[0][0], BNET["HEADLESS"])
self.assertEqual(self.envs[0]["PROTON_USE_XALIA"], "0")
os.environ["DISPLAY"] = ":0"
self.assertEqual(BNET["agent_env"]()["DISPLAY"], ":0")
+120 -80
View File
@@ -1,17 +1,67 @@
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"
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
HELPER = BIN / "droiddeck-curseforge"
HEADLESS = BIN / "droiddeck-headless"
URL = "ws://127.0.0.1:43117/0f8fad5b-d9cb-469f-a165-70867728950e"
class HeadlessTest(unittest.TestCase):
def setUp(self):
self.tmp = Path(tempfile.mkdtemp())
self.addCleanup(shutil.rmtree, self.tmp, True)
self.bin = self.tmp / "bin"
self.bin.mkdir()
self.seen = self.tmp / "seen"
gamescope = self.bin / "gamescope"
gamescope.write_text(
"#!/bin/bash\n"
"printf '%%s\\n' \"DISPLAY=${DISPLAY-}\" \"WAYLAND=${WAYLAND_DISPLAY-}\" \"GAMESCOPE=${GAMESCOPE_WAYLAND_DISPLAY-}\" "
"\"XAUTH=${XAUTHORITY-}\" \"RUNTIME=$XDG_RUNTIME_DIR\" \"$@\" > %s\n"
"echo logged-by-gamescope\n" % shlex.quote(str(self.seen)))
gamescope.chmod(0o755)
def env(self, extra=None):
base = dict(os.environ, PATH="%s:%s" % (self.bin, os.environ["PATH"]), DISPLAY=":0", WAYLAND_DISPLAY="wayland-0",
GAMESCOPE_WAYLAND_DISPLAY="gamescope-0", XAUTHORITY="/run/xauth")
base.update(extra or {})
return base
def run_headless(self, *args, env=None):
return subprocess.run(["bash", str(HEADLESS), *args], env=self.env(env), capture_output=True, text=True, timeout=30)
def test_it_runs_the_command_in_headless_gamescope_with_a_private_runtime_and_no_session_display(self):
runtime = self.tmp / "runtime"
out = self.run_headless(str(runtime), "--", "prog", "arg one")
self.assertEqual(0, out.returncode, out.stderr)
self.assertEqual(["DISPLAY=", "WAYLAND=", "GAMESCOPE=", "XAUTH=", "RUNTIME=%s" % runtime, "--backend", "headless",
"-w", "640", "-h", "480", "--", "prog", "arg one"], self.seen.read_text().splitlines())
self.assertEqual(0o700, runtime.stat().st_mode & 0o777)
def test_output_goes_to_the_log_which_rotates_when_large(self):
log = self.tmp / "agent.log"
log.write_bytes(b"x" * 100)
self.assertEqual(0, self.run_headless(str(self.tmp / "r"), "--log", str(log), "--", "prog").returncode)
self.assertTrue(log.read_text().endswith("logged-by-gamescope\n"))
self.assertEqual(100, log.stat().st_size - len("logged-by-gamescope\n"))
self.assertFalse((self.tmp / "agent.log.1").exists())
self.run_headless(str(self.tmp / "r"), "--log", str(log), "--", "prog", env={"DD_HEADLESS_LOG_LIMIT": "50"})
self.assertEqual(100 + len("logged-by-gamescope\n"), (self.tmp / "agent.log.1").stat().st_size)
self.assertEqual("logged-by-gamescope\n", log.read_text())
def test_bad_arguments_are_refused(self):
self.assertEqual(2, self.run_headless(str(self.tmp / "r"), "prog").returncode)
self.assertEqual(2, self.run_headless(str(self.tmp / "r"), "--").returncode)
self.assertEqual(2, self.run_headless().returncode)
class CurseForgeHelperTest(unittest.TestCase):
def setUp(self):
self.tmp = Path(tempfile.mkdtemp())
@@ -21,18 +71,23 @@ class CurseForgeHelperTest(unittest.TestCase):
self.dir = self.tmp / "curseforge"
(self.dir / "app").mkdir(parents=True)
self.state = self.tmp / "state"
self.bin = self.tmp / "bin"
self.bin.mkdir()
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"
"printf '%%s\\n' \"DISPLAY=${DISPLAY-}\" \"WAYLAND=${WAYLAND_DISPLAY-}\" \"DBUS=${DBUS_SESSION_BUS_ADDRESS-}\" "
"\"RUNTIME=$XDG_RUNTIME_DIR\" \"$@\" > %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"
"echo 'Debugger listening on %s' >&2\n"
"echo 'For help, see: https://nodejs.org/en/docs/inspector' >&2\n"
"sleep 60\n"
% (shlex.quote(str(self.seen)), shlex.quote(str(self.proc)), shlex.quote(str(self.proc)), URL))
self.runner.chmod(0o755)
gamescope = self.bin / "gamescope"
gamescope.write_text('#!/bin/bash\nwhile [ "$1" != -- ]; do shift; done\nshift\n"$@"\n')
gamescope.chmod(0o755)
def fake(self, pid, *argv):
d = self.proc / str(pid)
@@ -40,15 +95,27 @@ class CurseForgeHelperTest(unittest.TestCase):
(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 = dict(os.environ, PATH="%s:%s" % (self.bin, os.environ["PATH"]), DD_PROC=str(self.proc),
DD_CURSEFORGE_STATE=str(self.state), DD_APPIMAGE_RUN=str(self.runner), DD_HEADLESS_RUN=str(HEADLESS),
DD_CURSEFORGE_WAIT="10", DISPLAY=":0", WAYLAND_DISPLAY="wayland-0", XDG_RUNTIME_DIR="/run/user/session",
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 launch(self, directory=None):
holder = subprocess.Popen(["bash", str(HELPER), "start", str(directory or self.dir)], env=self.env(),
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
self.addCleanup(self.finish, holder)
return holder, holder.stdout.readline().strip()
def finish(self, holder):
if holder.poll() is None:
holder.kill()
holder.communicate()
def stop(self):
self.run_helper("stop", str(self.dir))
@@ -64,86 +131,56 @@ class CurseForgeHelperTest(unittest.TestCase):
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"})
out = self.run_helper("start", str(self.dir))
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))
def test_start_runs_the_app_in_headless_gamescope_with_a_secret_inspector_and_no_session_display(self):
holder, url = self.launch()
self.addCleanup(self.stop)
self.assertEqual(0, out.returncode, out.stderr)
self.assertEqual(URL, out.stdout.strip())
self.assertEqual(URL, url)
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(["DISPLAY=", "WAYLAND=", "DBUS=", "RUNTIME=%s/runtime" % self.state, 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(0o700, (self.state / "runtime").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()
_, again = self.launch()
self.assertEqual(URL, again)
def test_start_holds_the_app_until_it_is_stopped(self):
holder, url = self.launch()
self.assertEqual(URL, url)
app = self.pid()
time.sleep(1)
self.assertIsNone(holder.poll())
os.kill(app, 0)
self.stop()
self.assertEqual(0, holder.wait(timeout=30))
self.assertTrue(self.gone(app), "the app is still running")
def test_stop_ends_the_app_and_the_gamescope_it_ran_in(self):
(self.bin / "gamescope").write_text('#!/bin/bash\nwhile [ "$1" != -- ]; do shift; done\nshift\n"$@" &\nwait\n')
self.assertEqual(URL, self.launch()[1])
gamescope = self.pid()
app = int(next(self.proc.iterdir()).name)
self.assertNotEqual(gamescope, app)
os.kill(app, 0)
self.stop()
self.assertFalse((self.state / "pid").exists())
self.assertTrue(self.gone(pid), "the started instance is still running")
self.assertTrue(self.gone(gamescope), "gamescope is still running")
self.assertTrue(self.gone(app), "the app 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):
def test_a_launch_for_another_directory_is_busy_and_left_alone(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(URL, self.launch()[1])
out = self.run_helper("start", str(other))
self.assertEqual(3, out.returncode)
self.assertEqual("busy", out.stdout.strip())
pid = self.pid()
@@ -151,22 +188,25 @@ class CurseForgeHelperTest(unittest.TestCase):
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_each_launch_starts_a_fresh_log(self):
first, _ = self.launch()
self.stop()
first.wait(timeout=30)
self.addCleanup(self.stop)
self.assertEqual(URL, self.launch()[1])
self.assertEqual(1, (self.state / "log").read_text().count("Debugger listening"))
self.assertTrue((self.state / "log.1").exists())
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)
self.assertEqual("", out.stdout)
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)
self.assertEqual(2, self.run_helper("hold", str(self.dir)).returncode)
if __name__ == "__main__":
+22
View File
@@ -348,6 +348,28 @@ class AgentTest(unittest.TestCase):
self.assertEqual("INVALID_TARGET", caught.exception.code)
connect.assert_not_called()
def test_one_shot_inspector_eval_prints_the_session_answer_without_a_launch_dir(self):
import contextlib
import io
url = "ws://127.0.0.1:43117/0f8fad5b-d9cb-469f-a165-70867728950e"
seen = {}
def evaluate(agent_dir, expression, target=None, await_promise=True, timeout=15, inspector=None, command_line_api=False):
seen.update(expression=expression, timeout=timeout, inspector=inspector, api=command_line_api)
return {"target": "inspector", "type": "string", "value": "ok", "description": None}
out = io.StringIO()
with patch.dict(os.environ, {}, clear=False), patch.object(agent, "cdp_eval", evaluate), contextlib.redirect_stdout(out):
os.environ.pop("DD_LAUNCH_DIR", None)
self.assertEqual(0, agent.main(["--cdp-inspector", url, "12.5", "1 + 1"]))
self.assertEqual({"target": "inspector", "type": "string", "value": "ok", "description": None, "ok": True}, json.loads(out.getvalue()))
self.assertEqual({"expression": "1 + 1", "timeout": 12.5, "inspector": url, "api": True}, seen)
out = io.StringIO()
with contextlib.redirect_stdout(out):
self.assertEqual(0, agent.main(["--cdp-inspector", "ws://example.com:9229/x", "5", "1"]))
self.assertEqual("INVALID_REQUEST", json.loads(out.getvalue())["error"]["code"])
self.assertEqual(2, agent.main(["--cdp-inspector", url]))
def test_a_devtools_endpoint_lost_while_sending_is_reported_as_gone(self):
class Lost:
def __init__(self, *args, **kwargs):
@@ -0,0 +1,76 @@
import platform
import re
import shutil
import subprocess
import tempfile
import unittest
from pathlib import Path
FEX = Path(__file__).resolve().parents[1] / "fex"
PATCH = FEX / "patches/0008-signal-return-restores-syscall-state.patch"
PROBE = FEX / "probes/async-signal-context.c"
RESTORE = "Frame->InSyscallInfo = Context->InSyscallInfo;"
def hunks():
text = PATCH.read_text()
files = re.findall(r"^diff --git a/(\S+) ", text, re.M)
return files, re.findall(r"^@@ [^@]+ @@ ?(.*)\n((?:[ +\-].*\n?)*)", text, re.M)
class SignalReturnSyscallStateTest(unittest.TestCase):
def test_only_the_signal_delegator_changes(self):
files, found = hunks()
self.assertEqual(files, ["Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp"])
self.assertEqual(len(found), 1)
def test_every_guest_frame_return_restores_the_interrupted_syscall_state(self):
_, found = hunks()
function, body = found[0]
self.assertIn("SignalDelegator::RestoreThreadState", function)
lines = body.splitlines()
added = [line[1:].strip() for line in lines if line.startswith("+")]
removed = [line for line in lines if line.startswith("-")]
self.assertEqual(added, [RESTORE])
self.assertEqual(removed, [])
context = [line[1:].strip() for line in lines]
guest_frame = context.index("if (Context->UContextLocation) {")
self.assertEqual(context[guest_frame + 1], "auto Frame = Thread->CurrentFrame;")
self.assertEqual(context[guest_frame + 2], RESTORE)
self.assertLess(context.index(RESTORE), context.index("if (Context->Flags & ArchHelpers::Context::ContextFlags::CONTEXT_FLAG_INJIT) {"))
def test_thread_pause_returns_are_untouched(self):
_, found = hunks()
body = found[0][1]
self.assertNotIn("TYPE_PAUSE", "".join(line for line in body.splitlines() if line.startswith("+")))
def test_patch_is_applied_to_every_release(self):
self.assertNotIn("Fixed-upstream", PATCH.read_text())
self.assertIn("tools/fex/patches/*.patch", (FEX / "build-in-arch.sh").read_text())
@unittest.skipUnless(platform.machine() == "x86_64", "the probe is x86-64 code")
class AsyncSignalContextProbeTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
compiler = shutil.which("cc") or shutil.which("gcc") or shutil.which("clang")
if not compiler:
raise unittest.SkipTest("no C compiler")
cls.tmp = Path(tempfile.mkdtemp(prefix="fex-async-signal-"))
cls.binary = cls.tmp / "probe"
subprocess.run([compiler, "-O2", "-pthread", "-o", str(cls.binary), str(PROBE)], check=True, capture_output=True, text=True)
@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.tmp, ignore_errors=True)
def test_native_kernel_reports_the_interrupted_registers(self):
result = subprocess.run([str(self.binary), "500"], capture_output=True, text=True, timeout=120)
self.assertEqual(result.returncode, 0, result.stdout)
counts = dict(part.split("=") for part in result.stdout.split())
self.assertGreaterEqual(int(counts["matched"]), 500)
self.assertEqual(counts["stale"], "0")
if __name__ == "__main__":
unittest.main()
+3 -7
View File
@@ -43,15 +43,11 @@ 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("CompositorHost.start(", start)]
block = text[start:text.index("DriverSetupLog.write", start)]
request = block[block.index("nativeSetHdrRequest("):block.index("Log.i", block.index("nativeSetHdrRequest("))]
self.assertNotIn("SessionPrefs.hdr", block)
self.assertNotIn("SessionPrefs.hdr", block[:block.index("if (!SessionState.running)")])
self.assertIn("capable, false", request)
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)
self.assertIn("SessionState.hdrCapable && SessionPrefs.hdr(this, mode)", block)
def test_both_switches_apply_to_the_running_session(self):
helper = (APP / "session/SessionHdr.kt").read_text()