Fixed terminal bug. Fixed tests which could leave the system without proper accessibility setup which could cause cthulhu to fail to start.
This commit is contained in:
1 parent
9e0ff41b16
commit
d717b93849
30 files changed
+611
-22
No files matched your search
@@ -8,6 +8,8 @@ import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
requiredTests = {
|
||||
"TestPrivateWineReviewUpdatesPreserveQueuedTitleSpeech",
|
||||
@@ -34,7 +36,7 @@ def run_checks(sourceRoot: Path) -> None:
|
||||
"./internal/app", "./internal/input", "./internal/speech", "./internal/wine",
|
||||
]
|
||||
print("Checking speech queues, Wine metadata and key interruption...", flush=True)
|
||||
result = subprocess.run(command, cwd=sourceRoot, env=testEnv, text=True,
|
||||
result = run_private_session(command, cwd=sourceRoot, env=testEnv, text=True,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=False)
|
||||
passedTests = set()
|
||||
diagnostics = []
|
||||
|
||||
@@ -8,6 +8,7 @@ import tempfile
|
||||
import time
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
def inside():
|
||||
@@ -69,7 +70,7 @@ def main():
|
||||
environment.pop("DBUS_SESSION_BUS_ADDRESS", None)
|
||||
environment.pop("AT_SPI_BUS_ADDRESS", None)
|
||||
environment.pop("WAYLAND_DISPLAY", None)
|
||||
subprocess.run(
|
||||
run_private_session(
|
||||
["dbus-run-session", "--", sys.executable, str(Path(__file__).resolve()), "--inside"],
|
||||
env=environment, check=True, timeout=50,
|
||||
)
|
||||
|
||||
@@ -9,6 +9,8 @@ import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
def wait_for(check, message, timeout=15):
|
||||
deadline = time.monotonic() + timeout
|
||||
@@ -265,7 +267,7 @@ def main() -> None:
|
||||
environment.pop("DBUS_SESSION_BUS_ADDRESS", None)
|
||||
environment.pop("AT_SPI_BUS_ADDRESS", None)
|
||||
environment.pop("WAYLAND_DISPLAY", None)
|
||||
subprocess.run(
|
||||
run_private_session(
|
||||
["dbus-run-session", "--", sys.executable, str(Path(__file__).resolve()),
|
||||
"--inside-screen-lock" if len(sys.argv) == 2 and sys.argv[1] == "--screen-lock" else
|
||||
"--inside-table" if len(sys.argv) == 2 and sys.argv[1] == "--table-only" else "--inside"],
|
||||
|
||||
@@ -8,6 +8,8 @@ import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
BROWSER_PROOFS = {
|
||||
"menu": ("./internal/app", "^TestNativeBrowserMenuControls$", 30, 35),
|
||||
@@ -122,7 +124,7 @@ def main():
|
||||
environment.pop("DBUS_SESSION_BUS_ADDRESS", None)
|
||||
environment.pop("AT_SPI_BUS_ADDRESS", None)
|
||||
environment.pop("WAYLAND_DISPLAY", None)
|
||||
subprocess.run(
|
||||
run_private_session(
|
||||
["dbus-run-session", "--", sys.executable, str(Path(__file__).resolve()), "--inside"],
|
||||
env=environment,
|
||||
check=True,
|
||||
|
||||
@@ -12,6 +12,7 @@ import time
|
||||
sys.dont_write_bytecode = True
|
||||
from native_echo_preview import PreviewSpeechServer
|
||||
from native_x11 import wait_for
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
def run_inside():
|
||||
@@ -175,7 +176,7 @@ def main():
|
||||
environment = dict(os.environ, DISPLAY=":" + number, XDG_SESSION_TYPE="x11")
|
||||
for name in ("DBUS_SESSION_BUS_ADDRESS", "AT_SPI_BUS_ADDRESS", "WAYLAND_DISPLAY"):
|
||||
environment.pop(name, None)
|
||||
subprocess.run(["dbus-run-session", "--", sys.executable, str(Path(__file__).resolve()), "--inside"],
|
||||
run_private_session(["dbus-run-session", "--", sys.executable, str(Path(__file__).resolve()), "--inside"],
|
||||
env=environment, check=True, timeout=120)
|
||||
finally:
|
||||
display.terminate()
|
||||
|
||||
@@ -10,6 +10,7 @@ import threading
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
from native_x11 import wait_for
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
def owner():
|
||||
@@ -211,7 +212,7 @@ def main():
|
||||
env = dict(os.environ, DISPLAY=":" + display, GDK_BACKEND="x11", GTK_MODULES="gail:atk-bridge", GIO_USE_VFS="local")
|
||||
for name in ("DBUS_SESSION_BUS_ADDRESS", "AT_SPI_BUS_ADDRESS", "WAYLAND_DISPLAY"):
|
||||
env.pop(name, None)
|
||||
subprocess.run(["dbus-run-session", "--", sys.executable, __file__, "--inside"], env=env, check=True, timeout=75)
|
||||
run_private_session(["dbus-run-session", "--", sys.executable, __file__, "--inside"], env=env, check=True, timeout=75)
|
||||
finally:
|
||||
server.terminate()
|
||||
server.wait(timeout=5)
|
||||
|
||||
@@ -9,6 +9,8 @@ import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
PAGE = Path(__file__).with_name("firefox-baseline.html")
|
||||
@@ -97,7 +99,7 @@ def main():
|
||||
environment.pop("DBUS_SESSION_BUS_ADDRESS", None)
|
||||
environment.pop("AT_SPI_BUS_ADDRESS", None)
|
||||
environment.pop("WAYLAND_DISPLAY", None)
|
||||
subprocess.run(
|
||||
run_private_session(
|
||||
["dbus-run-session", "--", sys.executable, str(Path(__file__).resolve()), "--inside"],
|
||||
env=environment, check=True, timeout=90,
|
||||
)
|
||||
|
||||
@@ -8,6 +8,8 @@ import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
def run_inside():
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
@@ -112,6 +114,6 @@ if __name__ == "__main__":
|
||||
elif "--inside" in sys.argv:
|
||||
run_inside()
|
||||
else:
|
||||
subprocess.run(["xvfb-run", "-a", "dbus-run-session", "--", sys.executable,
|
||||
run_private_session(["xvfb-run", "-a", "dbus-run-session", "--", sys.executable,
|
||||
__file__, "--inside"], check=True,
|
||||
env=dict(os.environ, GTK_MODULES="gail:atk-bridge", NO_AT_BRIDGE="0"))
|
||||
@@ -11,6 +11,8 @@ import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
def wait_for(check, message, timeout=15):
|
||||
deadline = time.monotonic() + timeout
|
||||
@@ -166,7 +168,7 @@ def main():
|
||||
XDG_DATA_HOME=temporary)
|
||||
for name in ("DBUS_SESSION_BUS_ADDRESS", "AT_SPI_BUS_ADDRESS", "WAYLAND_DISPLAY", "I3SOCK"):
|
||||
environment.pop(name, None)
|
||||
subprocess.run(
|
||||
run_private_session(
|
||||
["xvfb-run", "-a", "dbus-run-session", "--", sys.executable,
|
||||
str(Path(__file__).resolve()), "--inside"],
|
||||
env=environment, check=True, timeout=120,
|
||||
|
||||
@@ -12,6 +12,7 @@ import tempfile
|
||||
sys.dont_write_bytecode = True
|
||||
from native_echo_preview import PreviewSpeechServer
|
||||
from native_x11 import wait_for
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
TITLE = "Cthulhu Mozilla Reading Probe"
|
||||
@@ -197,7 +198,7 @@ def main():
|
||||
for name in ("DBUS_SESSION_BUS_ADDRESS", "AT_SPI_BUS_ADDRESS", "WAYLAND_DISPLAY"):
|
||||
environment.pop(name, None)
|
||||
with (directory / "session.log").open("w") as log:
|
||||
subprocess.run(["xvfb-run", "-a", "-s", "-screen 0 1280x900x24", "dbus-run-session", "--",
|
||||
run_private_session(["xvfb-run", "-a", "-s", "-screen 0 1280x900x24", "dbus-run-session", "--",
|
||||
sys.executable, str(Path(__file__).resolve()), application, "--inside"],
|
||||
env=environment, stderr=log, check=True, timeout=120)
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import sys
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
from native_x11 import wait_for
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
def inside():
|
||||
@@ -161,7 +162,7 @@ def main():
|
||||
)
|
||||
for key in ("DBUS_SESSION_BUS_ADDRESS", "AT_SPI_BUS_ADDRESS", "WAYLAND_DISPLAY"):
|
||||
environment.pop(key, None)
|
||||
subprocess.run(
|
||||
run_private_session(
|
||||
["dbus-run-session", "--", sys.executable, str(Path(__file__).resolve()), "--inside"],
|
||||
env=environment, check=True, timeout=60,
|
||||
)
|
||||
|
||||
@@ -12,6 +12,7 @@ import tempfile
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
from native_x11 import wait_for
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
def fixture(toolkit):
|
||||
@@ -347,7 +348,7 @@ def main():
|
||||
environment = dict(os.environ, DISPLAY=":"+display, XDG_SESSION_TYPE="x11", QT_ACCESSIBILITY="1", QT_LINUX_ACCESSIBILITY_ALWAYS_ON="1")
|
||||
for name in ("DBUS_SESSION_BUS_ADDRESS", "AT_SPI_BUS_ADDRESS", "WAYLAND_DISPLAY", "I3SOCK"):
|
||||
environment.pop(name, None)
|
||||
subprocess.run(["dbus-run-session", "--", sys.executable, __file__, "--inside", directory], env=environment, check=True, timeout=100)
|
||||
run_private_session(["dbus-run-session", "--", sys.executable, __file__, "--inside", directory], env=environment, check=True, timeout=100)
|
||||
finally:
|
||||
server.terminate(); server.wait(timeout=3)
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import time
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
from native_x11 import wait_for
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
class ResponseReader:
|
||||
@@ -1411,7 +1412,7 @@ def main():
|
||||
env["LC_ALL"] = "en_US.UTF-8"
|
||||
for key in ("DBUS_SESSION_BUS_ADDRESS", "AT_SPI_BUS_ADDRESS", "WAYLAND_DISPLAY"):
|
||||
env.pop(key, None)
|
||||
subprocess.run(["dbus-run-session", "--", sys.executable, str(Path(__file__).resolve()), "--inside"], env=env, check=True, timeout=90)
|
||||
run_private_session(["dbus-run-session", "--", sys.executable, str(Path(__file__).resolve()), "--inside"], env=env, check=True, timeout=90)
|
||||
finally:
|
||||
server.terminate()
|
||||
server.wait(timeout=5)
|
||||
|
||||
@@ -5,6 +5,8 @@ from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) == 2 and sys.argv[1] == "--inside":
|
||||
@@ -29,7 +31,7 @@ def main():
|
||||
GDK_BACKEND="x11", GTK_MODULES="gail:atk-bridge", GIO_USE_VFS="local")
|
||||
for name in ("DBUS_SESSION_BUS_ADDRESS", "AT_SPI_BUS_ADDRESS", "WAYLAND_DISPLAY"):
|
||||
environment.pop(name, None)
|
||||
subprocess.run(["dbus-run-session", "--", sys.executable, str(Path(__file__).resolve()),
|
||||
run_private_session(["dbus-run-session", "--", sys.executable, str(Path(__file__).resolve()),
|
||||
"--inside"], env=environment, check=True, timeout=45)
|
||||
finally:
|
||||
server.terminate()
|
||||
|
||||
@@ -11,6 +11,7 @@ import tempfile
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
from native_x11 import wait_for
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
def fixture(version):
|
||||
@@ -107,5 +108,5 @@ if __name__ == '__main__':
|
||||
QT_QPA_PLATFORM='xcb', QT_LINUX_ACCESSIBILITY_ALWAYS_ON='1',
|
||||
NO_AT_BRIDGE='0')
|
||||
environment.pop('AT_SPI_BUS_ADDRESS', None)
|
||||
subprocess.run(['xvfb-run', '-a', 'dbus-run-session', '--', sys.executable,
|
||||
run_private_session(['xvfb-run', '-a', 'dbus-run-session', '--', sys.executable,
|
||||
__file__, '--inside'], env=environment, check=True)
|
||||
@@ -9,6 +9,7 @@ import sys
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
from native_x11 import wait_for
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
def inside():
|
||||
@@ -133,7 +134,7 @@ def main():
|
||||
GTK_MODULES="gail:atk-bridge", GIO_USE_VFS="local")
|
||||
for key in ("DBUS_SESSION_BUS_ADDRESS", "AT_SPI_BUS_ADDRESS", "WAYLAND_DISPLAY"):
|
||||
environment.pop(key, None)
|
||||
subprocess.run(
|
||||
run_private_session(
|
||||
["dbus-run-session", "--", sys.executable, str(Path(__file__).resolve()), "--inside"],
|
||||
env=environment, check=True, timeout=60,
|
||||
)
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Real shell/VTE/reader regression with private X11, AT-SPI and recorded SSIP."""
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
sys.dont_write_bytecode = True
|
||||
from native_echo_preview import PreviewSpeechServer
|
||||
from native_x11 import wait_for
|
||||
from native_test_session import run_private_session
|
||||
|
||||
TITLE = "Terminal scrolling probe"
|
||||
PROMPT = "Username@Host> "
|
||||
|
||||
|
||||
def run_fixture():
|
||||
import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
gi.require_version("Vte", "2.91")
|
||||
from gi.repository import GLib, Gtk, Vte
|
||||
|
||||
window = Gtk.Window(title=TITLE)
|
||||
window.set_default_size(600, 220)
|
||||
terminal = Vte.Terminal()
|
||||
terminal.set_scrollback_lines(0)
|
||||
window.add(terminal)
|
||||
window.connect("destroy", Gtk.main_quit)
|
||||
window.show_all()
|
||||
terminal.grab_focus()
|
||||
childEnv = [f"HOME={os.environ['HOME']}", "PATH=/usr/bin:/bin", "TERM=xterm",
|
||||
"LC_ALL=C.UTF-8", "HISTFILE=/dev/null", "PS1=" + PROMPT, "PS2=Continue> "]
|
||||
terminal.spawn_async(Vte.PtyFlags.DEFAULT, os.environ["HOME"],
|
||||
["/bin/bash", "--noprofile", "--norc"], childEnv,
|
||||
GLib.SpawnFlags.DEFAULT, None, None, -1, None, None, None)
|
||||
Gtk.main()
|
||||
|
||||
|
||||
def run_inside():
|
||||
import pyatspi
|
||||
directory = Path(tempfile.mkdtemp(prefix="cthulhu-terminal-runtime-"))
|
||||
print(f"Evidence: {directory}", flush=True)
|
||||
server = PreviewSpeechServer(directory / "speech.sock")
|
||||
config = directory / "settings.toml"
|
||||
config.write_text('''schema-version = 2
|
||||
active-profile = "default"
|
||||
[profiles.default.speech]
|
||||
output-module = "main"
|
||||
[profiles.default.braille]
|
||||
enabled = false
|
||||
[profiles.default.sound]
|
||||
enabled = false
|
||||
[profiles.default.key-echo]
|
||||
enabled = false
|
||||
''')
|
||||
wmConfig = directory / "i3.config"
|
||||
wmConfig.write_text(f"font pango:monospace 10\nipc-socket {directory / 'i3.sock'}\n"
|
||||
f'for_window [title="^{TITLE}$"] floating enable\n')
|
||||
logPath = directory / "reader.log"
|
||||
processes = []
|
||||
report = {}
|
||||
|
||||
def key(chord):
|
||||
subprocess.run(["xdotool", "key", "--clearmodifiers", chord], check=True)
|
||||
|
||||
def type_text(text):
|
||||
offset = len(logs())
|
||||
subprocess.run(["xdotool", "type", "--clearmodifiers", "--delay", "40", "--", text], check=True)
|
||||
# Wait for the reader to receive VTE's final character event before
|
||||
# sending another edit; otherwise VTE can merge both redraws.
|
||||
wait_for(lambda: any(row.get("message") == "received accessibility event"
|
||||
and row.get("type") == "object:text-caret-moved"
|
||||
and row.get("native_caret_offset") == terminal.queryText().caretOffset
|
||||
for row in logs()[offset:]), "typed text did not reach the reader")
|
||||
|
||||
def logs():
|
||||
result = []
|
||||
for line in logPath.read_text().splitlines():
|
||||
try:
|
||||
result.append(json.loads(line))
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
return result
|
||||
|
||||
def settle():
|
||||
wait_for(lambda: server.snapshot() and server.snapshot()[-1]["finished"],
|
||||
"last speech request did not complete")
|
||||
|
||||
try:
|
||||
processes.append(subprocess.Popen(["i3", "-c", str(wmConfig)],
|
||||
stdout=subprocess.DEVNULL, stderr=(directory / "wm.log").open("w")))
|
||||
wait_for(lambda: "0x" in subprocess.check_output(
|
||||
["xprop", "-root", "_NET_SUPPORTING_WM_CHECK"], text=True), "private WM missing")
|
||||
processes.append(subprocess.Popen([
|
||||
os.environ["CTHULHU_BINARY"], "--config", str(config), "--no-tentacles",
|
||||
"--speech-socket", str(directory / "speech.sock"), "--debug-file", str(logPath)],
|
||||
stdout=subprocess.DEVNULL, stderr=(directory / "reader-stderr.log").open("w")))
|
||||
wait_for(lambda: logPath.exists() and "listening for focus events" in logPath.read_text(),
|
||||
"private reader did not start")
|
||||
processes.append(subprocess.Popen([sys.executable, __file__, "--fixture"],
|
||||
stdout=subprocess.DEVNULL, stderr=(directory / "fixture.log").open("w")))
|
||||
|
||||
def find_terminal():
|
||||
for application in pyatspi.Registry.getDesktop(0):
|
||||
for window in application:
|
||||
if window and window.name == TITLE:
|
||||
return next((child for child in window if child and child.getRoleName() == "terminal"), None)
|
||||
|
||||
terminal = wait_for(find_terminal, "terminal fixture missing")
|
||||
text = terminal.queryText()
|
||||
wait_for(lambda: PROMPT in text.getText(0, -1), "shell prompt missing")
|
||||
windowId = subprocess.check_output(
|
||||
["xdotool", "search", "--onlyvisible", "--name", "^" + TITLE + "$"], text=True).splitlines()[0]
|
||||
subprocess.run(["xdotool", "windowactivate", "--sync", windowId], check=True)
|
||||
settle()
|
||||
logOffset = len(logs())
|
||||
speechOffset = len(server.snapshot())
|
||||
for row in range(16):
|
||||
output = f"Output{row:02d}"
|
||||
type_text("echo " + output)
|
||||
key("Return")
|
||||
wait_for(lambda: any(output in item["text"] for item in server.snapshot()[speechOffset:]),
|
||||
f"command output {output} was not spoken")
|
||||
wait_for(lambda: text.getText(0, -1).rstrip().endswith(PROMPT.rstrip()), "prompt did not return")
|
||||
settle()
|
||||
scrollLogs = logs()[logOffset:]
|
||||
replay = [row["utterance"] for row in scrollLogs
|
||||
if row.get("message") == "delivering accessible presentation"
|
||||
and row.get("cause") == "object:text-changed:delete"
|
||||
and "Username@Host>" in row.get("utterance", "")]
|
||||
recorded = [row["text"] for row in server.snapshot()[speechOffset:]]
|
||||
ignored = sum(row.get("message") == "skipped terminal scrollback deletion" for row in scrollLogs)
|
||||
report.update(replayed_prompts=replay, ignored_scroll_deletions=ignored)
|
||||
if "--expect-replay" in sys.argv:
|
||||
assert replay and any(value in recorded for value in replay), (replay, recorded)
|
||||
print(f"CONFIRMED: X11 sent {len(replay)} old prompt deletions to SSIP", flush=True)
|
||||
else:
|
||||
assert not replay, replay
|
||||
assert ignored > 0, "fixture did not exercise scroll deletions"
|
||||
print(f"PASS: {ignored} scroll deletions suppressed; all 16 command outputs reached SSIP", flush=True)
|
||||
|
||||
def check_edit(chord, expected):
|
||||
offset = len(server.snapshot())
|
||||
key(chord)
|
||||
wait_for(lambda: any(row["text"] == expected for row in server.snapshot()[offset:]),
|
||||
f"{chord} did not speak {expected!r}")
|
||||
settle()
|
||||
report[chord] = [row["text"] for row in server.snapshot()[offset:]]
|
||||
|
||||
type_text("abcd")
|
||||
check_edit("BackSpace", "d")
|
||||
check_edit("ctrl+w", "abc")
|
||||
type_text("abcd")
|
||||
check_edit("Left", "d")
|
||||
check_edit("Delete", "d")
|
||||
wait_for(lambda: text.getText(0, -1).rstrip().endswith(PROMPT + "abc"), "Delete did not remove d")
|
||||
offset = len(server.snapshot())
|
||||
type_text("Z")
|
||||
key("Return")
|
||||
wait_for(lambda: any("abcZ" in row["text"] for row in server.snapshot()[offset:]),
|
||||
"editing command did not reach shell")
|
||||
settle()
|
||||
report["editing_command"] = [row["text"] for row in server.snapshot()[offset:]]
|
||||
# History and flat review must still announce terminal content.
|
||||
check_edit("Up", "abcZ")
|
||||
key("ctrl+u")
|
||||
check_edit("KP_Up", "Username@Host>")
|
||||
print("PASS: Backspace, Ctrl+W, Left, Delete, history and flat review", flush=True)
|
||||
finally:
|
||||
(directory / "speech.json").write_text(json.dumps(server.snapshot(), indent=2))
|
||||
(directory / "report.json").write_text(json.dumps(report, indent=2))
|
||||
for process in reversed(processes):
|
||||
if process.poll() is None:
|
||||
process.terminate()
|
||||
try:
|
||||
process.wait(timeout=5)
|
||||
except subprocess.TimeoutExpired:
|
||||
process.kill()
|
||||
process.wait()
|
||||
server.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if "--fixture" in sys.argv:
|
||||
run_fixture()
|
||||
elif "--inside" in sys.argv:
|
||||
run_inside()
|
||||
else:
|
||||
with tempfile.TemporaryDirectory(prefix="cthulhu-terminal-home-") as temporary:
|
||||
environment = dict(os.environ, HOME=temporary, XDG_CONFIG_HOME=temporary,
|
||||
XDG_DATA_HOME=temporary, XDG_CACHE_HOME=temporary,
|
||||
XDG_SESSION_TYPE="x11", GDK_BACKEND="x11",
|
||||
GTK_MODULES="gail:atk-bridge", GIO_USE_VFS="local")
|
||||
for name in ("DISPLAY", "WAYLAND_DISPLAY", "DBUS_SESSION_BUS_ADDRESS", "AT_SPI_BUS_ADDRESS"):
|
||||
environment.pop(name, None)
|
||||
run_private_session(["xvfb-run", "-a", "dbus-run-session", "--", sys.executable,
|
||||
__file__, "--inside", *sys.argv[1:]], env=environment, check=True, timeout=100)
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2026 Storm Dragon
|
||||
# Authors: Storm Dragon, Angus Kola
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Launch native tests with disposable runtime sockets and private D-Bus."""
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
|
||||
def run_private_session(command, *, env, **kwargs):
|
||||
"""Keep activated services away from the desktop's runtime sockets."""
|
||||
if not command or command[0] not in ("dbus-run-session", "xvfb-run"):
|
||||
raise ValueError("Start the private session with xvfb-run or dbus-run-session")
|
||||
if "dbus-run-session" not in command:
|
||||
raise ValueError("A private session requires dbus-run-session")
|
||||
if "xvfb-run" in command and command.index("xvfb-run") > command.index("dbus-run-session"):
|
||||
raise ValueError("Start Xvfb before D-Bus so activated services inherit the private display")
|
||||
|
||||
# Keep this path short: AT-SPI falls back from named sockets if its
|
||||
# generated socket path is 100 bytes or longer.
|
||||
with tempfile.TemporaryDirectory(prefix="cth-run-", dir="/tmp") as runtimeDir:
|
||||
sessionEnv = dict(env, XDG_RUNTIME_DIR=runtimeDir)
|
||||
for name in ("DBUS_SESSION_BUS_ADDRESS", "DBUS_STARTER_ADDRESS", "DBUS_STARTER_BUS_TYPE",
|
||||
"AT_SPI_BUS_ADDRESS", "WAYLAND_DISPLAY"):
|
||||
sessionEnv.pop(name, None)
|
||||
return subprocess.run(command, env=sessionEnv, **kwargs)
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit("Usage: native_test_session.py COMMAND [ARG ...]")
|
||||
result = run_private_session(
|
||||
["xvfb-run", "-a", "dbus-run-session", "--", *sys.argv[1:]], env=os.environ)
|
||||
return result.returncode
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -15,6 +15,7 @@ sys.dont_write_bytecode = True
|
||||
from native_echo_preview import PreviewSpeechServer
|
||||
from native_mozilla import walk, write_profile
|
||||
from native_x11 import wait_for
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
SUBJECTS = ["First test message", "Second test message"]
|
||||
@@ -372,7 +373,7 @@ def main():
|
||||
for name in ("DBUS_SESSION_BUS_ADDRESS", "AT_SPI_BUS_ADDRESS", "WAYLAND_DISPLAY"):
|
||||
environment.pop(name, None)
|
||||
with (directory / "session.log").open("w") as log:
|
||||
subprocess.run(["xvfb-run", "-a", "-s", "-screen 0 1280x900x24", "dbus-run-session", "--",
|
||||
run_private_session(["xvfb-run", "-a", "-s", "-screen 0 1280x900x24", "dbus-run-session", "--",
|
||||
sys.executable, str(Path(__file__).resolve()), "--format", composeFormat, "--inside"],
|
||||
env=environment, stderr=log, check=True, timeout=120)
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if sys.argv[1:] == ["--inside"]:
|
||||
@@ -30,7 +32,7 @@ def main() -> None:
|
||||
environment = dict(os.environ, DISPLAY=":" + display, XDG_SESSION_TYPE="x11")
|
||||
for key in ("DBUS_SESSION_BUS_ADDRESS", "AT_SPI_BUS_ADDRESS", "WAYLAND_DISPLAY"):
|
||||
environment.pop(key, None)
|
||||
subprocess.run(
|
||||
run_private_session(
|
||||
["dbus-run-session", "--", sys.executable, str(Path(__file__).resolve()), "--inside"],
|
||||
env=environment, check=True, timeout=45,
|
||||
)
|
||||
|
||||
+3
-1
@@ -9,6 +9,8 @@ import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
def wait_for(check, message, timeout=15):
|
||||
deadline = time.monotonic() + timeout
|
||||
@@ -717,7 +719,7 @@ def main():
|
||||
environment.pop('AT_SPI_BUS_ADDRESS', None)
|
||||
environment.pop('WAYLAND_DISPLAY', None)
|
||||
environment['XDG_SESSION_TYPE'] = 'x11'
|
||||
subprocess.run(['dbus-run-session', '--', sys.executable, str(Path(__file__).resolve()), '--inside', directory], env=environment, check=True, timeout=60)
|
||||
run_private_session(['dbus-run-session', '--', sys.executable, str(Path(__file__).resolve()), '--inside', directory], env=environment, check=True, timeout=60)
|
||||
finally:
|
||||
server.terminate()
|
||||
server.wait(timeout=3)
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2026 Storm Dragon
|
||||
# Authors: Storm Dragon, Angus Kola
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Runtime isolation and real AT-SPI socket collision regressions."""
|
||||
import ast
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import socket
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from native_test_session import run_private_session
|
||||
|
||||
|
||||
class PrivateSessionTests(unittest.TestCase):
|
||||
def test_child_runtime_and_bus_are_private(self):
|
||||
environment = dict(os.environ, XDG_RUNTIME_DIR="/invalid/desktop-runtime",
|
||||
DBUS_SESSION_BUS_ADDRESS="unix:path=/invalid/desktop-bus",
|
||||
AT_SPI_BUS_ADDRESS="unix:path=/invalid/accessibility-bus",
|
||||
DBUS_STARTER_ADDRESS="unix:path=/invalid/starter-bus",
|
||||
DBUS_STARTER_BUS_TYPE="session", WAYLAND_DISPLAY="desktop-wayland")
|
||||
originalEnv = environment.copy()
|
||||
script = """import json, os, socket, stat
|
||||
from pathlib import Path
|
||||
runtime = Path(os.environ['XDG_RUNTIME_DIR'])
|
||||
listener = socket.socket(socket.AF_UNIX)
|
||||
listener.bind(str(runtime / 'probe.sock'))
|
||||
print(json.dumps(dict(runtime=str(runtime), mode=stat.S_IMODE(runtime.stat().st_mode),
|
||||
bus=os.environ['DBUS_SESSION_BUS_ADDRESS'],
|
||||
inherited=[name for name in ('AT_SPI_BUS_ADDRESS', 'DBUS_STARTER_ADDRESS',
|
||||
'DBUS_STARTER_BUS_TYPE', 'WAYLAND_DISPLAY') if name in os.environ])))
|
||||
"""
|
||||
result = run_private_session(
|
||||
["dbus-run-session", "--", sys.executable, "-c", script], env=environment,
|
||||
capture_output=True, text=True, check=True, timeout=15)
|
||||
state = json.loads(result.stdout)
|
||||
self.assertEqual(state["mode"], 0o700)
|
||||
self.assertEqual(state["inherited"], [])
|
||||
self.assertNotEqual(state["bus"], originalEnv["DBUS_SESSION_BUS_ADDRESS"])
|
||||
self.assertFalse(Path(state["runtime"]).exists(), "child runtime was not cleaned up")
|
||||
self.assertEqual(environment, originalEnv)
|
||||
|
||||
def test_cleanup_after_child_failure(self):
|
||||
script = "import os, sys; print(os.environ['XDG_RUNTIME_DIR'], flush=True); sys.exit(7)"
|
||||
with self.assertRaises(subprocess.CalledProcessError) as caught:
|
||||
run_private_session(
|
||||
["dbus-run-session", "--", sys.executable, "-c", script], env=os.environ,
|
||||
capture_output=True, text=True, check=True, timeout=15)
|
||||
self.assertEqual(caught.exception.returncode, 7)
|
||||
self.assertFalse(Path(caught.exception.stdout.strip()).exists())
|
||||
|
||||
def test_rejects_dbus_before_xvfb_without_launching(self):
|
||||
with patch("native_test_session.subprocess.run") as launch:
|
||||
with self.assertRaisesRegex(ValueError, "Start Xvfb before D-Bus"):
|
||||
run_private_session(
|
||||
["dbus-run-session", "--", "xvfb-run", "-a", "true"], env=os.environ)
|
||||
launch.assert_not_called()
|
||||
|
||||
def test_cli_activates_atspi_on_virtual_display(self):
|
||||
script = """import ast, json, os, subprocess
|
||||
result = subprocess.run(['gdbus', 'call', '--session', '--dest', 'org.a11y.Bus',
|
||||
'--object-path', '/org/a11y/bus', '--method', 'org.a11y.Bus.GetAddress'],
|
||||
capture_output=True, text=True, check=True, timeout=10)
|
||||
print(json.dumps(dict(display=os.environ['DISPLAY'], runtime=os.environ['XDG_RUNTIME_DIR'],
|
||||
address=ast.literal_eval(result.stdout)[0])))
|
||||
"""
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-B", str(Path(__file__).with_name("native_test_session.py")),
|
||||
sys.executable, "-c", script],
|
||||
env=dict(os.environ, DISPLAY=":7777"), capture_output=True, text=True,
|
||||
check=True, timeout=20)
|
||||
state = json.loads(result.stdout)
|
||||
self.assertNotEqual(state["display"], ":7777")
|
||||
expectedPath = Path(state["runtime"]) / "at-spi" / ("bus" + state["display"].replace(":", "_"))
|
||||
self.assertEqual(state["address"].split(",", 1)[0], "unix:path=" + str(expectedPath))
|
||||
self.assertFalse(Path(state["runtime"]).exists())
|
||||
|
||||
def test_atspi_activation_preserves_other_session_socket(self):
|
||||
# No real display is contacted. Reproduce D-Bus inheriting one display
|
||||
# while its client uses another, with a live canary in the parent runtime.
|
||||
with tempfile.TemporaryDirectory(prefix="cth-parent-", dir="/tmp") as parentRuntime:
|
||||
socketDir = Path(parentRuntime) / "at-spi"
|
||||
socketDir.mkdir(mode=0o700)
|
||||
socketPath = socketDir / "bus_7777"
|
||||
with socket.socket(socket.AF_UNIX) as listener:
|
||||
listener.bind(str(socketPath))
|
||||
listener.listen(1)
|
||||
originalInode = socketPath.stat().st_ino
|
||||
environment = dict(os.environ, XDG_RUNTIME_DIR=parentRuntime, DISPLAY=":7777",
|
||||
AT_SPI_BUS_ADDRESS="unix:path=/invalid/desktop-accessibility")
|
||||
result = run_private_session(
|
||||
["dbus-run-session", "--", "env", "DISPLAY=:7778", "gdbus", "call",
|
||||
"--session", "--dest", "org.a11y.Bus", "--object-path", "/org/a11y/bus",
|
||||
"--method", "org.a11y.Bus.GetAddress"], env=environment,
|
||||
capture_output=True, text=True, check=True, timeout=15)
|
||||
address = ast.literal_eval(result.stdout)[0]
|
||||
busPath = Path(address.split(",", 1)[0].removeprefix("unix:path="))
|
||||
self.assertEqual(busPath.name, "bus_7777", address)
|
||||
self.assertNotEqual(busPath.parent.parent, Path(parentRuntime))
|
||||
self.assertFalse(busPath.parent.parent.exists(), "private runtime survived cleanup")
|
||||
self.assertEqual(socketPath.stat().st_ino, originalInode)
|
||||
self.assertTrue(stat.S_ISSOCK(socketPath.stat().st_mode))
|
||||
with socket.socket(socket.AF_UNIX) as client:
|
||||
client.settimeout(2)
|
||||
client.connect(str(socketPath))
|
||||
connection, _ = listener.accept()
|
||||
connection.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -17,8 +17,8 @@ Run the focused checks from the repository root:
|
||||
```sh
|
||||
go test -race ./internal/app -run 'Title|WineReview|XTerm|Foreground' -count=1
|
||||
CTHULHU_NATIVE_BROWSER_TESTS=editing GOCACHE=/tmp/cthulhu-go-cache GOPROXY=off python3 tests/native_browser.py
|
||||
xvfb-run -a dbus-run-session -- env CTHULHU_NATIVE_WINDOW_TITLES=1 GOCACHE=/tmp/cthulhu-go-cache GOPROXY=off go test ./internal/app -run '^TestNativeAutomaticTitleDispatchLatency$' -count=1 -v
|
||||
dbus-run-session -- env CTHULHU_WINE_TITLE_DBUS=1 go test -race ./internal/app -run '^TestPrivateWineTitleSurvivesReviewFocusBurst$' -count=1 -v
|
||||
python3 tests/native_test_session.py env CTHULHU_NATIVE_WINDOW_TITLES=1 GOCACHE=/tmp/cthulhu-go-cache GOPROXY=off go test ./internal/app -run '^TestNativeAutomaticTitleDispatchLatency$' -count=1 -v
|
||||
python3 tests/native_test_session.py env CTHULHU_WINE_TITLE_DBUS=1 go test -race ./internal/app -run '^TestPrivateWineTitleSurvivesReviewFocusBurst$' -count=1 -v
|
||||
```
|
||||
|
||||
The private D-Bus test runs the event loop against copied foreground metadata
|
||||
@@ -40,7 +40,7 @@ is not implemented.
|
||||
|
||||
```sh
|
||||
go test ./internal/input ./internal/app -run 'WindowTitle|WhereAmI|CommandRuntimeRoutesFocusPresentationRequests' -count=1
|
||||
xvfb-run -a env CTHULHU_NATIVE_X11=1 go test ./internal/platform/xorg -run '^TestNativeDispatchBeforeRelease$' -count=1 -v
|
||||
python3 tests/native_test_session.py env CTHULHU_NATIVE_X11=1 go test ./internal/platform/xorg -run '^TestNativeDispatchBeforeRelease$' -count=1 -v
|
||||
```
|
||||
|
||||
The native automatic-title fixture above also checks the desktop title chord
|
||||
|
||||
Reference in new issue
Block a user