Repository Public MIT Selected
1# =============================================================================2# SP BOUCHER | INFRASTRUCTURE & AUTOMATION3# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4# =============================================================================5#6# Project : SPB Git7# File : scripts/qa/axe.py8# Description : Usage: python3 -I scripts/qa/axe.py BASE_URL [--repo9# spbgit] [--sha 810e402] [--themes light,dark,midnight]10# [--widths 375,1440]11# Module : scripts12# Repository : https://git.spboucher.ai/spbgit13# Project Website : https://git.spboucher.ai14# Created : 2026-11-0115# Last Modified : 2026-11-0916#17# Author : Simon-Pierre Boucher18# Position : Professor of Finance19# Institution : Université du Québec en Outaouais (UQO)20# Organization : SP Boucher21# Website : https://spboucher.ai22# Git : https://git.spboucher.ai23#24# Preferred Contact: admin@spboucher.ai25# Technical Contact: dev@spboucher.ai26# Security/Admin : admin@spboucher.ai27#28# Copyright (c) 202629# Simon-Pierre Boucher30# All rights reserved where applicable. This file is governed by the31# applicable project license, copyright notices and relevant law.32# Existing third-party rights and notices remain unaffected.33#34# SPDX Identifier : MIT35# License : MIT License36# License File : LICENSE37#38# Do not embed credentials, private keys, access tokens,39# certificates or confidential personal information.40#41# =============================================================================42# END OF SP BOUCHER SOURCE HEADER43# =============================================================================4445# ─────────────────────────────────────────────46# SPB Git — Personal Git Platform47# ─────────────────────────────────────────────48# Author : Simon-Pierre Boucher49# Contact : contact@spboucher.ai50# File : scripts/qa/axe.py51# Purpose : Accessibility audit — injects node_modules/axe-core and reports WCAG 2.x A/AA violations per page × theme × width52# License : MIT © Simon-Pierre Boucher53# ─────────────────────────────────────────────54"""Usage: python3 -I scripts/qa/axe.py BASE_URL [--repo spbgit] [--sha 810e402] [--themes light,dark,midnight] [--widths 375,1440]"""55import sys, os, asyncio, argparse, json56from playwright.async_api import async_playwright5758HERE = os.path.dirname(os.path.abspath(__file__))59AXE = os.path.join(HERE, "..", "..", "node_modules", "axe-core", "axe.min.js")60PAGES = {"home": "/", "repo": "/{repo}", "blob": "/{repo}/blob/main/src/server.mjs", "commits": "/{repo}/commits/main",61 "commit": "/{repo}/commit/{sha}", "search": "/search?q=git", "metrics": "/about/metrics", "api": "/about/api", "branches": "/{repo}/branches", "tags": "/{repo}/tags", "tree": "/{repo}/tree/main/src",62 "insights": "/{repo}/insights", "blame": "/{repo}/blame/main/package.json", "readme": "/{repo}/blob/main/README.md", "404": "/nope"}6364async def main():65 ap = argparse.ArgumentParser(); ap.add_argument("base"); ap.add_argument("--repo", default="spbgit"); ap.add_argument("--sha", default="810e402")66 ap.add_argument("--themes", default="light,dark,midnight"); ap.add_argument("--widths", default="375,1440"); ap.add_argument("--out", default="")67 a = ap.parse_args()68 axe_src = open(AXE).read()69 total = 0; report = []70 async with async_playwright() as p:71 b = await p.chromium.launch()72 for theme in a.themes.split(","):73 for w in [int(x) for x in a.widths.split(",")]:74 ctx = await b.new_context(viewport={"width": w, "height": 900}, is_mobile=w < 600, has_touch=w < 600, bypass_csp=True)75 await ctx.add_init_script(f"try{{localStorage.setItem('spbgit-theme','{theme}')}}catch(e){{}}")76 pg = await ctx.new_page()77 for name, path in PAGES.items():78 await pg.goto(a.base + path.format(repo=a.repo, sha=a.sha), wait_until="networkidle")79 await pg.add_script_tag(content=axe_src)80 res = await pg.evaluate("axe.run(document, {runOnly: {type: 'tag', values: ['wcag2a', 'wcag2aa', 'wcag21aa', 'best-practice']}})")81 viol = [v for v in res["violations"]]82 total += len(viol)83 for v in viol:84 report.append({"theme": theme, "width": w, "page": name, "id": v["id"], "impact": v["impact"], "nodes": len(v["nodes"]), "help": v["help"], "sample": v["nodes"][0]["html"][:160]})85 print(f"{theme:8} {w:5} {name:8} violations={len(viol)} " + ", ".join(f"{v['id']}({v['impact']},{len(v['nodes'])})" for v in viol))86 await ctx.close()87 await b.close()88 if a.out:89 with open(a.out, "w") as f: json.dump(report, f, indent=1)90 print(f"\n{'FAIL' if total else 'OK'} — {total} violation groups")91 sys.exit(1 if total else 0)9293asyncio.run(main())94