diff --git a/DECISIONS.md b/DECISIONS.md index e83f384..1fb8a5b 100644 --- a/DECISIONS.md +++ b/DECISIONS.md @@ -219,3 +219,46 @@ Ogni scelta non banale presa durante lo sviluppo (brief §0.4). Formato: data · - **Scelta:** in `lighthouserc.cjs` restano errori bloccanti le quattro soglie di §9.3 (Performance ≥ 0.95, Accessibility = 1, Best Practices ≥ 0.95, SEO = 1) e tutti gli audit del preset; sono declassati a `warn` solo: `network-dependency-tree-insight`, `critical-request-chains`, `render-blocking-insight`, `render-blocking-resources`, `uses-http2`, `bf-cache`, `csp-xss`. - **Alternative scartate:** togliere il preset (si perderebbero i controlli puntuali). - **Motivazione:** regole «rumorose» declassate come previsto dal brief (§11.6), senza allentare le soglie. + +## D-028 — Punti di interruzione in `em` e focus ciclico nel menu mobile + +- **Data:** 2026-10-15 +- **Contesto:** il test «testo al 200 %» (dimensione del carattere del browser raddoppiata) mostrava scorrimento orizzontale: con i punti di interruzione in px l'intestazione desktop restava attiva anche con testo doppio. Il test del menu mobile mostrava che il `` nativo lascia uscire il focus verso l'interfaccia del browser dopo l'ultimo elemento. +- **Scelta:** media query in `em` (960 px → 60em, 640 px → 40em, 1100 px → 68.75em, 420 px → 26.25em) e larghezze fisse in `rem`; nel menu mobile Tab/Maiusc+Tab ciclano tra il primo e l'ultimo elemento. +- **Alternative scartate:** lasciare il comportamento nativo del dialog (accettabile ma meno prevedibile per chi usa la tastiera). +- **Motivazione:** WCAG 1.4.4 (ridimensionamento del testo) e 2.4.3 (ordine del focus) senza eccezioni. + +## D-029 — Correzioni ai test durante la fase 6 + +- **Data:** 2026-10-15 +- **Contesto:** §0.6 chiede di spiegare ogni test corretto. +- **Scelta:** + 1. `check-compliance.mjs`, controllo «commercialista»: `DomUtils.findAll` restituisce solo elementi, quindi i nodi di testo non venivano esaminati; sostituito con una visita esplicita dei nodi di testo e una divisione in frasi che non spezza «Dott.», «n.», «sez.». Verificato con casi negativi iniettati (frasi errate rilevate, frasi sulla Dott.ssa Giulia Grasso accettate). + 2. Test «testo al 200 %»: la prima versione iniettava `html { font-size: 200% }`, che non agisce sulle media query e non corrisponde a nessuna impostazione reale; ora il test usa il protocollo DevTools (`Page.setFontSizes`) come la preferenza «Dimensione carattere» del browser. + 3. Test axe con mappa caricata: l'iframe è contenuto di terze parti (nei test una pagina finta): escluso dall'analisi, che resta sul markup del sito. +- **Alternative scartate:** nessuna (i test non sono stati allentati: le soglie restano zero violazioni gravi/critiche). +- **Motivazione:** test corretti che verificano davvero il requisito. + +## D-030 — Link esterni nel Markdown e processore Markdown di Astro 7 + +- **Data:** 2026-10-15 +- **Contesto:** in Astro 7 il processore Markdown predefinito (Sätteri) ignora `markdown.rehypePlugins` (deprecato); i link esterni dei testi legali risultavano senza `rel="noopener"` (rilevato da `check-compliance`). +- **Scelta:** l'HTML generato dal Markdown (servizi e testi legali) passa da `src/lib/html.ts`, che aggiunge `rel="noopener"` ai link verso altri domini; i link si aprono nella stessa scheda (§4.7). +- **Alternative scartate:** installare `@astrojs/markdown-remark` solo per un plugin. +- **Motivazione:** nessuna dipendenza in più, comportamento verificato dai test. + +## D-031 — Dipendenze di test esplicite + +- **Data:** 2026-10-15 +- **Contesto:** `@axe-core/playwright` dichiara `playwright-core` come peer e npm installava la 1.64.1 accanto alla 1.56.1 di Playwright (tipi incompatibili); `check-compliance.mjs` usa `htmlparser2`, già presente come dipendenza di linkinator. +- **Scelta:** `playwright-core@1.56.1` e `htmlparser2@12.0.0` dichiarati esplicitamente in `devDependencies`. +- **Alternative scartate:** affidarsi alle dipendenze transitive. +- **Motivazione:** una sola versione di Playwright nel progetto; nessuna dipendenza usata senza essere dichiarata. + +## D-032 — Test del modulo con il modulo attivo + +- **Data:** 2026-10-15 +- **Contesto:** con la configurazione predefinita (`contactForm.mode = 'off'`) i test del modulo (validazione, honeypot, tempo minimo, pagina di conferma) vengono saltati. +- **Scelta:** la variabile d'ambiente `CONTACT_FORM_MODE` (`off`, `php`, `endpoint`) ha la precedenza su `studio.ts`; i test del modulo sono stati eseguiti con `CONTACT_FORM_MODE=php npm run build` seguito da Playwright (tutti verdi, insieme a html-validate, axe e conformità). Il README spiega come ripeterli. L'invio a `/contact.php` è simulato nei test (nessun PHP in `astro preview`). +- **Alternative scartate:** attivare il modulo per impostazione predefinita (moduli rotti su hosting senza PHP, §10.1). +- **Motivazione:** il modulo resta verificato anche se disattivato. diff --git a/package-lock.json b/package-lock.json index 7db8d4b..51558fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,9 +30,11 @@ "eslint-plugin-astro": "3.2.1", "globals": "17.13.0", "html-validate": "11.16.2", + "htmlparser2": "12.0.0", "linkinator": "8.1.0", "opentype.js": "2.0.0", "playwright": "1.56.1", + "playwright-core": "1.56.1", "prettier": "3.9.10", "prettier-plugin-astro": "1.1.1", "sharp": "0.35.5", @@ -8151,17 +8153,16 @@ } }, "node_modules/playwright-core": { - "version": "1.64.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.64.1.tgz", - "integrity": "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ==", + "version": "1.56.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.56.1.tgz", + "integrity": "sha512-hutraynyn31F+Bifme+Ps9Vq59hKuUCz7H1kDOcBs+2oGguKkWTU50bBWrtz34OUWmIwpBTWDxaRPXrIXkgvmQ==", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "playwright-core": "cli.js" }, "engines": { - "node": ">=20" + "node": ">=18" } }, "node_modules/playwright/node_modules/fsevents": { @@ -8179,19 +8180,6 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, - "node_modules/playwright/node_modules/playwright-core": { - "version": "1.56.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.56.1.tgz", - "integrity": "sha512-hutraynyn31F+Bifme+Ps9Vq59hKuUCz7H1kDOcBs+2oGguKkWTU50bBWrtz34OUWmIwpBTWDxaRPXrIXkgvmQ==", - "dev": true, - "license": "Apache-2.0", - "bin": { - "playwright-core": "cli.js" - }, - "engines": { - "node": ">=18" - } - }, "node_modules/postcss": { "version": "8.5.30", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.30.tgz", diff --git a/package.json b/package.json index 448f1df..9729533 100644 --- a/package.json +++ b/package.json @@ -50,9 +50,11 @@ "eslint-plugin-astro": "3.2.1", "globals": "17.13.0", "html-validate": "11.16.2", + "htmlparser2": "12.0.0", "linkinator": "8.1.0", "opentype.js": "2.0.0", "playwright": "1.56.1", + "playwright-core": "1.56.1", "prettier": "3.9.10", "prettier-plugin-astro": "1.1.1", "sharp": "0.35.5", diff --git a/scripts/check-compliance.mjs b/scripts/check-compliance.mjs index a518505..06a1adb 100644 --- a/scripts/check-compliance.mjs +++ b/scripts/check-compliance.mjs @@ -1,2 +1,715 @@ -// Segnaposto della fase 0: l'implementazione completa arriva nelle fasi successive (vedi DECISIONS.md). -console.log('scripts/check-compliance.mjs: non ancora implementato (fase 0).'); +#!/usr/bin/env node +/** + * Controlli di conformità sul sito compilato (brief §11.5). Ogni errore indica COSA non va e + * DOVE (file di dist/). Richiede `npm run build`. Uscita con codice 1 se c'è almeno un errore. + * + * I dati attesi (abilitazioni, servizi, P.IVA, professionisti) sono letti dalle stesse fonti + * del sito: src/data/studio.ts e src/content/servizi/*.md. + */ +import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'; +import { join, resolve } from 'node:path'; +import { DomUtils, parseDocument } from 'htmlparser2'; +import { fileToPath, listHtmlFiles, readSitemapPaths } from './lib/pages.mjs'; +import { root } from './lib/preview-server.mjs'; + +const dist = resolve(root, 'dist'); +const { abilitazioni, professionisti, studio, contactForm } = await import( + resolve(root, 'src/data/studio.ts') +); + +const SITE = (process.env.SITE_URL || 'https://www.grassoezio.it').replace(/\/+$/, ''); +const PIVA = `P.IVA ${studio.partitaIva}`; +const LEGAL_PAGES = ['/privacy-policy/', '/cookie-policy/', '/note-legali/', '/accessibilita/']; +const NOINDEX_PAGES = ['/404.html', '/contatti/grazie/']; +const BUDGET_HTML_CSS = 120 * 1024; +const BUDGET_JS = 15 * 1024; +const BUDGET_FONTS = 110 * 1024; + +const errors = []; +const fail = (where, what) => errors.push(`${where}: ${what}`); +let checks = 0; +const check = (ok, where, what) => { + checks++; + if (!ok) fail(where, what); + return ok; +}; + +/* ------------------------------------------------------------------ utilità DOM */ + +const { findAll, findOne, getAttributeValue: attr, textContent, getParent } = DomUtils; +const isTag = (n) => n.type === 'tag' || n.type === 'script' || n.type === 'style'; +const all = (doc, pred) => findAll((n) => isTag(n) && pred(n), doc.children); +const byTag = (doc, name) => all(doc, (n) => n.name === name); +const normalize = (s) => s.replace(/\s+/g, ' ').replace(/[’‘]/g, "'").trim(); + +/** Testo visibile (esclusi script, style, noscript, template). */ +function visibleText(node) { + if (node.type === 'text') return node.data; + if (!isTag(node) && node.type !== 'root') return ''; + if (['script', 'style', 'noscript', 'template'].includes(node.name)) return ''; + return (node.children ?? []).map(visibleText).join(' '); +} + +const BLOCKS = new Set([ + 'p', + 'li', + 'dd', + 'dt', + 'h1', + 'h2', + 'h3', + 'h4', + 'h5', + 'h6', + 'td', + 'th', + 'address', + 'figcaption', + 'blockquote', + 'label', + 'button', + 'a', + 'title', +]); + +/** Tutti i nodi di testo del documento (DomUtils.findAll restituisce solo elementi). */ +function textNodes(node, out = []) { + for (const child of node.children ?? []) { + if (child.type === 'text') out.push(child); + else textNodes(child, out); + } + return out; +} + +/** Divide in frasi senza spezzare abbreviazioni come «Dott.», «Dott.ssa», «n.», «sez.». */ +function sentences(text) { + const protectedText = text.replace( + /\b(Dott|Dott\.ssa|Avv|Rag|Sig|n|nn|sez|art|artt|co|lett|par|D\.Lgs|D\.L|L|Reg|ecc|es|tel|p)\./gi, + (m) => m.replace(/\./g, '\u2024'), + ); + return protectedText.split(/(?<=[.!?;])\s+/).map((s) => s.replace(/\u2024/g, '.')); +} + +function closestBlock(node) { + let n = getParent(node); + while (n && !(isTag(n) && BLOCKS.has(n.name))) n = getParent(n); + return n; +} + +function ancestorWithAttr(node, name, value) { + for (let n = getParent(node); n; n = getParent(n)) { + if (isTag(n) && attr(n, name) === value) return n; + } + return null; +} + +/* ------------------------------------------------------------------ pagine */ + +check(existsSync(dist), 'dist/', 'cartella assente: esegui prima `npm run build`'); +const htmlFiles = listHtmlFiles(dist); +const pages = htmlFiles.map((file) => { + const html = readFileSync(join(dist, file), 'utf8'); + return { file: `dist/${file}`, path: fileToPath(file), html, doc: parseDocument(html) }; +}); +const byPath = new Map(pages.map((p) => [p.path, p])); + +check(pages.length >= 18, 'dist/', `attese almeno 18 pagine HTML, trovate ${pages.length}`); + +/* ------------------------------------------------------------------ file obbligatori */ + +for (const f of [ + '.htaccess', + '404.html', + 'robots.txt', + 'sitemap-index.xml', + 'favicon.svg', + 'favicon.ico', +]) { + check(existsSync(join(dist, f)), `dist/${f}`, 'file obbligatorio mancante'); +} +for (const p of LEGAL_PAGES) { + const page = byPath.get(p); + if (check(Boolean(page), `pagina ${p}`, 'pagina legale mancante')) { + check(byTag(page.doc, 'h1').length === 1, page.file, 'la pagina legale deve avere un

'); + } +} + +/* ------------------------------------------------------------------ robots e sitemap */ + +const robots = existsSync(join(dist, 'robots.txt')) + ? readFileSync(join(dist, 'robots.txt'), 'utf8') + : ''; +check( + robots.includes(`Sitemap: ${SITE}/sitemap-index.xml`), + 'dist/robots.txt', + `manca la riga «Sitemap: ${SITE}/sitemap-index.xml»`, +); +check( + /User-agent:\s*\*/i.test(robots) && /Allow:\s*\//i.test(robots), + 'dist/robots.txt', + 'mancano User-agent/Allow', +); + +const sitemapPaths = readSitemapPaths(dist); +const expectedInSitemap = pages + .map((p) => p.path) + .filter((p) => !NOINDEX_PAGES.includes(p)) + .sort(); +for (const p of expectedInSitemap) + check(sitemapPaths.includes(p), 'sitemap', `manca la pagina ${p}`); +for (const p of sitemapPaths) { + check(expectedInSitemap.includes(p), 'sitemap', `contiene ${p}, che non esiste o è noindex`); +} +for (const p of NOINDEX_PAGES) { + const page = byPath.get(p); + if (check(Boolean(page), `pagina ${p}`, 'pagina mancante')) { + const robotsMeta = findOne( + (n) => n.name === 'meta' && attr(n, 'name') === 'robots', + page.doc.children, + ); + check( + /noindex/.test(attr(robotsMeta ?? {}, 'content') ?? ''), + page.file, + 'manca ', + ); + } +} + +/* ------------------------------------------------------------------ controlli per pagina */ + +const PLACEHOLDERS = [ + /\bTODO\b/, + /lorem/i, + /XXX/, + /\[da\b/i, + /\{\{|\}\}/, + /\bundefined\b/, + /\bnull\b/, + /NaN/, +]; +const FORBIDDEN_REFS = [ + /fonts\.googleapis\.com/i, + /gstatic/i, + /analytics/i, + /gtag/i, + /\bcdn\./i, + /googletagmanager/i, +]; +const COMMERCIALISTA_OK = + /giulia|odcec|ordine dei dottori commercialisti|\bocc\b|organismo di composizione della crisi/i; +const titles = new Map(); +const descriptions = new Map(); +const year = String(new Date().getFullYear()); + +for (const page of pages) { + const { doc, file, path, html } = page; + const where = `${file} (${path})`; + + // lingua, viewport, titolo, descrizione, canonical + const htmlEl = byTag(doc, 'html')[0]; + check(attr(htmlEl ?? {}, 'lang') === 'it', where, 'manca lang="it" su '); + const viewport = findOne( + (n) => n.name === 'meta' && attr(n, 'name') === 'viewport', + doc.children, + ); + const vp = attr(viewport ?? {}, 'content') ?? ''; + check(Boolean(viewport), where, 'manca il meta viewport'); + check( + !/user-scalable\s*=\s*(no|0)|maximum-scale/i.test(vp), + where, + `meta viewport che blocca lo zoom: «${vp}»`, + ); + + const title = normalize(textContent(byTag(doc, 'title')[0] ?? { children: [] })); + check( + title.length > 0 && title.length <= 65, + where, + `titolo vuoto o oltre 65 caratteri: «${title}»`, + ); + if (titles.has(title)) fail(where, `titolo duplicato di ${titles.get(title)}: «${title}»`); + titles.set(title, path); + + const descEl = findOne( + (n) => n.name === 'meta' && attr(n, 'name') === 'description', + doc.children, + ); + const desc = normalize(attr(descEl ?? {}, 'content') ?? ''); + check( + desc.length >= 120 && desc.length <= 155, + where, + `descrizione di ${desc.length} caratteri (attesi 120–155)`, + ); + if (descriptions.has(desc)) fail(where, `descrizione duplicata di ${descriptions.get(desc)}`); + descriptions.set(desc, path); + + if (path !== '/404.html') { + const canonical = findOne( + (n) => n.name === 'link' && attr(n, 'rel') === 'canonical', + doc.children, + ); + check( + attr(canonical ?? {}, 'href') === `${SITE}${path}`, + where, + `canonical atteso ${SITE}${path}, trovato ${attr(canonical ?? {}, 'href')}`, + ); + } + + // un solo h1 + check( + byTag(doc, 'h1').length === 1, + where, + `attesa una sola intestazione

, trovate ${byTag(doc, 'h1').length}`, + ); + + // footer: P.IVA, anno, link legali + const footer = byTag(doc, 'footer')[0]; + const footerText = footer ? normalize(visibleText(footer)) : ''; + check(footerText.includes(PIVA), where, `il footer non contiene «${PIVA}»`); + check( + footerText.includes(`© ${year}`), + where, + `il footer non contiene «© ${year}» (anno di build)`, + ); + for (const legal of ['/privacy-policy/', '/cookie-policy/', '/note-legali/', '/accessibilita/']) { + const found = all(doc, (n) => n.name === 'a' && attr(n, 'href') === legal).length > 0; + check(found, where, `manca il link a ${legal}`); + } + + // risorse: niente http://, niente domini vietati, niente iframe statici + for (const el of all(doc, () => true)) { + for (const name of ['src', 'href', 'srcset', 'action', 'data-map-src', 'poster']) { + const v = attr(el, name); + if (v && /^\s*http:\/\//i.test(v)) + fail(where, `risorsa o link non sicuro (http://) in <${el.name} ${name}="${v}">`); + } + for (const [name, value] of Object.entries(el.attribs ?? {})) { + if (/^on[a-z]+$/i.test(name)) + fail(where, `gestore di evento inline vietato dalla CSP: <${el.name} ${name}="${value}">`); + } + } + for (const re of FORBIDDEN_REFS) + check(!re.test(html), where, `riferimento vietato a ${re.source.replace(/\\/g, '')}`); + check( + byTag(doc, 'iframe').length === 0, + where, + "