Repository Public MIT Selected
1# =============================================================================2# SP BOUCHER | INFRASTRUCTURE & AUTOMATION3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# Project : SPB Git7# File : scripts/qa/screens.py8# Module : scripts9# Repository : https://git.spboucher.ai/spbgit10# Project Website : https://git.spboucher.ai11# Created : 2026-11-0112# Last Modified : 2026-11-0913#14# Author : Simon-Pierre Boucher15# Position : Professor of Finance16# Institution : Université du Québec en Outaouais (UQO)17# Organization : SP Boucher18# Website : https://spboucher.ai19# Git : https://git.spboucher.ai20#21# Preferred Contact: admin@spboucher.ai22# Technical Contact: dev@spboucher.ai23# Security/Admin : admin@spboucher.ai24#25# Copyright (c) 202626# Simon-Pierre Boucher27# All rights reserved where applicable. This file is governed by the28# applicable project license, copyright notices and relevant law.29# Existing third-party rights and notices remain unaffected.30#31# SPDX Identifier : MIT32# License : MIT License33# License File : LICENSE34#35# Do not embed credentials, private keys, access tokens,36# certificates or confidential personal information.37#38# =============================================================================39# END OF SP BOUCHER SOURCE HEADER40# =============================================================================4142# ─────────────────────────────────────────────43# SPB Git — Personal Git Platform44# ─────────────────────────────────────────────45# Author : Simon-Pierre Boucher46# Contact : contact@spboucher.ai47# File : scripts/qa/screens.py48# Purpose : Responsive QA — screenshots + overflow + touch-target checks across widths, themes and engines (Playwright for Python)49# License : MIT © Simon-Pierre Boucher50# ─────────────────────────────────────────────51"""52Usage:53 python3 -I scripts/qa/screens.py BASE_URL OUT_DIR [--widths 320,375,1440] [--themes light,dark,midnight]54 [--engines chromium,webkit] [--pages home,repo,...] [--repo spbgit] [--no-shots]55Exit code 1 when any page overflows horizontally or an essential control is under 44×44 CSS px on a touch viewport.56"""57import sys, os, asyncio, argparse, json58from playwright.async_api import async_playwright5960PAGES = {61 "home": "/",62 "repo": "/{repo}",63 "tree": "/{repo}/tree/main/src",64 "blob": "/{repo}/blob/main/src/server.mjs",65 "readme": "/{repo}/blob/main/README.md",66 "commits": "/{repo}/commits/main",67 "commit": "/{repo}/commit/{sha}",68 "blame": "/{repo}/blame/main/package.json",69 "branches": "/{repo}/branches",70 "tags": "/{repo}/tags",71 "search": "/search?q=git",72 "metrics": "/about/metrics",73 "api": "/about/api",74 "insights": "/{repo}/insights",75 "search0": "/search?q=zzzznothing",76 "404": "/this-does-not-exist",77}78ESSENTIAL = ".app-header button, .app-header a.brand, .tab, .btn:not(.hide-mobile *), .icon-btn, .sha-chip, .ref-select, #repo-filter, .catalog-filters select, .sheet-nav a, .theme-choices button, .clone-url, .clone-box-links a, .clone-box-links button, .link-arrow, .sha-inline"79CHECK_JS = """(sel) => {80 const de = document.documentElement;81 const out = { scrollWidth: de.scrollWidth, clientWidth: de.clientWidth, small: [] };82 for (const el of document.querySelectorAll(sel)) {83 const r = el.getBoundingClientRect();84 if (r.width === 0 || r.height === 0) continue; // hidden85 if (el.closest('dialog:not([open])')) continue;86 if (r.height < 43.5 || r.width < 43.5) out.small.push(el.tagName.toLowerCase() + (el.id ? '#' + el.id : '') + (el.className && typeof el.className === 'string' ? '.' + el.className.trim().split(/\\s+/).slice(0, 2).join('.') : '') + ' ' + Math.round(r.width) + 'x' + Math.round(r.height));87 }88 return out;89}"""9091async def main():92 ap = argparse.ArgumentParser()93 ap.add_argument("base"); ap.add_argument("out")94 ap.add_argument("--widths", default="320,360,375,390,430,768,1024,1440,1920")95 ap.add_argument("--themes", default="light,dark,midnight")96 ap.add_argument("--engines", default="chromium")97 ap.add_argument("--pages", default=",".join(PAGES))98 ap.add_argument("--repo", default="spbgit"); ap.add_argument("--sha", default="810e402")99 ap.add_argument("--no-shots", action="store_true"); ap.add_argument("--zoom", type=float, default=1.0)100 a = ap.parse_args()101 os.makedirs(a.out, exist_ok=True)102 widths = [int(w) for w in a.widths.split(",")]103 themes = a.themes.split(","); engines = a.engines.split(",")104 pages = [(k, PAGES[k].format(repo=a.repo, sha=a.sha)) for k in a.pages.split(",") if k in PAGES]105 failures = 0; rows = []106 async with async_playwright() as p:107 for engine in engines:108 b = await getattr(p, engine).launch()109 for theme in themes:110 for w in widths:111 mobile = w < 600112 h = 812 if mobile else 900113 ctx = await b.new_context(viewport={"width": w, "height": h}, is_mobile=mobile and engine == "chromium", has_touch=mobile, device_scale_factor=1)114 await ctx.add_init_script(f"try{{localStorage.setItem('spbgit-theme','{theme}')}}catch(e){{}}")115 if a.zoom != 1.0:116 await ctx.add_init_script(f"document.addEventListener('DOMContentLoaded',()=>{{document.documentElement.style.zoom='{a.zoom}'}})")117 pg = await ctx.new_page()118 for name, path in pages:119 try:120 await pg.goto(a.base + path, wait_until="networkidle", timeout=45000)121 await pg.wait_for_timeout(300)122 r = await pg.evaluate(CHECK_JS, ESSENTIAL)123 overflow = r["scrollWidth"] > r["clientWidth"]124 small = r["small"] if mobile else []125 bad = overflow or bool(small)126 failures += int(bad)127 rows.append({"engine": engine, "theme": theme, "width": w, "page": name, "scrollWidth": r["scrollWidth"], "clientWidth": r["clientWidth"], "small": small})128 flag = ("OVERFLOW " if overflow else "") + (f"SMALL:{small[:3]}" if small else "")129 print(f"{engine:8} {theme:8} {w:5} {name:9} sw={r['scrollWidth']:5} cw={r['clientWidth']:5} {flag}")130 if not a.no_shots and w in (320, 375, 430, 1440):131 await pg.screenshot(path=f"{a.out}/{name}-{w}-{theme}-{engine}.png", full_page=True)132 except Exception as e:133 failures += 1; print(f"{engine} {theme} {w} {name} ERROR {str(e)[:120]}")134 await ctx.close()135 await b.close()136 with open(f"{a.out}/report.json", "w") as f: json.dump(rows, f, indent=1)137 print(f"\n{'FAIL' if failures else 'OK'} — {failures} failing page/width combinations")138 sys.exit(1 if failures else 0)139140asyncio.run(main())141