# Quality checks

`composer check` is the gate before any work is called done. It runs Pint, Larastan, Rector, the Pest suite in
parallel, the SaaS edition's suite (`composer test:saas`, [The SaaS edition](saas.md)), type coverage, the **accessibility check** and the Composer and npm audits.

## Accessibility (`composer a11y`)

`scripts/quality/a11y.mjs` runs [axe-core](https://github.com/dequelabs/axe-core) through Playwright with the
WCAG 2.1 A and AA rules (PLAN › EAA, DESIGN.md §12). It visits the storefront's page types (home in both languages,
a category, a product, a brand, search, the store locator and a store page) and the admin sign-in, at desktop and
phone width. Products, categories, brands and stores are taken from the sitemaps, so no slug is assumed. Any
violation fails the check and is listed with the elements involved.

It checks the shop at `APP_URL` (read from `.env`, that key only) or at `QUALITY_URL`, so the shop must be running
there with some catalogue data (`php artisan db:seed` gives the demo catalogue). It uses the Chrome installed on the
machine; Playwright's own Chromium is used only when Chrome is missing (`npx playwright install chromium`).

## Core Web Vitals (`composer lighthouse`)

`scripts/quality/lighthouse.mjs` runs Lighthouse's mobile profile (a mid-range phone on a throttled network) three
times on the home page, a category, a product and the store locator, and judges the median run against the budget
in PLAN › Core Web Vitals:

| Metric | Budget |
|---|---|
| Largest Contentful Paint | ≤ 2.5 s |
| Cumulative Layout Shift | ≤ 0.1 |
| Total Blocking Time (lab stand-in for INP) | ≤ 200 ms |
| Lighthouse scores | performance ≥ 90, accessibility ≥ 95, best practices ≥ 90, SEO ≥ 95 |

It measures built assets: stop the Vite dev server (`npm run dev`, which writes `public/hot`) and run
`npm run build` first; the script refuses to run while `public/hot` exists (`QUALITY_ALLOW_DEV=1` overrides, for a
rough look only). It is not part of `composer check` because it takes a few minutes; run it before a release and
for the phase gates. A local server that does not compress responses makes the results pessimistic: production
nginx serves the storefront's HTML and CSS gzipped.

What keeps the storefront inside the budget is described in [Storefront › Page speed](storefront.md#theme).

## Phase gates

`tests/Feature/Gate/` holds the phase gates that can run as tests. `PhaseTwoRehearsalTest` takes one order through
the whole Phase 2 journey with the demo payment and courier drivers: a goods receipt, a card payment, an AWB tracked
to delivered, a withdrawal from the order page, the goods received back into stock, the card refunded, and the profit
ledger rows for each step. The real gate repeats it on the providers' sandboxes.

## npm audit

`composer npm-audit` (in `composer check`) runs `scripts/quality/npm-audit.mjs`: it fails on any advisory of moderate
severity or above except those listed as reviewed in the script, each with its reason and a date after which it fails
again. Today: GHSA-fc5q-39xc-vjpf (picomatch ReDoS, no fixed version released; used only by the build tooling).
