@kinti/a11y-toolkit 5.26.0 → 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 +27 -4
- package/a11y_toolkit/a11yact.py +9 -1
- package/a11y_toolkit/a11yannotate.py +185 -0
- package/a11y_toolkit/a11yaudit.py +853 -193
- 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 +425 -95
- package/a11y_toolkit/a11yen301549.py +53 -1
- package/a11y_toolkit/a11yengines.py +157 -0
- package/a11y_toolkit/a11yevidence.py +81 -33
- 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 +10 -3
- 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 +45 -18
- package/a11y_toolkit/a11yscope.py +67 -15
- 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 +34 -7
- 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 +177 -20
- package/a11y_toolkit/locales/es.json +178 -21
- package/a11y_toolkit/rgaa.json +2661 -0
- package/a11y_toolkit/server.py +149 -50
- package/package.json +2 -2
- package/a11y_toolkit/a11yplan.py +0 -214
- package/a11y_toolkit/a11ywcagem.py +0 -237
package/a11y_toolkit/a11yplan.py
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""Remediation plan — turn a findings list into an ordered ROUTE.
|
|
3
|
-
|
|
4
|
-
An inventory of 40 findings overwhelms; nobody answers "in what order?".
|
|
5
|
-
Planning matters because fixes change the cost of other fixes: semantic
|
|
6
|
-
infrastructure (headings, landmarks, labels) makes later work cheaper, one
|
|
7
|
-
design-token decision kills many contrast findings at once, and instances
|
|
8
|
-
on a page headed for redesign are wasted minutes. Cross-industry origin:
|
|
9
|
-
planning over evolving state (candidate-generation MDPs, arXiv 2607.02115)
|
|
10
|
-
— translated here into a deterministic, auditable heuristic. No ML, no
|
|
11
|
-
network: batches, declared phases, declared minute assumptions, a root
|
|
12
|
-
seal. The human reorders; the plan is evidence, not an oracle.
|
|
13
|
-
|
|
14
|
-
Phases (in order):
|
|
15
|
-
infrastructure — structural semantics first (they reprice everything else)
|
|
16
|
-
design-system — shared-cause decisions (contrast as a system fix)
|
|
17
|
-
instances — per-instance work, severity high → medium → low
|
|
18
|
-
redesign-zone — one page accumulating many distinct signals: flagged,
|
|
19
|
-
moved last, with an explicit note
|
|
20
|
-
|
|
21
|
-
CLI:
|
|
22
|
-
a11ytoolkit plan --report audit.json [-o plan.json]
|
|
23
|
-
a11ytoolkit plan --report audit.json --from-pack pack.json # pack effort
|
|
24
|
-
"""
|
|
25
|
-
|
|
26
|
-
import argparse
|
|
27
|
-
import hashlib
|
|
28
|
-
import json
|
|
29
|
-
import sys
|
|
30
|
-
|
|
31
|
-
# Phase assignment by signal class (declared, not learned).
|
|
32
|
-
INFRA_SIGNALS = {'no_h1', 'heading_order', 'landmark', 'bypass_missing',
|
|
33
|
-
'region_missing', 'field_label', 'button_name', 'link_name',
|
|
34
|
-
'img_no_alt', 'iframe_title', 'html_lang_missing',
|
|
35
|
-
'title_missing', 'viewport_zoom_blocked'}
|
|
36
|
-
DESIGN_SIGNALS = {'contrast_low', 'contrast_image_fail', 'color_alone',
|
|
37
|
-
'focus_visibility', 'text_spacing'}
|
|
38
|
-
MINUTES_BY_SEVERITY = {'high': [12, 20], 'medium': [5, 10], 'low': [2, 4]}
|
|
39
|
-
REDESIGN_SIGNAL_THRESHOLD = 4 # distinct signals on one URL → zone flag
|
|
40
|
-
|
|
41
|
-
# What each assumption means, printed with the plan (honesty by default).
|
|
42
|
-
ASSUMPTIONS_HEURISTIC = {
|
|
43
|
-
'source': 'severity heuristic',
|
|
44
|
-
'minutes': MINUTES_BY_SEVERITY,
|
|
45
|
-
'note': ('per-finding heuristic ranges, NOT measured effort; the pack '
|
|
46
|
-
'effort pricing (a11y_evidence) is the better source when '
|
|
47
|
-
'available'),
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def _canon(obj):
|
|
52
|
-
return json.dumps(obj, ensure_ascii=False, sort_keys=True,
|
|
53
|
-
separators=(',', ':'))
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def _minutes_for(findings, effort_by_criterion=None):
|
|
57
|
-
"""Sum of per-finding minute ranges. With pack effort pricing, the
|
|
58
|
-
criterion's MIN/MED/MAX range replaces the severity heuristic."""
|
|
59
|
-
lo = hi = 0
|
|
60
|
-
for f in findings:
|
|
61
|
-
eff = effort_by_criterion.get((f.get('criterion') or '').split(' ')[0])
|
|
62
|
-
if eff and eff.get('minutes'):
|
|
63
|
-
lo += eff['minutes'][0]
|
|
64
|
-
hi += eff['minutes'][1]
|
|
65
|
-
else:
|
|
66
|
-
r = MINUTES_BY_SEVERITY.get(f.get('severity', 'low'), MINUTES_BY_SEVERITY['low'])
|
|
67
|
-
lo += r[0]
|
|
68
|
-
hi += r[1]
|
|
69
|
-
return [lo, hi]
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def build_plan(report, pack=None):
|
|
73
|
-
"""Report (dict with findings[]) → sealed fix-plan dict. Deterministic:
|
|
74
|
-
same report, same plan. Malformed findings are skipped, never fatal."""
|
|
75
|
-
findings = [f for f in (report.get('findings') or []) if isinstance(f, dict)
|
|
76
|
-
and f.get('signal')]
|
|
77
|
-
effort_by_criterion = {}
|
|
78
|
-
if pack:
|
|
79
|
-
for c in pack.get('criteria', []):
|
|
80
|
-
if c.get('effort', {}).get('minutes'):
|
|
81
|
-
effort_by_criterion[c['criterion'].split(' ')[0]] = c['effort']
|
|
82
|
-
assumptions = dict(ASSUMPTIONS_HEURISTIC)
|
|
83
|
-
if pack:
|
|
84
|
-
assumptions = {'source': 'pack effort',
|
|
85
|
-
'note': 'minutes from the evidence pack effort pricing'}
|
|
86
|
-
|
|
87
|
-
# redesign zones: one URL accumulating many distinct signals
|
|
88
|
-
by_url = {}
|
|
89
|
-
for f in findings:
|
|
90
|
-
u = f.get('url') or report.get('url') or ''
|
|
91
|
-
by_url.setdefault(u, set()).add(f['signal'])
|
|
92
|
-
zones = {u for u, sigs in by_url.items() if len(sigs) >= REDESIGN_SIGNAL_THRESHOLD}
|
|
93
|
-
|
|
94
|
-
# batch by signal inside each phase (one signal = one kind of fix)
|
|
95
|
-
by_signal = {}
|
|
96
|
-
for f in findings:
|
|
97
|
-
by_signal.setdefault(f['signal'], []).append(f)
|
|
98
|
-
|
|
99
|
-
def phase_of(signal):
|
|
100
|
-
if signal in INFRA_SIGNALS:
|
|
101
|
-
return 'infrastructure'
|
|
102
|
-
if signal in DESIGN_SIGNALS:
|
|
103
|
-
return 'design-system'
|
|
104
|
-
return 'instances'
|
|
105
|
-
|
|
106
|
-
sev_rank = {'high': 0, 'medium': 1, 'low': 2}
|
|
107
|
-
batches = []
|
|
108
|
-
infra_signals = sorted(s for s in by_signal if phase_of(s) == 'infrastructure')
|
|
109
|
-
for signal in sorted(by_signal):
|
|
110
|
-
if signal in infra_signals and signal != (infra_signals or [signal])[0]:
|
|
111
|
-
continue # infrastructure is ONE combined batch (one work session)
|
|
112
|
-
fs = by_signal[signal]
|
|
113
|
-
if signal == (infra_signals or [None])[0] and infra_signals:
|
|
114
|
-
fs = [f for sg in infra_signals for f in by_signal[sg]]
|
|
115
|
-
signal = 'document_structure'
|
|
116
|
-
phase = 'infrastructure' if signal == 'document_structure' else phase_of(signal)
|
|
117
|
-
zone = bool(zones & {f.get('url') or '' for f in fs})
|
|
118
|
-
if phase == 'instances' and zone and len({f.get('url') for f in fs}) == 1 \
|
|
119
|
-
and len(by_url[list(zones & {f.get('url') for f in fs})[0]]) >= REDESIGN_SIGNAL_THRESHOLD:
|
|
120
|
-
phase = 'redesign-zone'
|
|
121
|
-
sev = min((sev_rank.get(f.get('severity', 'low'), 2) for f in fs))
|
|
122
|
-
batch = {
|
|
123
|
-
'title': (f"Fix document structure semantics ({len(fs)} findings)"
|
|
124
|
-
if signal == 'document_structure' else
|
|
125
|
-
f"Fix {signal.replace('_', ' ')} ({len(fs)} finding"
|
|
126
|
-
f"{'s' if len(fs) != 1 else ''})"),
|
|
127
|
-
'phase': phase, 'signal': signal,
|
|
128
|
-
'finding_count': len(fs), 'severity': ('high', 'medium', 'low')[sev],
|
|
129
|
-
'signals': infra_signals if signal == 'document_structure' else [signal],
|
|
130
|
-
'urls': sorted({f.get('url') or '' for f in fs})[:8],
|
|
131
|
-
'criteria': sorted({(f.get('criterion') or '').split(' ')[0] for f in fs}),
|
|
132
|
-
'minutes': _minutes_for(fs, effort_by_criterion),
|
|
133
|
-
'note': ('same kind of fix repeated — fix the pattern once and '
|
|
134
|
-
're-apply; itemized minutes are the upper bound'
|
|
135
|
-
if len(fs) > 1 else ''),
|
|
136
|
-
}
|
|
137
|
-
if phase == 'redesign-zone':
|
|
138
|
-
batch['note'] = ('this URL accumulates %d distinct signals — '
|
|
139
|
-
'consider fixing it in a redesign pass, not '
|
|
140
|
-
'piecemeal' % len(by_url[list(zones & {f.get('url') for f in fs})[0]]))
|
|
141
|
-
batches.append(batch)
|
|
142
|
-
|
|
143
|
-
order = {'infrastructure': 0, 'design-system': 1, 'instances': 2, 'redesign-zone': 3}
|
|
144
|
-
batches.sort(key=lambda b: (order[b['phase']], sev_rank[b['severity']],
|
|
145
|
-
b['signal']))
|
|
146
|
-
|
|
147
|
-
# design-system note when contrast concentrates: one decision, many fixes
|
|
148
|
-
design = [b for b in batches if b['phase'] == 'design-system']
|
|
149
|
-
if design and sum(b['finding_count'] for b in design) >= 3:
|
|
150
|
-
design[0]['note'] = (design[0]['note'] or '') + (
|
|
151
|
-
' — consider a design-token/theme decision: one change here '
|
|
152
|
-
'typically resolves every finding in this batch').strip(' —')
|
|
153
|
-
|
|
154
|
-
cumulative = [0, 0]
|
|
155
|
-
for b in batches:
|
|
156
|
-
cumulative[0] += b['minutes'][0]
|
|
157
|
-
cumulative[1] += b['minutes'][1]
|
|
158
|
-
b['cumulative_minutes'] = list(cumulative)
|
|
159
|
-
|
|
160
|
-
itemized = [cumulative[0], cumulative[1]]
|
|
161
|
-
savings = [max(0, itemized[0] // 6), max(0, itemized[1] // 5)] # declared: 15-20% pattern reuse
|
|
162
|
-
|
|
163
|
-
plan = {
|
|
164
|
-
'format': 'a11y-fix-plan/1',
|
|
165
|
-
'source_report': {'url': report.get('url'), 'score': report.get('score'),
|
|
166
|
-
'mode': report.get('mode'),
|
|
167
|
-
'findings_total': len(findings)},
|
|
168
|
-
'assumptions': assumptions,
|
|
169
|
-
'batches': batches,
|
|
170
|
-
'total_minutes': list(cumulative),
|
|
171
|
-
'grouping_savings_minutes': savings,
|
|
172
|
-
'grouping_note': ('declared estimate of pattern-reuse savings from '
|
|
173
|
-
'fixing by batch instead of item by item — an '
|
|
174
|
-
'optimistic bound, not a promise'),
|
|
175
|
-
'redesign_zones': sorted(zones),
|
|
176
|
-
'note': ('the order is a declared heuristic: infrastructure first '
|
|
177
|
-
'(it reprices everything else), then design decisions, '
|
|
178
|
-
'then instances; the human reorders — re-run the seal '
|
|
179
|
-
'after reordering')
|
|
180
|
-
+ ('' if findings else ' NO FINDINGS in the source report '
|
|
181
|
-
'— nothing to plan (run the audit first).'),
|
|
182
|
-
}
|
|
183
|
-
plan['sha256'] = hashlib.sha256(
|
|
184
|
-
_canon({k: v for k, v in plan.items() if k != 'sha256'}).encode('utf-8')
|
|
185
|
-
).hexdigest()
|
|
186
|
-
return plan
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
def verify_plan(plan):
|
|
190
|
-
expected = hashlib.sha256(
|
|
191
|
-
_canon({k: v for k, v in plan.items() if k != 'sha256'}).encode('utf-8')
|
|
192
|
-
).hexdigest()
|
|
193
|
-
return expected == plan.get('sha256'), 'root sha256'
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
def main(argv):
|
|
197
|
-
ap = argparse.ArgumentParser(description='Remediation plan: findings → ordered fix route')
|
|
198
|
-
ap.add_argument('--report', required=True, help='audit report JSON (findings[])')
|
|
199
|
-
ap.add_argument('--from-pack', help='evidence pack JSON: use its effort pricing for minutes')
|
|
200
|
-
ap.add_argument('-o', '--out', default='fix-plan.json')
|
|
201
|
-
a = ap.parse_args(argv)
|
|
202
|
-
report = json.load(open(a.report, encoding='utf-8'))
|
|
203
|
-
pack = json.load(open(a.from_pack, encoding='utf-8')) if a.from_pack else None
|
|
204
|
-
plan = build_plan(report, pack=pack)
|
|
205
|
-
with open(a.out, 'w', encoding='utf-8') as f:
|
|
206
|
-
json.dump(plan, f, ensure_ascii=False, indent=1)
|
|
207
|
-
print(json.dumps({'plan': a.out, 'sha256': plan['sha256'],
|
|
208
|
-
'batches': len(plan['batches']),
|
|
209
|
-
'total_minutes': plan['total_minutes']}, ensure_ascii=False))
|
|
210
|
-
return 0
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if __name__ == '__main__':
|
|
214
|
-
sys.exit(main(sys.argv[1:]))
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""WCAG-EM 2.0 evaluation mode — the sampling/aggregation layer.
|
|
3
|
-
|
|
4
|
-
WCAG-EM (W3C Group Note, 2026-07-23) is HOW a full evaluation is scoped,
|
|
5
|
-
sampled and reported. This module does the machine half honestly:
|
|
6
|
-
|
|
7
|
-
plan JSON → what is being evaluated (Step 1), the sample set (Step 3)
|
|
8
|
-
packs[] → the sealed evidence per sample (Step 4, a11y_evidence output)
|
|
9
|
-
report → per-criterion rollup ACROSS the sample (Step 5), sealed with
|
|
10
|
-
a root hash over the pack seals
|
|
11
|
-
|
|
12
|
-
Since a11y-wcagem-report/2 the rollup carries its STATISTICS layer
|
|
13
|
-
(a11ydistrib, the HEGM translation): per-criterion failure prevalence with a
|
|
14
|
-
Wilson interval (what a random unaudited page may hold), and per-page human
|
|
15
|
-
effort as a zero-inflated mixture + seeded bootstrap — intervals over the
|
|
16
|
-
sample, never claims about the site.
|
|
17
|
-
|
|
18
|
-
What it deliberately does NOT do: claim conformance. The report carries
|
|
19
|
-
evidence-status per criterion (the worst across the sample wins), the
|
|
20
|
-
priced human work that remains, and the standard's step trace. Random
|
|
21
|
-
sample selection stays with the evaluator (their methodology, their name);
|
|
22
|
-
structured samples and complete processes (journeys) are first-class.
|
|
23
|
-
|
|
24
|
-
CLI:
|
|
25
|
-
a11ywcagem.py --plan plan.json --packs p1.json p2.json -o report.json
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
import argparse
|
|
29
|
-
import hashlib
|
|
30
|
-
import json
|
|
31
|
-
import sys
|
|
32
|
-
|
|
33
|
-
from .a11ydistrib import effort_inference, wilson_interval
|
|
34
|
-
|
|
35
|
-
# El worst peor gana al agregar samples; never-flagged en TODAS no es pass
|
|
36
|
-
# (es "ninguna señal saltó en esta sample"), exactamente como el pack.
|
|
37
|
-
_RANK = {'automated-fail': 0, 'not-run': 1, 'automated-review': 2,
|
|
38
|
-
'manual-only': 3, 'not-flagged': 4, 'agent-verified': 5}
|
|
39
|
-
|
|
40
|
-
_TYPES = ('structured', 'random', 'process', 'common-view')
|
|
41
|
-
|
|
42
|
-
_STEPS = [
|
|
43
|
-
{'step': '1', 'what': 'Define the evaluation scope',
|
|
44
|
-
'where': 'plan.product (enclosure: all views, states, functionality)'},
|
|
45
|
-
{'step': '1.2', 'what': 'Conformance target', 'where': 'plan.conformance_target'},
|
|
46
|
-
{'step': '1.3', 'what': 'Accessibility support baseline', 'where': 'plan.support_baseline'},
|
|
47
|
-
{'step': '2', 'what': 'Explore the target product', 'where': 'plan.sample[].why'},
|
|
48
|
-
{'step': '3', 'what': 'Select a representative sample set',
|
|
49
|
-
'where': 'plan.sample[] (structured / random / process) + packs per sample'},
|
|
50
|
-
{'step': '4', 'what': 'Evaluate the selected sample set',
|
|
51
|
-
'where': 'the evidence packs (a11y-evidence-pack/2)'},
|
|
52
|
-
{'step': '5', 'what': 'Report the evaluation findings', 'where': 'this report'},
|
|
53
|
-
]
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def _canon(obj):
|
|
57
|
-
return json.dumps(obj, ensure_ascii=False, sort_keys=True,
|
|
58
|
-
separators=(',', ':'))
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def validate_plan(plan):
|
|
62
|
-
"""Plan (dict) → (ok, error). Solo estructura; el muestreo es del auditor."""
|
|
63
|
-
if not isinstance(plan, dict):
|
|
64
|
-
return False, 'el plan debe ser un objeto'
|
|
65
|
-
for field in ('product', 'conformance_target', 'sample'):
|
|
66
|
-
if field not in plan:
|
|
67
|
-
return False, f'falta {field} (WCAG-EM paso 1/3)'
|
|
68
|
-
if not isinstance(plan['product'], dict) or not plan['product'].get('name'):
|
|
69
|
-
return False, 'product.name es obligatorio (¿qué se evalúa?)'
|
|
70
|
-
if not isinstance(plan['conformance_target'], str):
|
|
71
|
-
return False, 'conformance_target debe ser texto (p. ej. "WCAG 2.2 AA")'
|
|
72
|
-
sample = plan['sample']
|
|
73
|
-
if not isinstance(sample, list) or not sample:
|
|
74
|
-
return False, 'sample debe ser una lista no vacía de samples'
|
|
75
|
-
for i, m in enumerate(sample):
|
|
76
|
-
if not isinstance(m, dict):
|
|
77
|
-
return False, f'sample #{i + 1} debe ser objeto'
|
|
78
|
-
for field in ('id', 'type'):
|
|
79
|
-
if not m.get(field):
|
|
80
|
-
return False, f'sample #{i + 1} sin {field}'
|
|
81
|
-
if m['type'] not in _TYPES:
|
|
82
|
-
return False, (f"sample {m['id']}: type debe ser "
|
|
83
|
-
f"{'/'.join(_TYPES)} (WCAG-EM 3.1-3.3)")
|
|
84
|
-
if not m.get('url') and not m.get('file'):
|
|
85
|
-
return False, f"sample {m['id']}: url o file requeridos"
|
|
86
|
-
if plan.get('estimated_pages') is not None:
|
|
87
|
-
ep = plan['estimated_pages']
|
|
88
|
-
# la proyección es una FIGURA del evaluador, no una medición — pero
|
|
89
|
-
# proyectar sobre menos páginas que la muestra propia es sin sentido
|
|
90
|
-
if not isinstance(ep, int) or isinstance(ep, bool) or ep < len(sample):
|
|
91
|
-
return False, (f'estimated_pages debe ser entero ≥ len(sample) '
|
|
92
|
-
f'({len(sample)}) para proyectar el esfuerzo')
|
|
93
|
-
return True, ''
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def aggregate(plan, packs, lang='en', inference_seed=7):
|
|
97
|
-
"""Plan válido + packs sellados → report agregado con sello raíz.
|
|
98
|
-
|
|
99
|
-
Regla de agregado por criterio: el PEOR worst de todas las samples
|
|
100
|
-
(un fallo en cualquier página muestreada es un fallo del report).
|
|
101
|
-
agent-verified no borra un fail (misma honestidad que el pack).
|
|
102
|
-
|
|
103
|
-
Desde /2: cada criterio lleva su prevalencia en la muestra con intervalo
|
|
104
|
-
Wilson (qué puede contener una página NO muestreada), y el reporte lleva
|
|
105
|
-
el bloque `inference` del esfuerzo (a11ydistrib, traducción HEGM:
|
|
106
|
-
mezcla cero-inflada + bootstrap sembrado sobre las bandas lo/hi de
|
|
107
|
-
minutos). Estadística sobre la muestra, jamás conformidad.
|
|
108
|
-
"""
|
|
109
|
-
ok, err = validate_plan(plan)
|
|
110
|
-
if not ok:
|
|
111
|
-
raise ValueError(err)
|
|
112
|
-
if len(packs) != len(plan['sample']):
|
|
113
|
-
raise ValueError(f'{len(plan["sample"])} samples, {len(packs)} packs: deben emparejar')
|
|
114
|
-
|
|
115
|
-
codes, names, effort = set(), {}, {'MIN': 0, 'MED': 0, 'MAX': 0}
|
|
116
|
-
worst = {} # code → peor worst
|
|
117
|
-
fail_counts = {} # code → cuántas SAMPLES fallaron (no filas)
|
|
118
|
-
for pack in packs:
|
|
119
|
-
seen = set() # un criterio aparece UNA vez por pack; duplicados de un
|
|
120
|
-
# pack manual no deben inflar prevalencia ni esfuerzo (cuentan 1 sample)
|
|
121
|
-
for c in pack.get('criteria', []):
|
|
122
|
-
code = c['criterion'].split(' ')[0]
|
|
123
|
-
if code in seen:
|
|
124
|
-
continue
|
|
125
|
-
seen.add(code)
|
|
126
|
-
codes.add(code)
|
|
127
|
-
names[code] = c['criterion']
|
|
128
|
-
st = c['status']
|
|
129
|
-
if code not in worst or _RANK[st] < _RANK[worst[code]]:
|
|
130
|
-
worst[code] = st
|
|
131
|
-
if st == 'automated-fail':
|
|
132
|
-
fail_counts[code] = fail_counts.get(code, 0) + 1
|
|
133
|
-
ef = c.get('effort', {}).get('class')
|
|
134
|
-
if ef in effort and st != 'agent-verified':
|
|
135
|
-
effort[ef] += 1
|
|
136
|
-
|
|
137
|
-
criteria = []
|
|
138
|
-
for code in sorted(codes, key=lambda x: tuple(int(n) for n in x.split('.'))):
|
|
139
|
-
k = fail_counts.get(code, 0)
|
|
140
|
-
row = {'criterion': names[code], 'status': worst[code],
|
|
141
|
-
'samples_failing': k,
|
|
142
|
-
'total_samples': len(packs)}
|
|
143
|
-
# estadística de la muestra: prevalencia observada + banda Wilson
|
|
144
|
-
row['prevalence'] = round(k / len(packs), 4) if packs else 0.0
|
|
145
|
-
row['prevalence_ci95_wilson'] = wilson_interval(k, len(packs))
|
|
146
|
-
if worst[code] == 'not-flagged':
|
|
147
|
-
row['note'] = ('no signal fired on ANY sampled page — explicitly '
|
|
148
|
-
'NOT pass; the human still owns this criterion')
|
|
149
|
-
criteria.append(row)
|
|
150
|
-
|
|
151
|
-
# esfuerzo por página: ambas bandas del rango de minutos por criterio
|
|
152
|
-
# (el agente-verificado ya está pagado, no cuenta — misma regla arriba);
|
|
153
|
-
# un pack manual puede traer la fila duplicada o el rango invertido: se
|
|
154
|
-
# deduplica por código y el rango se normaliza (min/max es idempotente)
|
|
155
|
-
lo_pages, hi_pages = [], []
|
|
156
|
-
for pack in packs:
|
|
157
|
-
seen, lo, hi = set(), 0, 0
|
|
158
|
-
for c in pack.get('criteria', []):
|
|
159
|
-
if c.get('status') == 'agent-verified':
|
|
160
|
-
continue
|
|
161
|
-
code = c['criterion'].split(' ')[0]
|
|
162
|
-
if code in seen:
|
|
163
|
-
continue
|
|
164
|
-
seen.add(code)
|
|
165
|
-
mins = c.get('effort', {}).get('minutes')
|
|
166
|
-
if isinstance(mins, (list, tuple)) and len(mins) == 2:
|
|
167
|
-
lo += min(mins)
|
|
168
|
-
hi += max(mins)
|
|
169
|
-
lo_pages.append(lo)
|
|
170
|
-
hi_pages.append(hi)
|
|
171
|
-
|
|
172
|
-
report = {
|
|
173
|
-
'format': 'a11y-wcagem-report/2',
|
|
174
|
-
'method': 'WCAG-EM 2.0 (W3C Group Note, 2026-07-23)',
|
|
175
|
-
'product': plan['product'],
|
|
176
|
-
'conformance_target': plan['conformance_target'],
|
|
177
|
-
'support_baseline': plan.get('support_baseline', []),
|
|
178
|
-
'sample': plan['sample'],
|
|
179
|
-
'wcag_em': {'steps': _STEPS,
|
|
180
|
-
'note': ('random selection (3.2) stays with the evaluator: '
|
|
181
|
-
'this tool aggregates, never chooses')},
|
|
182
|
-
'criteria': criteria,
|
|
183
|
-
'summary': {s: sum(1 for c in criteria if c['status'] == s)
|
|
184
|
-
for s in _RANK},
|
|
185
|
-
'effort_pending': effort,
|
|
186
|
-
'inference': effort_inference(
|
|
187
|
-
lo_pages, hi_pages, seed=inference_seed,
|
|
188
|
-
projected_pages=plan.get('estimated_pages'), lang=lang),
|
|
189
|
-
'packs': [{'sample': m['id'], 'type': m['type'],
|
|
190
|
-
'sha256': p['sha256'], 'format': p.get('format')}
|
|
191
|
-
for m, p in zip(plan['sample'], packs)],
|
|
192
|
-
# sin claim de conformidad: el report ES evidencia para el humano
|
|
193
|
-
}
|
|
194
|
-
report['sha256'] = hashlib.sha256(
|
|
195
|
-
_canon({k: v for k, v in report.items() if k != 'sha256'}).encode('utf-8')
|
|
196
|
-
).hexdigest()
|
|
197
|
-
return report
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
def verify_report(report):
|
|
201
|
-
"""(ok, detalle): el sello raíz del report (menos sha256)."""
|
|
202
|
-
expected = hashlib.sha256(
|
|
203
|
-
_canon({k: v for k, v in report.items() if k != 'sha256'}).encode('utf-8')
|
|
204
|
-
).hexdigest()
|
|
205
|
-
return expected == report.get('sha256'), 'root sha256'
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
def main(argv):
|
|
209
|
-
ap = argparse.ArgumentParser(description='WCAG-EM 2.0 aggregated evaluation report')
|
|
210
|
-
ap.add_argument('--plan', required=True, help='evaluation plan JSON (scope + sample set)')
|
|
211
|
-
ap.add_argument('--packs', nargs='+', required=True,
|
|
212
|
-
help='evidence pack JSON per sample, in plan.sample order')
|
|
213
|
-
ap.add_argument('--lang', default='en', choices=['en', 'es'],
|
|
214
|
-
help='inference note language (report data stays English)')
|
|
215
|
-
ap.add_argument('-o', '--out', default='wcagem-report.json')
|
|
216
|
-
a = ap.parse_args(argv)
|
|
217
|
-
plan = json.load(open(a.plan, encoding='utf-8'))
|
|
218
|
-
packs = [json.load(open(p, encoding='utf-8')) for p in a.packs]
|
|
219
|
-
try:
|
|
220
|
-
report = aggregate(plan, packs, lang=a.lang)
|
|
221
|
-
except ValueError as e:
|
|
222
|
-
print(json.dumps({'error': str(e)}))
|
|
223
|
-
return 2
|
|
224
|
-
with open(a.out, 'w', encoding='utf-8') as f:
|
|
225
|
-
json.dump(report, f, ensure_ascii=False, indent=1)
|
|
226
|
-
inf = report['inference']
|
|
227
|
-
print(json.dumps({'report': a.out, 'sha256': report['sha256'],
|
|
228
|
-
'criteria': len(report['criteria']),
|
|
229
|
-
'summary': report['summary'],
|
|
230
|
-
'effort_ci95_envelope_per_page': inf['ci95_mean_envelope'],
|
|
231
|
-
'projection': inf.get('projection')},
|
|
232
|
-
ensure_ascii=False))
|
|
233
|
-
return 0
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if __name__ == '__main__':
|
|
237
|
-
sys.exit(main(sys.argv[1:]))
|