fix: CI adattata a Forgejo, revisione completa del codice e avvio in debug
Le run della CI restavano «in attesa» perché l'unico runner dell'istanza («Ferrari») non si è mai collegato: il runner resta da configurare. La revisione completa del codice ha trovato anche difetti che avrebbero fatto fallire la CI con il runner online, oltre ad altri problemi del sito, dei controlli e della documentazione. CI e rilascio: - continue-on-error sullo step dei link esterni: Forgejo lo ignora sul job, e un sito esterno irraggiungibile avrebbe reso rossa la CI; - artifact con i file nascosti (report Lighthouse e .htaccess non venivano mai caricati); - token personale RELEASE_TOKEN: FORGEJO_TOKEN è riservato ed è sempre il token automatico; - dominio in un solo punto (site.config.mjs) e variabile del repository SITE_URL; - ripiego REST: release in bozza, file, poi pubblicazione; tag verificato sul server; sostituzione dei file senza mai lasciarli mancanti; - tar.gz identico su Windows, macOS e Linux (byte del sistema operativo nell'header gzip). Sito: CSS compatibile con Safari/iOS 15 (media query classiche, backdrop-filter), anello di focus con contrasto di almeno 3:1, bersagli touch di 44 px dove servono, intestazione desktop senza voci o logo a capo, HTML valido in /servizi/, colore delle chip, stampa senza mappe, giorni di apertura, ricerca e titolo delle mappe e numero breve ricavati dai dati. Modulo di contatto e contact.php: stesse regole nel browser e sul server (spazi, e-mail, a capo, lunghezze), tempo minimo misurato con un solo orologio (ts_invio), corpo in quoted-printable e oggetto RFC 2047, funzionamento con PHP a 32 bit, costante MODALITA_PREDEFINITA per attivarlo. Controlli e test: valori letti dai dati del sito, i sei servizi del brief con le ancore, «commercialista» anche in meta, attributi e dati strutturati, .htaccess su righe attive, HSTS attivabile con una scelta esplicita, contrasto del focus misurato nei test. Esempi di pubblicazione: nginx con gli header di sicurezza in un solo punto (HSTS compreso), deploy automatico che parte alla pubblicazione e sincronizza solo una cartella confermata, procedura nginx che toglie i file delle versioni precedenti. Debug: .vscode/launch.json e tasks.json, F5 avvia il server Astro e apre il browser con il debugger collegato. Documentazione aggiornata (README, DEPLOY, CONTENUTI, CONFORMITA, TODO-STUDIO, CHANGELOG) e decisioni D-045…D-055. Verificato: npm run verify su Windows e nel container della CI (Playwright 1.56.1, root); job dei link esterni in node:24; contact.php con PHP 7.4 e 8.3, a 64 e 32 bit; nginx in Docker; release-upload.sh e deploy di esempio contro API e shell simulate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5aea990dc2
commit
3befe7e266
50 files changed
+1309
-338
No files matched your search
+208
-27
@@ -3,13 +3,16 @@
|
||||
* 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.
|
||||
* I dati attesi (abilitazioni, servizi, P.IVA, professionisti, orari e giorni di apertura,
|
||||
* dominio) sono letti dalle stesse fonti del sito: src/data/studio.ts,
|
||||
* src/content/servizi/*.md e site.config.mjs. Così una modifica dei contenuti fatta come indica
|
||||
* docs/CONTENUTI.md non fa fallire i controlli.
|
||||
*/
|
||||
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
||||
import { join, resolve } from 'node:path';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
import { DomUtils, parseDocument } from 'htmlparser2';
|
||||
import { siteUrl } from '../site.config.mjs';
|
||||
import { fileToPath, listHtmlFiles, readSitemapPaths } from './lib/pages.mjs';
|
||||
import { root } from './lib/preview-server.mjs';
|
||||
|
||||
@@ -21,7 +24,7 @@ const { abilitazioni, professionisti, studio, contactForm } = await importSrc('s
|
||||
// stesso anno del footer: SOURCE_DATE_EPOCH, se impostata, altrimenti l'anno corrente
|
||||
const { buildYear } = await importSrc('src/lib/build.ts');
|
||||
|
||||
const SITE = (process.env.SITE_URL || 'https://www.grassoezio.it').replace(/\/+$/, '');
|
||||
const SITE = siteUrl();
|
||||
const PIVA = `P.IVA ${studio.partitaIva}`;
|
||||
const LEGAL_PAGES = ['/privacy-policy/', '/cookie-policy/', '/note-legali/', '/accessibilita/'];
|
||||
const NOINDEX_PAGES = ['/404.html', '/contatti/grazie/'];
|
||||
@@ -100,6 +103,24 @@ function closestBlock(node) {
|
||||
return n;
|
||||
}
|
||||
|
||||
/** Problemi di compatibilità nel CSS generato (pagina HTML o file .css). */
|
||||
function cssIssues(css) {
|
||||
checks++;
|
||||
const issues = [];
|
||||
const range = css.match(/@media[^{]*\(\s*(?:width|height)\s*[<>]/);
|
||||
if (range) {
|
||||
issues.push(
|
||||
`media query in sintassi a intervallo «${range[0]}…»: controllare vite.build.cssTarget in astro.config.mjs`,
|
||||
);
|
||||
}
|
||||
for (const block of css.match(/\{[^{}]*-webkit-backdrop-filter:[^{}]*\}/g) ?? []) {
|
||||
if (!/[{;]\s*backdrop-filter:/.test(block)) {
|
||||
issues.push(`-webkit-backdrop-filter senza backdrop-filter: «${block.slice(0, 80)}…»`);
|
||||
}
|
||||
}
|
||||
return issues;
|
||||
}
|
||||
|
||||
function ancestorWithAttr(node, name, value) {
|
||||
for (let n = getParent(node); n; n = getParent(n)) {
|
||||
if (isTag(n) && attr(n, name) === value) return n;
|
||||
@@ -201,10 +222,68 @@ const FORBIDDEN_REFS = [
|
||||
];
|
||||
const COMMERCIALISTA_OK =
|
||||
/giulia|odcec|(ordine|consiglio nazionale) dei dottori commercialisti|\bocc\b|organismo di composizione della crisi/i;
|
||||
const DICITURE_VIETATE = [
|
||||
'studio commercialista',
|
||||
'studio di commercialisti',
|
||||
'studio di commercialista',
|
||||
'commercialista ezio',
|
||||
'ezio grasso, commercialista',
|
||||
'ezio grasso commercialista',
|
||||
];
|
||||
const giulia = professionisti.find((p) => p.id === 'giulia-grasso');
|
||||
|
||||
/**
|
||||
* Testi non visibili che finiscono nei risultati di ricerca, nelle anteprime o agli screen
|
||||
* reader: meta (description, Open Graph, Twitter), attributi alt/title/aria-label e stringhe del
|
||||
* JSON-LD, esclusa la scheda della Dott.ssa Giulia Grasso. Coppie [provenienza, testo].
|
||||
*/
|
||||
function hiddenTexts(doc, ldNodes) {
|
||||
const out = [];
|
||||
for (const el of all(doc, (n) => n.name === 'meta')) {
|
||||
const key = attr(el, 'name') ?? attr(el, 'property') ?? '';
|
||||
if (/^(description$|og:|twitter:)/.test(key))
|
||||
out.push([`meta ${key}`, attr(el, 'content') ?? '']);
|
||||
}
|
||||
for (const el of all(doc, () => true)) {
|
||||
for (const n of ['alt', 'title', 'aria-label', 'data-map-title']) {
|
||||
const v = attr(el, n);
|
||||
if (v) out.push([`attributo ${n} di <${el.name}>`, v]);
|
||||
}
|
||||
}
|
||||
const walk = (value, path) => {
|
||||
if (typeof value === 'string') out.push([`JSON-LD ${path}`, value]);
|
||||
else if (Array.isArray(value)) value.forEach((v, i) => walk(v, `${path}[${i}]`));
|
||||
else if (value && typeof value === 'object') {
|
||||
if (value['@type'] === 'Person' && value.name === giulia?.nomeSenzaTitolo) return;
|
||||
for (const [k, v] of Object.entries(value)) walk(v, `${path}.${k}`);
|
||||
}
|
||||
};
|
||||
for (const n of ldNodes) walk(n, String(n['@type'] ?? 'nodo'));
|
||||
return out;
|
||||
}
|
||||
const titles = new Map();
|
||||
const descriptions = new Map();
|
||||
const year = String(buildYear);
|
||||
|
||||
// orari e giorni di apertura: formato dei dati in studio.ts e valore atteso nel JSON-LD
|
||||
const HHMM = /^([01]\d|2[0-3]):[0-5]\d$/;
|
||||
for (const f of studio.orari.fasce) {
|
||||
check(
|
||||
HHMM.test(f.apertura) && HHMM.test(f.chiusura) && f.apertura < f.chiusura,
|
||||
'src/data/studio.ts',
|
||||
`fascia oraria non valida «${f.apertura}–${f.chiusura}» (formato HH:MM, apertura prima della chiusura)`,
|
||||
);
|
||||
}
|
||||
check(
|
||||
studio.orari.giorniSettimana.length > 0,
|
||||
'src/data/studio.ts',
|
||||
'orari.giorniSettimana vuoto: indicare i giorni di apertura',
|
||||
);
|
||||
const EXPECTED_HOURS = studio.orari.fasce
|
||||
.map((f) => `${f.apertura}-${f.chiusura}`)
|
||||
.sort()
|
||||
.join(',');
|
||||
|
||||
for (const page of pages) {
|
||||
const { doc, file, path, html } = page;
|
||||
const where = `${file} (${path})`;
|
||||
@@ -383,14 +462,7 @@ for (const page of pages) {
|
||||
}
|
||||
}
|
||||
const lower = normalize(text).toLowerCase();
|
||||
for (const bad of [
|
||||
'studio commercialista',
|
||||
'studio di commercialisti',
|
||||
'studio di commercialista',
|
||||
'commercialista ezio',
|
||||
'ezio grasso, commercialista',
|
||||
'ezio grasso commercialista',
|
||||
]) {
|
||||
for (const bad of DICITURE_VIETATE) {
|
||||
check(!lower.includes(bad), where, `dicitura vietata «${bad}»`);
|
||||
}
|
||||
|
||||
@@ -414,6 +486,24 @@ for (const page of pages) {
|
||||
fail(where, `JSON-LD non valido: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// «commercialista» anche nei testi non visibili (meta, attributi, JSON-LD): ogni stringa è
|
||||
// controllata da sola, con le stesse regole del testo visibile
|
||||
for (const [origin, value] of hiddenTexts(doc, nodes)) {
|
||||
const t = normalize(value);
|
||||
if (!/commercialist/i.test(t)) continue;
|
||||
for (const s of sentences(t).filter((x) => /commercialist/i.test(x))) {
|
||||
check(
|
||||
COMMERCIALISTA_OK.test(s),
|
||||
where,
|
||||
`«commercialista» usato fuori contesto in ${origin} (ammesso solo per la Dott.ssa Giulia Grasso, ODCEC, OCC): «${s}»`,
|
||||
);
|
||||
}
|
||||
for (const bad of DICITURE_VIETATE) {
|
||||
check(!t.toLowerCase().includes(bad), where, `dicitura vietata «${bad}» in ${origin}`);
|
||||
}
|
||||
}
|
||||
|
||||
const org = nodes.find((n) => n['@type'] === 'AccountingService');
|
||||
if (check(Boolean(org), where, 'JSON-LD: manca AccountingService')) {
|
||||
for (const k of [
|
||||
@@ -461,10 +551,17 @@ for (const page of pages) {
|
||||
.sort()
|
||||
.join(',');
|
||||
check(
|
||||
hours === '09:00-12:30,15:00-18:30',
|
||||
hours === EXPECTED_HOURS,
|
||||
where,
|
||||
`JSON-LD: orari attesi 09:00-12:30 e 15:00-18:30, trovati ${hours}`,
|
||||
`JSON-LD: orari attesi ${EXPECTED_HOURS} (studio.orari.fasce), trovati ${hours}`,
|
||||
);
|
||||
for (const h of org.openingHoursSpecification ?? []) {
|
||||
check(
|
||||
JSON.stringify(h.dayOfWeek) === JSON.stringify(studio.orari.giorniSettimana),
|
||||
where,
|
||||
`JSON-LD: giorni di apertura ${JSON.stringify(h.dayOfWeek)} diversi da studio.orari.giorniSettimana`,
|
||||
);
|
||||
}
|
||||
const people = (org.employee ?? org.founder ?? []).filter((p) => p['@type'] === 'Person');
|
||||
check(people.length === professionisti.length, where, 'JSON-LD: professionisti mancanti');
|
||||
for (const p of professionisti) {
|
||||
@@ -491,6 +588,14 @@ for (const page of pages) {
|
||||
}
|
||||
}
|
||||
|
||||
// CSS compatibile con i browser di vite.build.cssTarget (astro.config.mjs): media query con
|
||||
// min-/max-width (la sintassi a intervallo non funziona su Safari/iOS < 16.4) e
|
||||
// backdrop-filter anche senza prefisso (Chrome, Edge e Firefox ignorano -webkit-)
|
||||
for (const issue of cssIssues(html)) fail(where, issue);
|
||||
|
||||
// nulla dopo </html> (es. uno <script> scritto fuori dal layout: errore di parsing HTML)
|
||||
check(/<\/html>\s*$/i.test(html), where, 'contenuto dopo </html>: spostarlo dentro il layout');
|
||||
|
||||
// budget HTML + CSS (il CSS è incluso nella pagina)
|
||||
const size = statSync(join(dist, file.replace(/^dist\//, ''))).size;
|
||||
check(
|
||||
@@ -523,7 +628,36 @@ function servicesFromCollection() {
|
||||
}
|
||||
|
||||
const servizi = servicesFromCollection();
|
||||
check(servizi.length === 6, 'src/content/servizi', `attesi 6 servizi, trovati ${servizi.length}`);
|
||||
// almeno i 6 servizi del brief (§4.5): se ne possono aggiungere altri (docs/CONTENUTI.md)
|
||||
check(
|
||||
servizi.length >= 6,
|
||||
'src/content/servizi',
|
||||
`attesi almeno i 6 servizi del brief, trovati ${servizi.length}`,
|
||||
);
|
||||
// i sei servizi del brief (§4.5) con l'ancora del vecchio sito (§5.3): requisiti, non contenuti
|
||||
const SERVIZI_BRIEF = [
|
||||
['consulenza-fiscale-tributaria-e-societaria', 'consulenza-fiscale-tributaria-e-societaria-1'],
|
||||
['contabilita-fiscale', 'contabilita-fiscale-2'],
|
||||
['contenzioso-tributario', 'contenzioso-tributario-3'],
|
||||
['centro-autorizzato-caf', 'centro-autorizzato-caf-4'],
|
||||
['servizi-imprese-dipendenti-pensionati', 'servizi-alle-imprese-dipendenti-e-pensionati-5'],
|
||||
['certificazione-atti-firma-digitale', 'certificazione-atti-mediante-firma-digitale-6'],
|
||||
];
|
||||
for (const [slug, anchor] of SERVIZI_BRIEF) {
|
||||
check(
|
||||
servizi.some((s) => s.slug === slug && s.anchor === anchor),
|
||||
'src/content/servizi',
|
||||
`manca il servizio del brief /servizi/${slug}/ con anchorLegacy «${anchor}» (link del vecchio sito)`,
|
||||
);
|
||||
}
|
||||
for (const [key, label] of [
|
||||
['slug', 'slug'],
|
||||
['anchor', 'anchorLegacy'],
|
||||
]) {
|
||||
const values = servizi.map((s) => s[key]);
|
||||
const repeated = [...new Set(values.filter((v, i) => values.indexOf(v) !== i))];
|
||||
check(repeated.length === 0, 'src/content/servizi', `${label} ripetuti: ${repeated.join(', ')}`);
|
||||
}
|
||||
const hub = byPath.get('/servizi/');
|
||||
const home = byPath.get('/');
|
||||
for (const s of servizi) {
|
||||
@@ -619,11 +753,13 @@ if (contatti) {
|
||||
contatti.file,
|
||||
'campo honeypot assente o raggiungibile da tastiera',
|
||||
);
|
||||
check(
|
||||
all(contatti.doc, (n) => n.name === 'input' && attr(n, 'name') === 'ts').length === 1,
|
||||
contatti.file,
|
||||
'campo ts assente',
|
||||
);
|
||||
for (const name of ['ts', 'ts_invio']) {
|
||||
check(
|
||||
all(contatti.doc, (n) => n.name === 'input' && attr(n, 'name') === name).length === 1,
|
||||
contatti.file,
|
||||
`campo ${name} assente`,
|
||||
);
|
||||
}
|
||||
const privacy = all(
|
||||
contatti.doc,
|
||||
(n) =>
|
||||
@@ -633,6 +769,22 @@ if (contatti) {
|
||||
}
|
||||
}
|
||||
|
||||
// gestore PHP del modulo: nel sito solo con contactForm.mode = 'php' (docs/DEPLOY.md, sezione 6)
|
||||
const phpHandler = existsSync(join(dist, 'contact.php'));
|
||||
if (contactForm.mode === 'php') {
|
||||
check(
|
||||
phpHandler,
|
||||
'dist/contact.php',
|
||||
'contactForm.mode = "php" ma contact.php manca: copiare deploy/optional-php-form/contact.php in public/',
|
||||
);
|
||||
} else {
|
||||
check(
|
||||
!phpHandler,
|
||||
'dist/contact.php',
|
||||
`contact.php pubblicato con contactForm.mode = "${contactForm.mode}": toglierlo da public/ (la privacy policy non lo descrive)`,
|
||||
);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ asset */
|
||||
|
||||
const astroDir = join(dist, '_astro');
|
||||
@@ -647,6 +799,7 @@ check(
|
||||
);
|
||||
for (const f of assets.filter((x) => /\.(js|css)$/.test(x))) {
|
||||
const src = readFileSync(join(astroDir, f), 'utf8');
|
||||
if (f.endsWith('.css')) for (const issue of cssIssues(src)) fail(`dist/_astro/${f}`, issue);
|
||||
for (const re of FORBIDDEN_REFS)
|
||||
check(
|
||||
!re.test(src),
|
||||
@@ -692,22 +845,50 @@ check(
|
||||
const htaccess = existsSync(join(dist, '.htaccess'))
|
||||
? readFileSync(join(dist, '.htaccess'), 'utf8')
|
||||
: '';
|
||||
// direttive cercate solo su righe attive (non commentate)
|
||||
for (const [re, what] of [
|
||||
[/ErrorDocument 404 \/404\.html/, 'ErrorDocument 404 /404.html'],
|
||||
[/^\s*ErrorDocument 404 \/404\.html\s*$/m, 'ErrorDocument 404 /404.html'],
|
||||
[
|
||||
/RedirectMatch 301 \^\/privacy\/\?\$ \/privacy-policy\//,
|
||||
/^\s*RedirectMatch 301 \^\/privacy\/\?\$ \/privacy-policy\/\s*$/m,
|
||||
'redirect /privacy → /privacy-policy/',
|
||||
],
|
||||
[/X-Content-Type-Options "nosniff"/, 'X-Content-Type-Options'],
|
||||
[/Referrer-Policy "strict-origin-when-cross-origin"/, 'Referrer-Policy'],
|
||||
[/Permissions-Policy/, 'Permissions-Policy'],
|
||||
[/X-Frame-Options "SAMEORIGIN"/, 'X-Frame-Options'],
|
||||
[/#\s*Header always set Strict-Transport-Security/, 'HSTS presente ma commentato'],
|
||||
[/\\\.map\$/, 'blocco dei file .map'],
|
||||
[/^\s*Header always set X-Content-Type-Options "nosniff"\s*$/m, 'X-Content-Type-Options'],
|
||||
[
|
||||
/^\s*Header always set Referrer-Policy "strict-origin-when-cross-origin"\s*$/m,
|
||||
'Referrer-Policy',
|
||||
],
|
||||
[/^\s*Header always set Permissions-Policy "[^"]+"\s*$/m, 'Permissions-Policy'],
|
||||
[/^\s*Header always set X-Frame-Options "SAMEORIGIN"\s*$/m, 'X-Frame-Options'],
|
||||
[/^\s*<FilesMatch "[^"]*\\\.map\$[^"]*">/m, 'blocco dei file .map'],
|
||||
]) {
|
||||
check(re.test(htaccess), 'dist/.htaccess', `manca: ${what}`);
|
||||
}
|
||||
|
||||
// HSTS: commentato finché HTTPS non è verificato su tutto il dominio. Per attivarlo decommentare
|
||||
// la riga in public/.htaccess E impostare qui HSTS_ATTIVO = true (docs/DEPLOY.md, sezione 2).
|
||||
const HSTS_ATTIVO = false;
|
||||
const hsts = /^\s*Header always set Strict-Transport-Security "max-age=(\d+)[^"]*"\s*$/m.exec(
|
||||
htaccess,
|
||||
);
|
||||
if (HSTS_ATTIVO) {
|
||||
check(
|
||||
Boolean(hsts) && Number(hsts[1]) >= 31536000,
|
||||
'dist/.htaccess',
|
||||
'HSTS_ATTIVO = true ma Strict-Transport-Security non è attivo (max-age di almeno un anno)',
|
||||
);
|
||||
} else {
|
||||
check(
|
||||
/^\s*#\s*Header always set Strict-Transport-Security/m.test(htaccess),
|
||||
'dist/.htaccess',
|
||||
'manca la riga di HSTS (commentata)',
|
||||
);
|
||||
check(
|
||||
!/^\s*Header always set Strict-Transport-Security/m.test(htaccess),
|
||||
'dist/.htaccess',
|
||||
'HSTS attivo: se HTTPS è verificato su tutto il dominio impostare HSTS_ATTIVO = true in scripts/check-compliance.mjs',
|
||||
);
|
||||
}
|
||||
|
||||
// Content-Security-Policy di §9.4, confrontata per direttive. Con il modulo esterno
|
||||
// (`contactForm.mode = 'endpoint'`) form-action deve ammettere anche l'origine del fornitore.
|
||||
const EXPECTED_CSP = {
|
||||
|
||||
Reference in new issue
Block a user