S009: Discord + media smoke test with a fake IPC server (SMOKE_FAKE_DISCORD)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
parent
048cb8be24
commit
0a86600a55
5 changed files with 126 additions and 0 deletions
13
tests/smoke/integ-discord-check.sh
Executable file
13
tests/smoke/integ-discord-check.sh
Executable file
|
|
@ -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 <outdir>
|
||||
log=${1:?usage: integ-discord-check.sh <outdir>}/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
|
||||
29
tests/smoke/integ-discord.txt
Normal file
29
tests/smoke/integ-discord.txt
Normal file
|
|
@ -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 <outdir>
|
||||
# Then check <outdir>/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
|
||||
58
tests/smoke/net/fake-discord.py
Executable file
58
tests/smoke/net/fake-discord.py
Executable file
|
|
@ -0,0 +1,58 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Fake Discord IPC server for smoke runs: python3 fake-discord.py <socket path> <log file>.
|
||||
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("<II", op, len(data)) + data
|
||||
|
||||
|
||||
def recv_exact(conn, n):
|
||||
buf = b""
|
||||
while len(buf) < n:
|
||||
chunk = conn.recv(n - len(buf))
|
||||
if not chunk:
|
||||
return None
|
||||
buf += chunk
|
||||
return buf
|
||||
|
||||
|
||||
def serve(conn):
|
||||
try:
|
||||
loop(conn)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
def loop(conn):
|
||||
while True:
|
||||
head = recv_exact(conn, 8)
|
||||
if head is None:
|
||||
return
|
||||
op, length = struct.unpack("<II", head)
|
||||
body = recv_exact(conn, length) or b"{}"
|
||||
data = json.loads(body)
|
||||
with lock, open(log, "a") as f:
|
||||
f.write(json.dumps({"op": op, "data": data}) + "\n")
|
||||
if op == 0:
|
||||
conn.sendall(frame(1, {"cmd": "DISPATCH", "evt": "READY", "data": {"v": 1, "user": {"username": "smoke"}}}))
|
||||
elif op == 1:
|
||||
try_send = lambda m: conn.sendall(m)
|
||||
conn.sendall(frame(1, {"cmd": data.get("cmd"), "evt": None, "nonce": data.get("nonce"), "data": data.get("args", {}).get("activity")}))
|
||||
|
||||
|
||||
if os.path.exists(path):
|
||||
os.unlink(path)
|
||||
srv = socket.socket(socket.AF_UNIX)
|
||||
srv.bind(path)
|
||||
srv.listen(4)
|
||||
signal.signal(signal.SIGTERM, lambda *_: os._exit(0))
|
||||
while True:
|
||||
c, _ = srv.accept()
|
||||
threading.Thread(target=serve, args=(c,), daemon=True).start()
|
||||
16
tests/smoke/pages/media.html
Normal file
16
tests/smoke/pages/media.html
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<!-- Integrations test page (S009): muted looping video (clip.webm) with Media Session metadata and a
|
||||
data: favicon, which Discord can't fetch, so the activity's icon must fall back to /favicon.ico. -->
|
||||
<head><meta charset="utf-8"><title>Smoke media page</title>
|
||||
<link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==">
|
||||
<style>body { margin: 0; background: #1c3a5e; color: #fff; font: bold 40px sans-serif; text-align: center; }
|
||||
video { display: block; margin: 20px auto; width: 480px; height: 270px; background: #000; }</style></head>
|
||||
<body>
|
||||
<div>SMOKE MEDIA</div>
|
||||
<video id="v" src="clip.webm" muted loop autoplay></video>
|
||||
<script>
|
||||
navigator.mediaSession.metadata = new MediaMetadata({ title: 'Smoke Track', artist: 'Smoke Artist', album: 'Smoke Album' });
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -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[@]}" \
|
||||
|
|
|
|||
Loading…
Reference in a new issue