@kinti/a11y-toolkit 5.35.2 → 5.35.3

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.
@@ -43,6 +43,7 @@ from .a11yaudit import audit_html
43
43
 
44
44
  CORPUS_FORMAT = 'a11y-corpus/1'
45
45
  EVAL_FORMAT = 'a11y-corpus-evaluation/1'
46
+ _CRITERION_CODE = re.compile(r'[1-4]\.[0-9]\.[1-9][0-9]?')
46
47
 
47
48
  _NOTE_README = """# a11y corpus {version}
48
49
 
@@ -61,6 +62,9 @@ on that page (criterion codes, e.g. "1.4.4" — not tool-specific rule ids).
61
62
  Placebo entries accept the same shape; anything you flag on them counts as a
62
63
  false positive by construction (no violation was injected).
63
64
 
65
+ Submit exactly one row per case, including a row with an empty
66
+ `criteria_found` array for each page that was checked without findings.
67
+
64
68
  Score it (from inside this directory):
65
69
 
66
70
  a11ytoolkit corpus evaluate --submission my-submission.jsonl .
@@ -267,67 +271,88 @@ def evaluate(submission, directory='corpus', submission_name='submission'):
267
271
  criterio. Contrato NEUTRAL: códigos WCAG, no señales nuestras."""
268
272
  entries = _load_entries(directory)
269
273
  by_id = {}
274
+ seen = set()
275
+ duplicates = set()
270
276
  unknown = []
271
277
  invalid = []
272
278
  for entry in submission:
273
279
  if not isinstance(entry, dict):
274
- unknown.append(repr(entry)[:40])
280
+ invalid.append({'entry': repr(entry)[:60]})
275
281
  continue
276
282
  cid = entry.get('case_id')
283
+ if not isinstance(cid, str) or not cid:
284
+ invalid.append({'case_id': repr(cid)[:60]})
285
+ continue
277
286
  if cid not in entries:
278
287
  unknown.append(cid)
279
288
  continue
280
- found = entry.get('criteria_found', [])
281
- if not isinstance(found, list):
282
- # un string iteraría CARACTERES y mentiría el veredicto en
283
- # silencio: se rechaza declarado, jamás se traga
289
+ if cid in seen:
290
+ duplicates.add(cid)
291
+ by_id.pop(cid, None)
292
+ continue
293
+ seen.add(cid)
294
+ found = entry.get('criteria_found')
295
+ if not isinstance(found, list) or any(
296
+ not isinstance(code, str) or not _CRITERION_CODE.fullmatch(code)
297
+ for code in found
298
+ ):
284
299
  invalid.append({'case_id': cid,
285
300
  'criteria_found': repr(found)[:60]})
286
301
  continue
287
- by_id[cid] = [str(c) for c in found]
288
- killed, missed, fps, additional = [], [], [], []
302
+ by_id[cid] = list(dict.fromkeys(found))
303
+ killed = mutants = controls = mutants_scored = controls_scored = 0
304
+ missed, fps, additional, missing = [], [], [], []
289
305
  per_crit = {}
290
306
  for cid, case in sorted(entries.items()):
291
- found = by_id.get(cid, [])
307
+ found = by_id.get(cid)
308
+ if found is None:
309
+ missing.append(cid)
292
310
  if case['kind'] == 'placebo':
311
+ controls += 1
312
+ controls_scored += found is not None
293
313
  if found:
294
314
  fps.append({'case_id': cid, 'criteria_flagged': found})
295
315
  continue
316
+ mutants += 1
296
317
  exp = case['expected']['criterion']
297
- per_crit.setdefault(exp, {'expected': 0, 'killed': 0})
298
- per_crit[exp]['expected'] += 1
318
+ tally = per_crit.setdefault(exp, {'expected': 0, 'killed': 0})
319
+ tally['expected'] += 1
320
+ if found is None:
321
+ continue
322
+ mutants_scored += 1
323
+ extra = [c for c in found if c != exp]
299
324
  if exp in found:
300
- killed.append(cid)
301
- per_crit[exp]['killed'] += 1
325
+ killed += 1
326
+ tally['killed'] += 1
302
327
  else:
303
328
  missed.append({'case_id': cid, 'expected_criterion': exp,
304
329
  'operator': case['expected']['operator'],
305
- 'found_instead': [c for c in found if c != exp]})
306
- extra = [c for c in found if c != exp]
330
+ 'found_instead': extra})
307
331
  if extra:
308
332
  additional.append({'case_id': cid, 'additional_criteria': extra})
309
- n_mut = sum(1 for c in entries.values() if c['kind'] == 'mutant')
310
- n_pla = len(entries) - n_mut
311
- # (7a pasada) lo que decide es la ENTREGA, no el corpus: omitir los
312
- # placebos del submission dejaba n_pla>0 (vienen del directorio) y la
313
- # evaluacion se declaraba completa con un claim de FP infalsable
314
- pla_scored = sum(1 for cid, c in entries.items()
315
- if c['kind'] == 'placebo' and cid in by_id)
316
- out = {
333
+ reasons = []
334
+ if not controls:
335
+ reasons.append('corpus has no control (placebo) pages')
336
+ if missing:
337
+ reasons.append('%d cases without a valid submission' % len(missing))
338
+ if duplicates:
339
+ reasons.append('duplicate case IDs')
340
+ if unknown:
341
+ reasons.append('unknown case IDs')
342
+ if invalid:
343
+ reasons.append('invalid submission entries')
344
+ return {
317
345
  'format': EVAL_FORMAT,
318
346
  'submission_name': submission_name,
319
- 'mutants': n_mut, 'killed': len(killed),
320
- 'kill_rate': round(len(killed) / n_mut, 4) if n_mut else None,
347
+ 'mutants': mutants, 'killed': killed,
348
+ 'mutant_pages_scored': mutants_scored,
349
+ 'kill_rate': round(killed / mutants, 4) if mutants else None,
321
350
  'missed_detail': missed,
322
- 'control_pages': n_pla,
351
+ 'control_pages': controls,
323
352
  'false_positives': fps,
324
- # (4ª pasada) sin páginas control, «cero falsos positivos» es
325
- # infalsable — la evaluación se declara incompleta, no limpia
326
- **({'incomplete': True,
327
- 'incomplete_reason': 'no control (placebo) pages in the submission: '
328
- 'the false-positive claim cannot be evaluated'}
329
- if pla_scored == 0 else {'incomplete': False}),
330
- 'control_pages_scored': pla_scored,
353
+ 'incomplete': bool(reasons),
354
+ **({'incomplete_reason': '; '.join(reasons)} if reasons else {}),
355
+ 'control_pages_scored': controls_scored,
331
356
  'additional_findings_on_mutants': {'count': len(additional),
332
357
  'note': 'reported, not scored: only '
333
358
  'placebo flags are false '
@@ -335,11 +360,11 @@ def evaluate(submission, directory='corpus', submission_name='submission'):
335
360
  'sample': additional[:10]},
336
361
  'per_criterion': per_crit,
337
362
  'unknown_case_ids': unknown,
363
+ 'duplicate_case_ids': sorted(duplicates),
338
364
  'invalid_entries': invalid,
339
- 'cases_without_submission': [cid for cid in sorted(entries)
340
- if cid not in by_id][:10],
365
+ 'cases_without_submission': missing[:10],
366
+ 'cases_without_submission_count': len(missing),
341
367
  }
342
- return out
343
368
 
344
369
 
345
370
  def reference(directory='corpus'):
@@ -364,7 +389,7 @@ def _read_submission(path):
364
389
  return [], None
365
390
  if text.startswith('['):
366
391
  try:
367
- return [e for e in json.loads(text) if isinstance(e, dict)], None
392
+ return json.loads(text), None
368
393
  except json.JSONDecodeError as e:
369
394
  return [], {'count': 1,
370
395
  'example': 'json array: %s' % str(e)[:120]}
@@ -380,8 +405,7 @@ def _read_submission(path):
380
405
  invalid = {'count': 0, 'example': 'line %d: %s' % (n, str(e)[:120])}
381
406
  invalid['count'] += 1
382
407
  continue
383
- if isinstance(obj, dict):
384
- out.append(obj)
408
+ out.append(obj)
385
409
  return out, invalid
386
410
 
387
411
 
@@ -418,15 +442,23 @@ def main(argv):
418
442
  print(json.dumps({'ok': ok, 'detail': detail}, ensure_ascii=False))
419
443
  return 0 if ok else 1
420
444
  if a.action == 'evaluate':
421
- entries, invalid = _read_submission(a.submission)
445
+ try:
446
+ entries, invalid = _read_submission(a.submission)
447
+ except (OSError, UnicodeError) as exc:
448
+ print(json.dumps({'error': str(exc)}, ensure_ascii=False))
449
+ return 1
422
450
  res = evaluate(entries, a.directory,
423
451
  submission_name=os.path.basename(a.submission))
424
452
  if invalid:
425
453
  # el grading sigue con las líneas válidas, pero las corruptas se
426
454
  # declaran — jamás un veredicto mudo sobre input roto
427
455
  res['invalid_lines'] = invalid
456
+ reason = res.get('incomplete_reason')
457
+ res['incomplete'] = True
458
+ res['incomplete_reason'] = (
459
+ reason + '; invalid JSON in submission' if reason else 'invalid JSON in submission')
428
460
  print(json.dumps(res, ensure_ascii=False, indent=1))
429
- return 0
461
+ return 1 if res['incomplete'] else 0
430
462
  if a.action == 'reference':
431
463
  outp = os.path.join(a.directory, 'results', 'reference.json')
432
464
  manifest_path = os.path.join(a.directory, 'MANIFEST.json')
@@ -97,7 +97,7 @@ try:
97
97
  except ImportError:
98
98
  ARIALIVE_JS = None # repo checkout: read the file
99
99
 
100
- VERSION = '5.35.2'
100
+ VERSION = '5.35.3'
101
101
 
102
102
  # Params renombrados a inglés en 5.11.0; se aceptan los nombres previos.
103
103
  PARAM_ALIASES = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kinti/a11y-toolkit",
3
- "version": "5.35.2",
3
+ "version": "5.35.3",
4
4
  "mcpName": "io.github.kinti/a11y-toolkit",
5
5
  "description": "Zero-dependency WCAG 2.2 accessibility engine (37 MCP tools + CLI): audits, contrast fixing, SHA-256-sealed evidence packs, SARIF, EARL/ACT, CI ratchet. Self-contained: the pure-stdlib Python engine ships inside and runs via python3 \u2014 no downloads, no installs.",
6
6
  "license": "MIT",