@kinti/a11y-toolkit 5.34.1 → 5.35.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/a11y_toolkit/a11y.py +1 -1
- package/a11y_toolkit/a11yaudit.py +30 -9
- package/a11y_toolkit/a11ybudget.py +21 -5
- package/a11y_toolkit/a11ycrit.py +3 -9
- package/a11y_toolkit/a11ydiff.py +15 -2
- package/a11y_toolkit/a11ydisprove.py +100 -69
- package/a11y_toolkit/a11ydom.py +58 -21
- package/a11y_toolkit/a11yengines.py +8 -6
- package/a11y_toolkit/a11yevidence.py +45 -65
- package/a11y_toolkit/a11yledger.py +15 -2
- package/a11y_toolkit/a11yopenacr.py +3 -3
- package/a11y_toolkit/a11ypatterns.py +3 -3
- package/a11y_toolkit/a11yscroll.py +3 -3
- package/a11y_toolkit/a11ytrace.py +51 -28
- package/a11y_toolkit/a11yvpat.py +3 -2
- package/a11y_toolkit/locales/en.json +1 -1
- package/a11y_toolkit/locales/es.json +1 -1
- package/a11y_toolkit/server.py +12 -16
- package/lib/_bootstrap.py +6 -4
- package/lib/runner.cjs +1 -1
- package/package.json +1 -1
package/a11y_toolkit/a11ydom.py
CHANGED
|
@@ -26,6 +26,32 @@ from .contrast import parse_color, decode_png, sample_rgb, hexs, luminance, rati
|
|
|
26
26
|
# carga y limits): bilingües aquí, igual que el catálogo (invariante es/en)
|
|
27
27
|
_LOAD_ERR = {'es': 'no se pudo cargar: {e}',
|
|
28
28
|
'en': 'could not load: {e}'}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class _NavigationHTTPError(RuntimeError):
|
|
32
|
+
def __init__(self, status, url):
|
|
33
|
+
super().__init__(f'HTTP {status}: could not load the requested page')
|
|
34
|
+
self.status = status
|
|
35
|
+
self.url = url
|
|
36
|
+
|
|
37
|
+
def report(self, lang='en'):
|
|
38
|
+
message = (f'HTTP {self.status}: no se pudo cargar la página solicitada'
|
|
39
|
+
if lang == 'es' else str(self))
|
|
40
|
+
return {'error': message, 'url': self.url, 'http_status': self.status}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _load_page(page, url, timeout, wait_until='load'):
|
|
44
|
+
response = page.goto(url, wait_until=wait_until, timeout=timeout)
|
|
45
|
+
if response is not None and response.status >= 400:
|
|
46
|
+
raise _NavigationHTTPError(response.status, page.url)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _load_error(error, lang, template='{e}'):
|
|
50
|
+
if isinstance(error, _NavigationHTTPError):
|
|
51
|
+
return error.report(lang)
|
|
52
|
+
return {'error': template.format(e=error)}
|
|
53
|
+
|
|
54
|
+
|
|
29
55
|
_LIMITS_HCM = {
|
|
30
56
|
'es': ('Heurística de revisión (1.4.3/1.4.11 en HCM): los fills '
|
|
31
57
|
'coloreados hardcoded en SVG suelen caer al heredado con '
|
|
@@ -155,7 +181,7 @@ class _NoPoolBrowser:
|
|
|
155
181
|
def __init__(self, headless, preferred):
|
|
156
182
|
from playwright.sync_api import sync_playwright
|
|
157
183
|
self._pw = sync_playwright().start()
|
|
158
|
-
self._nav, kind = _detect_browser(self._pw, preferred)
|
|
184
|
+
self._nav, self.kind = _detect_browser(self._pw, preferred)
|
|
159
185
|
self._live_pages = 0
|
|
160
186
|
|
|
161
187
|
def new_context(self, **kw):
|
|
@@ -1185,10 +1211,10 @@ def audit_forms(url, timeout=45, lang='en', auth_state=None, browser='auto'):
|
|
|
1185
1211
|
page, close_page = _pooled_page(nav, auth_state)
|
|
1186
1212
|
try:
|
|
1187
1213
|
try:
|
|
1188
|
-
page
|
|
1214
|
+
_load_page(page, url, timeout * 1000)
|
|
1189
1215
|
page.wait_for_timeout(400)
|
|
1190
1216
|
except Exception as e: # noqa: BLE001
|
|
1191
|
-
return
|
|
1217
|
+
return _load_error(e, lang, _t(lang, 'fetch_error'))
|
|
1192
1218
|
url_before = page.url
|
|
1193
1219
|
pre = page.evaluate(_JS_FORM_PRE)
|
|
1194
1220
|
try:
|
|
@@ -1259,10 +1285,10 @@ def sr_transcript(url, timeout=45, lang='en', auth_state=None, browser='auto'):
|
|
|
1259
1285
|
page, close_page = _pooled_page(nav, auth_state)
|
|
1260
1286
|
try:
|
|
1261
1287
|
try:
|
|
1262
|
-
page
|
|
1288
|
+
_load_page(page, url, timeout * 1000)
|
|
1263
1289
|
page.wait_for_timeout(400)
|
|
1264
1290
|
except Exception as e:
|
|
1265
|
-
return
|
|
1291
|
+
return _load_error(e, lang, '{e!s:.100}')
|
|
1266
1292
|
|
|
1267
1293
|
try:
|
|
1268
1294
|
tree = page.locator('body').aria_snapshot()
|
|
@@ -1343,10 +1369,10 @@ def audit_hover(url, timeout=45, lang='en', auth_state=None, browser='auto'):
|
|
|
1343
1369
|
page, close_page = _pooled_page(nav, auth_state)
|
|
1344
1370
|
try:
|
|
1345
1371
|
try:
|
|
1346
|
-
page
|
|
1372
|
+
_load_page(page, url, timeout * 1000)
|
|
1347
1373
|
page.wait_for_timeout(400)
|
|
1348
1374
|
except Exception as e:
|
|
1349
|
-
return
|
|
1375
|
+
return _load_error(e, lang, '{e!s:.100}')
|
|
1350
1376
|
# tooltips visibles ANTES de tocar nada: los preexistentes (ajenos)
|
|
1351
1377
|
# jamas se atribuyen a un control por el mero hecho de hoverear
|
|
1352
1378
|
_preexisting_tips = page.evaluate(_TOOLTIPS_VISIBLE_JS)
|
|
@@ -1538,10 +1564,10 @@ def audit_reflow(url, timeout=45, lang='en', auth_state=None, browser='auto'):
|
|
|
1538
1564
|
page, close_page = _pooled_page(nav, auth_state, viewport={'width': 1280, 'height': 800})
|
|
1539
1565
|
try:
|
|
1540
1566
|
try:
|
|
1541
|
-
page
|
|
1567
|
+
_load_page(page, url, timeout * 1000)
|
|
1542
1568
|
page.wait_for_timeout(300)
|
|
1543
1569
|
except Exception as e: # noqa: BLE001
|
|
1544
|
-
return
|
|
1570
|
+
return _load_error(e, lang, _LOAD_ERR.get(lang, _LOAD_ERR['en']))
|
|
1545
1571
|
|
|
1546
1572
|
page.set_viewport_size({'width': 320, 'height': 800})
|
|
1547
1573
|
page.wait_for_timeout(500)
|
|
@@ -1659,10 +1685,10 @@ def audit_keyboard(url, max_steps=60, lang='en', timeout=45, auth_state=None, br
|
|
|
1659
1685
|
page, close_page = _pooled_page(nav, auth_state)
|
|
1660
1686
|
try:
|
|
1661
1687
|
try:
|
|
1662
|
-
page
|
|
1688
|
+
_load_page(page, url, timeout * 1000)
|
|
1663
1689
|
page.wait_for_timeout(400)
|
|
1664
1690
|
except Exception as e: # noqa: BLE001
|
|
1665
|
-
return
|
|
1691
|
+
return _load_error(e, lang, _LOAD_ERR.get(lang, _LOAD_ERR['en']))
|
|
1666
1692
|
|
|
1667
1693
|
page.evaluate("document.querySelectorAll('[data-a11ystop]').forEach(e => {"
|
|
1668
1694
|
" e.removeAttribute('data-a11ystop'); e.removeAttribute('data-a11yruta'); })")
|
|
@@ -2015,14 +2041,14 @@ def audit_forced_colors(url, timeout=45, lang='en', auth_state=None, browser='au
|
|
|
2015
2041
|
page, close_page = _pooled_page(nav, auth_state)
|
|
2016
2042
|
try:
|
|
2017
2043
|
try:
|
|
2018
|
-
page
|
|
2044
|
+
_load_page(page, url, timeout * 1000)
|
|
2019
2045
|
page.wait_for_timeout(400)
|
|
2020
2046
|
normal = page.evaluate(_JS_FC)
|
|
2021
2047
|
page.emulate_media(forced_colors='active')
|
|
2022
2048
|
page.wait_for_timeout(400)
|
|
2023
2049
|
forced = page.evaluate(_JS_FC)
|
|
2024
2050
|
except Exception as e: # noqa: BLE001
|
|
2025
|
-
return
|
|
2051
|
+
return _load_error(e, lang, _t_audit(lang, 'fetch_error'))
|
|
2026
2052
|
finally:
|
|
2027
2053
|
close_page()
|
|
2028
2054
|
|
|
@@ -2087,14 +2113,14 @@ def audit_reduced_motion(url, timeout=45, lang='en', auth_state=None, browser='a
|
|
|
2087
2113
|
page, close_page = _pooled_page(nav, auth_state)
|
|
2088
2114
|
try:
|
|
2089
2115
|
try:
|
|
2090
|
-
page
|
|
2116
|
+
_load_page(page, url, timeout * 1000)
|
|
2091
2117
|
page.wait_for_timeout(600)
|
|
2092
2118
|
normal = page.evaluate(_JS_RM)
|
|
2093
2119
|
page.emulate_media(reduced_motion='reduce')
|
|
2094
2120
|
page.wait_for_timeout(600)
|
|
2095
2121
|
reduced = page.evaluate(_JS_RM)
|
|
2096
2122
|
except Exception as e: # noqa: BLE001
|
|
2097
|
-
return
|
|
2123
|
+
return _load_error(e, lang, _t_audit(lang, 'fetch_error'))
|
|
2098
2124
|
finally:
|
|
2099
2125
|
close_page()
|
|
2100
2126
|
|
|
@@ -2145,6 +2171,7 @@ def audit_dom_url(url, timeout=45, lang='en', auth_state=None, browser='auto', c
|
|
|
2145
2171
|
storage_state de Playwright (cookies/localStorage exportados con la sesión
|
|
2146
2172
|
iniciada) para auditar detrás de login."""
|
|
2147
2173
|
nav = _get_browser(preferred=browser)
|
|
2174
|
+
browser_kind = nav.kind if isinstance(nav, _NoPoolBrowser) else _POOL['type']
|
|
2148
2175
|
page, close_page = _pooled_page(nav, auth_state)
|
|
2149
2176
|
_resp = None
|
|
2150
2177
|
page_url_final = None
|
|
@@ -2157,8 +2184,7 @@ def audit_dom_url(url, timeout=45, lang='en', auth_state=None, browser='auto', c
|
|
|
2157
2184
|
_resp = page.goto(url, wait_until='load', timeout=timeout * 1000)
|
|
2158
2185
|
page.wait_for_timeout(400)
|
|
2159
2186
|
except Exception as e: # noqa: BLE001
|
|
2160
|
-
|
|
2161
|
-
return {'error': _LOAD_ERR.get(lang, _LOAD_ERR['en']).format(e=e)}
|
|
2187
|
+
return _load_error(e, lang, _LOAD_ERR.get(lang, _LOAD_ERR['en']))
|
|
2162
2188
|
data = page.evaluate(_JS, MAX_EXAMPLES)
|
|
2163
2189
|
# 1.4.12: inject the WCAG spacing overrides, count clipped texts
|
|
2164
2190
|
data['spacingClipped'] = page.evaluate(_JS_SPACING)
|
|
@@ -2209,6 +2235,8 @@ def audit_dom_url(url, timeout=45, lang='en', auth_state=None, browser='auto', c
|
|
|
2209
2235
|
# /account redirigió — antes conservaba /account y solo añadía la nota
|
|
2210
2236
|
final_url = (page_url_final or url).split('#')[0]
|
|
2211
2237
|
report_out = audit_dom(data, final_url, lang=lang, color_scheme=color_scheme)
|
|
2238
|
+
report_out['authenticated'] = bool(auth_state)
|
|
2239
|
+
report_out['browser'] = browser_kind
|
|
2212
2240
|
try:
|
|
2213
2241
|
_st = _resp.status if _resp is not None else None
|
|
2214
2242
|
except Exception: # noqa: BLE001 — respuesta ya consumida
|
|
@@ -2253,7 +2281,10 @@ def contrast_dom(url, selector, text_color=None, sample=4, lang='en', timeout=45
|
|
|
2253
2281
|
nav = _get_browser(preferred=browser)
|
|
2254
2282
|
page, close_page = _pooled_page(nav, auth_state)
|
|
2255
2283
|
try:
|
|
2256
|
-
|
|
2284
|
+
try:
|
|
2285
|
+
_load_page(page, url, timeout * 1000)
|
|
2286
|
+
except Exception as e: # noqa: BLE001
|
|
2287
|
+
return _load_error(e, lang, _LOAD_ERR.get(lang, _LOAD_ERR['en']))
|
|
2257
2288
|
page.wait_for_timeout(300)
|
|
2258
2289
|
loc = page.locator(selector).first
|
|
2259
2290
|
try:
|
|
@@ -2463,7 +2494,7 @@ def contrast_walk(url, max_walk=400, max_sample=24, dark=False,
|
|
|
2463
2494
|
if auth_state else nav.new_context(color_scheme=scheme))
|
|
2464
2495
|
page = ctx.new_page()
|
|
2465
2496
|
try:
|
|
2466
|
-
page
|
|
2497
|
+
_load_page(page, url, timeout * 1000)
|
|
2467
2498
|
page.wait_for_timeout(300)
|
|
2468
2499
|
return _pass(page)
|
|
2469
2500
|
finally:
|
|
@@ -2472,7 +2503,10 @@ def contrast_walk(url, max_walk=400, max_sample=24, dark=False,
|
|
|
2472
2503
|
except Exception: # noqa: BLE001
|
|
2473
2504
|
pass
|
|
2474
2505
|
|
|
2475
|
-
|
|
2506
|
+
try:
|
|
2507
|
+
entries, skipped, unparsed = _run('light')
|
|
2508
|
+
except _NavigationHTTPError as error:
|
|
2509
|
+
return error.report(lang)
|
|
2476
2510
|
report = {'mode': 'contrast-walk', 'url': url, 'scheme': 'light',
|
|
2477
2511
|
'checked': len(entries),
|
|
2478
2512
|
'elements': entries,
|
|
@@ -2489,7 +2523,10 @@ def contrast_walk(url, max_walk=400, max_sample=24, dark=False,
|
|
|
2489
2523
|
e['suggestion'] = s
|
|
2490
2524
|
|
|
2491
2525
|
if dark:
|
|
2492
|
-
|
|
2526
|
+
try:
|
|
2527
|
+
entries_d, skipped_d, _unp_d = _run('dark')
|
|
2528
|
+
except _NavigationHTTPError as error:
|
|
2529
|
+
return error.report(lang)
|
|
2493
2530
|
report['dark'] = {'scheme': 'dark', 'checked': len(entries_d),
|
|
2494
2531
|
'elements': entries_d,
|
|
2495
2532
|
'summary': _summarize(entries_d, skipped_d, _unp_d)}
|
|
@@ -41,7 +41,7 @@ DEFAULT_ENGINES = ('chromium', 'firefox', 'webkit')
|
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
def _capture(url, engine, auth_state=None):
|
|
44
|
-
"""
|
|
44
|
+
"""Capture one engine's snapshot."""
|
|
45
45
|
return a11ydiff.snapshot(url, engine=engine, auth_state=auth_state)
|
|
46
46
|
|
|
47
47
|
|
|
@@ -90,8 +90,11 @@ def matrix(url, engines=None, auth_state=None, capture=None):
|
|
|
90
90
|
failed.append({'engine': name, 'error': f'unknown engine (known: {", ".join(ENGINES)})'})
|
|
91
91
|
continue
|
|
92
92
|
try:
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
s = capture(url, name, auth_state)
|
|
94
|
+
if 'error' in s:
|
|
95
|
+
failed.append({**s, 'engine': name})
|
|
96
|
+
continue
|
|
97
|
+
snaps[name] = s
|
|
95
98
|
ok.append({'engine': name, 'elements': len(s.get('elements', [])),
|
|
96
99
|
'focus_steps': len(s.get('focus_order', [])),
|
|
97
100
|
'tree': 'accessibility_tree' in s or 'arbol_accesible' in s})
|
|
@@ -127,9 +130,8 @@ def matrix(url, engines=None, auth_state=None, capture=None):
|
|
|
127
130
|
'conformance claim.'),
|
|
128
131
|
}
|
|
129
132
|
if not enough:
|
|
130
|
-
report['note'] = ('fewer than 2 engines
|
|
131
|
-
'`playwright install firefox webkit
|
|
132
|
-
'engine cannot see cross-engine behavior')
|
|
133
|
+
report['note'] = ('fewer than 2 engines captured the page. Check the reported '
|
|
134
|
+
'errors. Install missing engines with `playwright install firefox webkit`.')
|
|
133
135
|
return report
|
|
134
136
|
|
|
135
137
|
|
|
@@ -27,9 +27,9 @@ CLI:
|
|
|
27
27
|
import argparse
|
|
28
28
|
import hashlib
|
|
29
29
|
import json
|
|
30
|
+
import re
|
|
30
31
|
|
|
31
32
|
from .a11yaudit import normalize_report # noqa: E402 (compat 5.10)
|
|
32
|
-
from .a11ycrit import _EFFORT_MINUTES # single source: a11ycrit prices the classes
|
|
33
33
|
import sys
|
|
34
34
|
from datetime import datetime, timezone
|
|
35
35
|
|
|
@@ -104,13 +104,10 @@ def apply_scope(pack, scope, lang='en'):
|
|
|
104
104
|
criteria.append(row)
|
|
105
105
|
out['criteria'] = criteria
|
|
106
106
|
out['summary'] = {e: sum(1 for m in criteria if m.get('status') == e) for e in _STATES}
|
|
107
|
-
# the scope changes what REMAINS to do: effort_pending and manual_pending
|
|
108
|
-
# must describe the resulting matrix (excluded = zero pending human
|
|
109
|
-
# effort), not the pre-scope pack — otherwise the human is overcharged
|
|
110
|
-
# and criteria already not-applicable keep being named as pending
|
|
111
107
|
out['effort_pending'] = _pending_effort(
|
|
112
108
|
criteria, tx.get('manual_remaining')
|
|
113
|
-
or a11yi18n.pack('en')['evidence']['manual_remaining']
|
|
109
|
+
or a11yi18n.pack('en')['evidence']['manual_remaining'],
|
|
110
|
+
legacy=pack.get('format') == 'a11y-evidence-pack/2')
|
|
114
111
|
out['manual_pending'] = [m['criterion'] for m in criteria
|
|
115
112
|
if m.get('status') == 'manual-only']
|
|
116
113
|
return out
|
|
@@ -120,31 +117,26 @@ def _sha256(obj):
|
|
|
120
117
|
return hashlib.sha256(_canon(obj).encode('utf-8')).hexdigest()
|
|
121
118
|
|
|
122
119
|
|
|
123
|
-
def _pending_effort(matrix, note):
|
|
124
|
-
"""
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
never the pre-scope one."""
|
|
129
|
-
pend = {}
|
|
130
|
-
for m in matrix:
|
|
131
|
-
if m.get('status') == 'agent-verified':
|
|
120
|
+
def _pending_effort(matrix, note, legacy=False):
|
|
121
|
+
"""Count pending review by class. Preserve supplied durations for v2."""
|
|
122
|
+
groups = {}
|
|
123
|
+
for row in matrix:
|
|
124
|
+
if row.get('status') in ('agent-verified', 'not-applicable') or not row.get('effort'):
|
|
132
125
|
continue
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
126
|
+
effort = row['effort']
|
|
127
|
+
bucket = groups.setdefault(effort['class'], {'criteria': 0})
|
|
128
|
+
bucket['criteria'] += 1
|
|
129
|
+
minutes = effort.get('minutes')
|
|
130
|
+
if legacy and isinstance(minutes, (list, tuple)) and len(minutes) == 2:
|
|
131
|
+
if all(type(value) in (int, float) for value in minutes):
|
|
132
|
+
totals = bucket.setdefault('minutes', [0, 0])
|
|
133
|
+
for index, value in enumerate(minutes):
|
|
134
|
+
totals[index] += value
|
|
135
|
+
result = {'by_class': dict(sorted(groups.items())), 'note': note}
|
|
136
|
+
if legacy:
|
|
137
|
+
result['total_minutes'] = [sum(group.get('minutes', [0, 0])[i] for group in groups.values())
|
|
138
|
+
for i in range(2)]
|
|
139
|
+
return result
|
|
148
140
|
|
|
149
141
|
|
|
150
142
|
def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
@@ -202,10 +194,11 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
202
194
|
# matriz de criterios: los que tocamos (estado según hallazgos) + manuales
|
|
203
195
|
from .a11ycrit import _C as _CAT, effort
|
|
204
196
|
codes_aa = sorted(k for k, v in _CAT.items() if v[0] in ('A', 'AA'))
|
|
205
|
-
touched = {}
|
|
197
|
+
touched, values = {}, {}
|
|
206
198
|
for inf in pages:
|
|
207
199
|
for h in inf.get('findings', []):
|
|
208
|
-
if
|
|
200
|
+
if (not isinstance(h, dict) or h.get('status') == 'rejected'
|
|
201
|
+
or h.get('disprover_status') == 'rejected'):
|
|
209
202
|
continue
|
|
210
203
|
crit = h.get('criterion')
|
|
211
204
|
if not crit or not isinstance(crit, str): # informe malformado: saltar
|
|
@@ -219,8 +212,23 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
219
212
|
and h.get('disprover_status') != 'not-rechecked'
|
|
220
213
|
else 'automated-review')
|
|
221
214
|
# el peor estado gana: fail > review
|
|
222
|
-
|
|
215
|
+
previous = touched.get(code)
|
|
216
|
+
if previous != 'automated-fail':
|
|
223
217
|
touched[code] = state
|
|
218
|
+
if previous != state:
|
|
219
|
+
values.pop(code, None)
|
|
220
|
+
if touched[code] == state and code not in values:
|
|
221
|
+
value = {}
|
|
222
|
+
issue = str(h.get('issue') or '')
|
|
223
|
+
if 'ratio' in issue.lower() or ':' in issue:
|
|
224
|
+
match = re.search(r'([\d.]+):1', issue)
|
|
225
|
+
if match:
|
|
226
|
+
value['measured'] = f'{match.group(1)}:1'
|
|
227
|
+
examples = h.get('examples')
|
|
228
|
+
if isinstance(examples, list) and examples:
|
|
229
|
+
value['example'] = str(examples[0])[:80]
|
|
230
|
+
if value:
|
|
231
|
+
values[code] = value
|
|
224
232
|
|
|
225
233
|
verified = {v.split(' ')[0] for v in (verified or [])}
|
|
226
234
|
|
|
@@ -241,25 +249,6 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
241
249
|
continue
|
|
242
250
|
reason = row.get('reason')
|
|
243
251
|
excluded[crit.split(' ')[0]] = reason if isinstance(reason, str) else ''
|
|
244
|
-
# extraer valores medidos clave de los hallazgos (ratio, ejemplos)
|
|
245
|
-
values = {}
|
|
246
|
-
for inf in pages:
|
|
247
|
-
for h in inf.get('findings', []):
|
|
248
|
-
code = str(h.get('criterion') or '').split(' ')[0]
|
|
249
|
-
if code not in values:
|
|
250
|
-
val = {}
|
|
251
|
-
issue_txt = str(h.get('issue') or '')
|
|
252
|
-
if 'ratio' in issue_txt.lower() or ':' in issue_txt:
|
|
253
|
-
import re as _re
|
|
254
|
-
m = _re.search(r'([\d.]+):1', issue_txt)
|
|
255
|
-
if m:
|
|
256
|
-
val['measured'] = f'{m.group(1)}:1'
|
|
257
|
-
_ex_list = h.get('examples', [])
|
|
258
|
-
if isinstance(_ex_list, list) and _ex_list:
|
|
259
|
-
val['example'] = str(_ex_list[0])[:80]
|
|
260
|
-
if val:
|
|
261
|
-
values[code] = val
|
|
262
|
-
|
|
263
252
|
# criterios que requieren modos que este pack no incluye → not-run con el
|
|
264
253
|
# nombre de la herramienta que falta (canónico en a11ycrit, re-derivado)
|
|
265
254
|
from .a11ycrit import MODES_BY_CRITERION as _MODES_BY
|
|
@@ -311,10 +300,7 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
311
300
|
'status': state, 'note': note}
|
|
312
301
|
ef = effort(code)
|
|
313
302
|
if ef:
|
|
314
|
-
|
|
315
|
-
# best signal (pricing input for human-review scoping)
|
|
316
|
-
entry['effort'] = {'class': ef['class'], 'minutes': ef['minutes'],
|
|
317
|
-
'why': ef['why']}
|
|
303
|
+
entry['effort'] = ef
|
|
318
304
|
if code in values:
|
|
319
305
|
entry['value'] = values[code]
|
|
320
306
|
matrix.append(entry)
|
|
@@ -331,8 +317,7 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
331
317
|
'note': tx['no_signal']}
|
|
332
318
|
ef = effort(code)
|
|
333
319
|
if ef:
|
|
334
|
-
row['effort'] =
|
|
335
|
-
'why': ef['why']}
|
|
320
|
+
row['effort'] = ef
|
|
336
321
|
matrix.append(row)
|
|
337
322
|
for code in sorted(verified):
|
|
338
323
|
# una exclusión confirmada gana a una verificación previa: el
|
|
@@ -346,16 +331,11 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
346
331
|
'note': 'verified against this sample per the manual checklist protocol'}
|
|
347
332
|
ef = effort(code)
|
|
348
333
|
if ef:
|
|
349
|
-
row['effort'] =
|
|
350
|
-
'why': ef['why']}
|
|
334
|
+
row['effort'] = ef
|
|
351
335
|
matrix.append(row)
|
|
352
336
|
|
|
353
337
|
summary = {e: sum(1 for m in matrix if m['status'] == e) for e in _STATES}
|
|
354
338
|
|
|
355
|
-
# remaining human review, in minutes: MIN/MED/MAX per class summed over
|
|
356
|
-
# every row a human still has to touch (everything except agent-verified).
|
|
357
|
-
# This is the scope input for human review: agent output in,
|
|
358
|
-
# priced human scope out. The class prices live in a11ycrit (single source).
|
|
359
339
|
pending_effort = _pending_effort(matrix, tx['manual_remaining'])
|
|
360
340
|
|
|
361
341
|
artifacts = report_artifacts
|
|
@@ -389,7 +369,7 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
389
369
|
}
|
|
390
370
|
|
|
391
371
|
pack = {
|
|
392
|
-
'format': 'a11y-evidence-pack/
|
|
372
|
+
'format': 'a11y-evidence-pack/3',
|
|
393
373
|
'lang': language,
|
|
394
374
|
'generated': now,
|
|
395
375
|
'tool': 'a11y-toolkit (github.com/kinti/a11y-toolkit)',
|
|
@@ -30,7 +30,8 @@ from datetime import datetime, timezone
|
|
|
30
30
|
|
|
31
31
|
import tempfile
|
|
32
32
|
|
|
33
|
-
from .a11yaudit import
|
|
33
|
+
from .a11yaudit import (audit_conditions, audit_conditions_match, completed_report_pages,
|
|
34
|
+
normalize_signal, page_identity)
|
|
34
35
|
|
|
35
36
|
# per-path lock: always multi-thread; multi-process on POSIX (fcntl).
|
|
36
37
|
# Without it, two concurrent writes left a truncated JSON (external review
|
|
@@ -120,7 +121,7 @@ def _record(url, report, ledger=None, path='a11y-ledger.json', lang='en'):
|
|
|
120
121
|
page_identity(pages[0].get('url'))}:
|
|
121
122
|
return {'error': ('La URL no coincide con el informe.' if lang == 'es' else
|
|
122
123
|
'The URL does not match the audit report.')}
|
|
123
|
-
page_modes, measured = {}, {}
|
|
124
|
+
page_modes, page_conditions, measured = {}, {}, {}
|
|
124
125
|
mode = report.get('mode', 'static')
|
|
125
126
|
for page in pages:
|
|
126
127
|
page_url = page.get('url') or (url if 'reports' not in report else None)
|
|
@@ -131,6 +132,9 @@ def _record(url, report, ledger=None, path='a11y-ledger.json', lang='en'):
|
|
|
131
132
|
if lang == 'es' else
|
|
132
133
|
'Every page must have a unique URL and an audit mode.')}
|
|
133
134
|
page_modes[page_url] = page_mode
|
|
135
|
+
conditions = audit_conditions(page)
|
|
136
|
+
if conditions:
|
|
137
|
+
page_conditions[page_url] = conditions
|
|
134
138
|
measured[identity] = page_mode
|
|
135
139
|
if ledger is None:
|
|
136
140
|
ledger = _load(path)
|
|
@@ -149,6 +153,14 @@ def _record(url, report, ledger=None, path='a11y-ledger.json', lang='en'):
|
|
|
149
153
|
'Usa un historial distinto para otro alcance.' if lang == 'es' else
|
|
150
154
|
'The audit mode changed or prior pages are missing. '
|
|
151
155
|
'Use a different ledger for a different scope.')}
|
|
156
|
+
current_conditions = {page_identity(page): value for page, value in page_conditions.items()}
|
|
157
|
+
previous_conditions = prev.get('page_conditions', {})
|
|
158
|
+
if prev and any(not audit_conditions_match(page_mode, previous_conditions.get(page, {}),
|
|
159
|
+
current_conditions.get(page_identity(page), {}))
|
|
160
|
+
for page, page_mode in previous_pages.items()):
|
|
161
|
+
return {'error': ('Cambiaron las condiciones de captura o el historial antiguo no las registra.'
|
|
162
|
+
if lang == 'es' else
|
|
163
|
+
'Capture conditions changed or were not recorded in the old ledger.')}
|
|
152
164
|
|
|
153
165
|
signals = set()
|
|
154
166
|
for page in pages:
|
|
@@ -195,6 +207,7 @@ def _record(url, report, ledger=None, path='a11y-ledger.json', lang='en'):
|
|
|
195
207
|
'resolutions': resolutions,
|
|
196
208
|
'mode': mode,
|
|
197
209
|
'page_modes': page_modes,
|
|
210
|
+
'page_conditions': page_conditions,
|
|
198
211
|
'disprover': report.get('disprover'),
|
|
199
212
|
}
|
|
200
213
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""OpenACR (GSA) generator — the machine-readable ACR for public procurement.
|
|
3
3
|
|
|
4
|
-
Input: an a11y
|
|
4
|
+
Input: an a11y evidence pack (v2 or v3) (from a11y_evidence / the a11y_evidence MCP
|
|
5
5
|
tool) or raw audit reports (the pack is built here). Output: OpenACR YAML
|
|
6
6
|
(the GSA open standard born from VPAT 2.4Rev 508; gsa.github.io/openacr)
|
|
7
7
|
with the full 55-criterion WCAG 2.2 A/AA matrix — chapters
|
|
@@ -75,8 +75,8 @@ def _remarks(row, finding, pack_sha):
|
|
|
75
75
|
parts.append('remediation: ' + str(finding['remediation'])[:220])
|
|
76
76
|
ef = row.get('effort')
|
|
77
77
|
if ef:
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
minutes = f" ({ef['minutes']} min)" if ef.get('minutes') else ''
|
|
79
|
+
parts.append(f"remaining human effort: {ef.get('class')}{minutes}")
|
|
80
80
|
parts.append('evidence pack sha256 ' + pack_sha)
|
|
81
81
|
return ' | '.join(p for p in parts if p)
|
|
82
82
|
|
|
@@ -356,16 +356,16 @@ def _test_sliders(page, findings, lang, cap=3):
|
|
|
356
356
|
|
|
357
357
|
def audit_patterns(url, timeout=45, lang='en', auth_state=None, browser='auto'):
|
|
358
358
|
"""One url → widget patterns found + contract findings (filter, not verdict)."""
|
|
359
|
-
from .a11ydom import _get_browser, _pooled_page
|
|
359
|
+
from .a11ydom import _get_browser, _load_error, _load_page, _pooled_page
|
|
360
360
|
lang = 'es' if lang == 'es' else 'en'
|
|
361
361
|
nav = _get_browser(preferred=browser)
|
|
362
362
|
page, close_page = _pooled_page(nav, auth_state)
|
|
363
363
|
try:
|
|
364
364
|
try:
|
|
365
|
-
page
|
|
365
|
+
_load_page(page, url, timeout * 1000)
|
|
366
366
|
page.wait_for_timeout(400)
|
|
367
367
|
except Exception as e: # noqa: BLE001
|
|
368
|
-
return
|
|
368
|
+
return _load_error(e, lang, 'could not load: {e}')
|
|
369
369
|
|
|
370
370
|
counts = page.evaluate(_COUNTS)
|
|
371
371
|
findings = []
|
|
@@ -80,17 +80,17 @@ def _add(findings, lang, sev, code, key, **fmt):
|
|
|
80
80
|
|
|
81
81
|
def audit_scroll(url, max_batches=5, lang='en', timeout=45, auth_state=None, browser='auto',
|
|
82
82
|
interactive=False, load_more=None):
|
|
83
|
-
from .a11ydom import _get_browser, _pooled_page
|
|
83
|
+
from .a11ydom import _get_browser, _load_error, _load_page, _pooled_page
|
|
84
84
|
nav = _get_browser(preferred=browser)
|
|
85
85
|
# BrowserContext.new_page() NO acepta viewport: _pooled_page lo manda al
|
|
86
86
|
# new_context cuando hay auth_state
|
|
87
87
|
page, close_page = _pooled_page(nav, auth_state, viewport={'width': 1280, 'height': 800})
|
|
88
88
|
try:
|
|
89
89
|
try:
|
|
90
|
-
page
|
|
90
|
+
_load_page(page, url, timeout * 1000)
|
|
91
91
|
page.wait_for_timeout(500)
|
|
92
92
|
except Exception as e: # noqa: BLE001
|
|
93
|
-
return
|
|
93
|
+
return _load_error(e, lang, 'no se pudo cargar: {e}')
|
|
94
94
|
page.evaluate(_MON)
|
|
95
95
|
page.evaluate("(() => { const c = document.querySelector("
|
|
96
96
|
" 'article a[href], [role=article] a[href], main li a[href]');"
|