@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/README.md
CHANGED
|
@@ -16,7 +16,7 @@ As an MCP server (stdio):
|
|
|
16
16
|
|
|
17
17
|
```json
|
|
18
18
|
{ "mcpServers": { "a11y-toolkit": {
|
|
19
|
-
"command": "npx", "args": ["-y", "@kinti/a11y-toolkit", "a11y-toolkit-mcp"] } } }
|
|
19
|
+
"command": "npx", "args": ["-y", "-p", "@kinti/a11y-toolkit", "a11y-toolkit-mcp"] } } }
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## Requirements
|
package/a11y_toolkit/a11y.py
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
a11ytoolkit wizard --url https://client.web --lang es # guided: standard, audit, scope, annex
|
|
38
38
|
a11ytoolkit mutants --seed 7 --n 12 # the engine's sealed self-exam
|
|
39
39
|
a11ytoolkit corpus build && a11ytoolkit corpus verify # versioned audit corpus (dataset + baselines)
|
|
40
|
-
a11ytoolkit fingerprints page1.html page2.html --dir p/ #
|
|
40
|
+
a11ytoolkit fingerprints page1.html page2.html --dir p/ # suggest a structural sample
|
|
41
41
|
a11ytoolkit audit --url https://web --standard en301549 # EN 301 549 clause on every finding
|
|
42
42
|
a11ytoolkit scope audit.json -o scope.json --standard en301549 # applicability: machine proposes, human confirms
|
|
43
43
|
a11ytoolkit annotate page.html --report r.json -o copy.html # per-element marks on a copy
|
|
@@ -1981,6 +1981,24 @@ def page_identity(url):
|
|
|
1981
1981
|
return (parts.scheme, parts.hostname, port, parts.path or '/', parts.query)
|
|
1982
1982
|
|
|
1983
1983
|
|
|
1984
|
+
def audit_conditions(report):
|
|
1985
|
+
"""Identify recorded capture conditions that affect comparability."""
|
|
1986
|
+
if report.get('mode') == 'rendered':
|
|
1987
|
+
return {'color_scheme': report.get('color_scheme') or report.get('scheme'),
|
|
1988
|
+
'authenticated': report.get('authenticated'), 'browser': report.get('browser')}
|
|
1989
|
+
return {}
|
|
1990
|
+
|
|
1991
|
+
|
|
1992
|
+
def rendered_conditions_recorded(conditions):
|
|
1993
|
+
return (conditions.get('color_scheme') in ('light', 'dark')
|
|
1994
|
+
and isinstance(conditions.get('authenticated'), bool)
|
|
1995
|
+
and isinstance(conditions.get('browser'), str) and bool(conditions['browser']))
|
|
1996
|
+
|
|
1997
|
+
|
|
1998
|
+
def audit_conditions_match(mode, previous, current):
|
|
1999
|
+
return previous == current and (mode != 'rendered' or rendered_conditions_recorded(current))
|
|
2000
|
+
|
|
2001
|
+
|
|
1984
2002
|
def completed_report_pages(report):
|
|
1985
2003
|
"""Return measured pages or the reason they cannot support a comparison."""
|
|
1986
2004
|
if not isinstance(report, dict) or report.get('error'):
|
|
@@ -3193,7 +3211,7 @@ def audit_site(url, max_pages=5, timeout=30, lang='en', from_sitemap=True,
|
|
|
3193
3211
|
continue
|
|
3194
3212
|
reports.append(report)
|
|
3195
3213
|
parsers.append(pg)
|
|
3196
|
-
if len(reports) < max_pages and not
|
|
3214
|
+
if len(reports) < max_pages and not urls_sm:
|
|
3197
3215
|
for new in _internal_links(html_pg, next_final, url):
|
|
3198
3216
|
if new not in seen:
|
|
3199
3217
|
queue.append(new)
|
|
@@ -3241,21 +3259,24 @@ def audit_changed(base='HEAD', lang='en', cwd='.'):
|
|
|
3241
3259
|
is no HTML to audit). Deleted files are skipped.
|
|
3242
3260
|
"""
|
|
3243
3261
|
import subprocess
|
|
3244
|
-
spec = ['git', 'diff', '--name-only', '--diff-filter=d',
|
|
3262
|
+
spec = ['git', 'diff', '--name-only', '-z', '--diff-filter=d',
|
|
3245
3263
|
base if base == 'HEAD' else f'{base}...HEAD']
|
|
3246
3264
|
try:
|
|
3247
|
-
out = subprocess.run(spec, cwd=cwd, capture_output=True,
|
|
3265
|
+
out = subprocess.run(spec, cwd=cwd, capture_output=True, timeout=30)
|
|
3248
3266
|
except FileNotFoundError:
|
|
3249
3267
|
return {'error': 'git not available'}
|
|
3250
3268
|
if out.returncode != 0:
|
|
3251
|
-
|
|
3252
|
-
|
|
3269
|
+
detail = os.fsdecode(out.stderr).strip()[:200]
|
|
3270
|
+
return {'error': f'git diff failed: {detail}'}
|
|
3253
3271
|
# los NUEVOS sin trackear no salen en git diff — entran también:
|
|
3254
3272
|
# una página recién creada no puede escaparse del gate local
|
|
3255
|
-
untracked = subprocess.run(['git', 'ls-files', '--others', '--exclude-standard'],
|
|
3256
|
-
cwd=cwd, capture_output=True,
|
|
3257
|
-
if untracked.returncode
|
|
3258
|
-
|
|
3273
|
+
untracked = subprocess.run(['git', 'ls-files', '-z', '--others', '--exclude-standard'],
|
|
3274
|
+
cwd=cwd, capture_output=True, timeout=30)
|
|
3275
|
+
if untracked.returncode != 0:
|
|
3276
|
+
detail = os.fsdecode(untracked.stderr).strip()[:200]
|
|
3277
|
+
return {'error': f'git ls-files failed: {detail}'}
|
|
3278
|
+
changed = [os.fsdecode(path) for path in dict.fromkeys((out.stdout + untracked.stdout).split(b'\0'))
|
|
3279
|
+
if path]
|
|
3259
3280
|
auditables, web_touched = [], []
|
|
3260
3281
|
for f in changed:
|
|
3261
3282
|
ext = os.path.splitext(f)[1].lower()
|
|
@@ -44,7 +44,7 @@ import datetime
|
|
|
44
44
|
import json
|
|
45
45
|
from collections import Counter
|
|
46
46
|
|
|
47
|
-
from .a11yaudit import completed_report_pages, normalize_signal
|
|
47
|
+
from .a11yaudit import audit_conditions, audit_conditions_match, completed_report_pages, normalize_signal
|
|
48
48
|
import sys
|
|
49
49
|
|
|
50
50
|
# mensajes CLI bilingües (patrón _labels): el stdin de --init espera el JSON
|
|
@@ -65,6 +65,14 @@ _CLI_MSG = {
|
|
|
65
65
|
BUDGET_FORMAT = 'a11y-budget/2'
|
|
66
66
|
|
|
67
67
|
|
|
68
|
+
def _active_findings(page):
|
|
69
|
+
for finding in page['findings']:
|
|
70
|
+
if not isinstance(finding, dict):
|
|
71
|
+
raise ValueError('invalid finding')
|
|
72
|
+
if finding.get('status') != 'rejected' and finding.get('disprover_status') != 'rejected':
|
|
73
|
+
yield finding
|
|
74
|
+
|
|
75
|
+
|
|
68
76
|
def _page_index(pages):
|
|
69
77
|
result = {}
|
|
70
78
|
for page in pages:
|
|
@@ -72,7 +80,7 @@ def _page_index(pages):
|
|
|
72
80
|
if not isinstance(url, str) or not url or url in result:
|
|
73
81
|
raise ValueError('every audited page must have a unique URL')
|
|
74
82
|
findings = {}
|
|
75
|
-
for finding in page
|
|
83
|
+
for finding in _active_findings(page):
|
|
76
84
|
signal = normalize_signal(finding['signal'])
|
|
77
85
|
paths = [path for path in (finding.get('paths') or []) if isinstance(path, str)]
|
|
78
86
|
count = finding.get('count')
|
|
@@ -80,7 +88,8 @@ def _page_index(pages):
|
|
|
80
88
|
count = max(len(paths), len(finding.get('examples') or []), 1)
|
|
81
89
|
findings[signal] = {'severity': finding['severity'], 'count': max(count, len(paths)),
|
|
82
90
|
'paths': sorted(paths)}
|
|
83
|
-
result[url] = {'mode': page.get('mode', 'static'), '
|
|
91
|
+
result[url] = {'mode': page.get('mode', 'static'), 'conditions': audit_conditions(page),
|
|
92
|
+
'findings': findings}
|
|
84
93
|
return result
|
|
85
94
|
|
|
86
95
|
|
|
@@ -136,6 +145,10 @@ def _compare_instances(budget, pages, blocking):
|
|
|
136
145
|
prior = base.get(url)
|
|
137
146
|
if prior and prior['mode'] != page['mode']:
|
|
138
147
|
return {'error': 'the audit mode changed for a baseline page', 'url': url}
|
|
148
|
+
if prior and not audit_conditions_match(page['mode'], prior.get('conditions', {}),
|
|
149
|
+
page['conditions']):
|
|
150
|
+
return {'error': 'the capture conditions changed or were not recorded in the baseline',
|
|
151
|
+
'url': url}
|
|
139
152
|
old = prior['findings'] if prior else {}
|
|
140
153
|
current = page['findings']
|
|
141
154
|
for signal in sorted(set(old) | set(current)):
|
|
@@ -162,7 +175,7 @@ def _compare_signals(budget, pages, blocking):
|
|
|
162
175
|
base = {normalize_signal(s) for s in budget.get('signals', [])}
|
|
163
176
|
current = {}
|
|
164
177
|
for pg in pages:
|
|
165
|
-
for h in pg
|
|
178
|
+
for h in _active_findings(pg):
|
|
166
179
|
current.setdefault(normalize_signal(h.get('signal', '')), []).append(h['severity'])
|
|
167
180
|
new = sorted(s for s in current if s not in base)
|
|
168
181
|
resolved = sorted(base - set(current))
|
|
@@ -182,9 +195,12 @@ def compare(budget, audit, today=None):
|
|
|
182
195
|
try:
|
|
183
196
|
blocking = set(budget.get('blocking', ['high', 'medium']))
|
|
184
197
|
max_new = int(budget.get('max_new', 0))
|
|
198
|
+
signals = {normalize_signal(h['signal']) for pg in pages for h in _active_findings(pg)}
|
|
185
199
|
if budget.get('format') == BUDGET_FORMAT:
|
|
186
200
|
verdict = _compare_instances(budget, _page_index(pages), blocking)
|
|
187
201
|
else:
|
|
202
|
+
if any(p.get('mode') == 'rendered' for p in pages):
|
|
203
|
+
return {'error': 'a rendered audit needs a baseline with recorded capture conditions'}
|
|
188
204
|
verdict = _compare_signals(budget, pages, blocking)
|
|
189
205
|
except (ValueError, KeyError, TypeError) as err:
|
|
190
206
|
return {'error': f'invalid budget input: {err}'}
|
|
@@ -201,7 +217,7 @@ def compare(budget, audit, today=None):
|
|
|
201
217
|
**verdict,
|
|
202
218
|
'summary': {
|
|
203
219
|
'baseline': len(set(budget.get('signals', []))),
|
|
204
|
-
'current': len(
|
|
220
|
+
'current': len(signals),
|
|
205
221
|
'new': len(verdict['new']),
|
|
206
222
|
'resolved': len(verdict['resolved']),
|
|
207
223
|
},
|
package/a11y_toolkit/a11ycrit.py
CHANGED
|
@@ -748,11 +748,7 @@ _C = {
|
|
|
748
748
|
_LEVEL = {'A': 'A', 'AA': 'AA', 'AAA': 'AAA'}
|
|
749
749
|
|
|
750
750
|
# Human-effort class for every A/AA criterion — what the HUMAN still does after
|
|
751
|
-
#
|
|
752
|
-
# and emitted in the evidence pack matrix.
|
|
753
|
-
# MIN (1-3 min): the agent verified with a measured signal; the human reads and confirms.
|
|
754
|
-
# MED (5-10 min): the agent prepares context; the human verifies in the browser.
|
|
755
|
-
# MAX (15-30 min): real interaction, real judgment, real tooling.
|
|
751
|
+
# The public evidence pack classifies the remaining review by effort.
|
|
756
752
|
# A not-flagged on a partially-covered criterion never earns a lower class:
|
|
757
753
|
# "the machine looked and found nothing" is weaker than a confirmation.
|
|
758
754
|
_EFFORT = {
|
|
@@ -813,8 +809,6 @@ _EFFORT = {
|
|
|
813
809
|
'4.1.3': ('MAX', 'fire each status message and listen for the announcement.'),
|
|
814
810
|
}
|
|
815
811
|
|
|
816
|
-
_EFFORT_MINUTES = {'MIN': (1, 3), 'MED': (5, 10), 'MAX': (15, 30)}
|
|
817
|
-
|
|
818
812
|
# Criterios A/AA que SOLO el modo renderizado puede medir (a11y_audit_dom):
|
|
819
813
|
# contraste computado, espaciado, tamaño de objetivo, foco, formularios vivos…
|
|
820
814
|
# El informe estático los declara en `not_measured` — un 100 estático jamás
|
|
@@ -1110,11 +1104,11 @@ def criterion(code=None, lang='en', signal=None):
|
|
|
1110
1104
|
|
|
1111
1105
|
|
|
1112
1106
|
def effort(code):
|
|
1113
|
-
"""Human
|
|
1107
|
+
"""Human review class and rationale for an A/AA criterion."""
|
|
1114
1108
|
if code not in _EFFORT:
|
|
1115
1109
|
return None
|
|
1116
1110
|
grade, why = _EFFORT[code]
|
|
1117
|
-
return {'class': grade, 'why': why
|
|
1111
|
+
return {'class': grade, 'why': why}
|
|
1118
1112
|
|
|
1119
1113
|
|
|
1120
1114
|
def main(argv):
|
package/a11y_toolkit/a11ydiff.py
CHANGED
|
@@ -142,7 +142,12 @@ def snapshot(url, output=None, auth_state=None, engine='chromium'):
|
|
|
142
142
|
nav = launch(p)
|
|
143
143
|
ctx = nav.new_context(storage_state=auth_state) if auth_state else nav
|
|
144
144
|
page = ctx.new_page() if auth_state else nav.new_page()
|
|
145
|
-
|
|
145
|
+
from .a11ydom import _NavigationHTTPError, _load_page
|
|
146
|
+
try:
|
|
147
|
+
_load_page(page, url, timeout=45000, wait_until='networkidle')
|
|
148
|
+
except _NavigationHTTPError as error:
|
|
149
|
+
nav.close()
|
|
150
|
+
return error.report()
|
|
146
151
|
elements = page.evaluate(COLLECTOR)
|
|
147
152
|
|
|
148
153
|
# Árbol de accesibilidad REAL (roles/nombres computados, lo que anuncia
|
|
@@ -177,6 +182,9 @@ _NOTE = {
|
|
|
177
182
|
|
|
178
183
|
|
|
179
184
|
def diff(a, b, lang='en'):
|
|
185
|
+
for capture in (a, b):
|
|
186
|
+
if 'error' in capture:
|
|
187
|
+
return {**capture, 'ok': False}
|
|
180
188
|
# multiset por firma: dos controles con el MISMO nombre (Edit por fila,
|
|
181
189
|
# botones-icono sin name) son dos elementos — un dict por clave los
|
|
182
190
|
# colapsaba y el diff decía «sin cambios» ante una duplicación
|
|
@@ -258,6 +266,9 @@ def main(argv):
|
|
|
258
266
|
except ImportError:
|
|
259
267
|
print(json.dumps({'error': 'Playwright not installed: pip install playwright && playwright install chromium'}))
|
|
260
268
|
return 1
|
|
269
|
+
if 'error' in d:
|
|
270
|
+
print(json.dumps(d, ensure_ascii=False))
|
|
271
|
+
return 1
|
|
261
272
|
print(json.dumps({'url': d['url'], 'elements': len(d['elements']),
|
|
262
273
|
'focus_steps': len(d['focus_order']), 'out': a.out},
|
|
263
274
|
ensure_ascii=False, indent=1))
|
|
@@ -266,8 +277,10 @@ def main(argv):
|
|
|
266
277
|
ja = json.load(f)
|
|
267
278
|
with open(a.b, encoding='utf-8') as f:
|
|
268
279
|
jb = json.load(f)
|
|
269
|
-
print(json.dumps(diff(ja, jb), ensure_ascii=False, indent=1))
|
|
270
280
|
verdict = diff(ja, jb)
|
|
281
|
+
print(json.dumps(verdict, ensure_ascii=False, indent=1))
|
|
282
|
+
if 'error' in verdict:
|
|
283
|
+
return 1
|
|
271
284
|
return 0 if verdict['ok'] else 2
|
|
272
285
|
|
|
273
286
|
|
|
@@ -8,8 +8,8 @@ accessibility findings:
|
|
|
8
8
|
|
|
9
9
|
1. Take an audit report
|
|
10
10
|
2. For each finding, re-check the signal against the live page
|
|
11
|
-
3. Findings that reproduce →
|
|
12
|
-
4. Findings that don't →
|
|
11
|
+
3. Findings that reproduce → status: confirmed
|
|
12
|
+
4. Findings that don't → status: rejected + reject_reason
|
|
13
13
|
|
|
14
14
|
This catches:
|
|
15
15
|
- False positives (the element changed, was fixed, or never existed)
|
|
@@ -26,47 +26,84 @@ import json
|
|
|
26
26
|
|
|
27
27
|
import sys
|
|
28
28
|
|
|
29
|
-
from .a11yaudit import audit_url, normalize_signal,
|
|
29
|
+
from .a11yaudit import (audit_conditions, audit_conditions_match, audit_url, normalize_signal,
|
|
30
|
+
page_identity, rendered_conditions_recorded)
|
|
30
31
|
|
|
31
32
|
|
|
32
|
-
def _recheck(url, expected_url,
|
|
33
|
-
"""
|
|
33
|
+
def _recheck(url, expected_url, timeout, lang, color_scheme=None, auth_state=None, browser='auto'):
|
|
34
|
+
"""Obtain a successful measurement of the same page."""
|
|
34
35
|
if color_scheme is None:
|
|
35
36
|
fresh = audit_url(url, timeout=timeout, lang=lang)
|
|
36
37
|
else:
|
|
37
38
|
from .a11ydom import audit_dom_url
|
|
38
|
-
fresh = audit_dom_url(url, timeout=timeout, lang=lang, color_scheme=color_scheme
|
|
39
|
+
fresh = audit_dom_url(url, timeout=timeout, lang=lang, color_scheme=color_scheme,
|
|
40
|
+
auth_state=auth_state, browser=browser)
|
|
39
41
|
if 'error' in fresh:
|
|
40
|
-
return
|
|
42
|
+
return None, fresh['error']
|
|
41
43
|
if page_identity(fresh.get('url')) != page_identity(expected_url):
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
return None, ('La reauditoría terminó en una URL distinta de la del informe original.'
|
|
45
|
+
if lang == 'es' else
|
|
46
|
+
'The re-audit ended at a different URL from the original report.')
|
|
47
|
+
return fresh, None
|
|
45
48
|
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
|
|
50
|
+
def _finding_key(finding):
|
|
51
|
+
return (normalize_signal(finding.get('signal', '')),
|
|
52
|
+
(finding.get('criterion') or '').split(' ', 1)[0])
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _location_evidence(finding):
|
|
56
|
+
paths = tuple(sorted(set(finding.get('paths') or [])))
|
|
57
|
+
if paths:
|
|
58
|
+
count = finding.get('count')
|
|
59
|
+
return paths, count == len(paths) if count is not None else len(paths) < 5
|
|
60
|
+
return (), False
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _classify_findings(previous, current, lang):
|
|
64
|
+
current = [dict(finding) for finding in current]
|
|
65
|
+
by_key = {}
|
|
66
|
+
for finding in current:
|
|
67
|
+
by_key.setdefault(_finding_key(finding), []).append(finding)
|
|
68
|
+
historical = []
|
|
69
|
+
rejected = ('El hallazgo anterior ya no aparece en la nueva auditoría de la página.'
|
|
48
70
|
if lang == 'es' else
|
|
49
|
-
'
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
71
|
+
'The earlier finding no longer appears in the new audit of the page.')
|
|
72
|
+
for old in previous:
|
|
73
|
+
if old.get('status') == 'rejected' or old.get('disprover_status') == 'rejected':
|
|
74
|
+
continue
|
|
75
|
+
key = _finding_key(old)
|
|
76
|
+
candidates = by_key.get(key, [])
|
|
77
|
+
paths, complete = _location_evidence(old)
|
|
78
|
+
locations = [_location_evidence(row) for row in candidates]
|
|
79
|
+
if not candidates or (complete and all(known and not set(paths).intersection(new_paths)
|
|
80
|
+
for new_paths, known in locations)):
|
|
81
|
+
historical.append(dict(old, status='rejected', reject_reason=rejected))
|
|
82
|
+
elif len(candidates) == 1 and ((complete and locations[0] == (paths, True))
|
|
83
|
+
or (not paths and not locations[0][0]
|
|
84
|
+
and old.get('examples') == candidates[0].get('examples')
|
|
85
|
+
and old.get('count') == candidates[0].get('count'))):
|
|
86
|
+
candidates[0]['status'] = 'confirmed'
|
|
57
87
|
else:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
88
|
+
historical.append(dict(old, disprover_status='not-rechecked'))
|
|
89
|
+
return current, historical
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _unverified(report, reason):
|
|
93
|
+
findings = [dict(h, disprover_status='not-rechecked') for h in report.get('findings', [])]
|
|
94
|
+
return dict(report, findings=findings, disprover={'executed': False, 'reason': reason})
|
|
62
95
|
|
|
63
96
|
|
|
64
|
-
def disprove(url, report=None, timeout=30, lang='en'):
|
|
97
|
+
def disprove(url, report=None, timeout=30, lang='en', auth_state=None):
|
|
65
98
|
"""Audit a URL and disprove findings, or verify an existing report.
|
|
66
99
|
|
|
67
|
-
|
|
100
|
+
Return the fresh measurement and the outcomes of prior findings."""
|
|
68
101
|
if report is None:
|
|
69
|
-
|
|
102
|
+
if auth_state:
|
|
103
|
+
from .a11ydom import audit_dom_url
|
|
104
|
+
report = audit_dom_url(url, timeout=timeout, lang=lang, auth_state=auth_state)
|
|
105
|
+
else:
|
|
106
|
+
report = audit_url(url, timeout=timeout, lang=lang)
|
|
70
107
|
if report.get('error'):
|
|
71
108
|
return report
|
|
72
109
|
mode_name = report.get('mode', 'static')
|
|
@@ -90,59 +127,52 @@ def disprove(url, report=None, timeout=30, lang='en'):
|
|
|
90
127
|
return res
|
|
91
128
|
|
|
92
129
|
if mode_name == 'static':
|
|
93
|
-
|
|
130
|
+
if auth_state:
|
|
131
|
+
return _unverified(report, 'El informe estático no admite una sesión de navegador.'
|
|
132
|
+
if lang == 'es' else
|
|
133
|
+
'The static report does not support a browser session.')
|
|
134
|
+
fresh, err = _recheck(url, expected_url, timeout, lang)
|
|
94
135
|
elif mode_name == 'rendered':
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
verified, err = _recheck(url, expected_url, findings, timeout, lang, color_scheme=scheme)
|
|
136
|
+
conditions = audit_conditions(report)
|
|
137
|
+
if not rendered_conditions_recorded(conditions):
|
|
138
|
+
return _unverified(report, ('El informe no registra todas las condiciones de captura. '
|
|
139
|
+
'Vuelve a auditar con a11y_audit_dom.' if lang == 'es' else
|
|
140
|
+
'Capture conditions are missing. Re-audit with a11y_audit_dom.'))
|
|
141
|
+
if bool(auth_state) != conditions['authenticated']:
|
|
142
|
+
return _unverified(report, ('La reauditoría necesita el mismo tipo de sesión que la captura. '
|
|
143
|
+
'Usa auth_state para una captura con sesión.' if lang == 'es' else
|
|
144
|
+
'Re-audit with the same session type as the capture. '
|
|
145
|
+
'Use auth_state for an authenticated capture.'))
|
|
146
|
+
scheme = conditions['color_scheme']
|
|
147
|
+
fresh, err = _recheck(url, expected_url, timeout, lang, color_scheme=scheme,
|
|
148
|
+
auth_state=auth_state, browser=conditions['browser'])
|
|
149
|
+
if not err and not audit_conditions_match(mode_name, conditions, audit_conditions(fresh)):
|
|
150
|
+
return _unverified(report, 'La reauditoría cambió las condiciones de captura.'
|
|
151
|
+
if lang == 'es' else 'Capture conditions changed during re-audit.')
|
|
112
152
|
else:
|
|
113
153
|
# no re-verifier for this mode: report not-rechecked, never a proxy
|
|
114
154
|
# audit (a keyboard finding must not vanish just because the wrong
|
|
115
155
|
# method ran). `rejected` is reserved for an equivalent check that
|
|
116
156
|
# actually disproves the original finding.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
res['disprover'] = {'executed': False,
|
|
120
|
-
'reason': f"no re-verifier for mode {mode_name!r}"}
|
|
121
|
-
return res
|
|
157
|
+
return _unverified(report, (f'No hay reauditoría para el modo {mode_name!r}.' if lang == 'es'
|
|
158
|
+
else f'No re-verifier for mode {mode_name!r}.'))
|
|
122
159
|
|
|
123
160
|
if err:
|
|
124
161
|
return dict(report, error=err, disprover={'executed': False, 'reason': err})
|
|
125
162
|
|
|
126
|
-
|
|
127
|
-
|
|
163
|
+
current, historical = _classify_findings(findings, fresh['findings'], lang)
|
|
164
|
+
rejected = [h for h in historical if h.get('status') == 'rejected']
|
|
165
|
+
result = dict(fresh, findings=current + rejected, score_original=report.get('score'))
|
|
128
166
|
result['disprover'] = {
|
|
129
167
|
'executed': True,
|
|
130
|
-
'confirmed': sum(
|
|
131
|
-
'rejected':
|
|
132
|
-
'
|
|
133
|
-
|
|
134
|
-
'
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
from .a11yaudit import compute_score
|
|
139
|
-
solo_confirmed = [h for h in verified if h.get('status') == 'confirmed']
|
|
140
|
-
result['score_original'] = report.get('score')
|
|
141
|
-
result['score'] = compute_score(solo_confirmed)
|
|
142
|
-
result['summary'] = {
|
|
143
|
-
'high': sum(1 for h in solo_confirmed if h['severity'] == 'high'),
|
|
144
|
-
'medium': sum(1 for h in solo_confirmed if h['severity'] == 'medium'),
|
|
145
|
-
'low': sum(1 for h in solo_confirmed if h['severity'] == 'low'),
|
|
168
|
+
'confirmed': sum(h.get('status') == 'confirmed' for h in current),
|
|
169
|
+
'rejected': len(rejected),
|
|
170
|
+
'previous_findings': historical,
|
|
171
|
+
'note': ('La puntuación y la cobertura corresponden a la nueva auditoría. '
|
|
172
|
+
'Se conservan los descartes y las coincidencias dudosas para su revisión.'
|
|
173
|
+
if lang == 'es' else
|
|
174
|
+
'Score and coverage describe the fresh audit. Rejected findings '
|
|
175
|
+
'and ambiguous historical matches are retained for review.'),
|
|
146
176
|
}
|
|
147
177
|
return result
|
|
148
178
|
|
|
@@ -151,6 +181,7 @@ def main(argv):
|
|
|
151
181
|
ap = argparse.ArgumentParser(description='Disprover: re-verify findings against the live page')
|
|
152
182
|
ap.add_argument('--url', required=True, help='URL to audit and disprove')
|
|
153
183
|
ap.add_argument('--file', help='existing report JSON (optional; if absent, audits first)')
|
|
184
|
+
ap.add_argument('--auth-state', help='local Playwright session for the original capture')
|
|
154
185
|
ap.add_argument('--lang', default='en', choices=['en', 'es'])
|
|
155
186
|
ap.add_argument('--timeout', type=int, default=30)
|
|
156
187
|
ap.add_argument('-o', '--out', help='save result JSON here')
|
|
@@ -159,7 +190,7 @@ def main(argv):
|
|
|
159
190
|
if a.file:
|
|
160
191
|
with open(a.file, encoding='utf-8') as f:
|
|
161
192
|
report = json.load(f)
|
|
162
|
-
res = disprove(a.url, report=report, timeout=a.timeout, lang=a.lang)
|
|
193
|
+
res = disprove(a.url, report=report, timeout=a.timeout, lang=a.lang, auth_state=a.auth_state)
|
|
163
194
|
if 'error' in res:
|
|
164
195
|
print(json.dumps(res))
|
|
165
196
|
return 1
|