@kinti/a11y-toolkit 5.25.2 → 5.27.0
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 +31 -4
- package/a11y_toolkit/a11yact.py +9 -1
- package/a11y_toolkit/a11yannotate.py +185 -0
- package/a11y_toolkit/a11yaudit.py +903 -186
- package/a11y_toolkit/a11ybadge.py +24 -17
- package/a11y_toolkit/a11ybudget.py +145 -1
- package/a11y_toolkit/a11ycorpus.py +58 -24
- package/a11y_toolkit/a11ycrit.py +110 -53
- package/a11y_toolkit/a11ydiff.py +104 -34
- package/a11y_toolkit/a11ydisprove.py +15 -8
- package/a11y_toolkit/a11ydocx.py +8 -6
- package/a11y_toolkit/a11ydom.py +451 -96
- package/a11y_toolkit/a11yen301549.py +147 -0
- package/a11y_toolkit/a11yengines.py +157 -0
- package/a11y_toolkit/a11yevidence.py +182 -36
- package/a11y_toolkit/a11yfix.py +131 -52
- package/a11y_toolkit/a11yinit.py +30 -5
- package/a11y_toolkit/a11yjourney.py +110 -4
- package/a11y_toolkit/a11yledger.py +119 -12
- package/a11y_toolkit/a11ylocate.py +247 -0
- package/a11y_toolkit/a11yopenacr.py +28 -7
- package/a11y_toolkit/a11ypatches.py +154 -0
- package/a11y_toolkit/a11ypatterns.py +344 -0
- package/a11y_toolkit/a11ypdf.py +109 -53
- package/a11y_toolkit/a11yrgaa.py +60 -0
- package/a11y_toolkit/a11yroute.py +34 -12
- package/a11y_toolkit/a11ysarif.py +70 -21
- package/a11y_toolkit/a11yscope.py +296 -0
- package/a11y_toolkit/a11yscroll.py +7 -5
- package/a11y_toolkit/a11ystatement.py +30 -6
- package/a11y_toolkit/a11ytrace.py +293 -0
- package/a11y_toolkit/a11yvalidate.py +21 -15
- package/a11y_toolkit/a11yvpat.py +54 -11
- package/a11y_toolkit/a11yvtt.py +22 -6
- package/a11y_toolkit/a11ywiz.py +121 -0
- package/a11y_toolkit/contrast.py +62 -24
- package/a11y_toolkit/locales/en.json +222 -24
- package/a11y_toolkit/locales/es.json +223 -25
- package/a11y_toolkit/rgaa.json +2661 -0
- package/a11y_toolkit/server.py +247 -59
- package/package.json +2 -2
- package/a11y_toolkit/a11yplan.py +0 -214
- package/a11y_toolkit/a11ywcagem.py +0 -237
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""EN 301 549 V4.1.1 (2026) — the clause map and the standard metadata.
|
|
3
|
+
|
|
4
|
+
EN 301 549 is the European harmonized ICT accessibility standard (the EAA's
|
|
5
|
+
technical backbone, and — since 2026 — the basis of Canada's ICT
|
|
6
|
+
accessibility standard). Its clauses 9 (web), 10 (non-web documents) and
|
|
7
|
+
11 (non-web software) each carry the WCAG success criteria under the SAME
|
|
8
|
+
numbering: SC 1.4.3 is clause 9.1.4.3 for web, 10.1.4.3 for documents and
|
|
9
|
+
11.1.4.3 for software.
|
|
10
|
+
|
|
11
|
+
That numbering identity was not assumed — it was verified against the
|
|
12
|
+
Government of Canada CIO applicability wizard built on EN 301 549 V4.1.1
|
|
13
|
+
(2026): all 55 WCAG 2.2 A/AA criteria carry their mirrored clause number in
|
|
14
|
+
clauses 9, 10 AND 11 (55/55 each). AAA is NOT claimed: clause 9 carries only
|
|
15
|
+
the AAA criteria the standard itself modifies, and A/AA is the conformance
|
|
16
|
+
level the toolkit evaluates.
|
|
17
|
+
|
|
18
|
+
The families beyond the WCAG mirror (5, 6, 7, 8, 12, 13) are real
|
|
19
|
+
applicability territory — closed functionality, RTT, hardware, relay — that
|
|
20
|
+
no HTML audit can answer. They appear here as honest rows for the scope
|
|
21
|
+
engine (a11yscope), never as something this toolkit evaluates. For software
|
|
22
|
+
targets the same honesty applies to the EN-only sub-clauses of clause 11
|
|
23
|
+
itself (11.5 interoperability with AT, 11.6 documented accessibility usage,
|
|
24
|
+
11.7 user preferences): surfaced as human-review rows, never evaluated.
|
|
25
|
+
|
|
26
|
+
No network, no third parties: this module is pure data.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
# Clause prefix per ICT target (EN 301 549 V4.1.1 structure).
|
|
30
|
+
_CLAUSE_PREFIX = {'web': '9', 'documents': '10', 'software': '11'}
|
|
31
|
+
|
|
32
|
+
STANDARD_NAME = 'EN 301 549 V4.1.1 (2026)'
|
|
33
|
+
|
|
34
|
+
# Targets the toolkit can map findings for. 'web' covers the HTML audits
|
|
35
|
+
# (static/rendered), 'documents' the PDF/DOCX screening, 'software' non-web
|
|
36
|
+
# UIs audited as HTML prototypes.
|
|
37
|
+
TARGETS = tuple(sorted(_CLAUSE_PREFIX))
|
|
38
|
+
|
|
39
|
+
# Families outside the WCAG mirror. status: machine proposal only where the
|
|
40
|
+
# product shape itself decides (a web-only product cannot carry RTT/hardware
|
|
41
|
+
# clauses); everything else is a human applicability question. Titles are
|
|
42
|
+
# the standard's own chapter titles (verified against the V4.1.1 wizard).
|
|
43
|
+
FAMILIES = (
|
|
44
|
+
{'family': '5', 'key': 'generic'},
|
|
45
|
+
{'family': '6', 'key': 'rtt'},
|
|
46
|
+
{'family': '7', 'key': 'video_capabilities'},
|
|
47
|
+
{'family': '8', 'key': 'hardware'},
|
|
48
|
+
{'family': '12', 'key': 'products_info'},
|
|
49
|
+
{'family': '13', 'key': 'relay_emergency'},
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# EN-only sub-clauses of clause 11 (software) beyond the WCAG mirror
|
|
53
|
+
# (11.1-11.4 mirror the SC by principle): 11.5-11.7. Titles are the
|
|
54
|
+
# standard's own clause titles (verified against the V4.1.1 table of
|
|
55
|
+
# contents). These are applicability rows only — the toolkit does NOT
|
|
56
|
+
# evaluate them and never proposes on them (unlike families 6/7/8 for web,
|
|
57
|
+
# the product's shape does not decide: a human answers).
|
|
58
|
+
SOFTWARE_CLAUSES = ('11.5', '11.6', '11.7')
|
|
59
|
+
|
|
60
|
+
# Module-level bilingual texts (the families live in locales; these clauses
|
|
61
|
+
# postdate them — same pattern as a11yaudit's _labels dicts)
|
|
62
|
+
_SOFTWARE_CLAUSE_TEXTS = {
|
|
63
|
+
'en': {
|
|
64
|
+
'11.5': ('Interoperability with assistive technology',
|
|
65
|
+
'Name, role, value and states exposed through the platform '
|
|
66
|
+
'accessibility services can only be verified with the software '
|
|
67
|
+
'running alongside a real assistive technology — human review.'),
|
|
68
|
+
'11.6': ('Documented accessibility usage',
|
|
69
|
+
'The software must document its accessibility features; a '
|
|
70
|
+
'documentation question no markup audit answers — human review.'),
|
|
71
|
+
'11.7': ('User preferences',
|
|
72
|
+
'Respecting the platform user-preference settings requires the '
|
|
73
|
+
'software running on each platform — human review.'),
|
|
74
|
+
},
|
|
75
|
+
'es': {
|
|
76
|
+
'11.5': ('Interoperabilidad con productos de apoyo',
|
|
77
|
+
'Exponer nombre, rol, valor y estados vía los servicios de '
|
|
78
|
+
'accesibilidad de la plataforma solo puede verificarse con el '
|
|
79
|
+
'software corriendo junto a un producto de apoyo real — '
|
|
80
|
+
'revisión humana.'),
|
|
81
|
+
'11.6': ('Uso documentado de la accesibilidad',
|
|
82
|
+
'El software debe documentar sus funciones de accesibilidad; '
|
|
83
|
+
'una pregunta de documentación que ninguna auditoría de '
|
|
84
|
+
'marcado responde — revisión humana.'),
|
|
85
|
+
'11.7': ('Preferencias del usuario',
|
|
86
|
+
'Respetar las preferencias del usuario de la plataforma exige '
|
|
87
|
+
'el software corriendo en cada plataforma — revisión humana.'),
|
|
88
|
+
},
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def clause_for(code, target='web'):
|
|
93
|
+
"""'1.4.3' + target → '9.1.4.3'. None si el código no es un SC válido.
|
|
94
|
+
|
|
95
|
+
Acepta la forma con nombre ('1.4.3 Contrast (Minimum)') que viaja en los
|
|
96
|
+
hallazgos y en la matriz del pack: solo el primer token es el código.
|
|
97
|
+
"""
|
|
98
|
+
token = str(code).split(' ')[0] if code is not None else ''
|
|
99
|
+
parts = token.split('.')
|
|
100
|
+
if len(parts) != 3 or not all(p.isdigit() for p in parts):
|
|
101
|
+
return None
|
|
102
|
+
prefix = _CLAUSE_PREFIX.get(target)
|
|
103
|
+
return f'{prefix}.{token}' if prefix else None
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def target_for_mode(mode):
|
|
107
|
+
"""Modo del informe → target EN: la web es 9.x, los documentos 10.x."""
|
|
108
|
+
return 'documents' if mode in ('pdf', 'docx') else 'web'
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def family_rows(lang='en'):
|
|
112
|
+
"""Filas de familias EN para el scope: número, título y nota del estándar
|
|
113
|
+
en el idioma pedido. El ESTADO lo decide el llamador (a11yscope): aquí
|
|
114
|
+
solo vive el texto, no la aplicabilidad."""
|
|
115
|
+
from .a11yi18n import pack
|
|
116
|
+
tx = pack(lang).get('scope', {}).get('families', {}) or {}
|
|
117
|
+
rows = []
|
|
118
|
+
for fam in FAMILIES:
|
|
119
|
+
entry = tx.get(fam['key'], {}) or {}
|
|
120
|
+
row = {'family': fam['family'],
|
|
121
|
+
'title': entry.get('title') or fam['key']}
|
|
122
|
+
if entry.get('note'):
|
|
123
|
+
row['note'] = entry['note']
|
|
124
|
+
rows.append(row)
|
|
125
|
+
return rows
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def software_clause_rows(lang='en'):
|
|
129
|
+
"""Filas de las cláusulas EN-only de software (11.5-11.7): número, título
|
|
130
|
+
bilingüe y nota honesta. Igual que family_rows: aquí solo vive el texto
|
|
131
|
+
— el estado (revisión humana, no evaluado por este motor) lo pone el
|
|
132
|
+
llamador (a11yscope, target software)."""
|
|
133
|
+
texts = _SOFTWARE_CLAUSE_TEXTS.get(lang) or _SOFTWARE_CLAUSE_TEXTS['en']
|
|
134
|
+
return [{'clause': cl, 'title': texts[cl][0], 'note': texts[cl][1]}
|
|
135
|
+
for cl in SOFTWARE_CLAUSES]
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def standard_block(target='web', lang='en'):
|
|
139
|
+
"""Bloque 'standard' para informes audit --standard en301549."""
|
|
140
|
+
from .a11yi18n import pack
|
|
141
|
+
tx = pack(lang).get('scope', {}) or {}
|
|
142
|
+
return {
|
|
143
|
+
'name': STANDARD_NAME,
|
|
144
|
+
'target': target,
|
|
145
|
+
'clause_prefix': _CLAUSE_PREFIX[target],
|
|
146
|
+
'mapping_note': tx.get('mapping_note'),
|
|
147
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""a11y_engines — cross-engine behavioral matrix (the same page, several engines).
|
|
3
|
+
|
|
4
|
+
Cross-industry translation of the cross-browser accessibility lab: teams run
|
|
5
|
+
static scans but cannot verify that an accessible task BEHAVES the same in
|
|
6
|
+
real engine configurations. This module captures the a11y snapshot
|
|
7
|
+
(interactives, real tab order, computed accessibility tree) of ONE URL in
|
|
8
|
+
SEVERAL browser engines and diffs every pair. What diverges between engines
|
|
9
|
+
is exactly what a single-engine audit can never see: elements that only exist
|
|
10
|
+
in one engine's DOM, tab order that forks, names that engines compute
|
|
11
|
+
differently.
|
|
12
|
+
|
|
13
|
+
Honesty (what this is and is not):
|
|
14
|
+
- Elements and focus order come from the DOM (spec-stable across engines):
|
|
15
|
+
divergence there is a REAL behavioral finding and blocks (ok=false).
|
|
16
|
+
- The accessibility tree is engine-computed: divergence is reported as
|
|
17
|
+
`tree_changed` per pair but does NOT block — different engines legitimately
|
|
18
|
+
compute some roles/names differently. It is the pointer for what a screen
|
|
19
|
+
reader on that platform would announce; judge it, don't gate on it.
|
|
20
|
+
- Engines must be installed locally (playwright install firefox webkit);
|
|
21
|
+
an engine that fails to launch is reported in engines_failed, never silently.
|
|
22
|
+
|
|
23
|
+
CLI (infrastructure, not a tool — D17, same tier as corpus/mutants):
|
|
24
|
+
a11yengines.py https://web # the 3 default engines
|
|
25
|
+
a11yengines.py https://web --engines chromium,firefox # your matrix
|
|
26
|
+
a11yengines.py https://web --auth-state session.json -o m.json
|
|
27
|
+
Exit: 0 no divergences / 2 behavioral divergences / 1 config error
|
|
28
|
+
(playwright missing or fewer than 2 engines launched).
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
import argparse
|
|
32
|
+
import itertools
|
|
33
|
+
import json
|
|
34
|
+
import sys
|
|
35
|
+
from datetime import datetime, timezone
|
|
36
|
+
|
|
37
|
+
from . import a11ydiff
|
|
38
|
+
|
|
39
|
+
ENGINES = ('chromium', 'firefox', 'webkit', 'chrome', 'msedge')
|
|
40
|
+
DEFAULT_ENGINES = ('chromium', 'firefox', 'webkit')
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _capture(url, engine, auth_state=None):
|
|
44
|
+
"""One engine's snapshot; raises on engine failure (caller records it)."""
|
|
45
|
+
return a11ydiff.snapshot(url, engine=engine, auth_state=auth_state)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _pair_entry(name_a, name_b, sa, sb):
|
|
49
|
+
d = a11ydiff.diff(sa, sb)
|
|
50
|
+
# behavioral verdict: DOM-level facts only — the tree is informational
|
|
51
|
+
# across engines (engines compute some roles/names differently by design)
|
|
52
|
+
focus = d['focus']
|
|
53
|
+
ok = not (d['added'] or d['removed'] or d['renamed']
|
|
54
|
+
or focus['removed'] or focus['reordered'])
|
|
55
|
+
return {
|
|
56
|
+
'engines': [name_a, name_b],
|
|
57
|
+
'ok': ok,
|
|
58
|
+
'added': d['added'],
|
|
59
|
+
'removed': d['removed'],
|
|
60
|
+
'renamed': d['renamed'],
|
|
61
|
+
'focus': {'removed': focus['removed'], 'added': focus['added'],
|
|
62
|
+
'reordered': focus['reordered'],
|
|
63
|
+
'first_divergence': focus['first_divergence']},
|
|
64
|
+
'tree_changed': bool(d['tree']['changed']),
|
|
65
|
+
'tree_first_differences': (d['tree']['first_differences'] or [])[:3],
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def matrix(url, engines=None, auth_state=None, capture=None):
|
|
70
|
+
"""One URL → per-engine snapshots → pairwise divergence report."""
|
|
71
|
+
engines = tuple(engines or DEFAULT_ENGINES)
|
|
72
|
+
capture = capture or _capture
|
|
73
|
+
|
|
74
|
+
ok, failed, snaps = [], [], {}
|
|
75
|
+
for name in engines:
|
|
76
|
+
if name not in ENGINES:
|
|
77
|
+
failed.append({'engine': name, 'error': f'unknown engine (known: {", ".join(ENGINES)})'})
|
|
78
|
+
continue
|
|
79
|
+
try:
|
|
80
|
+
snaps[name] = capture(url, name, auth_state)
|
|
81
|
+
s = snaps[name]
|
|
82
|
+
ok.append({'engine': name, 'elements': len(s.get('elements', [])),
|
|
83
|
+
'focus_steps': len(s.get('focus_order', [])),
|
|
84
|
+
'tree': 'accessibility_tree' in s or 'arbol_accesible' in s})
|
|
85
|
+
except ImportError:
|
|
86
|
+
# playwright ausente NO es «un motor muerto»: es un error de
|
|
87
|
+
# instalación que mata TODA la matriz — relanzar para que main
|
|
88
|
+
# aconseje `pip install playwright` (no `playwright install …`,
|
|
89
|
+
# el consejo equivocado cuando falta el paquete pip) y salga 1
|
|
90
|
+
raise
|
|
91
|
+
except Exception as e: # noqa: BLE001 — one dead engine must not kill the matrix
|
|
92
|
+
msg = str(e).splitlines()[0][:200] if str(e) else e.__class__.__name__
|
|
93
|
+
failed.append({'engine': name, 'error': msg})
|
|
94
|
+
|
|
95
|
+
pairs = [_pair_entry(a, b, snaps[a], snaps[b])
|
|
96
|
+
for a, b in itertools.combinations(sorted(snaps), 2)]
|
|
97
|
+
divergences = [p for p in pairs if not p['ok']]
|
|
98
|
+
|
|
99
|
+
enough = len(snaps) >= 2
|
|
100
|
+
report = {
|
|
101
|
+
'mode': 'engines',
|
|
102
|
+
'url': url,
|
|
103
|
+
'ts': datetime.now(timezone.utc).isoformat(),
|
|
104
|
+
'engines_ok': ok,
|
|
105
|
+
'engines_failed': failed,
|
|
106
|
+
'pairs': pairs,
|
|
107
|
+
'divergences': divergences,
|
|
108
|
+
'ok': bool(enough and not divergences),
|
|
109
|
+
'insufficient_engines': not enough,
|
|
110
|
+
'limits': ('elements and focus order are DOM facts: divergence blocks. '
|
|
111
|
+
'The computed accessibility tree is engine-specific: '
|
|
112
|
+
'tree_changed is informational, not a gate. A pass is '
|
|
113
|
+
'engine-pair evidence for THIS url at THIS time — not a '
|
|
114
|
+
'conformance claim.'),
|
|
115
|
+
}
|
|
116
|
+
if not enough:
|
|
117
|
+
report['note'] = ('fewer than 2 engines launched: install them with '
|
|
118
|
+
'`playwright install firefox webkit` — a matrix of one '
|
|
119
|
+
'engine cannot see cross-engine behavior')
|
|
120
|
+
return report
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def main(argv):
|
|
124
|
+
ap = argparse.ArgumentParser(description=__doc__)
|
|
125
|
+
ap.add_argument('url')
|
|
126
|
+
ap.add_argument('--engines', default=','.join(DEFAULT_ENGINES),
|
|
127
|
+
help=f'comma-separated engines (default: {",".join(DEFAULT_ENGINES)})')
|
|
128
|
+
ap.add_argument('--auth-state', help='Playwright storage_state JSON (session)')
|
|
129
|
+
ap.add_argument('-o', '--out', help='write the report here (default: stdout)')
|
|
130
|
+
a = ap.parse_args(argv)
|
|
131
|
+
|
|
132
|
+
engines = [e.strip() for e in a.engines.split(',') if e.strip()]
|
|
133
|
+
capture = _capture
|
|
134
|
+
try:
|
|
135
|
+
report = matrix(a.url, engines=engines, auth_state=a.auth_state,
|
|
136
|
+
capture=capture)
|
|
137
|
+
except ImportError:
|
|
138
|
+
print(json.dumps({'error': 'Playwright not installed: '
|
|
139
|
+
'pip install playwright && playwright install chromium'}))
|
|
140
|
+
return 1
|
|
141
|
+
out = json.dumps(report, ensure_ascii=False, indent=1)
|
|
142
|
+
if a.out:
|
|
143
|
+
with open(a.out, 'w', encoding='utf-8') as f:
|
|
144
|
+
f.write(out + '\n')
|
|
145
|
+
report = dict(report)
|
|
146
|
+
report['pairs'] = [{'engines': p['engines'], 'ok': p['ok']} for p in report['pairs']]
|
|
147
|
+
print(json.dumps({'url': a.url, 'engines_ok': [e['engine'] for e in report['engines_ok']],
|
|
148
|
+
'pairs': report['pairs'], 'out': a.out}, ensure_ascii=False))
|
|
149
|
+
else:
|
|
150
|
+
print(out)
|
|
151
|
+
if report.get('insufficient_engines'):
|
|
152
|
+
return 1
|
|
153
|
+
return 0 if report.get('ok') else 2
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
if __name__ == '__main__':
|
|
157
|
+
sys.exit(main(sys.argv[1:]))
|
|
@@ -29,6 +29,7 @@ import hashlib
|
|
|
29
29
|
import json
|
|
30
30
|
|
|
31
31
|
from .a11yaudit import normalize_report # noqa: E402 (compat 5.10)
|
|
32
|
+
from .a11ycrit import _EFFORT_MINUTES # single source: a11ycrit prices the classes
|
|
32
33
|
import sys
|
|
33
34
|
from datetime import datetime, timezone
|
|
34
35
|
|
|
@@ -43,19 +44,89 @@ MANUAL_AA = [
|
|
|
43
44
|
]
|
|
44
45
|
|
|
45
46
|
_STATES = ('automated-fail', 'automated-review', 'not-flagged', 'manual-only',
|
|
46
|
-
'agent-verified', 'not-run')
|
|
47
|
+
'agent-verified', 'not-run', 'not-applicable')
|
|
47
48
|
|
|
48
49
|
|
|
49
50
|
def _canon(obj):
|
|
50
51
|
return json.dumps(obj, ensure_ascii=False, sort_keys=True, separators=(',', ':'))
|
|
51
52
|
|
|
52
53
|
|
|
54
|
+
def apply_scope(pack, scope, lang='en'):
|
|
55
|
+
"""Aplica un a11y-scope/1 a un pack YA construido (VPAT/OpenACR con
|
|
56
|
+
pack + scope): las exclusiones CONFIRMADAS por humano pasan sus filas a
|
|
57
|
+
not-applicable con su razón. Las propuestas jamás. Devuelve una copia —
|
|
58
|
+
el sha256 del pack original queda intacto (el sello sella el pack; el
|
|
59
|
+
scope viaja aparte con su propio sello)."""
|
|
60
|
+
from . import a11yi18n
|
|
61
|
+
tx = a11yi18n.pack(lang).get('evidence', {})
|
|
62
|
+
note_base = tx.get('not_applicable_note') or a11yi18n.pack('en')['evidence']['not_applicable_note']
|
|
63
|
+
excluded = {}
|
|
64
|
+
rows = scope.get('criteria') if isinstance(scope.get('criteria'), list) else []
|
|
65
|
+
for row in rows:
|
|
66
|
+
if not isinstance(row, dict) or row.get('status') != 'excluded':
|
|
67
|
+
continue
|
|
68
|
+
crit = row.get('criterion')
|
|
69
|
+
if not isinstance(crit, str) or not crit:
|
|
70
|
+
continue
|
|
71
|
+
reason = row.get('reason')
|
|
72
|
+
excluded[crit.split(' ')[0]] = reason if isinstance(reason, str) else ''
|
|
73
|
+
out = dict(pack)
|
|
74
|
+
criteria = []
|
|
75
|
+
for row in pack.get('criteria', []):
|
|
76
|
+
code = (row.get('criterion') or '').split(' ')[0] if isinstance(row, dict) else ''
|
|
77
|
+
if code in excluded:
|
|
78
|
+
note = note_base + (f' {excluded[code]}' if excluded[code] else '')
|
|
79
|
+
row = {**row, 'status': 'not-applicable', 'note': note,
|
|
80
|
+
'scope_reason': excluded[code] or None}
|
|
81
|
+
row.pop('effort', None) # fuera de alcance: cero trabajo humano
|
|
82
|
+
criteria.append(row)
|
|
83
|
+
out['criteria'] = criteria
|
|
84
|
+
out['summary'] = {e: sum(1 for m in criteria if m.get('status') == e) for e in _STATES}
|
|
85
|
+
# the scope changes what REMAINS to do: effort_pending and manual_pending
|
|
86
|
+
# must describe the resulting matrix (excluded = zero pending human
|
|
87
|
+
# effort), not the pre-scope pack — otherwise the human is overcharged
|
|
88
|
+
# and criteria already not-applicable keep being named as pending
|
|
89
|
+
out['effort_pending'] = _pending_effort(
|
|
90
|
+
criteria, tx.get('manual_remaining')
|
|
91
|
+
or a11yi18n.pack('en')['evidence']['manual_remaining'])
|
|
92
|
+
out['manual_pending'] = [m['criterion'] for m in criteria
|
|
93
|
+
if m.get('status') == 'manual-only']
|
|
94
|
+
return out
|
|
95
|
+
|
|
96
|
+
|
|
53
97
|
def _sha256(obj):
|
|
54
98
|
return hashlib.sha256(_canon(obj).encode('utf-8')).hexdigest()
|
|
55
99
|
|
|
56
100
|
|
|
101
|
+
def _pending_effort(matrix, note):
|
|
102
|
+
"""Remaining human review, in minutes: MIN/MED/MAX per class summed over
|
|
103
|
+
every row a human still has to touch (agent-verified excluded; rows out
|
|
104
|
+
of applicability scope carry no effort). Shared by build_pack AND
|
|
105
|
+
apply_scope — the priced scope must always describe the CURRENT matrix,
|
|
106
|
+
never the pre-scope one."""
|
|
107
|
+
pend = {}
|
|
108
|
+
for m in matrix:
|
|
109
|
+
if m.get('status') == 'agent-verified':
|
|
110
|
+
continue
|
|
111
|
+
ef = m.get('effort')
|
|
112
|
+
if ef:
|
|
113
|
+
lo, hi = _EFFORT_MINUTES[ef['class']]
|
|
114
|
+
pend.setdefault(ef['class'], [0, 0])
|
|
115
|
+
pend[ef['class']][0] += lo
|
|
116
|
+
pend[ef['class']][1] += hi
|
|
117
|
+
return {
|
|
118
|
+
'by_class': {k: {'criteria': sum(1 for m in matrix
|
|
119
|
+
if m.get('status') != 'agent-verified'
|
|
120
|
+
and m.get('effort', {}).get('class') == k),
|
|
121
|
+
'minutes': v}
|
|
122
|
+
for k, v in sorted(pend.items())},
|
|
123
|
+
'total_minutes': [sum(v[0] for v in pend.values()), sum(v[1] for v in pend.values())],
|
|
124
|
+
'note': note,
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
57
128
|
def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
58
|
-
sr_transcript=None, lang='en'):
|
|
129
|
+
sr_transcript=None, lang='en', scope=None, build=None):
|
|
59
130
|
"""Informes (lista de dicts JSON) → paquete de evidencia verificable.
|
|
60
131
|
|
|
61
132
|
verificados: lista de códigos de criterio ("1.4.1", "3.3.1"…) que un
|
|
@@ -63,7 +134,11 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
63
134
|
(protocolo del checklist del skill). El criterio pasa a estado
|
|
64
135
|
'agent-verified' — salvo que una señal automática diera fail, que
|
|
65
136
|
permanece como fail (el fallo no se borra verificando). La fuente
|
|
66
|
-
(agente/humano, fecha) queda registrada en el bloque verificacion.
|
|
137
|
+
(agente/humano, fecha) queda registrada en el bloque verificacion.
|
|
138
|
+
|
|
139
|
+
alcance (a11y_scope): las exclusiones CONFIRMADAS por una persona pasan
|
|
140
|
+
a 'not-applicable' con su razón; las propuestas de la máquina jamás
|
|
141
|
+
excluyen (a11y-scope/1 las marca 'proposed-excluded' y aquí no entran)."""
|
|
67
142
|
now = datetime.now(timezone.utc).isoformat(timespec='seconds')
|
|
68
143
|
from . import a11yi18n
|
|
69
144
|
tx = a11yi18n.pack(lang).get('evidence', {})
|
|
@@ -71,12 +146,31 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
71
146
|
tx = tx or a11yi18n.pack('en')['evidence']
|
|
72
147
|
reports = [normalize_report(i) for i in reports] # compat 5.10: señales previas al rename
|
|
73
148
|
|
|
149
|
+
# site crawls (audit_site) nest the per-page reports under 'reports': a
|
|
150
|
+
# pack built from a crawl must flatten them BEFORE deriving (the same
|
|
151
|
+
# shape a11ysarif reads), or the whole crawl counts as automated-fail: 0
|
|
152
|
+
# while pages carry real failures. Artifacts stay one-per-INPUT report —
|
|
153
|
+
# the seal seals what came in, not the flattened view.
|
|
154
|
+
pages = []
|
|
155
|
+
for inf in reports:
|
|
156
|
+
subs = inf.get('reports')
|
|
157
|
+
# PREFERENCIA: si el informe tiene findings TOP-LEVEL son las COPIAS
|
|
158
|
+
# RE-VERIFICADAS (la salida del disprover sobre un site report las
|
|
159
|
+
# escribe arriba, no dentro de reports[]) — aplanarlas encima usaría
|
|
160
|
+
# los ejemplares MUERTOS y los hallazgos desmentidos resucitarían
|
|
161
|
+
if isinstance(inf.get('findings'), list) and inf['findings']:
|
|
162
|
+
pages.append(inf)
|
|
163
|
+
elif isinstance(subs, list) and subs:
|
|
164
|
+
pages.extend(normalize_report(s) for s in subs if isinstance(s, dict))
|
|
165
|
+
else:
|
|
166
|
+
pages.append(inf)
|
|
167
|
+
|
|
74
168
|
# matriz de criterios: los que tocamos (estado según hallazgos) + manuales
|
|
75
169
|
from .a11ycrit import _C as _CAT, effort
|
|
76
170
|
codes_aa = sorted(k for k, v in _CAT.items() if v[0] in ('A', 'AA'))
|
|
77
|
-
modes_included = {inf.get('mode', 'static') for inf in
|
|
171
|
+
modes_included = {inf.get('mode', 'static') for inf in pages}
|
|
78
172
|
touched = {}
|
|
79
|
-
for inf in
|
|
173
|
+
for inf in pages:
|
|
80
174
|
for h in inf.get('findings', []):
|
|
81
175
|
if (h.get('status') == 'rejected'
|
|
82
176
|
or h.get('disprover_status') in ('rejected', 'not-rechecked')):
|
|
@@ -88,22 +182,45 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
88
182
|
continue
|
|
89
183
|
code = crit.split(' ')[0]
|
|
90
184
|
severity = h.get('severity')
|
|
91
|
-
|
|
185
|
+
# severity ausente/None/abajo de high-medium: la máquina no puede
|
|
186
|
+
# afirmar un FALLO — el hallazgo queda como review (evidencia, no
|
|
187
|
+
# veredicto). Solo un fail del motor es un automated-fail.
|
|
188
|
+
state = ('automated-fail' if severity in ('high', 'medium')
|
|
189
|
+
else 'automated-review')
|
|
92
190
|
# el peor estado gana: fail > review
|
|
93
191
|
if touched.get(code) != 'automated-fail':
|
|
94
192
|
touched[code] = state
|
|
95
193
|
|
|
96
194
|
verified = {v.split(' ')[0] for v in (verified or [])}
|
|
195
|
+
|
|
196
|
+
# exclusiones confirmadas por humano (a11y-scope/1): código → razón.
|
|
197
|
+
# Solo status 'excluded' — una 'proposed-excluded' NO descuenta aquí.
|
|
198
|
+
# Filas malformadas (scope editado a mano, JSON hostil) se saltan, como
|
|
199
|
+
# los hallazgos malformados: la entrada sucia jamás tira el pack.
|
|
200
|
+
excluded = {}
|
|
201
|
+
if scope is not None and not isinstance(scope, dict):
|
|
202
|
+
raise ValueError('scope must be an object (a11y-scope/1 JSON)')
|
|
203
|
+
if isinstance(scope, dict) and scope.get('format') == 'a11y-scope/1':
|
|
204
|
+
rows = scope.get('criteria')
|
|
205
|
+
for row in rows if isinstance(rows, list) else []:
|
|
206
|
+
if not isinstance(row, dict) or row.get('status') != 'excluded':
|
|
207
|
+
continue
|
|
208
|
+
crit = row.get('criterion')
|
|
209
|
+
if not isinstance(crit, str) or not crit:
|
|
210
|
+
continue
|
|
211
|
+
reason = row.get('reason')
|
|
212
|
+
excluded[crit.split(' ')[0]] = reason if isinstance(reason, str) else ''
|
|
97
213
|
# extraer valores medidos clave de los hallazgos (ratio, ejemplos)
|
|
98
214
|
values = {}
|
|
99
|
-
for inf in
|
|
215
|
+
for inf in pages:
|
|
100
216
|
for h in inf.get('findings', []):
|
|
101
|
-
code = (h.get('criterion') or '').split(' ')[0]
|
|
217
|
+
code = str(h.get('criterion') or '').split(' ')[0]
|
|
102
218
|
if code not in values:
|
|
103
219
|
val = {}
|
|
104
|
-
|
|
220
|
+
issue_txt = h.get('issue') or '' # issue null explícito: sin crash
|
|
221
|
+
if 'ratio' in issue_txt.lower() or ':' in issue_txt:
|
|
105
222
|
import re as _re
|
|
106
|
-
m = _re.search(r'([\d.]+):1',
|
|
223
|
+
m = _re.search(r'([\d.]+):1', issue_txt)
|
|
107
224
|
if m:
|
|
108
225
|
val['measured'] = f'{m.group(1)}:1'
|
|
109
226
|
_ex_list = h.get('examples', [])
|
|
@@ -117,11 +234,19 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
117
234
|
# modo que la produce no se incluyó)
|
|
118
235
|
from .a11ycrit import RENDERED_ONLY as _RENDERED_ONLY # canónico (a11ycrit)
|
|
119
236
|
|
|
120
|
-
verified_set = {v.split(' ')[0] for v in (verified or [])}
|
|
121
|
-
|
|
122
237
|
matrix = []
|
|
123
238
|
_manual_codes = {m.split(' ')[0] for m in MANUAL_AA}
|
|
124
239
|
for code in codes_aa:
|
|
240
|
+
if code in excluded:
|
|
241
|
+
# aplicabilidad confirmada fuera de alcance por una persona: no
|
|
242
|
+
# queda trabajo humano ni estado de máquina — solo la razón
|
|
243
|
+
note = tx['not_applicable_note']
|
|
244
|
+
if excluded[code]:
|
|
245
|
+
note = f"{note} {excluded[code]}"
|
|
246
|
+
matrix.append({'criterion': f"{code} {(_CAT[code][1].get(language) or _CAT[code][1]['en'])[0]}",
|
|
247
|
+
'status': 'not-applicable', 'note': note,
|
|
248
|
+
'scope_reason': excluded[code] or None})
|
|
249
|
+
continue
|
|
125
250
|
if code in _manual_codes:
|
|
126
251
|
continue # covered by the manual-only rows appended below
|
|
127
252
|
state = touched.get(code, 'not-flagged')
|
|
@@ -132,7 +257,7 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
132
257
|
|
|
133
258
|
# verificados: promueve not-flagged/not-run/manual-only → agent-verified
|
|
134
259
|
# (pero automated-fail permanece: un fallo no se borra verificando)
|
|
135
|
-
if code in
|
|
260
|
+
if code in verified and state != 'automated-fail':
|
|
136
261
|
state = 'agent-verified'
|
|
137
262
|
|
|
138
263
|
note = None
|
|
@@ -155,7 +280,9 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
155
280
|
if code in values:
|
|
156
281
|
entry['value'] = values[code]
|
|
157
282
|
matrix.append(entry)
|
|
158
|
-
manual_remaining = [m for m in MANUAL_AA
|
|
283
|
+
manual_remaining = [m for m in MANUAL_AA
|
|
284
|
+
if m.split(' ')[0] not in verified
|
|
285
|
+
and m.split(' ')[0] not in excluded]
|
|
159
286
|
# los not-run son adicionalmente "pendientes" (la máquina no miró)
|
|
160
287
|
for name in manual_remaining:
|
|
161
288
|
code = name.split(' ')[0]
|
|
@@ -170,6 +297,11 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
170
297
|
'why': ef['why']}
|
|
171
298
|
matrix.append(row)
|
|
172
299
|
for code in sorted(verified):
|
|
300
|
+
# una exclusión confirmada gana a una verificación previa: el
|
|
301
|
+
# criterio fuera de alcance no puede reaparecer como verificado
|
|
302
|
+
# (fila doble, niveles contradictorios en VPAT/OpenACR)
|
|
303
|
+
if code in excluded:
|
|
304
|
+
continue
|
|
173
305
|
if any(code in m for m in MANUAL_AA) and not any(m.startswith(code) for m in manual_remaining):
|
|
174
306
|
row = {'criterion': f"{code} {(_CAT[code][1].get(language) or _CAT[code][1]['en'])[0]}",
|
|
175
307
|
'status': 'agent-verified',
|
|
@@ -185,27 +317,8 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
185
317
|
# remaining human review, in minutes: MIN/MED/MAX per class summed over
|
|
186
318
|
# every row a human still has to touch (everything except agent-verified).
|
|
187
319
|
# This is the scope input for human review: agent output in,
|
|
188
|
-
# priced human scope out.
|
|
189
|
-
|
|
190
|
-
pend = {}
|
|
191
|
-
for m in matrix:
|
|
192
|
-
if m['status'] == 'agent-verified':
|
|
193
|
-
continue
|
|
194
|
-
ef = m.get('effort')
|
|
195
|
-
if ef:
|
|
196
|
-
lo, hi = _MIN[ef['class']]
|
|
197
|
-
pend.setdefault(ef['class'], [0, 0])
|
|
198
|
-
pend[ef['class']][0] += lo
|
|
199
|
-
pend[ef['class']][1] += hi
|
|
200
|
-
pending_effort = {
|
|
201
|
-
'by_class': {k: {'criteria': sum(1 for m in matrix
|
|
202
|
-
if m['status'] != 'agent-verified'
|
|
203
|
-
and m.get('effort', {}).get('class') == k),
|
|
204
|
-
'minutes': v}
|
|
205
|
-
for k, v in sorted(pend.items())},
|
|
206
|
-
'total_minutes': [sum(v[0] for v in pend.values()), sum(v[1] for v in pend.values())],
|
|
207
|
-
'note': tx['manual_remaining'],
|
|
208
|
-
}
|
|
320
|
+
# priced human scope out. The class prices live in a11ycrit (single source).
|
|
321
|
+
pending_effort = _pending_effort(matrix, tx['manual_remaining'])
|
|
209
322
|
|
|
210
323
|
artifacts = []
|
|
211
324
|
for i, inf in enumerate(reports):
|
|
@@ -220,6 +333,27 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
220
333
|
artifacts.append({'type': 'sr_transcript', 'url': sr_transcript.get('url'),
|
|
221
334
|
'sha256': _sha256(sr_transcript), 'announcements': sr_transcript.get('total', 0),
|
|
222
335
|
'linearized': sr_transcript.get('announcements', [])[:50]})
|
|
336
|
+
scope_block = None
|
|
337
|
+
if isinstance(scope, dict) and scope.get('format') == 'a11y-scope/1':
|
|
338
|
+
artifacts.append({'type': 'scope:a11y', 'sha256': _sha256(scope),
|
|
339
|
+
'standard': scope.get('standard'), 'target': scope.get('target'),
|
|
340
|
+
'body': scope}) # embedded: pack self-verifying
|
|
341
|
+
cnt = scope.get('counters', {})
|
|
342
|
+
scope_block = {
|
|
343
|
+
'format': 'a11y-scope/1',
|
|
344
|
+
'standard': scope.get('standard'),
|
|
345
|
+
'target': scope.get('target'),
|
|
346
|
+
'in_scope': cnt.get('in_scope'),
|
|
347
|
+
'proposed_excluded': cnt.get('proposed_excluded'),
|
|
348
|
+
'excluded': cnt.get('excluded'),
|
|
349
|
+
# lo que aguas abajo (VPAT/OpenACR) puede tratar como N/A:
|
|
350
|
+
# SOLO exclusiones humanas, con su razón
|
|
351
|
+
'not_applicable': {r['criterion'].split(' ')[0]: r.get('reason')
|
|
352
|
+
for r in (scope.get('criteria') if isinstance(scope.get('criteria'), list) else [])
|
|
353
|
+
if isinstance(r, dict) and r.get('status') == 'excluded'
|
|
354
|
+
and isinstance(r.get('criterion'), str) and r.get('criterion')},
|
|
355
|
+
'sha256': scope.get('sha256'),
|
|
356
|
+
}
|
|
223
357
|
|
|
224
358
|
pack = {
|
|
225
359
|
'format': 'a11y-evidence-pack/2',
|
|
@@ -228,6 +362,7 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
228
362
|
'tool': 'a11y-toolkit (github.com/kinti/a11y-toolkit)',
|
|
229
363
|
'summary': summary,
|
|
230
364
|
'effort_pending': pending_effort,
|
|
365
|
+
'scope': scope_block,
|
|
231
366
|
'criteria': matrix,
|
|
232
367
|
'manual_pending': [m['criterion'] for m in matrix if m['status'] == 'manual-only'],
|
|
233
368
|
'verification': ({'source': 'agent', 'protocol': 'skill manual checklist'}
|
|
@@ -241,6 +376,7 @@ def build_pack(reports, snapshot=None, reviewer=None, notes=None, verified=None,
|
|
|
241
376
|
'note': tx['reviewer_note'],
|
|
242
377
|
},
|
|
243
378
|
'notes': notes,
|
|
379
|
+
'build': build, # claim→artifact chain: the build reference is SEALED into the sha
|
|
244
380
|
'notice': tx['notice'],
|
|
245
381
|
}
|
|
246
382
|
# the seal excludes sha256 AND the clock ('generated'): re-emitting the
|
|
@@ -254,13 +390,23 @@ def main(argv):
|
|
|
254
390
|
ap = argparse.ArgumentParser(description='Evidence pack (verifiable handoff)')
|
|
255
391
|
ap.add_argument('reports', nargs='+', help='audit report JSON files (any mode)')
|
|
256
392
|
ap.add_argument('--snapshot', help='a11y snapshot JSON (optional)')
|
|
393
|
+
ap.add_argument('--scope', help='a11y_scope output JSON: confirmed exclusions '
|
|
394
|
+
'become not-applicable rows (proposals never exclude)')
|
|
257
395
|
ap.add_argument('--reviewer', help='JSON: {"name":…, "credential":…, "review_date":…}')
|
|
396
|
+
ap.add_argument('--build', help='build reference, e.g. "git:716d870" or JSON '
|
|
397
|
+
'{"commit":…, "ci_url":…} — sealed into the pack sha (claim→artifact chain)')
|
|
258
398
|
ap.add_argument('-o', '--out', default='evidence-pack.json')
|
|
259
399
|
a = ap.parse_args(argv)
|
|
260
400
|
reports = [json.load(open(f, encoding='utf-8')) for f in a.reports]
|
|
261
401
|
snapshot = json.load(open(a.snapshot, encoding='utf-8')) if a.snapshot else None
|
|
402
|
+
scope = json.load(open(a.scope, encoding='utf-8')) if a.scope else None
|
|
262
403
|
reviewer = json.loads(a.reviewer) if a.reviewer else None
|
|
263
|
-
|
|
404
|
+
try:
|
|
405
|
+
build = json.loads(a.build) if a.build else None
|
|
406
|
+
except json.JSONDecodeError:
|
|
407
|
+
build = {'ref': a.build} if a.build else None
|
|
408
|
+
pack = build_pack(reports, snapshot=snapshot, reviewer=reviewer, scope=scope,
|
|
409
|
+
build=build)
|
|
264
410
|
with open(a.out, 'w', encoding='utf-8') as f:
|
|
265
411
|
json.dump(pack, f, ensure_ascii=False, indent=1)
|
|
266
412
|
print(json.dumps({'pack': a.out, 'sha256': pack['sha256'],
|