ultra11y 5.55.5 → 5.56.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.
@@ -10,7 +10,7 @@
10
10
  "name": "ultra11y",
11
11
  "source": "./",
12
12
  "description": "RGAA 4.1.2 accessibility audits on a WCAG 2.2 AA core: automatic review before commit, push and pull request, plus dated, evidenced Markdown, HTML and per-page conformance reports in Claude Code.",
13
- "version": "5.55.5",
13
+ "version": "5.56.0",
14
14
  "author": { "name": "maxgfr" },
15
15
  "homepage": "https://github.com/SocialGouv/ultra11y",
16
16
  "repository": "https://github.com/SocialGouv/ultra11y",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ultra11y",
3
3
  "description": "RGAA 4.1.2 accessibility audits, the French State's standard, on a WCAG 2.2 AA core: automatic review before commit, push and pull request, plus dated, evidenced Markdown, HTML and per-page conformance reports. Never declares conforming what it has not verified.",
4
- "version": "5.55.5",
4
+ "version": "5.56.0",
5
5
  "author": { "name": "maxgfr" },
6
6
  "homepage": "https://github.com/SocialGouv/ultra11y",
7
7
  "repository": "https://github.com/SocialGouv/ultra11y",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ultra11y",
3
3
  "description": "RGAA 4.1.2 accessibility audits, the French State's standard, on a WCAG 2.2 AA core: automatic review before commit, push and pull request, plus dated, evidenced Markdown, HTML and per-page conformance reports. Never declares conforming what it has not verified.",
4
- "version": "5.55.5",
4
+ "version": "5.56.0",
5
5
  "author": { "name": "maxgfr", "url": "https://github.com/maxgfr" },
6
6
  "homepage": "https://github.com/SocialGouv/ultra11y",
7
7
  "repository": "https://github.com/SocialGouv/ultra11y",
@@ -27,7 +27,7 @@ import { fileURLToPath } from "node:url";
27
27
  // Ownership marker: `ultra11y install --opencode` refuses to overwrite a plugin file that
28
28
  // does not carry it, so a user's own ultra11y.js is never clobbered.
29
29
  const ULTRA11Y_OPENCODE_PLUGIN = "ULTRA11Y_OPENCODE_PLUGIN";
30
- const ULTRA11Y_PLUGIN_VERSION = "5.55.5";
30
+ const ULTRA11Y_PLUGIN_VERSION = "5.56.0";
31
31
 
32
32
  const here = dirname(fileURLToPath(import.meta.url));
33
33
 
package/README.md CHANGED
@@ -359,9 +359,11 @@ The generated [106-criterion / 258-test matrix](skills/ultra11y/references/rgaa-
359
359
  is the source of truth; CI rebuilds it from the vendored DINUM data and rejects drift.
360
360
 
361
361
  **Downloadable PDF documents (RGAA 13.3).** The engine reads PDFs with its own zero-dependency
362
- reader (Node `zlib` only): `audit report.pdf` / `audit "public/**/*.pdf"`, and `scan` downloads
363
- the same-origin PDFs each captured page links to (bounded, `--no-pdf` to opt out) into
364
- `.ultra11y/documents/`. Five document checks — `pdf-untagged`, `pdf-lang-missing`,
362
+ reader (Node `zlib` only): `audit report.pdf` / `audit "public/**/*.pdf"`, and `scan` — or the
363
+ Playwright fixture, through the test's own session — downloads the same-origin PDFs each captured
364
+ page links to into `.ultra11y/documents/`: a `.pdf` path, a `download` link, a link or route
365
+ naming PDF (`/api/declaration-pdf`), kept only when the response is a PDF; `scan --storage-state`
366
+ sends the session's matching cookies (bounded, `--no-pdf` / `pdf: false` to opt out). Five document checks — `pdf-untagged`, `pdf-lang-missing`,
365
367
  `pdf-title-missing` (title + `DisplayDocTitle`), `pdf-no-text` (image-only scan) and the advisory
366
368
  `pdf-structure-shallow` — are listed per document in the report and reach RGAA 13.3 as
367
369
  **candidate** evidence: an accessible alternative version may exist, so they never decide a
@@ -25,6 +25,22 @@ interface PlaywrightPage {
25
25
  mouse?: {
26
26
  move(x: number, y: number): Promise<void>;
27
27
  };
28
+ context?(): {
29
+ request?: PlaywrightRequest;
30
+ };
31
+ }
32
+ /** Playwright's APIRequestContext, to exactly what the document download uses. */
33
+ interface PlaywrightRequest {
34
+ get(url: string, opts: {
35
+ timeout?: number;
36
+ maxRedirects?: number;
37
+ failOnStatusCode?: boolean;
38
+ }): Promise<{
39
+ status(): number;
40
+ headers(): Record<string, string>;
41
+ body(): Promise<Buffer>;
42
+ dispose?(): Promise<void>;
43
+ }>;
28
44
  }
29
45
  interface PlaywrightCheckOptions extends CheckOptions {
30
46
  /** Also write the per-page report once this page is recorded. Off by default: a report
@@ -34,7 +50,22 @@ interface PlaywrightCheckOptions extends CheckOptions {
34
50
  standard?: string;
35
51
  lang?: string;
36
52
  };
53
+ /** Download the same-origin PDF documents this page links to (on by default, as in `scan`;
54
+ * `false` is `--no-pdf`). A candidate — a `.pdf` path, `download`, a text / `aria-label` /
55
+ * `title` or a route naming PDF — is fetched with the page's own request context, so the
56
+ * test's session goes with it, and kept only when the response is `application/pdf` or
57
+ * starts `%PDF-`. Stored in `.ultra11y/documents/<sha256>.pdf` with a sidecar naming the URL
58
+ * and every page linking it; `audit` re-reads them. Never fails the test: a refusal is
59
+ * printed with its reason. */
60
+ pdf?: boolean;
61
+ /** Most documents downloaded per test worker (default 20, each capped at 20 MiB) — `--max-pdf`. */
62
+ maxPdf?: number;
37
63
  }
64
+ /** Download the documents a recorded page links to. Returns the files it holds for this page. */
65
+ declare function downloadPageDocuments(page: PlaywrightPage, pageId: string, opts?: {
66
+ maxPdf?: number;
67
+ root?: string;
68
+ }): Promise<string[]>;
38
69
  /** Collect the current page, persist it as a snapshot, audit it, and fail on the threshold. */
39
70
  declare function checkA11y(page: PlaywrightPage, opts?: PlaywrightCheckOptions): Promise<AuditLike>;
40
71
  /** Optional fixture form. Import `test` from here instead of `@playwright/test`.
@@ -122,4 +153,4 @@ declare function sweepCheckOptions(check?: SweepOptions["check"]): SweepOptions[
122
153
  };
123
154
  declare function sweepSample(opts?: SweepOptions): void;
124
155
 
125
- export { AuditLike, CheckOptions, type PlaywrightCheckOptions, type SamplePageLike, type SweepOptions, checkA11y, samplePagesFor, sweepCheckOptions, sweepSample, sweepTarget, test };
156
+ export { AuditLike, CheckOptions, type PlaywrightCheckOptions, type SamplePageLike, type SweepOptions, checkA11y, downloadPageDocuments, samplePagesFor, sweepCheckOptions, sweepSample, sweepTarget, test };
@@ -1,7 +1,7 @@
1
1
  // src/integrations/playwright.ts
2
- import { readFileSync } from "fs";
2
+ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
3
3
  import { createRequire as createRequire2 } from "module";
4
- import { join } from "path";
4
+ import { join as join2 } from "path";
5
5
 
6
6
  // src/collector.ts
7
7
  var COLLECTED_CSS = [
@@ -161,6 +161,139 @@ var COLLECT_SNAPSHOT = `(() => {
161
161
  };
162
162
  })()`;
163
163
 
164
+ // src/document-store.ts
165
+ import { createHash } from "crypto";
166
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
167
+ import { join } from "path";
168
+ var DOCUMENTS_DIR = ".ultra11y/documents";
169
+ var DOCUMENT_MAX_COUNT = 20;
170
+ var DOCUMENT_MAX_BYTES = 20 * 1024 * 1024;
171
+ var DOCUMENT_TIMEOUT_MS = 2e4;
172
+ var PDF_WORD = /(?:^|[^\p{L}\p{N}])pdf(?:$|[^\p{L}\p{N}])/iu;
173
+ function namesPdf(s) {
174
+ return !!s && PDF_WORD.test(s);
175
+ }
176
+ function urlNamesPdf(u) {
177
+ let s = `${u.pathname}${u.search}`;
178
+ try {
179
+ s = decodeURIComponent(s);
180
+ } catch {
181
+ }
182
+ return s.split(/[^\p{L}\p{N}]+/u).some((tok) => tok.toLowerCase() === "pdf");
183
+ }
184
+ function documentCandidate(link, page, base = page) {
185
+ const href = (link.href ?? "").trim();
186
+ if (!href || href.startsWith("#") || /^(?:javascript|mailto|tel|data|blob):/i.test(href)) return void 0;
187
+ let u;
188
+ try {
189
+ u = new URL(href, base);
190
+ } catch {
191
+ return void 0;
192
+ }
193
+ if (u.protocol !== page.protocol) return void 0;
194
+ if (u.protocol !== "http:" && u.protocol !== "https:" && u.protocol !== "file:") return void 0;
195
+ if ((u.protocol === "http:" || u.protocol === "https:") && u.host !== page.host) return void 0;
196
+ const candidate = /\.pdf$/i.test(u.pathname) || (link.type ?? "").trim().toLowerCase() === "application/pdf" || link.download === true || namesPdf(link.text) || namesPdf(link.ariaLabel) || namesPdf(link.title) || urlNamesPdf(u);
197
+ if (!candidate) return void 0;
198
+ u.hash = "";
199
+ return u.href;
200
+ }
201
+ function hasPdfHeader(bytes) {
202
+ return bytes.toString("latin1", 0, Math.min(bytes.length, 1024)).includes("%PDF-");
203
+ }
204
+ function looksLikePdf(contentType, bytes) {
205
+ const ct = (contentType ?? "").split(";")[0].trim().toLowerCase();
206
+ return ct === "application/pdf" || hasPdfHeader(bytes);
207
+ }
208
+ function sameOriginHop(start, next) {
209
+ if (next.protocol !== "http:" && next.protocol !== "https:") return false;
210
+ if (next.origin === start.origin) return true;
211
+ return start.protocol === "http:" && next.protocol === "https:" && next.hostname === start.hostname;
212
+ }
213
+ async function fetchDocument(url, fetcher, opts = {}) {
214
+ const maxBytes = opts.maxBytes ?? DOCUMENT_MAX_BYTES;
215
+ const maxRedirects = opts.maxRedirects ?? 5;
216
+ let start;
217
+ try {
218
+ start = new URL(url);
219
+ } catch {
220
+ return { reason: `unreadable URL ${url}` };
221
+ }
222
+ let current = url;
223
+ for (let hop = 0; ; hop++) {
224
+ let res;
225
+ try {
226
+ res = await fetcher(current);
227
+ } catch (e) {
228
+ return { reason: `request failed: ${e instanceof Error ? e.message : String(e)}` };
229
+ }
230
+ if (res.status >= 300 && res.status < 400 && res.header("location")) {
231
+ await res.discard?.().catch(() => void 0);
232
+ if (hop >= maxRedirects) return { reason: `more than ${maxRedirects} redirects` };
233
+ let next;
234
+ try {
235
+ next = new URL(res.header("location"), current);
236
+ } catch {
237
+ return { reason: `unreadable redirect to ${res.header("location")}` };
238
+ }
239
+ if (!sameOriginHop(start, next)) return { reason: `redirected off-origin to ${next.href}` };
240
+ current = next.href;
241
+ continue;
242
+ }
243
+ if (res.status < 200 || res.status >= 300) {
244
+ await res.discard?.().catch(() => void 0);
245
+ return { reason: `HTTP ${res.status}` };
246
+ }
247
+ const declared = Number(res.header("content-length") ?? "");
248
+ if (Number.isFinite(declared) && declared > maxBytes) {
249
+ await res.discard?.().catch(() => void 0);
250
+ return { reason: `larger than ${maxBytes} bytes` };
251
+ }
252
+ let bytes;
253
+ try {
254
+ bytes = await res.body(maxBytes);
255
+ } catch (e) {
256
+ return { reason: `request failed: ${e instanceof Error ? e.message : String(e)}` };
257
+ }
258
+ if (!bytes) return { reason: `larger than ${maxBytes} bytes` };
259
+ const type = res.header("content-type");
260
+ if (!looksLikePdf(type, bytes))
261
+ return { reason: `not a PDF \u2014 the response is ${type ? type.split(";")[0].trim() : "untyped"} with no %PDF- header (a login page, an error page?)` };
262
+ return { bytes, url: current };
263
+ }
264
+ }
265
+ var SIDECAR_KIND = "ultra11y-document";
266
+ var SIDECAR_VERSION = 1;
267
+ function readDocumentOrigin(pdfPath) {
268
+ const side = pdfPath.replace(/\.pdf$/i, ".json");
269
+ if (side === pdfPath || !existsSync(side)) return void 0;
270
+ try {
271
+ const raw = JSON.parse(readFileSync(side, "utf8"));
272
+ if (!raw || typeof raw !== "object" || raw.v !== SIDECAR_VERSION) return void 0;
273
+ if (raw.kind !== SIDECAR_KIND && !(raw.kind === void 0 && /(?:^|[\\/])[0-9a-f]{64}\.pdf$/i.test(pdfPath))) return void 0;
274
+ const url = typeof raw.url === "string" ? raw.url : void 0;
275
+ const pages = Array.isArray(raw.pages) ? raw.pages.filter((p) => typeof p === "string") : void 0;
276
+ return { ...url ? { url } : {}, ...pages?.length ? { pages: [...new Set(pages)].sort() } : {} };
277
+ } catch {
278
+ return void 0;
279
+ }
280
+ }
281
+ function recordDocumentPages(file, url, pageIds) {
282
+ const prev = readDocumentOrigin(file);
283
+ const pages = [.../* @__PURE__ */ new Set([...prev?.pages ?? [], ...pageIds])].sort();
284
+ writeFileSync(file.replace(/\.pdf$/i, ".json"), `${JSON.stringify({ kind: SIDECAR_KIND, v: SIDECAR_VERSION, url: prev?.url ?? url, pages }, null, 2)}
285
+ `);
286
+ }
287
+ function storeDocument(root, url, bytes, pageIds) {
288
+ const dir = join(root, DOCUMENTS_DIR);
289
+ const sha = createHash("sha256").update(bytes).digest("hex");
290
+ const file = join(dir, `${sha}.pdf`);
291
+ mkdirSync(dir, { recursive: true });
292
+ writeFileSync(file, bytes);
293
+ recordDocumentPages(file, url, pageIds);
294
+ return file;
295
+ }
296
+
164
297
  // src/probes.ts
165
298
  var PROBES_VERSION = 2;
166
299
  var PRELUDE = `
@@ -1052,6 +1185,82 @@ function writePagesReport(opts = {}, engine = enginePath()) {
1052
1185
  }
1053
1186
 
1054
1187
  // src/integrations/playwright.ts
1188
+ var LINKS_SCRIPT = `(() => Array.from(document.querySelectorAll("a[href]"), (a) => ({
1189
+ href: a.href,
1190
+ download: a.hasAttribute("download"),
1191
+ type: a.getAttribute("type") || "",
1192
+ text: (a.textContent || "").replace(/\\s+/g, " ").trim().slice(0, 500),
1193
+ ariaLabel: a.getAttribute("aria-label") || "",
1194
+ title: a.getAttribute("title") || "",
1195
+ })))()`;
1196
+ var storedDocuments = /* @__PURE__ */ new Map();
1197
+ function requestFetcher(request) {
1198
+ return async (url) => {
1199
+ const res = await request.get(url, { timeout: DOCUMENT_TIMEOUT_MS, maxRedirects: 0, failOnStatusCode: false });
1200
+ const headers = res.headers();
1201
+ return {
1202
+ status: res.status(),
1203
+ header: (name) => headers[name.toLowerCase()],
1204
+ discard: async () => {
1205
+ await res.dispose?.();
1206
+ },
1207
+ // The request context buffers the whole body; the declared length is checked first, and a
1208
+ // body over the bound is still never kept.
1209
+ body: async (maxBytes) => {
1210
+ const bytes = await res.body();
1211
+ await res.dispose?.();
1212
+ return bytes.length > maxBytes ? void 0 : bytes;
1213
+ }
1214
+ };
1215
+ };
1216
+ }
1217
+ async function downloadPageDocuments(page, pageId, opts = {}) {
1218
+ const request = page.context?.()?.request;
1219
+ if (!request) return [];
1220
+ const root = opts.root ?? process.cwd();
1221
+ const max = opts.maxPdf ?? DOCUMENT_MAX_COUNT;
1222
+ let pageUrl;
1223
+ try {
1224
+ pageUrl = new URL(page.url());
1225
+ } catch {
1226
+ return [];
1227
+ }
1228
+ if (pageUrl.protocol !== "http:" && pageUrl.protocol !== "https:") return [];
1229
+ const links = await page.evaluate(LINKS_SCRIPT) ?? [];
1230
+ const candidates = [...new Set(links.map((l) => documentCandidate(l, pageUrl)).filter((u) => !!u))].sort();
1231
+ const files = [];
1232
+ const inRoot = (url) => `${root}
1233
+ ${url}`;
1234
+ let attempts = 0;
1235
+ for (const url of candidates) {
1236
+ const known = storedDocuments.get(inRoot(url));
1237
+ if (known && existsSync2(known)) {
1238
+ recordDocumentPages(known, url, [pageId]);
1239
+ files.push(known);
1240
+ continue;
1241
+ }
1242
+ const held = [...storedDocuments.keys()].filter((k) => k.startsWith(`${root}
1243
+ `)).length;
1244
+ if (held >= max || attempts >= max) {
1245
+ console.warn(`ultra11y: document not downloaded \u2014 ${url}: document cap reached (${max}).`);
1246
+ continue;
1247
+ }
1248
+ attempts++;
1249
+ try {
1250
+ const r = await fetchDocument(url, requestFetcher(request), { maxBytes: DOCUMENT_MAX_BYTES });
1251
+ if ("reason" in r) {
1252
+ console.warn(`ultra11y: document not downloaded \u2014 ${url}: ${r.reason}.`);
1253
+ continue;
1254
+ }
1255
+ const file = storeDocument(root, url, r.bytes, [pageId]);
1256
+ storedDocuments.set(inRoot(url), file);
1257
+ files.push(file);
1258
+ } catch (e) {
1259
+ console.warn(`ultra11y: document not downloaded \u2014 ${url}: failed: ${e instanceof Error ? e.message : String(e)}.`);
1260
+ }
1261
+ }
1262
+ return files;
1263
+ }
1055
1264
  function probeOptions(p) {
1056
1265
  if (p === true || p === void 0) return fromConfig();
1057
1266
  if (p === false) return {};
@@ -1061,7 +1270,7 @@ function probeOptions(p) {
1061
1270
  }
1062
1271
  function fromConfig() {
1063
1272
  try {
1064
- const cfg = JSON.parse(readFileSync(join(process.cwd(), ".ultra11yrc.json"), "utf8"));
1273
+ const cfg = JSON.parse(readFileSync2(join2(process.cwd(), ".ultra11yrc.json"), "utf8"));
1065
1274
  if (!cfg.probes) return {};
1066
1275
  const { only, ...limits } = cfg.probes;
1067
1276
  return { ...only ? { only } : {}, limits };
@@ -1074,7 +1283,7 @@ async function runAxe(page, mode) {
1074
1283
  const demanded = mode === true;
1075
1284
  let AxeBuilder;
1076
1285
  let lastError;
1077
- for (const from of [join(process.cwd(), "package.json"), import.meta.url]) {
1286
+ for (const from of [join2(process.cwd(), "package.json"), import.meta.url]) {
1078
1287
  try {
1079
1288
  const mod = createRequire2(from)("@axe-core/playwright");
1080
1289
  AxeBuilder = mod.default ?? mod;
@@ -1133,6 +1342,13 @@ async function checkA11y(page, opts = {}) {
1133
1342
  const axe = await runAxe(page, opts.axe ?? "auto");
1134
1343
  const payload = buildPayload(collected, url, "playwright", opts, shot, probes, axe);
1135
1344
  const result = auditSnapshot(payload);
1345
+ if (opts.pdf !== false) {
1346
+ try {
1347
+ await downloadPageDocuments(page, String(payload.meta.id), { ...opts.maxPdf !== void 0 ? { maxPdf: opts.maxPdf } : {} });
1348
+ } catch (e) {
1349
+ console.warn(`ultra11y: the document download failed on this page \u2014 ${e instanceof Error ? e.message : String(e)}. The snapshot was still recorded.`);
1350
+ }
1351
+ }
1136
1352
  if (opts.report) writePagesReport(typeof opts.report === "object" ? opts.report : {});
1137
1353
  gate(result, String(payload.meta.name), opts.failOn);
1138
1354
  return result;
@@ -1158,7 +1374,7 @@ function samplePagesFor(opts = {}) {
1158
1374
  const cwd = opts.cwd ?? process.cwd();
1159
1375
  let declared;
1160
1376
  try {
1161
- const raw = readFileSync(join(cwd, ".ultra11yrc.json"), "utf8");
1377
+ const raw = readFileSync2(join2(cwd, ".ultra11yrc.json"), "utf8");
1162
1378
  declared = JSON.parse(raw).sample?.pages ?? [];
1163
1379
  } catch {
1164
1380
  throw new Error(`ultra11y: no readable .ultra11yrc.json in ${cwd} \u2014 sweepSample reads the page sample from it.`);
@@ -1206,6 +1422,7 @@ function sweepSample(opts = {}) {
1206
1422
  }
1207
1423
  export {
1208
1424
  checkA11y,
1425
+ downloadPageDocuments,
1209
1426
  samplePagesFor,
1210
1427
  sweepCheckOptions,
1211
1428
  sweepSample,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ultra11y",
3
- "version": "5.55.5",
3
+ "version": "5.56.0",
4
4
  "description": "Audit d'accessibilité RGAA 4.1.2, le référentiel de l'État : rapport daté, grille des 106 critères, backlog et tickets. Moteur statique, navigateur et jugement IA contre-vérifié. Il ne déclare jamais conforme ce qu'il n'a pas vérifié. Socle WCAG 2.2 AA.",
5
5
  "homepage": "https://socialgouv.github.io/ultra11y/",
6
6
  "type": "module",