audit-score
Opt-in scoring over a11y-report: profiles, a score and a coverage that are never merged, a full breakdown, and a CI gate.
An opt-in layer (L2) on top of a11y-report for hosts that need a single number.
It only computes; the finding model stays untouched.
Status
New, unreleased. Depends only on a11y-report and serde; builds for
wasm32-unknown-unknown.
Why a separate crate
a11y-report deliberately has no score: one percentage would flatten
Fail, Review, Pass and Untested, and hide whether a rule ran at all.
a11y-report stays score-free. audit-score is where the number lives, and
it keeps the honesty by returning two numbers that are never merged:
| Field | Meaning |
|---|---|
score | 0.0..=100.0, one decimal. 100 minus the capped deductions of all findings. |
coverage | 0.0..=1.0. executed / (executed + not_run) over Report::rule_runs. |
A report with no deductions and half its rules not run is score 100.0,
coverage 0.5. An empty report has coverage 0.0 (not NaN).
How the report maps
a11y-report | Effect |
|---|---|
Outcome::Fail | deduction from fail_penalties[severity]; counted in fail_counts |
Outcome::Review | deduction from review_penalties[severity]; counted in open_reviews |
Outcome::Review with Basis::BestPractice | never a deduction; counted in best_practice_notes |
Outcome::Pass | nothing |
Outcome::Untested | no deduction (no judgement was made); counted in untested_findings |
RuleRun ran | counts as executed |
NotRun::CapabilityMissing, Disabled, Errored (and future variants) | coverage gap |
NotRun::NotApplicable | nothing to check: neither executed nor a gap; not_applicable_rules |
Severity has four levels (Low, Medium, High, Critical), so
SeverityWeights has four fields. Rule runs are keyed per (rule_id, viewport)
in the report, so a rule that ran on desktop but not on mobile counts once on
each side.
Calculation
Per finding: weight(severity) * prefix_weight(rule_id), floored at 0 (a
negative or NaN weight never gives points back). Per rule the deductions are
summed (raw_deduction), then limited by max_penalty_per_rule
(capped_deduction). score = round1(clamp(100 - sum(capped), 0, 100)).
Prefix weights: the longest matching prefix wins; with identical prefixes the
first entry wins. The empty prefix "" matches every rule and so acts as the
default weight. No match means 1.0.
breakdown lists rules with a deduction above zero, sorted by capped deduction
descending, then rule id ascending. raw_deduction > capped_deduction means the
cap applied.
Profiles
| Profile | Fail crit/high/med/low | Review crit/high/med/low | Cap per rule | Prefix weights |
|---|---|---|---|---|
wcag_strict | 20 / 10 / 5 / 1 | 0 | 50 | none |
balanced (default) | 10 / 5 / 2 / 0.5 | 2 / 1 / 0.5 / 0 | 15 | none |
visual_focus | as balanced | as balanced | 15 | visual/ 1.5, everything else 0.75 |
wcag_strict makes a violation hurt and treats a heuristic suspicion as not
yet a violation. balanced is about half as strict; reviews cost at most a
fifth of a confirmed fail. visual_focus shifts weight towards rules under
visual/ without hiding the rest. Custom profiles are plain data
(ScoringProfile, serde-capable); ..ScoringProfile::balanced() derives one.
CI gate
GatePolicy::decide(&ScoreResult) -> GateResult returns Pass, Warn or
Fail plus the reasons (check, level, actual, threshold). Each threshold is
optional.
min_score/min_coverage:Failif the value is strictly below. A value exactly on the threshold passes.warn_score/warn_coverage: same, butWarn.max_blocking_failswithblocking_severity:Failif the number ofOutcome::Failfindings at that severity or higher is greater than the maximum.Some(0)withHighmeans “no critical or high fail”.
GatePolicy::default(): fail below score 70 or coverage 0.5 or with any
critical/high fail; warn below score 90 or coverage 0.8.
Not in scope
No HTML or other formatting, no history across builds (that belongs to a host), no I/O and no clock.