From 0a86600a55a145b4340e002fe8e94e7c28f4f1a3 Mon Sep 17 00:00:00 2001 From: astar76 Date: Thu, 12 Nov 2026 14:27:18 -0600 Subject: [PATCH] S009: Discord + media smoke test with a fake IPC server (SMOKE_FAKE_DISCORD) Co-Authored-By: Claude Sonnet 5.5 --- tests/smoke/integ-discord-check.sh | 13 +++++++ tests/smoke/integ-discord.txt | 29 +++++++++++++++ tests/smoke/net/fake-discord.py | 58 ++++++++++++++++++++++++++++++ tests/smoke/pages/media.html | 16 +++++++++ tools/smoke.sh | 10 ++++++ 5 files changed, 126 insertions(+) create mode 100755 tests/smoke/integ-discord-check.sh create mode 100644 tests/smoke/integ-discord.txt create mode 100755 tests/smoke/net/fake-discord.py create mode 100644 tests/smoke/pages/media.html diff --git a/tests/smoke/integ-discord-check.sh b/tests/smoke/integ-discord-check.sh new file mode 100755 index 0000000..20b6b16 --- /dev/null +++ b/tests/smoke/integ-discord-check.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# Checks the fake Discord log of tests/smoke/integ-discord.txt: tests/smoke/integ-discord-check.sh +log=${1:?usage: integ-discord-check.sh }/discord.log +fail=0 +check() { grep -q -- "$2" "$log" && echo "ok: $1" || { echo "FAIL: $1"; fail=1; }; } +check "handshake with the test application ID" '"client_id": "100000000000000001"' +check "SET_ACTIVITY sent" '"cmd": "SET_ACTIVITY"' +check "media title and artist" '"details": "Smoke Track", "state": "by Smoke Artist"' +check "icon falls back to the origin favicon" '"large_image": "https://127.0.0.1/favicon.ico"' +check "progress bar timestamps" '"timestamps": {"start": [0-9]*, "end"' +check "paused state" '"small_text": "Paused"' +check "browsing activity for a plain page" '"type": 3' +exit $fail diff --git a/tests/smoke/integ-discord.txt b/tests/smoke/integ-discord.txt new file mode 100644 index 0000000..bb2e315 --- /dev/null +++ b/tests/smoke/integ-discord.txt @@ -0,0 +1,29 @@ +# Integrations pass (S009): Discord Rich Presence against a fake IPC server, plus media state. +# Offline. Run: +# python3 -m http.server 8768 --bind 127.0.0.1 --directory tests/smoke/pages & +# SMOKE_FAKE_DISCORD=1 tools/smoke.sh tests/smoke/integ-discord.txt +# Then check /discord.log (see tests/smoke/integ-discord-check.sh): handshake (op 0) with the test client +# ID, SET_ACTIVITY with details "Smoke Track", state "by Smoke Artist", and assets.large_image +# https://127.0.0.1/favicon.ico (the page's favicon is a data: URL). +set /rpc/enabled true +set /rpc/client_id "100000000000000001" +set /rpc/custom ["127.0.0.1"] +set /rpc/browsing "site" +wait 2 +open http://127.0.0.1:8768/media.html +waitload +waitfor 15 (window.__nacre && window.__nacre.media && window.__nacre.media.state() && !window.__nacre.media.state().paused) +log media state follows +js JSON.stringify(window.__nacre.media.state()) +wait 6 +status presence +# Media pause: the activity becomes "Paused". +js document.getElementById('v').pause() +wait 4 +# A plain page (not a media site) is reported as browsing. +set /rpc/custom [] +open http://127.0.0.1:8768/hello.html +waitload +wait 6 +status done +quit diff --git a/tests/smoke/net/fake-discord.py b/tests/smoke/net/fake-discord.py new file mode 100755 index 0000000..4dffd63 --- /dev/null +++ b/tests/smoke/net/fake-discord.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +"""Fake Discord IPC server for smoke runs: python3 fake-discord.py . +Answers the handshake with READY and every SET_ACTIVITY with an ack; appends each frame it receives to the +log as one JSON line {"op": n, "data": ...}. Stops on SIGTERM.""" +import json, os, signal, socket, struct, sys, threading + +path, log = sys.argv[1], sys.argv[2] +lock = threading.Lock() + + +def frame(op, payload): + data = json.dumps(payload).encode() + return struct.pack(" + + +Smoke media page + + + +
SMOKE MEDIA
+ + + + diff --git a/tools/smoke.sh b/tools/smoke.sh index c5ee72f..5173e82 100755 --- a/tools/smoke.sh +++ b/tools/smoke.sh @@ -16,6 +16,8 @@ # SMOKE_SIZE=WxH screen size (default 1280x800) # SMOKE_BIN=path browser binary (default target/release/nacre) # NACRE_NO_BRIDGE=1 passed through: no network bridge +# SMOKE_FAKE_DISCORD=1 start tests/smoke/net/fake-discord.py on $XDG_RUNTIME_DIR/discord-ipc-0; it logs every frame +# it gets to outdir/discord.log (one JSON line each) # SMOKE_VISIBLE=1 show the window on the user's screen (their Wayland display, niri monitor # SMOKE_MONITOR, default DP-1) with the real GPU instead of hidden Xvfb + software GL; # only the Wayland socket is shared, profile/runtime dir/bus stay throwaway @@ -56,6 +58,7 @@ chmod 700 "$runtime" xvfb_pid= cleanup() { [ -n "$xvfb_pid" ] && kill "$xvfb_pid" 2>/dev/null + [ -n "${discord_pid:-}" ] && kill "$discord_pid" 2>/dev/null rm -rf "$runtime" } trap cleanup EXIT @@ -79,6 +82,13 @@ else dispvars=(DISPLAY=":$display" XDG_SESSION_TYPE=x11 LIBGL_ALWAYS_SOFTWARE=1) fi +if [ -n "${SMOKE_FAKE_DISCORD:-}" ]; then + : >"$out/discord.log" + python3 "$root/tests/smoke/net/fake-discord.py" "$runtime/discord-ipc-0" "$out/discord.log" & + discord_pid=$! + for _ in $(seq 50); do [ -S "$runtime/discord-ipc-0" ] && break; sleep 0.1; done +fi + env -u WAYLAND_DISPLAY -u DISPLAY -u DBUS_SESSION_BUS_ADDRESS -u NACRE_HOME \ -u http_proxy -u https_proxy -u all_proxy -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY \ "${dispvars[@]}" \