test(ui): Playwright viewport suite and profile bar rendering fix
Adds tests/e2e.py (1440/1024/390, overflow + KPI + table assertions) and makes the profile/model bars actually paint by giving the track and fill an explicit block display inside the grid row.
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-11 07:02:19
Commit924a8847
Parentsd21ce350
Changed files
src/plugin_sessionstats.c+2−2■■■■
tests/e2e.py+136−0■■■■■
5 files+138−2
Diff
docs/shot-1024x768.png+0−0■
11new file mode 100644
index 0000000..115470c
binary image
Binary image file
docs/shot-1440x900.png+0−0■
11new file mode 100644
index 0000000..d12fc40
binary image
Binary image file
docs/shot-390x844.png+0−0■
11new file mode 100644
index 0000000..97f6152
binary image
Binary image file
src/plugin_sessionstats.c+2−2■■■■
index 716d9c8..bcc8ffe 100644
--- a/src/plugin_sessionstats.c
+++ b/src/plugin_sessionstats.c
@@ -931,8 +931,8 @@ static void html_head(int embed, const char *initial_id)
931931 ".bars{display:flex;flex-direction:column;gap:7px}"
932932 ".row{display:grid;grid-template-columns:150px 1fr 78px;align-items:center;gap:9px;font-size:12px}"
933933 ".row .nm{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--muted)}"
934- ".track{height:9px;border-radius:999px;background:var(--surface2);overflow:hidden}"
935- ".fill{height:100%;border-radius:999px;background:var(--blue);min-width:2px}"
934+ ".track{display:block;height:9px;border-radius:999px;background:var(--surface2);overflow:hidden}"
935+ ".fill{display:block;height:100%;border-radius:999px;background:linear-gradient(90deg,var(--blue),var(--purple));min-width:3px}"
936936 ".val{text-align:right;font-variant-numeric:tabular-nums;font-size:11px;color:var(--muted)}"
937937 ".tbl{width:100%;border-collapse:collapse;font-size:12px}"
938938 ".tbl th{text-align:left;font-size:10px;text-transform:uppercase;letter-spacing:.5px;"
tests/e2e.py+136−0■■■■■
11new file mode 100644
index 0000000..238b1a5
--- /dev/null
+++ b/tests/e2e.py
@@ -0,0 +1,136 @@
1+#!/usr/bin/env python3
2+"""tests/e2e.py - viewport checks for the plugin_sessionstats dashboard.
3+
4+Serves the plugin through a tiny CGI-style HTTP shim on a loopback port, opens
5+it with Playwright at 1440 / 1024 / 390 CSS pixels, and asserts there is no
6+horizontal overflow, no console error, and that the KPI cards, the profile bars
7+and the session table all rendered from the live session store. Skips cleanly
8+(exit 0) when Playwright is not installed, so the offline suite stays
9+dependency-free.
10+
11+ python3 tests/e2e.py # run if Playwright is available
12+ python3 tests/e2e.py --strict # exit 2 when Playwright is missing
13+"""
14+
15+import argparse
16+import http.server
17+import os
18+import socketserver
19+import subprocess
20+import sys
21+import threading
22+
23+ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
24+BIN = os.path.join(ROOT, "plugin_sessionstats")
25+VIEWPORTS = [(1440, 900), (1024, 768), (390, 844)]
26+
27+
28+class Handler(http.server.BaseHTTPRequestHandler):
29+ def do_GET(self): # noqa: N802
30+ from urllib.parse import urlparse
31+ u = urlparse(self.path)
32+ env = dict(os.environ)
33+ env["QUERY_STRING"] = u.query
34+ env["REQUEST_METHOD"] = "GET"
35+ env.pop("BOT_PASSWORD", None)
36+ out = subprocess.run([BIN], capture_output=True, env=env, timeout=60).stdout
37+ sep = out.find(b"\r\n\r\n")
38+ headers = out[:sep].decode("utf-8", "replace") if sep >= 0 else ""
39+ body = out[sep + 4:] if sep >= 0 else out
40+ ctype = "text/html; charset=utf-8"
41+ for line in headers.splitlines():
42+ if line.lower().startswith("content-type:"):
43+ ctype = line.split(":", 1)[1].strip()
44+ self.send_response(200)
45+ self.send_header("Content-Type", ctype)
46+ self.send_header("Cache-Control", "no-store")
47+ self.send_header("Content-Length", str(len(body)))
48+ self.end_headers()
49+ self.wfile.write(body)
50+
51+ def log_message(self, *_a):
52+ pass
53+
54+
55+def main():
56+ ap = argparse.ArgumentParser()
57+ ap.add_argument("--strict", action="store_true")
58+ args = ap.parse_args()
59+
60+ if not os.path.exists(BIN):
61+ print("plugin_sessionstats is not built; run make first", file=sys.stderr)
62+ return 1
63+
64+ try:
65+ from playwright.sync_api import sync_playwright
66+ except Exception:
67+ msg = "playwright not installed - skipping viewport e2e"
68+ if args.strict:
69+ print(msg, file=sys.stderr)
70+ return 2
71+ print(msg)
72+ return 0
73+
74+ with socketserver.TCPServer(("127.0.0.1", 0), Handler) as srv:
75+ port = srv.server_address[1]
76+ threading.Thread(target=srv.serve_forever, daemon=True).start()
77+ url = "http://127.0.0.1:%d/plugin_sessionstats" % port
78+
79+ failures = []
80+ with sync_playwright() as p:
81+ browser = p.chromium.launch()
82+ for (w, h) in VIEWPORTS:
83+ page = browser.new_page(viewport={"width": w, "height": h})
84+ errors = []
85+ page.on("console", lambda m: errors.append(m.text)
86+ if m.type == "error" else None)
87+ page.goto(url, wait_until="load")
88+ page.wait_for_timeout(2200)
89+
90+ sw = page.evaluate("document.documentElement.scrollWidth")
91+ iw = page.evaluate("window.innerWidth")
92+ if sw > iw + 1:
93+ failures.append("%dx%d horizontal overflow %d > %d" % (w, h, sw, iw))
94+
95+ sessions = page.evaluate(
96+ "document.getElementById('kSessions').textContent")
97+ if not sessions.strip().isdigit():
98+ failures.append("%dx%d sessions KPI did not render (%r)"
99+ % (w, h, sessions))
100+
101+ duty = page.evaluate(
102+ "document.getElementById('kDuty').textContent")
103+ if "%" not in duty:
104+ failures.append("%dx%d duty KPI did not render (%r)"
105+ % (w, h, duty))
106+
107+ bars = page.evaluate(
108+ "document.querySelectorAll('#profBars .row').length")
109+ if bars < 1:
110+ failures.append("%dx%d no profile bar rendered" % (w, h))
111+
112+ rows = page.evaluate(
113+ "document.querySelectorAll('#tbody tr').length")
114+ if rows < 1:
115+ failures.append("%dx%d session table is empty" % (w, h))
116+
117+ if errors:
118+ failures.append("%dx%d console errors: %s" % (w, h, errors[:3]))
119+
120+ page.screenshot(path=os.path.join(ROOT, "docs",
121+ "shot-%dx%d.png" % (w, h)))
122+ page.close()
123+ browser.close()
124+
125+ if failures:
126+ print("FAIL")
127+ for f in failures:
128+ print(" " + f)
129+ return 1
130+
131+ print("PASS - %d viewports clean" % len(VIEWPORTS))
132+ return 0
133+
134+
135+if __name__ == "__main__":
136+ sys.exit(main())
0137
docs/shot-1024x768.png+0−0■
1new file mode 1006441new file mode 100644
index 0000000..115470cindex 0000000..115470c
binary image
Binary image file
docs/shot-1440x900.png+0−0■
1new file mode 1006441new file mode 100644
index 0000000..d12fc40index 0000000..d12fc40
binary image
Binary image file
docs/shot-390x844.png+0−0■
1new file mode 1006441new file mode 100644
index 0000000..97f6152index 0000000..97f6152
binary image
Binary image file
src/plugin_sessionstats.c+2−2■■■■
index 716d9c8..bcc8ffe 100644index 716d9c8..bcc8ffe 100644
--- a/src/plugin_sessionstats.c--- a/src/plugin_sessionstats.c
+++ b/src/plugin_sessionstats.c+++ b/src/plugin_sessionstats.c
@@ -931,8 +931,8 @@ static void html_head(int embed, const char *initial_id)@@ -931,8 +931,8 @@ static void html_head(int embed, const char *initial_id)
931 ".bars{display:flex;flex-direction:column;gap:7px}"931 ".bars{display:flex;flex-direction:column;gap:7px}"
932 ".row{display:grid;grid-template-columns:150px 1fr 78px;align-items:center;gap:9px;font-size:12px}"932 ".row{display:grid;grid-template-columns:150px 1fr 78px;align-items:center;gap:9px;font-size:12px}"
933 ".row .nm{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--muted)}"933 ".row .nm{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--muted)}"
934- ".track{height:9px;border-radius:999px;background:var(--surface2);overflow:hidden}"934+ ".track{display:block;height:9px;border-radius:999px;background:var(--surface2);overflow:hidden}"
935- ".fill{height:100%;border-radius:999px;background:var(--blue);min-width:2px}"935+ ".fill{display:block;height:100%;border-radius:999px;background:linear-gradient(90deg,var(--blue),var(--purple));min-width:3px}"
936 ".val{text-align:right;font-variant-numeric:tabular-nums;font-size:11px;color:var(--muted)}"936 ".val{text-align:right;font-variant-numeric:tabular-nums;font-size:11px;color:var(--muted)}"
937 ".tbl{width:100%;border-collapse:collapse;font-size:12px}"937 ".tbl{width:100%;border-collapse:collapse;font-size:12px}"
938 ".tbl th{text-align:left;font-size:10px;text-transform:uppercase;letter-spacing:.5px;"938 ".tbl th{text-align:left;font-size:10px;text-transform:uppercase;letter-spacing:.5px;"
tests/e2e.py+136−0■■■■■
1new file mode 1006441new file mode 100644
index 0000000..238b1a5index 0000000..238b1a5
--- /dev/null--- /dev/null
+++ b/tests/e2e.py+++ b/tests/e2e.py
@@ -0,0 +1,136 @@@@ -0,0 +1,136 @@
1+#!/usr/bin/env python3
2+"""tests/e2e.py - viewport checks for the plugin_sessionstats dashboard.
3+
4+Serves the plugin through a tiny CGI-style HTTP shim on a loopback port, opens
5+it with Playwright at 1440 / 1024 / 390 CSS pixels, and asserts there is no
6+horizontal overflow, no console error, and that the KPI cards, the profile bars
7+and the session table all rendered from the live session store. Skips cleanly
8+(exit 0) when Playwright is not installed, so the offline suite stays
9+dependency-free.
10+
11+ python3 tests/e2e.py # run if Playwright is available
12+ python3 tests/e2e.py --strict # exit 2 when Playwright is missing
13+"""
14+
15+import argparse
16+import http.server
17+import os
18+import socketserver
19+import subprocess
20+import sys
21+import threading
22+
23+ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
24+BIN = os.path.join(ROOT, "plugin_sessionstats")
25+VIEWPORTS = [(1440, 900), (1024, 768), (390, 844)]
26+
27+
28+class Handler(http.server.BaseHTTPRequestHandler):
29+ def do_GET(self): # noqa: N802
30+ from urllib.parse import urlparse
31+ u = urlparse(self.path)
32+ env = dict(os.environ)
33+ env["QUERY_STRING"] = u.query
34+ env["REQUEST_METHOD"] = "GET"
35+ env.pop("BOT_PASSWORD", None)
36+ out = subprocess.run([BIN], capture_output=True, env=env, timeout=60).stdout
37+ sep = out.find(b"\r\n\r\n")
38+ headers = out[:sep].decode("utf-8", "replace") if sep >= 0 else ""
39+ body = out[sep + 4:] if sep >= 0 else out
40+ ctype = "text/html; charset=utf-8"
41+ for line in headers.splitlines():
42+ if line.lower().startswith("content-type:"):
43+ ctype = line.split(":", 1)[1].strip()
44+ self.send_response(200)
45+ self.send_header("Content-Type", ctype)
46+ self.send_header("Cache-Control", "no-store")
47+ self.send_header("Content-Length", str(len(body)))
48+ self.end_headers()
49+ self.wfile.write(body)
50+
51+ def log_message(self, *_a):
52+ pass
53+
54+
55+def main():
56+ ap = argparse.ArgumentParser()
57+ ap.add_argument("--strict", action="store_true")
58+ args = ap.parse_args()
59+
60+ if not os.path.exists(BIN):
61+ print("plugin_sessionstats is not built; run make first", file=sys.stderr)
62+ return 1
63+
64+ try:
65+ from playwright.sync_api import sync_playwright
66+ except Exception:
67+ msg = "playwright not installed - skipping viewport e2e"
68+ if args.strict:
69+ print(msg, file=sys.stderr)
70+ return 2
71+ print(msg)
72+ return 0
73+
74+ with socketserver.TCPServer(("127.0.0.1", 0), Handler) as srv:
75+ port = srv.server_address[1]
76+ threading.Thread(target=srv.serve_forever, daemon=True).start()
77+ url = "http://127.0.0.1:%d/plugin_sessionstats" % port
78+
79+ failures = []
80+ with sync_playwright() as p:
81+ browser = p.chromium.launch()
82+ for (w, h) in VIEWPORTS:
83+ page = browser.new_page(viewport={"width": w, "height": h})
84+ errors = []
85+ page.on("console", lambda m: errors.append(m.text)
86+ if m.type == "error" else None)
87+ page.goto(url, wait_until="load")
88+ page.wait_for_timeout(2200)
89+
90+ sw = page.evaluate("document.documentElement.scrollWidth")
91+ iw = page.evaluate("window.innerWidth")
92+ if sw > iw + 1:
93+ failures.append("%dx%d horizontal overflow %d > %d" % (w, h, sw, iw))
94+
95+ sessions = page.evaluate(
96+ "document.getElementById('kSessions').textContent")
97+ if not sessions.strip().isdigit():
98+ failures.append("%dx%d sessions KPI did not render (%r)"
99+ % (w, h, sessions))
100+
101+ duty = page.evaluate(
102+ "document.getElementById('kDuty').textContent")
103+ if "%" not in duty:
104+ failures.append("%dx%d duty KPI did not render (%r)"
105+ % (w, h, duty))
106+
107+ bars = page.evaluate(
108+ "document.querySelectorAll('#profBars .row').length")
109+ if bars < 1:
110+ failures.append("%dx%d no profile bar rendered" % (w, h))
111+
112+ rows = page.evaluate(
113+ "document.querySelectorAll('#tbody tr').length")
114+ if rows < 1:
115+ failures.append("%dx%d session table is empty" % (w, h))
116+
117+ if errors:
118+ failures.append("%dx%d console errors: %s" % (w, h, errors[:3]))
119+
120+ page.screenshot(path=os.path.join(ROOT, "docs",
121+ "shot-%dx%d.png" % (w, h)))
122+ page.close()
123+ browser.close()
124+
125+ if failures:
126+ print("FAIL")
127+ for f in failures:
128+ print(" " + f)
129+ return 1
130+
131+ print("PASS - %d viewports clean" % len(VIEWPORTS))
132+ return 0
133+
134+
135+if __name__ == "__main__":
136+ sys.exit(main())
0137